Sylib
A C++ Library For V5
Loading...
Searching...
No Matches
sylib::Motor Class Reference

V5 Smart Motor. More...

#include <motor.hpp>

Inheritance diagram for sylib::Motor:
sylib::Device

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...
 

Detailed Description

V5 Smart Motor.

Constructor & Destructor Documentation

◆ 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.

Parameters
smart_portThe 1-indexed smart port the motor uses
gearingThe output speed of the motor, in RPM, if the motor internally is spinning at 3600 RPM. 200 is default for a green motor cartridge
reverseOptional motor reversed flag
speedControllerOptional velocity controller used by set_velocity_custom_controller

Member Function Documentation

◆ get_acceleration()

double sylib::Motor::get_acceleration ( ) const

Gets the motor acceleration.

Uses the sylib velocity estimator

Returns
RPM per millisecond

◆ get_amps()

std::int32_t sylib::Motor::get_amps ( ) const

Gets the motor current draw.

Returns
Amps

◆ get_amps_limit()

std::int32_t sylib::Motor::get_amps_limit ( ) const

Gets the user-provided motor current limit.

Returns
Amps

◆ get_applied_voltage()

std::int32_t sylib::Motor::get_applied_voltage ( ) const

Gets the voltage most recently sent to the motor, when using a sylib control mode.

Returns
Millivolts

◆ get_braking_mode()

std::int32_t sylib::Motor::get_braking_mode ( ) const

Gets the current motor brake mode.

Returns
V5MotorBrakeMode

◆ get_d_voltage()

std::int32_t sylib::Motor::get_d_voltage ( ) const

Gets the current output of the user-provided D controller.

Returns
Millivolts

◆ get_device_timestamp()

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.

Returns
Milliseconds

◆ get_efficiency()

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.

Returns
Millivolts

◆ get_estimator_voltage()

std::int32_t sylib::Motor::get_estimator_voltage ( ) const

Gets the current output of the user-provided feedforward controller.

Returns
Millivolts

◆ get_faults()

std::int32_t sylib::Motor::get_faults ( ) const

Gets the motor-reported faults.

Returns
Who knows ¯\_(ツ)_/¯

◆ get_flags()

std::int32_t sylib::Motor::get_flags ( ) const

Gets the motor-reported flags.

Returns
Who knows ¯\_(ツ)_/¯

◆ get_gearing()

std::int32_t sylib::Motor::get_gearing ( ) const

Gets the user-set motor gearing.

Returns
RPM

◆ get_i_voltage()

std::int32_t sylib::Motor::get_i_voltage ( ) const

Gets the current output of the user-provided I controller.

Returns
Millivolts

◆ get_p_voltage()

std::int32_t sylib::Motor::get_p_voltage ( ) const

Gets the current output of the user-provided P controller.

Returns
Millivolts

◆ get_position()

double sylib::Motor::get_position ( ) const

Gets the current raw motor position.

Returns
Ticks

◆ get_position_and_timestamp()

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

Returns
Ticks

◆ get_position_target()

double sylib::Motor::get_position_target ( ) const

Gets the current target motor position.

Returns
Ticks

◆ get_smart_port()

std::int32_t sylib::Motor::get_smart_port ( ) const

Gets 1-indexed smart port used by the motor.

Returns
Smart Port Number

◆ get_tbh_voltage()

std::int32_t sylib::Motor::get_tbh_voltage ( ) const

Gets the current output of the user-provided TBH controller.

Returns
Millivolts

◆ get_temperature()

double sylib::Motor::get_temperature ( ) const

Gets the motor temperature.

Returns
Degrees Celsius, rounded to the nearest 5

◆ get_torque()

double sylib::Motor::get_torque ( ) const

Gets the motor torque.

Returns
Newton-Metres

◆ get_velocity()

double sylib::Motor::get_velocity ( ) const

Gets the current motor velocity.

Uses the sylib velocity estimator

Returns
RPM

◆ get_velocity_error()

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

Returns
RPM

◆ get_velocity_motor_reported()

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.

Returns
RPM

◆ get_velocity_raw()

double sylib::Motor::get_velocity_raw ( ) const

Gets the unfiltered motor velocity.

Uses the sylib velocity estimator

Returns
RPM

◆ get_velocity_sma_filter_only()

double sylib::Motor::get_velocity_sma_filter_only ( ) const

Gets the partially-filtered motor velocity.

Uses the sylib velocity estimator

Returns
RPM

◆ get_velocity_target()

double sylib::Motor::get_velocity_target ( ) const

Gets the current motor velocity target.

Returns
RPM

◆ get_volts_limit()

std::int32_t sylib::Motor::get_volts_limit ( ) const

Gets the user-provided motor voltage limit.

Returns
Millivolts

◆ get_watts()

double sylib::Motor::get_watts ( ) const

Gets the motor power consumption.

Returns
Watts

◆ is_over_current()

bool sylib::Motor::is_over_current ( ) const

Gets if the motor is over current, as reported by the motor.

Returns
True or False

◆ is_over_temp()

bool sylib::Motor::is_over_temp ( ) const

Gets if the motor is over temperature, as reported by the motor.

Returns
True or False

◆ is_reversed()

bool sylib::Motor::is_reversed ( ) const

Gets if the motor reversed flag is set.

Returns
True or False

◆ is_stopped()

bool sylib::Motor::is_stopped ( ) const

Gets if the motor is stopped.

Returns
True if the most recent raw velocity measurement is 0, otherwise False

◆ set_amps_limit()

void sylib::Motor::set_amps_limit ( std::int32_t  limit)

Sets the motor amperage limit.

Parameters
limitLimit in milliamps

◆ set_braking_mode()

void sylib::Motor::set_braking_mode ( V5MotorBrakeMode  mode)

Sets the motor braking mode.

Parameters
modeBrake mode to use

◆ set_is_reversed()

void sylib::Motor::set_is_reversed ( bool  reverse)

Sets the motor reversed flag.

Parameters
reverseReverse flag

◆ set_position_target_absolute()

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

Parameters
new_positionAbsolute position to move to
velocity_capTarget speed to perform the movement at

◆ set_position_target_relative()

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

Parameters
new_positionPosition to move to
velocity_capTarget speed to perform the movement at

◆ set_velocity()

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

Parameters
new_velocity_targetMotor velocity target

◆ set_velocity_custom_controller()

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

Parameters
new_velocity_targetMotor velocity target

◆ set_voltage()

void sylib::Motor::set_voltage ( std::int16_t  new_voltage_target)

Sets the voltage sent to the motor directly.

Parameters
new_voltage_targetVoltage in millivolts

◆ set_volts_limit()

void sylib::Motor::set_volts_limit ( std::int32_t  limit)

Sets the motor voltage limit.

Parameters
limitLimit in millivolts

◆ stop()

void sylib::Motor::stop ( )

Stops the motor.

◆ tare_encoder()

void sylib::Motor::tare_encoder ( )

Tares the motor encoder.

◆ update()

void sylib::Motor::update ( )
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.

◆ updateSpeedController()

void sylib::Motor::updateSpeedController ( sylib::SpeedControllerInfo  controller)

Sets the custom speed controller used by set_velocity_custom_controller.

Parameters
controllerVelocity controller