43 inline static FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> can2;
73 static int send_message(
unsigned len,
const unsigned char* buffer,
unsigned id);
131 can2.setBaudRate(500000);
135 can2.enableFIFOInterrupt();
138 can2.setFIFOFilter(REJECT_ALL);
140 can2.setFIFOFilter(fifoCode.key, fifoCode.code, STD);
144 can2.setFIFOFilter(fifoExtendedCode.key, fifoExtendedCode.code, EXT);
150 can2.mailboxStatus();
158 double right_wheel_rpm = (buf[4] << 24) | (buf[3] << 16) | (buf[2] << 8) | buf[1];
163 double left_wheel_rpm = (buf[4] << 24) | (buf[3] << 16) | (buf[2] << 8) | buf[1];
171 bool emg_stop1 = buf[0] & 0x01;
172 bool emg_stop2 = buf[3] >> 7 & 0x01;
173 bool go_switch = (buf[0] >> 1) & 0x01;
174 bool go_button = (buf[0] >> 2) & 0x01;
183 if (go_button || go_switch)
185 else if (!emg_stop1 && !emg_stop2) {
192 bool signal_loss = (buf[7] >> 6) & 0x01;
219 if (buf[1] ==
false) {
223 }
else if (buf[0] ==
VDC_BUS) {
224 int dc_voltage = (buf[2] << 8) | buf[1];
282 const uint8_t
msg[] = {
STATE_MSG,
static_cast<uint8_t
>(state_id)};
290 const uint8_t
msg[] = {
MISSION_MSG,
static_cast<uint8_t
>(mission_id)};
305 CAN_message_t can_message;
307 can_message.len = len;
308 for (
unsigned i = 0; i < len; i++) {
309 can_message.buf[i] = buffer[i];
311 can2.write(can_message);
Class that contains definitions of typical messages to send via CAN It serves only as an example of t...
static void c1Callback(const uint8_t *buf)
Callback for data from C1 Teensy.
static int publish_mission(int mission_id)
Publish AS Mission to CAN.
void init()
Initializes the CAN bus.
Communicator(SystemData *systemdata)
Constructor for the Communicator class Initializes the Communicator with the given system data instan...
static void parse_message(const CAN_message_t &msg)
Parses the message received from the CAN bus.
static void resStateCallback(const uint8_t *buf)
Callback RES default callback.
static int send_message(unsigned len, const unsigned char *buffer, unsigned id)
Sends a message to the CAN bus.
static void resReadyCallback()
Callback for RES activation.
static void pcCallback(const uint8_t *buf)
Callback for message from AS CU.
static void bamocarCallback(const uint8_t *buf)
Callback from inversor, for alive signal and data.
static void steeringCallback()
Callback for steering actuator information.
static SystemData * _systemData
static int publish_left_wheel_rpm(double value)
Publish rl wheel rpm to CAN.
static int publish_state(int state_id)
Publish AS State to CAN.
void reset()
Resets the timer to the current time.
Code fifoExtendedCodes[]
Array of extended CAN message codes to be used for FIFO filtering Contains the key and corresponding ...
Code fifoCodes[]
Array of standard CAN message codes to be used for FIFO filtering Each Code struct contains a key and...
constexpr auto RIGHT_WHEEL_CODE
constexpr auto AS_CU_EMERGENCY_SIGNAL
constexpr auto RES_ACTIVATE
constexpr auto STEERING_ID
constexpr auto MISSION_FINISHED
constexpr auto MISSION_MSG
constexpr auto HYDRAULIC_LINE
constexpr auto LEFT_WHEEL_CODE
constexpr auto DC_THRESHOLD
constexpr auto BAMO_RESPONSE_ID
constexpr auto WHEEL_PRECISION
#define DEBUG_PRINT_VAR(var)
Metro resSignalLossTimestamp
Metro inversorAliveTimestamp
Metro steerAliveTimestamp
bool processGoSignal()
Processes the go signal.
int _hydraulic_line_pressure
The whole model of the system: holds all the data necessary.
FailureDetection failureDetection
void create_left_wheel_msg(uint8_t *msg, double value)
Function to create left wheel msg.