Rigid Body Simulation
A rigid-body helicopter simulated from Newton-Euler dynamics, its rotors generating lift and torque, integrated forward with the Euler method.
╌╌╌╌
A rigid-bodyhelicopter simulated in C++ from its rotational dynamics. Rotor blades generate lift and thrust; the body's state — position, orientation, and their velocities — advances by numerically integrating the Newton-Euler equations of motion with the Euler method.
Unlike a point mass, a rigid body has orientation and spins, so its state carries a position and linear velocity for the center of mass, plus an orientation (a rotation ) and an angular velocity . Linear motion follows Newton's second law; rotation follows Euler's equation, coupling angular acceleration to torque through the inertia tensor :
The term is the gyroscopic coupling; without it a tumbling body would not precess.
A rotor spinning at angular speed generates a thrust along its axis roughly proportional to the square of its speed, . Summed, the thrusts lift the craft; differences between them produce a net torque about the center of mass, which is what tilts and yaws it. Both feed the equations above.
Steering comes from differential thrust. With the rotors laid out around the body, the three attitude moments come from spinning them unequally. Speeding up the rotors on one side and slowing the other tilts the thrust asymmetry into a roll about the forward axis; doing the same front-to-back produces pitch. Yaw is subtler: each rotor also drags against the air with a reaction torque opposite its spin, so running the clockwise rotors faster than the counter-clockwise ones leaves a net twist about the vertical axis without changing total lift. A controller therefore never commands torque directly — it solves for the four rotor speeds whose combined thrust and reaction torque hit a desired total lift and , the inverse of the map above. The simulation stub closes that loop each frame: read the current state, compare it to the target attitude, set rotor speeds, integrate, repeat.
- 1state: position , velocity , rotation , angular velocity
- 2repeat each frame
- 3read the target attitude from input
- 4set each rotor speed from the controller (differential thrust)
- 5thrust of rotor at body offset
- 6
- 7draw the craft from
- 8until the window closes
The coupled nonlinear system has no closed form, so the simulator steps it forward with semi-implicit Euler at a fixed timestep , taking velocities first and then positions from the new velocities:
- 1input: timestep , rotor forces at offsets
- 2;
- 3
- 4
- 5
- 6
The orientation update comes from , where is the skew-symmetric cross-product matrix; a Euler step drifts off the rotation group, so it is re-orthonormalized each frame. Updating velocity before position, rather than after, keeps the integrator stable at the timesteps a real-time simulation can afford, whereas explicit Euler gains energy and diverges.
References
- Project repository
- Reference notes: Linear Algebra
╌╌ END ╌╌