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-04-23
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 "status.h"
18
19/* Intra-component Headers */
20
27/* CAN Message Base Addresses */
28#define WS22_CAN_BASE_CONTROL 0x500U
29#define WS22_CAN_BASE_STATUS 0x80U
31#define VEHICLE_RPM_TO_KPH 0.10367f
32
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_RESET (WS22_CAN_BASE_CONTROL + 0x03U)
39#define WS22_CAN_ID_PHASE_CURRENT (WS22_CAN_BASE_STATUS + 0x04U)
40#define WS22_CAN_ID_MOTOR_VOLTAGE (WS22_CAN_BASE_STATUS + 0x05U)
41#define WS22_CAN_ID_MOTOR_CURRENT (WS22_CAN_BASE_STATUS + 0x06U)
42#define WS22_CAN_ID_MOTOR_BACK_EMF (WS22_CAN_BASE_STATUS + 0x07U)
43#define WS22_CAN_ID_RAIL_15V (WS22_CAN_BASE_STATUS + 0x08U)
44#define WS22_CAN_ID_TEMPERATURE (WS22_CAN_BASE_STATUS + 0x0BU)
45
49typedef struct {
50 float current;
51 float velocity;
53
57typedef struct {
58 /* Status Information (0x401/0x81) */
59 uint16_t error_flags;
60 uint16_t limit_flags;
61 uint16_t merged_flags;
63 /* Bus Measurements (0x402/0x82) */
67 /* Velocity Measurements (0x403/0x83) */
71 /* Phase Currents (0x404/0x84) */
75 /* Motor Voltages (0x405/0x85) */
76 float voltage_d;
77 float voltage_q;
79 /* Motor Currents (0x406/0x86) */
80 float current_d;
81 float current_q;
83 /* Motor Back EMF (0x407/0x87) */
84 float back_emf_d;
85 float back_emf_q;
87 /* Power Rail (0x408/0x88) */
90 /* Temperature Measurements (0x40B/0x8B) */
92 float motor_temp;
94
95typedef struct {
107
111typedef struct Ws22MotorCanStorage {
115
122
129
136
142StatusCode ws22_motor_can_process_rx(uint8_t *msg_data_u8, uint32_t msg_id_raw, uint8_t msg_dlc);
143
149
155
StatusCode
StatusCodes for various errors.
Definition: status.h:27
StatusCode ws22_motor_can_set_current(float current)
Set motor control current command.
Definition: ws22_motor_can.c:146
StatusCode ws22_motor_can_init(Ws22MotorCanStorage *storage, Ws22MotorCanConfig *config)
Initialize the WS22 motor CAN interface.
Definition: ws22_motor_can.c:135
StatusCode ws22_motor_can_set_velocity(float velocity)
Set motor control velocity command.
Definition: ws22_motor_can.c:155
StatusCode ws22_motor_can_process_rx(uint8_t *msg_data_u8, uint32_t msg_id_raw, uint8_t msg_dlc)
Process received CAN message for motor controller.
Definition: ws22_motor_can.c:164
Ws22MotorControlData * ws22_motor_can_get_control_data(void)
Get current motor control data.
Definition: ws22_motor_can.c:235
Ws22MotorTelemetryData * ws22_motor_can_get_telemetry_data(void)
Get current motor telemetry data.
Definition: ws22_motor_can.c:239
Definition: ws22_motor_can.h:95
bool ws22_bus_measurement_enabled
Definition: ws22_motor_can.h:97
bool ws22_velocity_measurement_enabled
Definition: ws22_motor_can.h:98
bool ws22_drive_cmd_enabled
Definition: ws22_motor_can.h:105
bool ws22_motor_back_emf_enabled
Definition: ws22_motor_can.h:102
bool ws22_motor_voltage_enabled
Definition: ws22_motor_can.h:100
bool ws22_rail_15v_enabled
Definition: ws22_motor_can.h:103
bool ws22_phase_current_enabled
Definition: ws22_motor_can.h:99
bool ws22_temperature_enabled
Definition: ws22_motor_can.h:104
bool ws22_status_info_enabled
Definition: ws22_motor_can.h:96
bool ws22_motor_current_enabled
Definition: ws22_motor_can.h:101
WS22 motor CAN interface storage structure.
Definition: ws22_motor_can.h:111
Ws22MotorControlData control
Definition: ws22_motor_can.h:112
Ws22MotorTelemetryData telemetry
Definition: ws22_motor_can.h:113
Motor control command data structure.
Definition: ws22_motor_can.h:49
float velocity
Definition: ws22_motor_can.h:51
float current
Definition: ws22_motor_can.h:50
Motor status and telemetry data structure.
Definition: ws22_motor_can.h:57
float voltage_d
Definition: ws22_motor_can.h:76
uint16_t limit_flags
Definition: ws22_motor_can.h:60
float phase_b_current
Definition: ws22_motor_can.h:72
float voltage_q
Definition: ws22_motor_can.h:77
float current_d
Definition: ws22_motor_can.h:80
uint16_t merged_flags
Definition: ws22_motor_can.h:61
float back_emf_q
Definition: ws22_motor_can.h:85
float back_emf_d
Definition: ws22_motor_can.h:84
float motor_velocity
Definition: ws22_motor_can.h:69
float phase_c_current
Definition: ws22_motor_can.h:73
float bus_voltage
Definition: ws22_motor_can.h:65
float heat_sink_temp
Definition: ws22_motor_can.h:91
float rail_15v_supply
Definition: ws22_motor_can.h:88
float bus_current
Definition: ws22_motor_can.h:64
float vehicle_velocity_kph
Definition: ws22_motor_can.h:68
float current_q
Definition: ws22_motor_can.h:81
uint16_t error_flags
Definition: ws22_motor_can.h:59
float motor_temp
Definition: ws22_motor_can.h:92