Resurgence (PY2022)
Codebase for the Husky Robotics 2021-2022 rover Resurgence
|
Utilities for interacting with motor boards over a CAN interface. More...
Classes | |
struct | sensor_t |
The supported motor position sensors. More... | |
Enumerations | |
enum class | motormode_t { pwm = MOTOR_UNIT_MODE_PWM , pid = MOTOR_UNIT_MODE_PID } |
The possible motor modes. | |
Functions | |
void | initEncoder (deviceserial_t serial, bool invertEncoder, bool zeroEncoder, int32_t pulsesPerJointRev, std::optional< std::chrono::milliseconds > telemetryPeriod) |
Initialize an encoder attached to the given motor. | |
void | initPotentiometer (deviceserial_t serial, int32_t posLo, int32_t posHi, uint16_t adcLo, uint16_t adcHi, std::optional< std::chrono::milliseconds > telemetryPeriod) |
Initialize a potentiometer attached to the given motor. | |
void | emergencyStopMotors () |
Emergency stop all motors on the CAN bus. | |
void | initMotor (deviceserial_t serial) |
Initialize a motor. | |
void | setLimitSwitchLimits (deviceserial_t serial, int32_t lo, int32_t hi) |
Set the limits of the limit switch on a motor board. | |
void | setMotorPIDConstants (deviceserial_t serial, int32_t kP, int32_t kI, int32_t kD) |
Set the PID constants for a motor board. | |
void | setMotorMode (deviceserial_t serial, motormode_t mode) |
Set the mode of a motor board. | |
void | setMotorPower (deviceserial_t serial, double power) |
Set the power output of a motor board. | |
void | setMotorPower (deviceserial_t serial, int16_t power) |
Set the power output of a motor board. | |
void | setMotorPIDTarget (deviceserial_t serial, int32_t target) |
Set the position PID target of a motor board. | |
void | setServoPos (deviceserial_t serial, uint8_t servoNum, int32_t angle) |
Set the angle of the PCA servo. | |
DataPoint< int32_t > | getMotorPosition (deviceserial_t serial) |
Get the last reported position of a motor. | |
void | pullMotorPosition (deviceserial_t serial) |
Poll the position data from a motor board. | |
callbackid_t | addLimitSwitchCallback (deviceserial_t serial, const std::function< void( deviceserial_t serial, robot::types::DataPoint< robot::types::LimitSwitchData > limitSwitchData)> &callback) |
Add a callback that is invoked when the limit switch is triggered for a motor board. | |
void | removeLimitSwitchCallback (callbackid_t id) |
Remove a previously registered limit switch callback. | |
Utilities for interacting with motor boards over a CAN interface.
These motor boards can either be AVR or PSoC boards.
callbackid_t can::motor::addLimitSwitchCallback | ( | deviceserial_t | serial, |
const std::function< void(deviceserial_t serial, robot::types::DataPoint< robot::types::LimitSwitchData > limitSwitchData)> & | callback ) |
Add a callback that is invoked when the limit switch is triggered for a motor board.
The event is only triggered when the limit switch is clicked, not released.
serial | The CAN serial number of the motor board. |
callback | The callback to invoke when the limit switch is triggered. |
void can::motor::emergencyStopMotors | ( | ) |
Emergency stop all motors on the CAN bus.
This cuts power to all motors and resets them.
robot::types::DataPoint< int32_t > can::motor::getMotorPosition | ( | deviceserial_t | serial | ) |
Get the last reported position of a motor.
This only reports the cached position, it does not poll the motor board for new data.
serial | The serial number of the motor board. |
void can::motor::initEncoder | ( | deviceserial_t | serial, |
bool | invertEncoder, | ||
bool | zeroEncoder, | ||
int32_t | pulsesPerJointRev, | ||
std::optional< std::chrono::milliseconds > | telemetryPeriod ) |
Initialize an encoder attached to the given motor.
For potentiometers, use initPotentiometer().
serial | The CAN serial number of the motor board. |
invertEncoder | If true, invert the encoder direction. Use this to correct sensor phase. |
zeroEncoder | If true, reset the encoder position to zero. |
pulsesPerJointRev | The number of encoder pulses per revolution of the physical joint. Measure/calculate this using the gear ratios and encoder specs. |
telemetryPeriod | An optional parameter specifying the telemetry period. The telemetry will be fetched at this period automatically. An empty optional disables this behavior, in which case the motor position must be explicitly pulled. |
void can::motor::initMotor | ( | deviceserial_t | serial | ) |
Initialize a motor.
This does not initialize any sensor or controller.
serial | The CAN serial number of the motor to initialize. |
void can::motor::initPotentiometer | ( | deviceserial_t | serial, |
int32_t | posLo, | ||
int32_t | posHi, | ||
uint16_t | adcLo, | ||
uint16_t | adcHi, | ||
std::optional< std::chrono::milliseconds > | telemetryPeriod ) |
Initialize a potentiometer attached to the given motor.
serial | The CAN serial number of the motor board. |
posLo | The joint position that corresponds to adcLo |
posHi | The joint position that corresponds to adcHi |
adcLo | The ADC value when the joint is at posLo |
adcHi | The ADC value when the joint is at posHi |
telemetryPeriod | An optional parameter specifying the telemetry period. The telemetry will be fetched at this period automatically. An empty optional disables this behavior, in which case the motor position must be explicitly pulled. |
void can::motor::pullMotorPosition | ( | deviceserial_t | serial | ) |
Poll the position data from a motor board.
This may not be supported by every motor board implementation.
serial | The CAN serial number of the motor board. |
void can::motor::removeLimitSwitchCallback | ( | callbackid_t | id | ) |
Remove a previously registered limit switch callback.
id | The callback ID that was returned when the callback was registered with addLimitSwitchCallback(). |
void can::motor::setLimitSwitchLimits | ( | deviceserial_t | serial, |
int32_t | lo, | ||
int32_t | hi ) |
Set the limits of the limit switch on a motor board.
When the corresponding limit switch is triggered, the encoder value is set to this value. Use this method for motorboard with both encoders and limit switches
serial | The CAN serial number of the motor board. |
lo | The joint position in millidegrees of the low limit switch. |
hi | The joint position in millidegrees of the high limit switch. |
void can::motor::setMotorMode | ( | deviceserial_t | serial, |
motormode_t | mode ) |
Set the mode of a motor board.
serial | The CAN serial number of the motor board. |
mode | The mode to set. |
void can::motor::setMotorPIDConstants | ( | deviceserial_t | serial, |
int32_t | kP, | ||
int32_t | kI, | ||
int32_t | kD ) |
Set the PID constants for a motor board.
Note that the PID constants are specified in units of 10000, so a 1 is interpreted as a
serial | The CAN serial number of the motor board. |
kP | The P coefficient. |
kI | The I coefficient. |
kD | The D coefficient. |
void can::motor::setMotorPIDTarget | ( | deviceserial_t | serial, |
int32_t | target ) |
Set the position PID target of a motor board.
The motor mode should have been set to motormode_t::pid. Additionally, both the sensor and the PID coefficients must have been initialized.
serial | The CAN serial number of the motor board. |
target | The position in millidegrees to track with the PID controller. |
void can::motor::setMotorPower | ( | deviceserial_t | serial, |
double | power ) |
Set the power output of a motor board.
serial | The CAN serial number of the motor board. |
power | Percent power, in the range [-1,1]. |
void can::motor::setMotorPower | ( | deviceserial_t | serial, |
int16_t | power ) |
Set the power output of a motor board.
The motor mode should have been set to motormode_t::pwm.
serial | The CAN serial number of the motor board. |
power | The power to set. Any signed 16-bit integer is valid. |
void can::motor::setServoPos | ( | deviceserial_t | serial, |
uint8_t | servoNum, | ||
int32_t | angle ) |
Set the angle of the PCA servo.
serial | The CAN serial number of the motor board. |
servoNum | the servo number. |
angle | the angle of the servo in millidegrees. |