Motors#

Description#

The Motors component is used to simulate a series of brushless electric motor driven propellers. The do not have a fuel requirement, but generate a net torque around their thrust axis.

More concisely, the Motors component is similar to the Boosters component, except with more linear dynamics and the ability to have reversed thrust. Similar to Boosters, the thrust generated depends on a ramp up time constant plus some noise:

  1. The actual duty cycle depends on the pwm command and the ramp up time constant, actual_duty_cycle += 1 / physics_hz / tau * (target_duty_cycle - actual_duty_cycle).

  2. The RPM of the motor then depends on the actual duty cycle plus some noise, rpm = (actual_duty_cycle * max_rpm) * (1 + noise * noise_ratio). noise is sampled from a standard Normal.

  3. Thrust and torque then depend on the RPM value and the propeller coefficients, thrust = thrust_coef * rpm and torque = torque_coef * rpm.

The motor additionally accepts a rotation matrix argument in physics_update. This allows the thrust of the motor to be redirected. Conveniently, the Gimbals component outputs this exact rotation matrix.

Class Description#

class PyFlyt.core.abstractions.motors.Motors(p: BulletClient, physics_period: float, np_random: Generator, uav_id: ndarray | int, motor_ids: ndarray | list[int], tau: ndarray, max_rpm: ndarray, thrust_coef: ndarray, torque_coef: ndarray, thrust_unit: ndarray, noise_ratio: ndarray)#

Simulates an array of brushless motor driven propellers.

The Motors component is used to simulate a series of brushless motor driven propellers at arbitrary locations of the drone. Counter rotating motors (producing reversed torque) can be represented using negative torque_coef values. The maximum RPM can be easily computed using max_rpm = max_thrust / thrust_coef.

Parameters:
  • p (bullet_client.BulletClient) – PyBullet physics client ID.

  • physics_period (float) – physics period of the simulation.

  • np_random (np.random.Generator) – random number generator of the simulation.

  • uav_id (int) – ID of the drone.

  • motor_ids (list[int]) – a (n,) list of integers representing the link IDs for n motors.

  • tau (np.ndarray) – an (n,) of floats array representing the ramp time constant of each motor.

  • max_rpm (np.ndarray) – an (n,) array of floats representing the maximum RPM of each motor.

  • thrust_coef (np.ndarray) – an (n,) array of floats representing all motor thrust coefficients.

  • torque_coef (np.ndarray) – an (n,) array of floats representing all motor torque coefficients, uses right hand rotation rule around the thrust_unit axis.

  • thrust_unit (np.ndarray) – an (n, 3) array of floats representing n unit vectors along with the thrust of each motor acts.

  • noise_ratio (np.ndarray) – an (n,) array of floats representing the ratio amount of noise fluctuation present in each motor.

get_states() ndarray#

Gets the current state of the components.

Returns:

an (num_motors, ) array for the current throttle level of each motor

Return type:

np.ndarray

physics_update(pwm: ndarray, rotation: None | ndarray = None) None#

Converts motor PWM values to forces, this motor allows negative thrust.

Parameters:
  • pwm (np.ndarray) – [num_motors, ] array defining the pwm values of each motor from -1 to 1.

  • rotation (np.ndarray) – (num_motors, 3, 3) rotation matrices to rotate each booster’s thrust axis around, this is readily obtained from the gimbals component.

reset() None#

Reset the motors.

state_update() None#

This does not need to be called for motors.