4#include <elapsedMillis.h>
12#define BRAKE_LIGHT_LOWER_THRESH 165
13#define BRAKE_LIGHT_UPPER_THRESH 510
14#define BRAKE_LIGHT_BRIGHTNESS 150
15#define BRAKE_LIGHT_MIN_ACTIVE_PERIOD 200
17#define BRAKE_SENSOR_PIN A5
18#define CURRENT_SENSOR_PIN A4
19#define RIGHT_WHEEL_ENCODER_PIN 30
20#define LEFT_WHEEL_ENCODER_PIN 28
22#define RPM_PUBLISH_PERIOD 5000
23#define WPS_PULSES_PER_ROTATION 36
24#define LIMIT_RPM_INTERVAL 500000
25#define SENSOR_SAMPLE_PERIOD 20
27#define CAN_BAUD_RATE 500000
28#define CAN_TRANSMISSION_PERIOD 100
32#define BRAKE_MSG_1ST_BYTE 0x90
33#define RR_RPM_MSG_1ST_BYTE 0x11
34#define RL_RPM_MSG_1ST_BYTE 0x12
36#define LOGGING_PERIOD 10
38#define BAMO_SPEED 0x30
39#define BAMO_RPM_MOTOR 0xCE
40#define BAMO_ACTUAL_CURRENT 0x5f
41#define BAMO_MOTOR_TEMP 0x49
42#define BAMO_POWER_STAGE_TEMP 0x4A
43#define BAMO_MOTOR_VOLTAGE 0x8A
44#define BAMO_MOTOR_TORQUE 0xA0
45#define BAMO_DC_VOLTAGE 0xeb
87FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16>
can1;
105 for (
int i = 0; i < n; i++)
114 for (
int i = 0; i < n - 1; i++)
116 buffer[i] = buffer[i + 1];
118 buffer[n - 1] = value;
142 Serial.println(
"CAN message received");
143 Serial.print(
"Message ID: ");
144 Serial.println(
msg.id, HEX);
201 can1.setBaudRate(500000);
203 can1.enableFIFOInterrupt();
204 can1.setFIFOFilter(REJECT_ALL);
205 can1.setFIFOFilter(0, 0x111, STD);
273 Serial.print(
"Reading Brake line:");
279 Serial.println(
"Brake Light ON");
292 Serial.print(
"Publishing RR RPM: ");
294 Serial.print(
"Publishing RL RPM: ");
321 loggingInstance.
write_to_file(
current,
voltage,
mintmp,
maxtmp,
avgtmp,
apps1,
apps2,
brake,
speed,
I_actual,
powerStageTemp,
motorTemp,
torque,
motor_voltage,
battery_voltage);
void loop()
AMI main loop: Button gets picked and lights up the corresponding LED LAST BUTTON CHECKED WINS.
#define BRAKE_LIGHT_UPPER_THRESH
#define BAMO_POWER_STAGE_TEMP
bool brakeLightControl(int brake_val)
elapsedMicros rpm_publisher_timer
unsigned long last_wheel_pulse_rl
#define LEFT_WHEEL_ENCODER_PIN
void bufferInsert(int *buffer, int n, int value)
unsigned long second_to_last_wheel_pulse_rl
void canbusSniffer(const CAN_message_t &msg)
#define RL_RPM_MSG_1ST_BYTE
CAN_message_t brake_sensor_c3
#define WPS_PULSES_PER_ROTATION
CAN_message_t current_controll
#define BRAKE_LIGHT_MIN_ACTIVE_PERIOD
void sendBrakeVal(uint16_t brake_value)
#define BAMO_MOTOR_VOLTAGE
CAN_message_t current_message_bamo
#define BAMO_ACTUAL_CURRENT
elapsedMillis brake_sensor_timer
unsigned long second_to_last_wheel_pulse_rr
elapsedMillis brake_light_active_timer
#define SENSOR_SAMPLE_PERIOD
#define BRAKE_MSG_1ST_BYTE
#define CAN_TRANSMISSION_PERIOD
#define BAMO_MOTOR_TORQUE
elapsedMillis CURRENTtimer
#define LIMIT_RPM_INTERVAL
unsigned long last_wheel_pulse_rr
#define BRAKE_LIGHT_BRIGHTNESS
#define RPM_PUBLISH_PERIOD
#define BRAKE_LIGHT_LOWER_THRESH
#define RR_RPM_MSG_1ST_BYTE
#define RIGHT_WHEEL_ENCODER_PIN
FlexCAN_T4< CAN1, RX_SIZE_256, TX_SIZE_16 > can1
int avgBuffer1[AVG_SAMPLES]
void write_to_file(int current, int voltage, int mintmp, int maxtmp, int avgtmp, int apps1, int apps2, int brake, int rpm, int I_actual, int powerStageTmp, int motorTmp, int Torque, int motor_voltage, int battery_voltage)
void rpm_2_byte(float rr_rpm, char *rr_rpm_byte)