Resurgence (PY2022)
Codebase for the Husky Robotics 2021-2022 rover Resurgence
Loading...
Searching...
No Matches
CANUtils.h
1#pragma once
2
3extern "C" {
4#include <HindsightCAN/CANCommon.h>
5#include <HindsightCAN/CANMotorUnit.h>
6#include <HindsightCAN/CANPacket.h>
7}
8
9#include <chrono>
10#include <string>
11#include <utility>
12
13namespace can {
14
20enum class devicegroup_t {
21 broadcast = DEVICE_GROUP_BROADCAST,
22 reserved = DEVICE_GROUP_RESERVED,
23 master = DEVICE_GROUP_MASTER,
24 power = DEVICE_GROUP_POWER,
25 motor = DEVICE_GROUP_MOTOR_CONTROL,
26 telemetry = DEVICE_GROUP_TELEMETRY,
27 gpio = DEVICE_GROUP_GPIO_BOARDS,
28 science = DEVICE_GROUP_SCIENCE
29};
30
36enum class telemtype_t {
37 voltage = PACKET_TELEMETRY_VOLTAGE,
38 current = PACKET_TELEMETRY_CURRENT,
39 pwr_rail = PACKET_TELEMETRY_PWR_RAIL_STATE,
40 temp = PACKET_TELEMETRY_TEMPERATURE,
41 angle = PACKET_TELEMETRY_ANG_POSITION,
42 gps_lat = PACKET_TELEMETRY_GPS_LAT,
43 gps_lon = PACKET_TELEMETRY_GPS_LON,
44 mag_dir = PACKET_TELEMETRY_MAG_DIR,
45 accel_x = PACKET_TELEMETRY_ACCEL_X,
46 accel_y = PACKET_TELEMETRY_ACCEL_Y,
47 accel_z = PACKET_TELEMETRY_ACCEL_Z,
48 gyro_x = PACKET_TELEMETRY_GYRO_X,
49 gyro_y = PACKET_TELEMETRY_GYRO_Y,
50 gyro_z = PACKET_TELEMETRY_GYRO_Z,
51 limit_switch = PACKET_TELEMETRY_LIM_SW_STATE,
52 adc_raw = PACKET_TELEMETRY_ADC_RAW
53 // add further telemetry types if required
54};
55
60 enum { telemetry = ID_TELEMETRY_REPORT, limit_alert = ID_MOTOR_UNIT_LIM_ALERT };
61};
62
65
68
75
82devicegroup_t getDeviceGroup(const CANPacket& packet);
83
90deviceserial_t getDeviceSerial(const CANPacket& packet);
91
98deviceid_t getDeviceGroupAndSerial(const CANPacket& packet);
99
106deviceserial_t getSenderDeviceSerial(const CANPacket& packet);
107
114devicegroup_t getSenderDeviceGroup(const CANPacket& packet);
115
123deviceid_t getSenderDeviceGroupAndSerial(const CANPacket& packet);
124
136std::string packetToString(const CANPacket& packet);
137
138} // namespace can
_GLIBCXX_END_NAMESPACE_CXX11 typedef basic_string< char > string
Utilities for interacting with motor boards over a CAN interface.
Definition CANMotor.cpp:20
Utilities for interacting with CAN devices.
Definition CAN.cpp:43
devicegroup_t
The possible device group codes.
Definition CANUtils.h:20
devicegroup_t getDeviceGroup(const CANPacket &packet)
Get the device group from the id of the given packet.
Definition CANUtils.cpp:11
deviceid_t getSenderDeviceGroupAndSerial(const CANPacket &packet)
Get the device group and serial code of the sender of the given packet.
Definition CANUtils.cpp:33
int32_t telemetry_t
The type of telemetry data.
Definition CANUtils.h:67
std::string packetToString(const CANPacket &packet)
Get a string representation of the given CAN packet.
Definition CANUtils.cpp:37
devicegroup_t getSenderDeviceGroup(const CANPacket &packet)
Get the device group of the sender of the given packet.
Definition CANUtils.cpp:28
deviceid_t getDeviceGroupAndSerial(const CANPacket &packet)
Get the unique identifier from the id of the given packet.
Definition CANUtils.cpp:20
deviceserial_t getDeviceSerial(const CANPacket &packet)
Get the serial number from the id of the given packet.
Definition CANUtils.cpp:16
uint8_t deviceserial_t
The type of the device serial number.
Definition CANUtils.h:64
std::pair< devicegroup_t, deviceserial_t > deviceid_t
A unique identifier for a CAN device.
Definition CANUtils.h:74
deviceserial_t getSenderDeviceSerial(const CANPacket &packet)
Get the device serial code of the sender of the given packet.
Definition CANUtils.cpp:24
telemtype_t
The type of telemetries that devices can report.
Definition CANUtils.h:36
::uint8_t uint8_t
::int32_t int32_t
The types of CAN packets that we recognize.
Definition CANUtils.h:59