Sylib
A C++ Library For V5
|
#include <motor.hpp>
Public Member Functions | |
Motor (const uint8_t smart_port, const double gearing=200, const bool reverse=false, const SpeedControllerInfo speedController=SpeedControllerInfo()) | |
Creates a smart motor object. More... | |
void | update () override |
Motor update loop. More... | |
void | set_position_target_absolute (double new_position, std::int32_t velocity_cap=200) |
Sets the absolute motor position target. More... | |
void | set_position_target_relative (double new_position, std::int32_t velocity_cap=200) |
Sets a motor position target relative to its current position. More... | |
void | set_velocity_custom_controller (std::int16_t new_velocity_target) |
Sets the motor velocity target and changes control modes. More... | |
void | stop () |
Stops the motor. More... | |
void | set_voltage (std::int16_t new_voltage_target) |
Sets the voltage sent to the motor directly. More... | |
void | set_braking_mode (V5MotorBrakeMode mode) |
Sets the motor braking mode. More... | |
void | set_amps_limit (std::int32_t limit) |
Sets the motor amperage limit. More... | |
void | set_is_reversed (bool reverse) |
Sets the motor reversed flag. More... | |
void | set_volts_limit (std::int32_t limit) |
Sets the motor voltage limit. More... | |
void | tare_encoder () |
Tares the motor encoder. More... | |
void | set_velocity (std::int32_t new_velocity_target) |
Sets the motor velocity target. More... | |
void | updateSpeedController (sylib::SpeedControllerInfo controller) |
Sets the custom speed controller used by set_velocity_custom_controller. More... | |
double | get_velocity_error () const |
Gets the current error between the motor's actual velocity and the velocity target. More... | |
std::int32_t | get_p_voltage () const |
Gets the current output of the user-provided P controller. More... | |
std::int32_t | get_i_voltage () const |
Gets the current output of the user-provided I controller. More... | |
std::int32_t | get_d_voltage () const |
Gets the current output of the user-provided D controller. More... | |
std::int32_t | get_estimator_voltage () const |
Gets the current output of the user-provided feedforward controller. More... | |
std::int32_t | get_tbh_voltage () const |
Gets the current output of the user-provided TBH controller. More... | |
double | get_position () const |
Gets the current raw motor position. More... | |
double | get_position_target () const |
Gets the current target motor position. More... | |
double | get_velocity () const |
Gets the current motor velocity. More... | |
double | get_velocity_target () const |
Gets the current motor velocity target. More... | |
double | get_velocity_motor_reported () const |
Gets the current motor velocity as reported by the motor itself. More... | |
double | get_velocity_raw () const |
Gets the unfiltered motor velocity. More... | |
double | get_velocity_sma_filter_only () const |
Gets the partially-filtered motor velocity. More... | |
double | get_acceleration () const |
Gets the motor acceleration. More... | |
double | get_temperature () const |
Gets the motor temperature. More... | |
double | get_torque () const |
Gets the motor torque. More... | |
double | get_watts () const |
Gets the motor power consumption. More... | |
std::int32_t | get_amps () const |
Gets the motor current draw. More... | |
std::int32_t | get_amps_limit () const |
Gets the user-provided motor current limit. More... | |
std::int32_t | get_applied_voltage () const |
Gets the voltage most recently sent to the motor, when using a sylib control mode. More... | |
std::int32_t | get_volts_limit () const |
Gets the user-provided motor voltage limit. More... | |
std::int32_t | get_efficiency () const |
Gets the motor-reported efficiency value in percent. More... | |
std::int32_t | get_faults () const |
Gets the motor-reported faults. More... | |
std::int32_t | get_flags () const |
Gets the motor-reported flags. More... | |
std::uint32_t | get_device_timestamp () const |
Gets the most recent time at which the motor has updated its tick count. More... | |
std::int32_t | get_position_and_timestamp (std::uint32_t *timestamp) |
Gets the current motor tick count and timestamp value. More... | |
std::int32_t | get_braking_mode () const |
Gets the current motor brake mode. More... | |
std::int32_t | get_gearing () const |
Gets the user-set motor gearing. More... | |
std::int32_t | get_smart_port () const |
Gets 1-indexed smart port used by the motor. More... | |
bool | is_stopped () const |
Gets if the motor is stopped. More... | |
bool | is_over_current () const |
Gets if the motor is over current, as reported by the motor. More... | |
bool | is_over_temp () const |
Gets if the motor is over temperature, as reported by the motor. More... | |
bool | is_reversed () const |
Gets if the motor reversed flag is set. More... | |
V5 Smart Motor.
sylib::Motor::Motor | ( | const uint8_t | smart_port, |
const double | gearing = 200 , |
||
const bool | reverse = false , |
||
const SpeedControllerInfo | speedController = SpeedControllerInfo() |
||
) |
Creates a smart motor object.
smart_port | The 1-indexed smart port the motor uses |
gearing | The output speed of the motor, in RPM, if the motor internally is spinning at 3600 RPM. 200 is default for a green motor cartridge |
reverse | Optional motor reversed flag |
speedController | Optional velocity controller used by set_velocity_custom_controller |
double sylib::Motor::get_acceleration | ( | ) | const |
Gets the motor acceleration.
Uses the sylib velocity estimator
std::int32_t sylib::Motor::get_amps | ( | ) | const |
Gets the motor current draw.
std::int32_t sylib::Motor::get_amps_limit | ( | ) | const |
Gets the user-provided motor current limit.
std::int32_t sylib::Motor::get_applied_voltage | ( | ) | const |
Gets the voltage most recently sent to the motor, when using a sylib control mode.
std::int32_t sylib::Motor::get_braking_mode | ( | ) | const |
Gets the current motor brake mode.
std::int32_t sylib::Motor::get_d_voltage | ( | ) | const |
Gets the current output of the user-provided D controller.
std::uint32_t sylib::Motor::get_device_timestamp | ( | ) | const |
Gets the most recent time at which the motor has updated its tick count.
This value is based on the motor's internal clock, and drifts from the brain's system timer by approximately 1 part in 95.
std::int32_t sylib::Motor::get_efficiency | ( | ) | const |
Gets the motor-reported efficiency value in percent.
100% efficiency means the motor is moving while drawing no power, and 0% efficiency means the motor is drawing power while not moving.
std::int32_t sylib::Motor::get_estimator_voltage | ( | ) | const |
Gets the current output of the user-provided feedforward controller.
std::int32_t sylib::Motor::get_faults | ( | ) | const |
Gets the motor-reported faults.
std::int32_t sylib::Motor::get_flags | ( | ) | const |
Gets the motor-reported flags.
std::int32_t sylib::Motor::get_gearing | ( | ) | const |
Gets the user-set motor gearing.
std::int32_t sylib::Motor::get_i_voltage | ( | ) | const |
Gets the current output of the user-provided I controller.
std::int32_t sylib::Motor::get_p_voltage | ( | ) | const |
Gets the current output of the user-provided P controller.
double sylib::Motor::get_position | ( | ) | const |
Gets the current raw motor position.
std::int32_t sylib::Motor::get_position_and_timestamp | ( | std::uint32_t * | timestamp | ) |
Gets the current motor tick count and timestamp value.
Sets the value at the pointer provided to the motor timestamp in milliseconds
double sylib::Motor::get_position_target | ( | ) | const |
Gets the current target motor position.
std::int32_t sylib::Motor::get_smart_port | ( | ) | const |
Gets 1-indexed smart port used by the motor.
std::int32_t sylib::Motor::get_tbh_voltage | ( | ) | const |
Gets the current output of the user-provided TBH controller.
double sylib::Motor::get_temperature | ( | ) | const |
Gets the motor temperature.
double sylib::Motor::get_torque | ( | ) | const |
Gets the motor torque.
double sylib::Motor::get_velocity | ( | ) | const |
Gets the current motor velocity.
Uses the sylib velocity estimator
double sylib::Motor::get_velocity_error | ( | ) | const |
Gets the current error between the motor's actual velocity and the velocity target.
Uses the sylib velocity estimator
double sylib::Motor::get_velocity_motor_reported | ( | ) | const |
Gets the current motor velocity as reported by the motor itself.
This number is complete garbage and should not be used for anything.
double sylib::Motor::get_velocity_raw | ( | ) | const |
Gets the unfiltered motor velocity.
Uses the sylib velocity estimator
double sylib::Motor::get_velocity_sma_filter_only | ( | ) | const |
Gets the partially-filtered motor velocity.
Uses the sylib velocity estimator
double sylib::Motor::get_velocity_target | ( | ) | const |
Gets the current motor velocity target.
std::int32_t sylib::Motor::get_volts_limit | ( | ) | const |
Gets the user-provided motor voltage limit.
double sylib::Motor::get_watts | ( | ) | const |
Gets the motor power consumption.
bool sylib::Motor::is_over_current | ( | ) | const |
Gets if the motor is over current, as reported by the motor.
bool sylib::Motor::is_over_temp | ( | ) | const |
Gets if the motor is over temperature, as reported by the motor.
bool sylib::Motor::is_reversed | ( | ) | const |
Gets if the motor reversed flag is set.
bool sylib::Motor::is_stopped | ( | ) | const |
Gets if the motor is stopped.
void sylib::Motor::set_amps_limit | ( | std::int32_t | limit | ) |
Sets the motor amperage limit.
limit | Limit in milliamps |
void sylib::Motor::set_braking_mode | ( | V5MotorBrakeMode | mode | ) |
Sets the motor braking mode.
mode | Brake mode to use |
void sylib::Motor::set_is_reversed | ( | bool | reverse | ) |
Sets the motor reversed flag.
reverse | Reverse flag |
void sylib::Motor::set_position_target_absolute | ( | double | new_position, |
std::int32_t | velocity_cap = 200 |
||
) |
Sets the absolute motor position target.
This uses the smart motor's own built-in controller
new_position | Absolute position to move to |
velocity_cap | Target speed to perform the movement at |
void sylib::Motor::set_position_target_relative | ( | double | new_position, |
std::int32_t | velocity_cap = 200 |
||
) |
Sets a motor position target relative to its current position.
This uses the smart motor's own built-in controller
new_position | Position to move to |
velocity_cap | Target speed to perform the movement at |
void sylib::Motor::set_velocity | ( | std::int32_t | new_velocity_target | ) |
Sets the motor velocity target.
This uses the smart motor's own built-in controller
new_velocity_target | Motor velocity target |
void sylib::Motor::set_velocity_custom_controller | ( | std::int16_t | new_velocity_target | ) |
Sets the motor velocity target and changes control modes.
This uses a controller provided by the user
new_velocity_target | Motor velocity target |
void sylib::Motor::set_voltage | ( | std::int16_t | new_voltage_target | ) |
Sets the voltage sent to the motor directly.
new_voltage_target | Voltage in millivolts |
void sylib::Motor::set_volts_limit | ( | std::int32_t | limit | ) |
Sets the motor voltage limit.
limit | Limit in millivolts |
void sylib::Motor::stop | ( | ) |
Stops the motor.
void sylib::Motor::tare_encoder | ( | ) |
Tares the motor encoder.
|
overridevirtual |
Motor update loop.
Updates the motor to the most recently set values
Users do not need to call this function, it is handled by the sylib daemon. Don't use this. It won't help.
Implements sylib::Device.
void sylib::Motor::updateSpeedController | ( | sylib::SpeedControllerInfo | controller | ) |
Sets the custom speed controller used by set_velocity_custom_controller.
controller | Velocity controller |