Midnight Sun Firmware
Loading...
Searching...
No Matches
motor_can.h
1#pragma once
2
3/************************************************************************************************
4 * @file motor_can.h
5 *
6 * @brief Header file for Motor controller CAN
7 *
8 * @date 2025-01-30
9 * @author Midnight Sun Team #24 - MSXVI
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <stdint.h>
14
15/* Inter-component Headers */
16#include "global_enums.h"
17
18/* Intra-component Headers */
19
26#define CURRENT_SCALE 100
27#define VOLTAGE_SCALE 100
28#define VELOCITY_SCALE 100
29#define TEMP_SCALE 100
30
31// also used as the current for regen braking, might need to be seperated
32#define ACCERLATION_FORCE 1
33#define CRUISE_THROTTLE_THRESHOLD 0
34#define TORQUE_CONTROL_VEL 20000 // unobtainable rpm for current control
35
36#define MATH_PI 3.14
37#define WHEEL_DIAMETER 0.57147
38#define VEL_TO_RPM_RATIO (60 / (2 * MATH_PI) * WHEEL_DIAMETER) // TODO: set actual ratio, m/s to motor (rpm for m/s)
39#define CONVERT_VELOCITY_TO_KPH 13234
40// wheel diameter 557mm
41// 1000 / (557 * pi) = 0.57147
42
43#define DRIVER_CONTROL_BASE 0x500
44#define MOTOR_CONTROLLER_BASE_L 0x400
45#define MOTOR_CONTROLLER_BASE_R 0x80 // TODO: set to actual values
46
47typedef enum MotorControllerMessageIds {
48 IDENTIFICATION = 0,
49 STATUS,
50 BUS_MEASUREMENT,
51 VEL_MEASUREMENT,
52 PHASE_CURRENT,
53 MOTOR_VOLTAGE,
54 MOTOR_CURRENT,
55 MOTOR_BACK_EMF,
56 RAIL_15V,
57 RAIL_3V_9V,
58 RESERVED,
59 HEAT_SINK_MOTOR_TEMP,
60 DSP_BOARD_TEMP,
61 RESERVED_2,
62 ODOMETER_BUS_AMPHOUR,
63 SLIP_SPEED = 0x17,
64} MotorControllerMessageIds;
65
66void init_motor_controller_can();
67float prv_get_float(uint32_t u);
68float clamp_float(float value);
69void prv_update_target_current_velocity();
70