@@ -119,8 +119,8 @@ class SimControls:
119
119
"""Integral of the rpy error."""
120
120
pos_err_i : Array # (N, M, 3)
121
121
"""Integral of the position error."""
122
- last_rpy : Array # (N, M, 3)
123
- """Last rpy for 'xyz' euler angles .
122
+ prev_ang_vel : Array # (N, M, 3)
123
+ """Aangular velocity from the last controller step .
124
124
125
125
Required to compute the integral term in the attitude controller.
126
126
"""
@@ -144,58 +144,123 @@ def create(
144
144
staged_attitude = jnp .zeros ((n_worlds , n_drones , 4 ), device = device ),
145
145
attitude_steps = - jnp .ones ((n_worlds , 1 ), dtype = jnp .int32 , device = device ),
146
146
attitude_freq = attitude_freq ,
147
- thrust = jnp .zeros ((n_worlds , n_drones , 4 ), device = device ),
147
+ thrust = jnp .ones ((n_worlds , n_drones , 4 ), device = device )
148
+ * 0.08 , # TODO remove and rather make floor solid!
148
149
thrust_steps = - jnp .ones ((n_worlds , 1 ), dtype = jnp .int32 , device = device ),
149
150
thrust_freq = thrust_freq ,
150
151
rpms = jnp .zeros ((n_worlds , n_drones , 4 ), device = device ),
151
152
rpy_err_i = jnp .zeros ((n_worlds , n_drones , 3 ), device = device ),
152
153
pos_err_i = jnp .zeros ((n_worlds , n_drones , 3 ), device = device ),
153
- last_rpy = jnp .zeros ((n_worlds , n_drones , 3 ), device = device ),
154
+ prev_ang_vel = jnp .zeros ((n_worlds , n_drones , 3 ), device = device ),
154
155
)
155
156
156
157
157
158
@dataclass
158
159
class SimParams :
159
- mass : Array # (N, M, 1)
160
+ # Variable params (for domain randomization) => (N, M, shape)
161
+ MASS : Array # (N, M, 1)
160
162
"""Mass of the drone."""
161
163
J : Array # (N, M, 3, 3)
162
164
"""Inertia matrix of the drone."""
163
165
J_INV : Array # (N, M, 3, 3)
164
166
"""Inverse of the inertia matrix of the drone."""
167
+ L : Array # (N, M, 1)
168
+ """Arm length of the drone, aka distance of the motors from the center of mass."""
165
169
166
- # TODO: Remove duplicate definition of constants. Move into constants from lsy_models
167
- THRUST_TAU : float = field (pytree_node = False )
168
- SIGN_MATRIX : NDArray = field (pytree_node = False )
169
- L : float = field (pytree_node = False )
170
- KF : float = field (pytree_node = False )
171
- KM : float = field (pytree_node = False )
172
- GRAVITY_VEC : NDArray = field (pytree_node = False )
173
- MASS : float = field (pytree_node = False )
174
- J_inv : NDArray = field (pytree_node = False )
170
+ # TODO maybe params, maybe constants?
171
+ KF : float = field (pytree_node = False ) # (N, M, 1)
172
+ """RPM squared to Force factor."""
173
+ KM : float = field (pytree_node = False ) # (N, M, 1)
174
+ """RPM squared to Torque factor."""
175
+ THRUST_MIN : float = field (pytree_node = False ) # (N, M, 1)
176
+ """Min thrust per motor."""
177
+ THRUST_MAX : float = field (pytree_node = False ) # (N, M, 1)
178
+ """Max thrust per motor."""
179
+ THRUST_TAU : float = field (pytree_node = False ) # (N, M, 1)
180
+ # TODO maybe N, M, 4, for each of the motors individually
181
+ """Time constant for the thrust dynamics."""
182
+
183
+ # Constants
184
+ GRAVITY_VEC : Array = field (pytree_node = False )
185
+ # MIX_MATRIX: Array = field(pytree_node=False) # TODO not needed? => remove
186
+ SIGN_MATRIX : Array = field (pytree_node = False )
187
+ PWM_MIN : float = field (pytree_node = False )
188
+ PWM_MAX : float = field (pytree_node = False )
189
+
190
+ # System Identification (SI) parameters
191
+ SI_ROLL : Array = field (pytree_node = False )
192
+ SI_PITCH : Array = field (pytree_node = False )
193
+ SI_YAW : Array = field (pytree_node = False )
194
+ SI_PARAMS : Array = field (pytree_node = False )
195
+ SI_ACC : Array = field (pytree_node = False )
196
+
197
+ # System Identification parameters for the double integrator (DI) model
198
+ DI_ROLL : Array = field (pytree_node = False )
199
+ DI_PITCH : Array = field (pytree_node = False )
200
+ DI_YAW : Array = field (pytree_node = False )
201
+ DI_PARAMS : Array = field (pytree_node = False )
202
+ DI_ACC : Array = field (pytree_node = False )
175
203
176
204
@staticmethod
177
205
def create (
178
- n_worlds : int , n_drones : int , mass : float , J : Array , J_INV : Array , device : Device
206
+ n_worlds : int ,
207
+ n_drones : int ,
208
+ mass : float ,
209
+ J : Array ,
210
+ device : Device ,
211
+ L : float | None = None ,
212
+ KF : float | None = None ,
213
+ KM : float | None = None ,
214
+ THRUST_MIN : float | None = None ,
215
+ THRUST_MAX : float | None = None ,
216
+ THRUST_TAU : float | None = None ,
179
217
) -> SimParams :
180
218
"""Create a default set of parameters for the simulation."""
181
- mass = jnp .ones ((n_worlds , n_drones , 1 ), device = device ) * mass
182
- j , j_inv = jnp .array (J , device = device ), jnp .array (J_INV , device = device )
219
+ MASS = jnp .ones ((n_worlds , n_drones , 1 ), device = device ) * mass
220
+ j = jnp .array (J , device = device )
221
+ j_inv = jnp .linalg .inv (j )
183
222
J = jnp .tile (j [None , None , :, :], (n_worlds , n_drones , 1 , 1 ))
184
223
J_INV = jnp .tile (j_inv [None , None , :, :], (n_worlds , n_drones , 1 , 1 ))
224
+
185
225
constants = Constants .from_config ("cf2x_L250" )
186
226
227
+ if L is None :
228
+ L = constants .L
229
+ if KF is None :
230
+ KF = constants .KF
231
+ if KM is None :
232
+ KM = constants .KM
233
+ if THRUST_MIN is None :
234
+ THRUST_MIN = constants .THRUST_MIN
235
+ if THRUST_MAX is None :
236
+ THRUST_MAX = constants .THRUST_MAX
237
+ if THRUST_TAU is None :
238
+ THRUST_TAU = constants .THRUST_TAU
239
+
187
240
return SimParams (
188
- mass = mass ,
189
- J = constants . J ,
241
+ MASS = MASS ,
242
+ J = J ,
190
243
J_INV = J_INV ,
191
- THRUST_TAU = constants .THRUST_TAU ,
192
- SIGN_MATRIX = constants .SIGN_MATRIX ,
193
- L = constants .L ,
194
- KF = constants .KF ,
195
- KM = constants .KM ,
244
+ L = L ,
245
+ KF = KF ,
246
+ KM = KM ,
247
+ THRUST_MIN = THRUST_MIN ,
248
+ THRUST_MAX = THRUST_MAX ,
249
+ THRUST_TAU = THRUST_TAU * 1 , # TODO remove
196
250
GRAVITY_VEC = constants .GRAVITY_VEC ,
197
- MASS = constants .MASS ,
198
- J_inv = constants .J_inv ,
251
+ SIGN_MATRIX = constants .SIGN_MATRIX ,
252
+ PWM_MIN = constants .PWM_MIN ,
253
+ PWM_MAX = constants .PWM_MAX ,
254
+ SI_ROLL = constants .SI_ROLL ,
255
+ SI_PITCH = constants .SI_PITCH ,
256
+ SI_YAW = constants .SI_YAW ,
257
+ SI_PARAMS = constants .SI_PARAMS ,
258
+ SI_ACC = constants .SI_ACC ,
259
+ DI_ROLL = constants .DI_ROLL ,
260
+ DI_PITCH = constants .DI_PITCH ,
261
+ DI_YAW = constants .DI_YAW ,
262
+ DI_PARAMS = constants .DI_PARAMS ,
263
+ DI_ACC = constants .DI_ACC ,
199
264
)
200
265
201
266
0 commit comments