|
bitsim
Model, simulate, estimate and control robots in C++
|
The QuadrotorDynamics class. Implements quadrotor dynamics The implementation of this class follows the System Modeling section at https://wilselby.com/research/arducopter/modeling/ and https://scholarsarchive.byu.edu/cgi/viewcontent.cgi?article=2324&context=facpub The quadrotor is assumed to have four rotors Each rotor consists of a brushless DC motor and rotor with a fixed pitch. It is assumed that the quadrotor can move in 6 degrees of freedom; 3-translational and 3-rotational, The motion of the quadrotor is controlled via 4 inputs namely the speeds of the 4 motors. The quadrotor model that this class implements assumes the following: More...
#include <quadrotor_dynamics.h>


Public Types | |
| using | base_type = MotionModelDynamicsBase<SysState<12>, DynamicsMatrixDescriptor, RealVec> |
| using | state_type = base_type::state_type |
| The type of the state handled by this dynamics object. | |
| using | input_type = base_type::input_type |
| input_t The type of the input for solving the dynamics | |
| using | matrix_type = base_type::matrix_type |
| matrix_t Matrix type that describes the dynamics | |
| using | vector_type = base_type::vector_type |
| vector_t | |
| Public Types inherited from bitsim::dynamics::MotionModelDynamicsBase< SysState< 12 >, DynamicsMatrixDescriptor, RealVec > | |
| using | state_type |
| using | output_type |
| using | input_type |
| using | matrix_descriptor_type |
| using | matrix_type |
| using | vector_type |
Public Member Functions | |
| QuadrotorDynamics (QuadrotorDynamicsConfig config, SysState< 12 > &state) | |
| QuadrotorDynamics Constructor. Specify the configuration parameters of the simulated quadrotor. It is assumed that the mass of the quadrotor remains fixed and the system state to be tracked. | |
| virtual state_type & | evaluate (const input_type &input) override |
| Evaluate the new state using the given input it also updates the various matrices if needed. | |
| void | integrate (const RealVec &motor_w) |
| Integrate the new state. It also uses error terms. | |
| void | translational_dynamics (const RealVec &motor_w) |
| Implements the translational dynamics. It accepts the motors angular velocities. Notice that this model will squared and input velocities. | |
| void | rotational_dynamics (const RealVec &motor_w) |
| Implements the translational dynamics. It accepts the motors angular velocities. Notice that this model will squared and input velocities. | |
| RealColVec3d | get_position () const |
| Returns the current position in the NED world frame. The height above the start is -z. | |
| RealColVec3d | get_velocity () const |
| Returns the current linear velocity (body frame). | |
| RealColVec3d | get_angular_velocity () const |
| Returns the current angular velocity (body frame). | |
| RealColVec3d | get_euler_angles () const |
| Returns the Euler angles (0: phi, 1: theta, 2:psi). | |
| real_t | phi () const noexcept |
| The phi Euler angle in rad. | |
| real_t | theta () const noexcept |
| The theta Euler angle in rad. | |
| real_t | psi () const noexcept |
| The psi Euler angle in rad. | |
| Public Member Functions inherited from bitsim::dynamics::MotionModelDynamicsBase< SysState< 12 >, DynamicsMatrixDescriptor, RealVec > | |
| virtual | ~MotionModelDynamicsBase ()=default |
| Destructor. | |
| virtual state_type & | evaluate (const input_type &input)=0 |
| Updates and returns the value of the state given the input. | |
| const state_type & | get_state () const |
| Read access to the state. | |
| state_type & | get_state () |
| Read/write access to the state. | |
| std::vector< std::string_view > | get_state_variables_names () const |
| get_state_variables_names. Returns the name of the variables in the state | |
| matrix_type & | get_matrix (const std::string &name) |
| const matrix_type & | get_matrix (const std::string &name) const |
| void | set_matrix (const std::string &name, const matrix_type &mat) |
| vector_type & | get_vector (const std::string &name) |
| const vector_type & | get_vector (const std::string &name) const |
| void | set_vector (const std::string &name, const vector_type &vec) |
| void | set_matrix_update_flag (bool f) |
| set the matrix update flag | |
| bool | allows_matrix_updates () const |
| Set the flag for updating or not the matrices describing the model. | |
| bool | has_matrix (const std::string &name) const |
| Returns true if the matrix with the given name already exists. | |
| real_t | get_state_property (const std::string &name) const |
| Returns the state property with the given name. | |
| void | set_state_property (const std::string &name, real_t value) |
| Set the name-th value of the state. | |
| void | set_state_name_value (uint_t i, const std::string &name, real_t val) |
| Set the state names. | |
| void | set_state_name_value (uint_t i, const std::pair< std::string, real_t > &val) |
| Set the state names. | |
| void | set_time_step (real_t dt) |
| Set the time step. | |
| real_t | get_time_step () const |
| get_time_step Returns the sampling time the dynamics model is using | |
| real_t | get_tolerance () const |
| get_tolerance Returns the general tolerance used in the calculations | |
| void | set_tolerance (real_t tol) |
| set_tolerance Set the general tolerance used in the calculations. Default is KernelConsts::tolerance() | |
Additional Inherited Members | |
| Static Public Attributes inherited from bitsim::dynamics::MotionModelDynamicsBase< SysState< 12 >, DynamicsMatrixDescriptor, RealVec > | |
| static const uint_t | state_dimension |
| The dimension of the state. | |
| Protected Member Functions inherited from bitsim::dynamics::MotionModelDynamicsBase< SysState< 12 >, DynamicsMatrixDescriptor, RealVec > | |
| MotionModelDynamicsBase (bool update_description_matrices_on_evaluate=true) | |
| Constructor. | |
| MotionModelDynamicsBase (const state_type &init_state, bool update_description_matrices_on_evaluate=true) | |
| Constructor. | |
| Protected Attributes inherited from bitsim::dynamics::MotionModelDynamicsBase< SysState< 12 >, DynamicsMatrixDescriptor, RealVec > | |
| state_type | state_ |
| The object describing the state of the object of which its dynamics are described/modeled by this MotionModel. | |
| matrix_descriptor_type | matrix_description_ |
| matrix descriptor | |
| bool | update_description_matrices_on_evaluate_ |
| flag indicating the update of the matrices the model is using to describe itself | |
| real_t | dt_ |
| The time step the integrator uses. | |
| real_t | tol_ |
| tolerance | |
The QuadrotorDynamics class. Implements quadrotor dynamics The implementation of this class follows the System Modeling section at https://wilselby.com/research/arducopter/modeling/ and https://scholarsarchive.byu.edu/cgi/viewcontent.cgi?article=2324&context=facpub The quadrotor is assumed to have four rotors Each rotor consists of a brushless DC motor and rotor with a fixed pitch. It is assumed that the quadrotor can move in 6 degrees of freedom; 3-translational and 3-rotational, The motion of the quadrotor is controlled via 4 inputs namely the speeds of the 4 motors. The quadrotor model that this class implements assumes the following:
The class integrates the translational and rotational dynamics equations on the body frame.
Frames. The world frame is NED: x north, y east and z down, so a quadrotor that climbs has a decreasing z. The body frame has x forward, y to the right and z down. The state is the position (x, y, z) in the world, the velocity (u, v, w) and the angular velocity (p, q, r) in the body frame, and the Euler angles roll, pitch and yaw (phi, theta, psi): the body is turned from the world by \(R = R_z(\psi) R_y(\theta) R_x(\phi)\).
Rotors. The input is the speed of each rotor [rad/s], in a plus layout: rotor 1 in front (+x), 2 on the right (+y), 3 behind and 4 on the left, each at the arm length l from the centre. Rotor i pushes up, along -z, with a thrust \(k_1 \omega_i^2\), and rotors 1 and 3 spin the other way to 2 and 4, so their drag torques \(k_2 \omega_i^2\) cancel when the speeds are equal. The torques about x, y and z are
\[\tau_\phi = l k_1 (\omega_4^2 - \omega_2^2), \quad \tau_\theta = l k_1 (\omega_1^2 - \omega_3^2), \quad \tau_\psi = k_2 (\omega_1^2 - \omega_2^2 + \omega_3^2 - \omega_4^2) \]
so a faster left rotor rolls the quadrotor right, a faster front rotor pitches its nose up, and faster rotors 1 and 3 yaw it clockwise seen from above.
Equations. With the thrust \(T = k_1 \sum_i \omega_i^2\) and gravity in the body frame \(g_b = R^T (0, 0, g)\),
\[\dot v = -\omega \times v + g_b - \frac{1}{m} (0, 0, T), \qquad J \dot\omega = -\omega \times J \omega + \tau, \qquad \dot p = R v \]
and the Euler angles change with the usual matrix of \(\omega\), which is singular at a pitch of 90 degrees. integrate() takes one semi-implicit Euler step of dt: the velocities first, then the angles and the position with the new velocities.
| using bitsim::dynamics::QuadrotorDynamics::base_type = MotionModelDynamicsBase<SysState<12>, DynamicsMatrixDescriptor, RealVec> |
input_t The type of the input for solving the dynamics
matrix_t Matrix type that describes the dynamics
The type of the state handled by this dynamics object.
vector_t
| bitsim::dynamics::QuadrotorDynamics::QuadrotorDynamics | ( | QuadrotorDynamicsConfig | config, |
| SysState< 12 > & | state ) |
QuadrotorDynamics Constructor. Specify the configuration parameters of the simulated quadrotor. It is assumed that the mass of the quadrotor remains fixed and the system state to be tracked.
|
overridevirtual |
Evaluate the new state using the given input it also updates the various matrices if needed.
|
inline |
Returns the current angular velocity (body frame).
|
inline |
Returns the Euler angles (0: phi, 1: theta, 2:psi).
|
inline |
Returns the current position in the NED world frame. The height above the start is -z.
|
inline |
Returns the current linear velocity (body frame).
| void bitsim::dynamics::QuadrotorDynamics::integrate | ( | const RealVec & | motor_w | ) |
Integrate the new state. It also uses error terms.
|
inlinenoexcept |
The phi Euler angle in rad.
|
inlinenoexcept |
The psi Euler angle in rad.
| void bitsim::dynamics::QuadrotorDynamics::rotational_dynamics | ( | const RealVec & | motor_w | ) |
Implements the translational dynamics. It accepts the motors angular velocities. Notice that this model will squared and input velocities.
|
inlinenoexcept |
The theta Euler angle in rad.
| void bitsim::dynamics::QuadrotorDynamics::translational_dynamics | ( | const RealVec & | motor_w | ) |
Implements the translational dynamics. It accepts the motors angular velocities. Notice that this model will squared and input velocities.