Midnight Sun Firmware
Loading...
Searching...
No Matches
ws22_motor_can.h
1#pragma once
2
3/************************************************************************************************
4 * @file ws22_motor_can.h
5 *
6 * @brief Header file for Wavesculptor 22 CAN interface
7 *
8 * @date 2025-06-29
9 * @author Midnight Sun Team #24 - MSXVI
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <stdbool.h>
14#include <stdint.h>
15
16/* Inter-component Headers */
17#include "can.h"
18#include "status.h"
19
20/* Intra-component Headers */
21#include "front_controller.h"
22
29/* CAN Message Base Addresses */
30#define WS22_CAN_BASE_CONTROL 0x500U
31#define WS22_CAN_BASE_STATUS 0x400U
33/* CAN Message IDs */
34#define WS22_CAN_ID_DRIVE_CMD (WS22_CAN_BASE_CONTROL + 0x01U)
35#define WS22_CAN_ID_STATUS_INFO (WS22_CAN_BASE_STATUS + 0x01U)
36#define WS22_CAN_ID_BUS_MEASUREMENT (WS22_CAN_BASE_STATUS + 0x02U)
37#define WS22_CAN_ID_VELOCITY_MEASUREMENT (WS22_CAN_BASE_STATUS + 0x03U)
38#define WS22_CAN_ID_PHASE_CURRENT (WS22_CAN_BASE_STATUS + 0x04U)
39#define WS22_CAN_ID_MOTOR_VOLTAGE (WS22_CAN_BASE_STATUS + 0x05U)
40#define WS22_CAN_ID_MOTOR_CURRENT (WS22_CAN_BASE_STATUS + 0x06U)
41#define WS22_CAN_ID_MOTOR_BACK_EMF (WS22_CAN_BASE_STATUS + 0x07U)
42#define WS22_CAN_ID_RAIL_15V (WS22_CAN_BASE_STATUS + 0x08U)
43#define WS22_CAN_ID_TEMPERATURE (WS22_CAN_BASE_STATUS + 0x0BU)
44
48typedef struct {
49 float current;
50 uint32_t velocity;
52
56typedef struct {
57 /* Status Information (0x401) */
58 uint16_t error_flags;
59 uint16_t limit_flags;
61 /* Bus Measurements (0x402) */
65 /* Velocity Measurements (0x403) */
69 /* Phase Currents (0x404) */
73 /* Motor Voltages (0x405) */
74 float voltage_d;
75 float voltage_q;
77 /* Motor Currents (0x406) */
78 float current_d;
79 float current_q;
81 /* Motor Back EMF (0x407) */
82 float back_emf_d;
83 float back_emf_q;
85 /* Power Rail (0x408) */
88 /* Temperature Measurements (0x40B) */
90 float motor_temp;
92
96typedef struct Ws22MotorCanStorage {
100
107
114
120StatusCode ws22_motor_can_set_velocity(uint32_t velocity);
121
127
134
140
146
StatusCode ws22_motor_can_set_current(float current)
Set motor control current command.
Definition: ws22_motor_can.c:165
StatusCode ws22_motor_can_process_rx(CanMessage *msg)
Process received CAN message for motor controller.
Definition: ws22_motor_can.c:194
StatusCode ws22_motor_can_transmit_drive_command(void)
Build and transmit motor drive command.
Definition: ws22_motor_can.c:183
StatusCode ws22_motor_can_set_velocity(uint32_t velocity)
Set motor control velocity command.
Definition: ws22_motor_can.c:174
Ws22MotorControlData * ws22_motor_can_get_control_data(void)
Get current motor control data.
Definition: ws22_motor_can.c:232
Ws22MotorTelemetryData * ws22_motor_can_get_telemetry_data(void)
Get current motor telemetry data.
Definition: ws22_motor_can.c:236
StatusCode ws22_motor_can_init(FrontControllerStorage *storage)
Initialize the WS22 motor CAN interface.
Definition: ws22_motor_can.c:154
StatusCode
StatusCodes for various errors.
Definition: status.h:27
CAN message structure.
Definition: can_msg.h:56
Front Controller storage.
Definition: front_controller.h:59
WS22 motor CAN interface storage structure.
Definition: ws22_motor_can.h:96
Ws22MotorControlData control
Definition: ws22_motor_can.h:97
Ws22MotorTelemetryData telemetry
Definition: ws22_motor_can.h:98
Motor control command data structure.
Definition: ws22_motor_can.h:48
uint32_t velocity
Definition: ws22_motor_can.h:50
float current
Definition: ws22_motor_can.h:49
Motor status and telemetry data structure.
Definition: ws22_motor_can.h:56
float voltage_d
Definition: ws22_motor_can.h:74
uint16_t limit_flags
Definition: ws22_motor_can.h:59
float phase_b_current
Definition: ws22_motor_can.h:70
float voltage_q
Definition: ws22_motor_can.h:75
float current_d
Definition: ws22_motor_can.h:78
float vehicle_velocity
Definition: ws22_motor_can.h:66
float back_emf_q
Definition: ws22_motor_can.h:83
float back_emf_d
Definition: ws22_motor_can.h:82
float motor_velocity
Definition: ws22_motor_can.h:67
float phase_c_current
Definition: ws22_motor_can.h:71
float bus_voltage
Definition: ws22_motor_can.h:63
float heat_sink_temp
Definition: ws22_motor_can.h:89
float rail_15v_supply
Definition: ws22_motor_can.h:86
float bus_current
Definition: ws22_motor_can.h:62
float current_q
Definition: ws22_motor_can.h:79
uint16_t error_flags
Definition: ws22_motor_can.h:58
float motor_temp
Definition: ws22_motor_can.h:90