Midnight Sun Firmware
Loading...
Searching...
No Matches
ws22_motor_can.h
1#pragma once
2
3/************************************************************************************************
4 * @file motor_can.h
5 *
6 * @brief Header file for Motor CAN interface
7 *
8 * @date 2025-06-29
9 * @author Midnight Sun Team #24 - MSXVI
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <stdint.h>
14
15/* Inter-component Headers */
16#include "can.h"
17#include "can_hw.h"
18#include "can_msg.h"
19
20/* Intra-component Headers */
21
28#define MOTOR_CAN_CONTROL_BASE 0x500
29#define MOTOR_CAN_CONTROLLER_BASE 0x400
30
31#define STATUS_INFO (MOTOR_CAN_CONTROLLER_BASE + 0X01)
32#define BUS_MEASUREMENT (MOTOR_CAN_CONTROLLER_BASE + 0X02)
33#define VELOCTIY_MEASUREMENT (MOTOR_CAN_CONTROLLER_BASE + 0X03)
34#define PHASE_CURRENT (MOTOR_CAN_CONTROLLER_BASE + 0X04)
35#define MOTOR_VOLTAGE (MOTOR_CAN_CONTROLLER_BASE + 0X05)
36#define MOTOR_CURRENT (MOTOR_CAN_CONTROLLER_BASE + 0X06)
37#define MOTOR_BACK_EMF (MOTOR_CAN_CONTROLLER_BASE + 0x07)
38#define RAIL_15V (MOTOR_CAN_CONTROLLER_BASE + 0x08)
39#define HEAT_SINK_MOTOR_TEMP (MOTOR_CAN_CONTROLLER_BASE + 0x0B)
40
41typedef struct TxData {
42 float current; // Range: 0.0 to 1.0
43 uint32_t velocity; // Range: 0 to ~12000 rpm
44} TxData;
45
46typedef struct RxData {
47 // Status Info - base address + 0x01
48 uint16_t error_flags;
49 uint16_t limit_flags;
50
51 // Bus Measurement - base address + 0x02
52 float bus_current;
53 float bus_voltage;
54
55 // Velocity Measurement - base address + 0x03
56 float vehicle_velocity;
57 float motor_velocity;
58
59 // Phase Current - base address + 0x04
60 float phase_c_current;
61 float phase_b_current;
62
63 // Motor Voltage - base address + 0x05
64 float voltage_d;
65 float voltage_q;
66
67 // Motor Current - base address + 0x06
68 float current_d;
69 float current_q;
70
71 // Motor BackEMF - base address + 0x07
72 float back_EMF_d; // always zero
73 float back_EMF_q;
74
75 // 15V Voltage Rail Measurement - base address + 0x08
76 float rail_15V_supply;
77
78 // Heat-sink and Motor Temp - base address + 0x0B
79 float heat_sink_temp;
80 float motor_temp;
81} RxData;
82
83StatusCode motor_can_transmit(uint32_t id, bool extended, const uint8_t *msg, uint8_t dlc);
84
85void tx_set_current(float current);
86void tx_set_velocity(uint32_t velocity);
87
88RxData get_rx_data(void);
89
90void rx_set_limit_flags(uint16_t flags);
91void rx_set_error_flags(uint16_t flags);
92void rx_set_bus_current(float current);
93void rx_set_bus_voltage(float voltage);
94void rx_set_vehicle_velocity(float velocity);
95void rx_set_motor_velocity(float velocity);
96void rx_set_phase_c_current(float current);
97void rx_set_phase_b_current(float current);
98void rx_set_voltage_d(float voltage);
99void rx_set_voltage_q(float voltage);
100void rx_set_current_d(float current);
101void rx_set_current_q(float current);
102void rx_set_back_EMF_d(float voltage);
103void rx_set_back_EMF_q(float voltage);
104void rx_set_rail_15v_supply(float voltage);
105void rx_set_heat_sink_temp(float degrees);
106void rx_set_motor_temp(float degrees);
107
StatusCode
StatusCodes for various errors.
Definition: status.h:27
Definition: ws22_motor_can.h:46
Definition: ws22_motor_can.h:41