Post · 7 min read· pp. 724–730

Units in the library

On this page

All the motor/driver/sensor parameters and control variables are defined in the following units:

Physical valueDescriptionUnitComment
Position/angleRadiansRADMotor and sensor position in radians
VelocityRadians per secondRAD/sMotor and sensor velocity in radians per second
Torque/CurrentAmperesAMotor torque or current
VoltageVoltsVMotor/Driver voltage
Phase resistanceOhmsΩMotor phase resistance
Phase inductanceHenriesHMotor phase inductance
KV ratingRotations per minute per voltrpm/VMotor velocity constant
PWM frequencyHertzHzMotor/driver PWM frequency
PMW duty cycleNo unit-All duty cycles have the range: 0 - 1.0

Position/angle units

The motor and sensor position is defined in radians. One full rotation of the motor is equal to 2π2\pi (6.14) radians is equal to 360 degrees.

Some important variables in radians (RAD)

  • motor.shaft_angle - the current motor position in radians
  • motor.electrical_angle - the current motor electrical position in radians
  • motor.target - the target motor position in radians ( in closed-loop and open-loop angle control)
  • sensor.getAngle() - the current sensor position in radians ( in closed-loop control)

Converting the angle to degrees

In order to convert the angle from radians to degrees, you can use the following formula:

adeg=arad⋅3602πa_{deg} = a_{rad} \cdot \frac{360}{2\pi}

Setting the target angle in degrees

For example, if you wish to set the target angle in degrees:

cpp
motor.target = my_target_in_degrees * _2PI/360;

Or for example if you’re using commander interface to set the target angle in degrees:

cpp
void onTarget(char* cmd){ 
    // get the target angle in degrees
    float target_angle_deg = atof(cmd);
    // set the target angle in radians
    motor.target = target_angle_deg * _2PI/360;
}
...
void setup(){
    ...
    // add the command to the commander
    commander.add('A', onTarget, "angle in degrees");
    ...
}

Reading the sensor angle in degrees

If you wish to read motor position in degrees, you can easily convert it using

cpp
float angle_deg = motor.shaft_angle * 360/_2PI;

The same can be done for the outputs of the Sensor class:

cpp
float angle_deg = sensor.getAngle() * 360/_2PI;

Converting the angle to rotations (turns)

To convert the angle from radians to turns (rotations) you can use the following formula:

arot=arad⋅12πa_{rot} = a_{rad} \cdot \frac{1}{2\pi}

Setting the target angle in turns

For example, if you wish to set the target angle in turns:

cpp
motor.target = my_target_in_turns / _2PI;

Or for example if you’re using commander interface to set the target angle in turns:

cpp
void onTarget(char* cmd){ 
    // get the target angle in turns
    float target_angle_turns = atof(cmd);
    // set the target angle in radians
    motor.target = target_angle_turns / _2PI;
}
... 
void setup(){
    ...
    // add the command to the commander
    commander.add('A', onTarget, "angle in turns");
    ...
}

Reading the sensor angle in turns

If you wish to read motor position in turns, you can easily convert it using

cpp
float angle_turns = motor.shaft_angle / _2PI;

The same can be done for the outputs of the Sensor class:

cpp
float angle_turns = sensor.getAngle() / _2PI;

Velocity units

All the parameters/variables related to the velocity, both for the motor and sensor, are defined in radians per second. One full rotation of the motor is equal to 2π2\pi (6.14) radians is equal to 360 degrees. Some other standard units for the velocity are RPM (revolutions per minute) and 1/s (turns per second).

Some important variables in radians per second (RAD/s)

  • motor.shaft_velocity - the current motor velocity in radians per second
  • motor.velocity_limit - the velocity limit in radians per second
  • motor.shaft_velocity - the current motor velocity in radians per second ( in closed-loop control)
  • motor.target - the target motor velocity in radians per second ( in closed-loop and open-loop velocity control)
  • sensor.getVelocity() - the current sensor velocity in radians per second ( in closed-loop control)

Converting the velocity to RPM

In order to convert the velocity from radians per second to RPM, you can use the following formula:

vRPM=vRAD/s⋅602πv_{RPM} = v_{RAD/s} \cdot \frac{60}{2\pi}

RULE OF THUMB

The motor velocity in RPM is approximately 10 times the motor velocity in radians per second RAD/s, as 602π≈10\frac{60}{2\pi}\approx 10

So the conversion can be approximated as:

vRPM=10⋅vRAD/sv_{RPM} = 10 \cdot v_{RAD/s}

Setting the target velocity in RPM

For example, if you wish to set the target velocity in RPM:

cpp
motor.target = my_target_in_RPM * _2PI/60;

Or for example if you’re using commander interface to set the target velocity in RPM:

cpp
void onTarget(char* cmd){ 
    // get the target velocity in RPM
    float target_velocity_RPM = atof(cmd);
    // set the target velocity in radians per second
    motor.target = target_velocity_RPM * _2PI/60;
}
...
void setup(){
    ...
    // add the command to the commander
    commander.add('V', onTarget, "velocity in RPM");
    ...
}

Reading the sensor velocity in RPM

If you wish to read motor velocity in RPM, you can easily convert it using

cpp
float velocity_RPM = motor.shaft_velocity * 60/_2PI;

The same can be done for the outputs of the Sensor class:

cpp
float velocity_RPM = sensor.getVelocity() * 60/_2PI;

Converting the velocity to turns per second

To convert the velocity from radians per second to turns per second, you can use the following formula:

vtps=vrad/s⋅12πv_{tps} = v_{rad/s} \cdot \frac{1}{2\pi}

Setting the target velocity in turns per second

For example, if you wish to set the target velocity in turns per second:

cpp
motor.target = my_target_in_tps / _2PI;

Or for example if you’re using commander interface to set the target velocity in turns per second:

cpp
void onTarget(char* cmd){ 
    // get the target velocity in turns per second
    float target_velocity_tps = atof(cmd);
    // set the target velocity in radians per second
    motor.target = target_velocity_tps / _2PI;
}
...
void setup(){
    ...
    // add the command to the commander
    commander.add('V', onTarget, "velocity in turns per second");
    ...
}

Reading the sensor velocity in turns per second

If you wish to read motor velocity in turns per second, you can easily convert it using

cpp
float velocity_tps = motor.shaft_velocity / _2PI;

The same can be done for the outputs of the Sensor class:

cpp
float velocity_tps = sensor.getVelocity() / _2PI;

Torque/Current units

The motor torque or current is defined in Amperes. The torque is directly proportional to the current flowing through the motor windings. The torque constant KtK_t is a parameter that describes the relationship between the motor torque and the current.

Some important variables in Amperes [A]

  • motor.current_limit - the current motor limit in Amperes
  • motor.target - the target motor current in Amperes ( in closed-loop torque control or in voltage control with current estimation)
  • motor.currents.q - the current motor currents in Amperes
  • motor.currents.q - the current motor currents in Amperes
  • current_sense.getFOCCurrents() - the current motor currents in Amperes
  • current_sense.getDCCurrent() - the current measured current magnitude in Amperes
  • current_sense.getPhaseCurrents() - the current motor phase currents in Amperes
  • PhaseCurrent_s - the structure that holds the motor phase currents in Amperes
  • DQCurrent_s - the structure that holds the D and Q motor currents in Amperes
  • ABCurrent_s - the structure that holds the Alpha and Beta motor currents in Amperes

Converting the current to torque

The motor torque is directly proportional to the current through the torque constant KtK_t. The torque constant is defined in the motor datasheet and often can be approximated to be the same as the electrical (BEMF) constant Kt≈KeK_t \approx K_e.

τ=Kt⋅I\tau = K_t \cdot I

Setting the target torque in Nm

For example, if you wish to set the target torque in Nm:

cpp
float Kt = ....; // datasheet value
motor.target = my_target_in_Nm / Kt; // Nm / (Nm/A) = Amps

Or for example if you’re using commander interface to set the target torque in Nm:

cpp
void onTarget(char* cmd){ 
    // get the target torque in Nm
    float target_torque_Nm = atof(cmd);
    // set the target current in Amperes
    motor.target = target_torque_Nm / Kt;
}
...
void setup(){
    ...
    // add the command to the commander
    commander.add('T', onTarget, "torque in Nm");
    ...
}

Reading the sensor current in Nm

If you wish to read motor current in Nm, you can easily convert it using

cpp
float current_Nm = motor.currents.q * Kt;

Or directly from the current sensor:

cpp
DQCurrent_s c = current_sense.getFOCCurrents();
float current_Nm = c.q * Kt; // torque in Nm

Copyright © 2026. Distributed by an MIT license.