Arbitrary motor count - #114
Lagnesh2003 wants to merge 4 commits into
Conversation
Derive motor count from mixing_matrix.shape[-1] instead of hardcoding 4 in SimState/SimStateDeriv/SimControls buffers, rotor_vel_limits, and the Mellinger power-distribution stages.
|
Thanks for working on this. The change is a little more complex than just replacing the 4s with the last dim of the mixing matrix. We want to achieve a collective thrust and 3 torques with N rotors. This happens to have a unique solution in our current setup, but with more than 4 rotors, this requires some form of the inverse of the mixing matrix, e.g. the pseudo-inverse for a least-squares allocation. The Mellinger controller was not built to run this, so I would rather not add support for N rotors into it if the firmware cannot handle that case. PX4 on the other hand should be able to compute that, and I suspect we will find the pseudo-inverse in its controller code. So my feeling rn is we should wait until we have a JAX version of PX4 and then add support for arbitrary rotors. On the other hand, if there is a controller that can fly N rotors that is open-source and you want to contribute, that would be fine as well. Not sure if e.g. betaflight can take more than 4 rotors. |
|
Thanks for the explanation, that makes a lot of sense. I looked around a bit and couldn't find any existing JAX port of PX4, so that'd be starting from scratch rather than porting something that already exists — good to know before anyone commits to it. I'd like to split this into two parts if that works for you.
|
|
Sounds good, though it might be tricky if we assume that some drones only have abstracted models without mixing matrix. Btw, what's your motivation for working on this? Are you doing research in this area? |
Derive motor count from
mixing_matrix.shape[-1]instead of hardcoding 4, so the simulator is more generalized.Changes
SimState,SimStateDeriv,SimControls(crazyflow/sim/data.py): rotor buffers (rotor_vel,rotor_acc) are now sized byn_motors.Sim.init_dataandrotor_vel_limits(crazyflow/sim/sim.py):n_motorsis derived frommixing_matrix.shape[-1]and threaded through; thrust limits scale withn_motorsinstead of4 *.rotor_vel_control(crazyflow/sim/functional.py): the per-motor shape assertion now reads the motor count offdata.states.rotor_velinstead of asserting a fixed 4.action_space(crazyflow/envs/drone_env.py): attitude-mode thrust bounds now scale withn_motorsinstead of* 4.crazyflow/control/mellinger/control.py):force_torque2rotor_veland_attitude2force_torquedivide bymixing_matrix.shape[-1]instead of4;state2attitudenow takesmixing_matrixas a keyword-only parameter (auto-bound viaload_params/parametrize) instead of hardcoding* 4.tests/unit/test_arbitrary_motor_count.py: 6 regression tests exercising every changed function directly with a synthetic 6-motormixing_matrix/SimData, without registering a full hexacopter drone. Verified each test fails against the pre-fix code and passes against the fix.Fixes #104
Test plan
pytest -v tests— 656 passed (650 existing + 6 new)pytest --markdown-docs ...(doctests/docs examples) — 101 passedruff check crazyflow/ tests/— clean