multirotor.simulation¶
Module Contents¶
Classes¶
Models the thrust and aerodynamics of the propeller blades spinning at a |
|
Models the electronic and mechanical characterists of the rotation of the |
|
Models the state of charge of the battery of the Multirotor. |
|
The multirotor class models dynamics and control allocation of a vehicle. |
- class multirotor.simulation.Propeller(params: multirotor.vehicle.PropellerParams, simulation: multirotor.vehicle.SimulationParams)¶
Models the thrust and aerodynamics of the propeller blades spinning at a certain rate.
- property state: float¶
- property rpm: float¶
- speed: float = 0.0¶
Radians per second
- reset()¶
- apply_speed(u: float, **kwargs) float¶
Calculate the actual speed of the propeller after the speed signal is given. This method is pure and does not change the state of the propeller. It is used by the multirotor’s dxdt_* methods to calculate derivatives.
Parameters¶
- ufloat
Radians per second speed command
Returns¶
- float
The actual speed
- step(u: float, **kwargs) float¶
Step through the speed command. This method changes the state of the propeller.
Parameters¶
- ufloat
Speed command in radians per second.
Returns¶
- float
The actual speed achieved.
- _thrust_constant(speed, airstream_velocity: numpy.ndarray = np.zeros(3)) float¶
- _thrust_physics(speed, airstream_velocity: numpy.ndarray = np.zeros(3)) float¶
- class multirotor.simulation.Motor(params: multirotor.vehicle.MotorParams, simulation: multirotor.vehicle.SimulationParams)¶
Models the electronic and mechanical characterists of the rotation of the propeller shaft.
- speed: float = 0.0¶
Radians per second
- reset() float¶
- current_average(max_voltage: float) float¶
Average current consumption given the duty cycle of the speed controller. Duty cycle depends on max voltage which causes 100% duty cycle.
Parameters¶
- max_voltagefloat
The peak voltage corresponding to 100% duty cycle.
Returns¶
- float
Current consumption
- apply_speed(u: float, max_voltage: float = np.inf) float¶
Apply a voltage speed signal to the motor. This method is pure and doesn’t change the state of the motor.
Parameters¶
- ufloat
Voltage signal.
- max_voltagefloat, optional
The maximum voltage supply from power source. By default infinite.
Returns¶
- float
The speed of the motor (rad /s)
- step(u: float, max_voltage: float = np.inf) float¶
Apply a voltage speed signal to the motor. This method changes the state of the motor.
Parameters¶
- ufloat
Speed signal (rad/s).
- max_voltagefloat, optional
The maximum voltage supply from power source. By default infinite.
Returns¶
- float
The speed of the motor (rad /s)
- class multirotor.simulation.Battery(params: multirotor.vehicle.BatteryParams, simulation: multirotor.vehicle.SimulationParams)¶
Models the state of charge of the battery of the Multirotor.
- property state: float¶
- reset()¶
- step()¶
- class multirotor.simulation.Multirotor(params: multirotor.vehicle.VehicleParams, simulation: multirotor.vehicle.SimulationParams)¶
The multirotor class models dynamics and control allocation of a vehicle.
- property position¶
Position in the inertial frame.
- property velocity: numpy.ndarray¶
Body-frame velocity
- property inertial_velocity: numpy.ndarray¶
Velocity in the intertial frame.
- property acceleration: numpy.ndarray¶
Body-frame acceleration
- property inertial_acceleration: numpy.ndarray¶
Acceleration in the intertial frame.
- property orientation: numpy.ndarray¶
Euler rotations (roll, pitch, yaw)
- property angular_rate: numpy.ndarray¶
Angular rate of body frame axes (not same as rate of roll, pitch, yaw)
- property euler_rate: numpy.ndarray¶
Euler rate of vehicle d(roll, pitch, yaw)/dt
- property weight: float¶
- property current_average: float¶
Duty-cycle adjusted currrent draw from battery.
- property speeds: numpy.ndarray¶
- reset() numpy.ndarray¶
Reset the state of the vehicle. This includes resetting each propeller and re-calculating inertia and allocation matrices.
Can simulate dynamics with propellers with/out motors.
Returns¶
- np.ndarray
The state of the vehicle.
- get_forces_torques(speeds: numpy.ndarray, state: numpy.ndarray) Tuple[numpy.ndarray, numpy.ndarray]¶
Calculate the forces and torques acting on the vehicle’s center of gravity given its current state and speed of propellers.
Parameters¶
- speedsnp.ndarray
Propeller speeds (rad/s)
- statenp.ndarray
State of the vehicle (position, velocity, orientation, angular rate)
Returns¶
- Tuple[np.ndarray, np.ndarray]
The forces and torques acting on the body.
- dxdt_dynamics(t: float, x: numpy.ndarray, u: numpy.ndarray, params=None)¶
Calculate the rate of change of state given the dynamics (forces, torques) acting on the system.
Parameters¶
- tfloat
Time. Currently this function is time invariant.
- xnp.ndarray
State of the vehicle.
- unp.ndarray
A 6-vector of forces and torques.
Returns¶
- np.ndarray
The rate of change of state.
- dxdt_speeds(t: float, x: numpy.ndarray, u: numpy.ndarray, disturb_forces: numpy.ndarray = 0.0, disturb_torques: numpy.ndarray = 0.0, params=None)¶
Calculate the rate of change of state given the propeller speeds on the system (rad/s).
Parameters¶
- tfloat
Time. Currently this function is time invariant.
- xnp.ndarray
State of the vehicle.
- unp.ndarray
A p-vector of propeller speeds (rad/s), where p=number of propellers.
- disturb_forcesnp.ndarray, optional
Disturbinng x,y,z forces in the vehicle’s local frame, by default 0.
- disturb_torquesnp.ndarray, optional
Disturbing x,y,z torques in the vehicle’s local frame, by default 0.
Returns¶
- np.ndarray
The rate of change of state.
- step_dynamics(u: numpy.ndarray) numpy.ndarray¶
Given the 6-vector of x,y,z-forces and roll,pitch,yaw-torques, calculate the next state of the vehicle.
Parameters¶
- unp.ndarray
The 6-vector, where the first 3 elements are forces (N) and the next 3 elements are the torques (Nm)
Returns¶
- np.ndarray
The new state of the vehicle.
- step_speeds(u: numpy.ndarray, disturb_forces: numpy.ndarray = 0.0, disturb_torques: numpy.ndarray = 0.0) numpy.ndarray¶
Given the n-vector of propeller speed signals, calculate the next state of the vehicle. Where n is number of propellers.
Parameters¶
- unp.ndarray
The speed signals to be sent to each propeller’s step() method. Can be the actual speed (rad/s) or the voltage signal (V) if a motor is used and MotorParams.speed_voltage_scaling constant is set.
- disturb_forcesnp.ndarray, optional
Disturbinng x,y,z forces in the vehicle’s local frame, by default 0.
- disturb_torquesnp.ndarray, optional
Disturbing x,y,z torques in the vehicle’s local frame, by default 0.
Returns¶
- np.ndarray
The new state of the vehicle.
- allocate_control(thrust: float, torques: numpy.ndarray) numpy.ndarray¶
Allocate control to propellers by converting prescribed forces and torqes into propeller speeds. Uses the control allocation matrix.
Parameters¶
- thrustfloat
The thrust in the body z-direction.
- torquesnp.ndarray
The roll, pitch, yaw torques required about (x, y, z) axes.
Returns¶
- np.ndarray
The prescribed propeller speeds (rad /s)
- nonlinear_dynamics_controls_system(linearize: bool = False, perturbation: float = 0.1, about_state: numpy.ndarray = 0, about_action: numpy.ndarray = 0)¶
Create a system representation using the python controls library. The system takes net forces and torques as input.
Parameters¶
- linearizebool, optional
Whether to linearize the system about a state/action, by default False
- perturbationfloat, optional
The change in time to use to calculate dx/dt, by default 1e-1
- about_statenp.ndarray, optional
The state about which to linearize, by default 0
- about_actionnp.ndarray, optional
The action about which to linearize, by default 0
Returns¶
- Union[control.LinearIOSystem, control.NonlinearIOSystem]
The system object
- nonlinear_speeds_controls_system(linearize: bool = False, perturbation: float = 0.1, about_state: numpy.ndarray = 0, about_action: numpy.ndarray = 0)¶
Create a system representation using the python controls library. The system takes propeller speed signals as input.
Parameters¶
- linearizebool, optional
Whether to linearize the system about a state/action, by default False
- perturbationfloat, optional
The change in time to use to calculate dx/dt, by default 1e-1
- about_statenp.ndarray, optional
The state about which to linearize, by default 0
- about_actionnp.ndarray, optional
The action about which to linearize, by default 0
Returns¶
- Union[control.LinearIOSystem, control.NonlinearIOSystem]
The system object