1
1
import gymnasium
2
2
import numpy as np
3
3
from gymnasium .wrappers .vector import JaxToNumpy # , JaxToTorch
4
- from ml_collections import config_dict
5
- from scipy .interpolate import splev
6
4
7
- from crazyflow .control import Control
8
5
from crazyflow .gymnasium_envs import CrazyflowRL # noqa: F401
9
- from crazyflow .sim . physics import Physics
6
+ from crazyflow .utils import enable_cache
10
7
11
8
12
9
def main ():
13
- # set config for simulation
14
- sim_config = config_dict .ConfigDict ()
15
- sim_config .device = "cpu"
16
- sim_config .physics = Physics .sys_id
17
- sim_config .control = Control .attitude
18
- sim_config .attitude_freq = 50
19
- sim_config .n_drones = 1
20
- sim_config .n_worlds = 20
21
-
10
+ enable_cache ()
22
11
SEED = 42
23
-
24
12
# Create environment that contains a figure eight trajectory. You can parametrize the
25
13
# observation space, i.e., which part of the trajectory is contained in the observation. Please
26
14
# refer to the documentation of the environment for more information.
27
15
envs = gymnasium .make_vec (
28
16
"DroneFigureEightTrajectory-v0" ,
29
- n_trajectory_sample_points = 10 ,
30
- dt_trajectory_sample_points = 0.1 ,
17
+ num_envs = 20 ,
18
+ freq = 50 ,
19
+ n_samples = 10 ,
20
+ samples_dt = 0.1 ,
31
21
trajectory_time = 10.0 ,
32
- render_trajectory_sample = True , # useful for debug purposes
33
- time_horizon_in_seconds = 10.0 ,
34
- num_envs = sim_config .n_worlds ,
35
- ** sim_config ,
22
+ render_samples = True ,
36
23
)
37
24
38
25
# RL wrapper to clip the actions to [-1, 1] and rescale them for use with common DRL libraries.
@@ -43,19 +30,12 @@ def main():
43
30
envs = JaxToNumpy (envs )
44
31
45
32
# dummy action for going up (in attitude control)
46
- action = np .zeros ((sim_config . n_worlds * sim_config . n_drones , 4 ), dtype = np .float32 )
47
- action [..., 0 ] = 0.34
33
+ action = np .zeros ((20 , 4 ), dtype = np .float32 )
34
+ action [..., 0 ] = 0.31
48
35
49
36
obs , info = envs .reset (seed = SEED )
50
-
51
- # The trajectory is defined as a scipy spline. Its parameter can be retrieved using
52
- # `envs.unwrapped.tck`. The spline can be reconstructed using scipy's splev.
53
- spline_params = envs .unwrapped .tck
54
- tau = envs .unwrapped .tau # 1D parameters of the spline for the current timestep, in [0,1]
55
- value = splev (tau , spline_params ) # noqa: F841, used for demonstration purposes
56
-
57
37
# Step through the environment
58
- for _ in range (1500 ):
38
+ for _ in range (500 ):
59
39
observation , reward , terminated , truncated , info = envs .step (action )
60
40
envs .render ()
61
41
0 commit comments