reaction_wheels
cosmic_warp.actuators.reaction_wheels
Reaction wheel models for spacecraft attitude control.
Supports up to 4 wheels per body with arbitrary spin axes (e.g. 3 orthogonal wheels or a 4-wheel pyramid), with: - Momentum storage and hardware saturation (max_momentum) - Torque limits - Wheel momentum tracking (speed = momentum / wheel_inertia)
ReactionWheelConfig
Configuration for reaction wheel assembly.
Supports up to 4 reaction wheels with individual spin axes.
ReactionWheelManager
ReactionWheelManager(
num_envs: int,
device: str = "cuda",
num_bodies: int = 1,
actuator_states: array = None,
)
Manages reaction wheel configurations and states for parallel entities (envs * bodies).
Initialize reaction wheel manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_envs
|
int
|
Number of parallel environments |
required |
device
|
str
|
Compute device |
'cuda'
|
num_bodies
|
int
|
Number of bodies per environment |
1
|
actuator_states
|
array
|
The simulator's ActuatorState array, so a new max_momentum can be checked against the stored wheel momenta (None: no check) |
None
|
Source code in cosmic_warp/actuators/reaction_wheels.py
set_config
set_config(
*,
max_torque: float = None,
max_momentum: float = None,
wheel_inertia: float = None,
viscous_damping: float = None,
spin_axes: list = None,
env_ids: list = None,
body_ids: list = None,
entity_ids: list = None,
) -> None
Set RW configuration for all entities or a subset.
Only the fields given are checked and written; None leaves a field unchanged for the selected entities. A new simulator starts with max_torque 0.1, max_momentum 0 (no limit), wheel_inertia 0.01, no damping and three orthogonal wheels (DEFAULT_SPIN_AXES).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_torque
|
float
|
Maximum torque per wheel [N*m], >= 0 |
None
|
max_momentum
|
float
|
Momentum capacity per wheel [kg*m^2/s], >= 0; the wheel saturates (absorbs no further momentum) at this value. 0 disables the limit. A positive value below a selected wheel's stored momentum is rejected (the next step would dump the excess into the body at once). |
None
|
wheel_inertia
|
float
|
Wheel moment of inertia [kg*m^2], > 0 |
None
|
viscous_damping
|
float
|
Viscous friction coefficient [Nms/rad], >= 0 |
None
|
spin_axes
|
list
|
List of (x, y, z) tuples for each wheel's spin axis (max 4), normalized here; (0, 0, 0) leaves the wheel unused |
None
|
env_ids
|
list
|
List of environment indices to configure (None = all) |
None
|
body_ids
|
list
|
List of body indices to configure (None = all bodies) |
None
|
entity_ids
|
list
|
Optional flat entity indices (env_id * num_bodies + body_id) |
None
|
Source code in cosmic_warp/actuators/reaction_wheels.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
relaxation_factor
(1 - exp(-x)) / x for x >= 0, which tends to 1 as x -> 0.
The direct form loses all precision for small x (1 - exp(-x) cancels) and Warp has no expm1, so small x uses Kahan's expm1 form (1 - u) / -log(u), u = exp(-x) rounded, accurate to a few ulps.
Source code in cosmic_warp/actuators/reaction_wheels.py
compute_rw_angular_momentum
compute_rw_angular_momentum(
config: ReactionWheelConfig,
cmd: ActuatorCommand,
actuator_state: ActuatorState,
wheel_index: int,
dt: float64,
) -> float64
Update reaction wheel angular momentum using analytical solution.
For the dynamics: J * ω̇ = τ_cmd - b*ω
The exact analytical solution is: ω(t) = ω₀ * exp(-b/J * t) + (τ_cmd/b) * (1 - exp(-b/J * t))
This is more accurate than Euler integration, especially for larger time steps or higher damping coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
ReactionWheelConfig
|
RW configuration |
required |
cmd
|
ActuatorCommand
|
Actuator command (vec4 with torques for all wheels) |
required |
actuator_state
|
ActuatorState
|
Actuator state (current wheel angular momenta) |
required |
wheel_index
|
int
|
Index of the wheel (0-3) |
required |
dt
|
float64
|
Time step [s] |
required |
Returns:
| Type | Description |
|---|---|
float64
|
New wheel angular momentum (scalar) [kg*m^2/s] |