Resurgence (PY2022)
Codebase for the Husky Robotics 2021-2022 rover Resurgence
|
Utilities for interacting with CAN devices. More...
Namespaces | |
namespace | motor |
Utilities for interacting with motor boards over a CAN interface. | |
Classes | |
struct | packettype_t |
The types of CAN packets that we recognize. More... | |
Typedefs | |
using | callbackid_t = std::tuple<deviceid_t, telemtype_t, uint32_t> |
An ID for a telemetry callback. | |
using | deviceserial_t = uint8_t |
The type of the device serial number. | |
using | telemetry_t = int32_t |
The type of telemetry data. | |
using | deviceid_t = std::pair<devicegroup_t, deviceserial_t> |
A unique identifier for a CAN device. | |
Enumerations | |
enum class | devicegroup_t { broadcast = DEVICE_GROUP_BROADCAST , reserved = DEVICE_GROUP_RESERVED , master = DEVICE_GROUP_MASTER , power = DEVICE_GROUP_POWER , motor = DEVICE_GROUP_MOTOR_CONTROL , telemetry = DEVICE_GROUP_TELEMETRY , gpio = DEVICE_GROUP_GPIO_BOARDS , science = DEVICE_GROUP_SCIENCE } |
The possible device group codes. More... | |
enum class | telemtype_t { voltage = PACKET_TELEMETRY_VOLTAGE , current = PACKET_TELEMETRY_CURRENT , pwr_rail = PACKET_TELEMETRY_PWR_RAIL_STATE , temp = PACKET_TELEMETRY_TEMPERATURE , angle = PACKET_TELEMETRY_ANG_POSITION , gps_lat = PACKET_TELEMETRY_GPS_LAT , gps_lon = PACKET_TELEMETRY_GPS_LON , mag_dir = PACKET_TELEMETRY_MAG_DIR , accel_x = PACKET_TELEMETRY_ACCEL_X , accel_y = PACKET_TELEMETRY_ACCEL_Y , accel_z = PACKET_TELEMETRY_ACCEL_Z , gyro_x = PACKET_TELEMETRY_GYRO_X , gyro_y = PACKET_TELEMETRY_GYRO_Y , gyro_z = PACKET_TELEMETRY_GYRO_Z , limit_switch = PACKET_TELEMETRY_LIM_SW_STATE , adc_raw = PACKET_TELEMETRY_ADC_RAW } |
The type of telemetries that devices can report. More... | |
Functions | |
void | initCAN () |
Initialize the CAN interface. | |
void | sendCANPacket (const CANPacket &packet) |
Send a CAN packet. | |
robot::types::DataPoint< telemetry_t > | getDeviceTelemetry (deviceid_t id, telemtype_t telemType) |
Get the latest telemetry from a CAN device. | |
void | pullDeviceTelemetry (deviceid_t id, telemtype_t telemType) |
Ping the given CAN device to send the given telemetry data. | |
void | scheduleTelemetryPull (deviceid_t id, telemtype_t telemType, std::chrono::milliseconds period) |
Periodically pull the latest telemetry data from the specified CAN device asychronously. | |
void | unscheduleTelemetryPull (deviceid_t id, telemtype_t telemType) |
Stop pulling the latest telemetry data from the given device. | |
void | unscheduleAllTelemetryPulls () |
Stop pulling the latest telemetry data from all currently scheduled devices. | |
callbackid_t | addDeviceTelemetryCallback (deviceid_t id, telemtype_t telemType, const std::function< void(deviceid_t, telemtype_t, robot::types::DataPoint< telemetry_t >)> &callback) |
void | removeDeviceTelemetryCallback (callbackid_t id) |
Remove a previously registered telemetry callback. | |
callbackid_t | addDeviceTelemetryCallback (deviceid_t id, telemtype_t telemType, const std::function< void(deviceid_t, telemtype_t, robot::types::DataPoint< telemetry_t >)> &callback) |
Add a callback which is invoked when data is recieved. | |
devicegroup_t | getDeviceGroup (const CANPacket &packet) |
Get the device group from the id of the given packet. | |
deviceserial_t | getDeviceSerial (const CANPacket &packet) |
Get the serial number from the id of the given packet. | |
deviceid_t | getDeviceGroupAndSerial (const CANPacket &packet) |
Get the unique identifier from the id of the given packet. | |
deviceserial_t | getSenderDeviceSerial (const CANPacket &packet) |
Get the device serial code of the sender of the given packet. | |
devicegroup_t | getSenderDeviceGroup (const CANPacket &packet) |
Get the device group of the sender of the given packet. | |
deviceid_t | getSenderDeviceGroupAndSerial (const CANPacket &packet) |
Get the device group and serial code of the sender of the given packet. | |
std::string | packetToString (const CANPacket &packet) |
Get a string representation of the given CAN packet. | |
Utilities for interacting with CAN devices.
using can::callbackid_t = std::tuple<deviceid_t, telemtype_t, uint32_t> |
An ID for a telemetry callback.
Users should not construct these themselves.
using can::deviceid_t = std::pair<devicegroup_t, deviceserial_t> |
A unique identifier for a CAN device.
A CAN device is uniquely identified by its group code and its serial number.
|
strong |
The possible device group codes.
Every can device is in a group. These are the possible groups.
|
strong |
The type of telemetries that devices can report.
A device may offer some or none of these telemetry types.
callbackid_t can::addDeviceTelemetryCallback | ( | deviceid_t | id, |
telemtype_t | telemType, | ||
const std::function< void(deviceid_t, telemtype_t, robot::types::DataPoint< telemetry_t >)> & | callback ) |
Add a callback which is invoked when data is recieved.
The callback is invoked when telemetry data of the given type is received from the given device.
id | The ID of the device the callback is listening for. |
telemType | The type of telemetry the callback is listening for. |
callback | The callback that will be invoked with the device ID, telemetry type, and the telemetry data. |
devicegroup_t can::getDeviceGroup | ( | const CANPacket & | packet | ) |
Get the device group from the id of the given packet.
packet | The packet to extract the group from. |
deviceid_t can::getDeviceGroupAndSerial | ( | const CANPacket & | packet | ) |
Get the unique identifier from the id of the given packet.
packet | The packet ot extract the identifier from. |
deviceserial_t can::getDeviceSerial | ( | const CANPacket & | packet | ) |
Get the serial number from the id of the given packet.
packet | The packet to extract the serial number from. |
robot::types::DataPoint< telemetry_t > can::getDeviceTelemetry | ( | deviceid_t | id, |
telemtype_t | telemType ) |
Get the latest telemetry from a CAN device.
This method does NOT query for new data, it just returns the last reported value.
id | The device group and serial number of the device. |
telemType | The type of telemetry to get, as dictated by the specific device specs. |
devicegroup_t can::getSenderDeviceGroup | ( | const CANPacket & | packet | ) |
Get the device group of the sender of the given packet.
packet | The packet to extract the device group from. |
deviceid_t can::getSenderDeviceGroupAndSerial | ( | const CANPacket & | packet | ) |
Get the device group and serial code of the sender of the given packet.
packet | The packet to extract the information from. |
deviceserial_t can::getSenderDeviceSerial | ( | const CANPacket & | packet | ) |
Get the device serial code of the sender of the given packet.
packet | The packet to extract the sender code from. |
void can::initCAN | ( | ) |
Initialize the CAN interface.
This should only be called once.
std::string can::packetToString | ( | const CANPacket & | packet | ) |
Get a string representation of the given CAN packet.
The returned string representation is in the format specified by cansend, which allows easy copy-pasting.
packet | The packet to convert to a string. |
void can::pullDeviceTelemetry | ( | deviceid_t | id, |
telemtype_t | telemType ) |
Ping the given CAN device to send the given telemetry data.
The CAN device will asynchronously send the new data in an unspecified amount of time. Not all CAN devices may support pulling telemetry.
id | The device group and serial number of the device. |
telemType | The type of telemetry to get, as dictated by the specific device specs. |
void can::removeDeviceTelemetryCallback | ( | callbackid_t | id | ) |
Remove a previously registered telemetry callback.
The callback associated with the given callback ID is removed.
id | A callback ID which was previously returned by addDeviceTelemetryCallback(). |
void can::scheduleTelemetryPull | ( | deviceid_t | id, |
telemtype_t | telemType, | ||
std::chrono::milliseconds | period ) |
Periodically pull the latest telemetry data from the specified CAN device asychronously.
This method is NOT thread safe.
id | The device group and serial number of the device. |
telemType | The type of telemetry to get, as dictated by the specific device specs. |
period | The period to wait in between sending pull requests. |
void can::sendCANPacket | ( | const CANPacket & | packet | ) |
Send a CAN packet.
No further formatting is done on the packet. This method is thread-safe.
packet | The CAN packet to send. |
void can::unscheduleAllTelemetryPulls | ( | ) |
Stop pulling the latest telemetry data from all currently scheduled devices.
This method is NOT thread safe.
void can::unscheduleTelemetryPull | ( | deviceid_t | id, |
telemtype_t | telemType ) |
Stop pulling the latest telemetry data from the given device.
This method is NOT thread safe.
id | The device group and serial number of the device. |
telemType | The type of telemetry to get, as dictated by the specific device specs. |