Formula Student Electronics & Software
The code for the embedded software
Loading...
Searching...
No Matches
main.cpp File Reference
#include <Arduino.h>
#include <FlexCAN_T4.h>
#include <math.h>
#include <elapsedMillis.h>
#include <logging.h>
#include "rpm.h"
Include dependency graph for main.cpp:

Go to the source code of this file.

Macros

#define AVG_SAMPLES   20
 
#define BRAKE_LIGHT   2
 
#define BRAKE_LIGHT_LOWER_THRESH   165
 
#define BRAKE_LIGHT_UPPER_THRESH   510
 
#define BRAKE_LIGHT_BRIGHTNESS   150
 
#define BRAKE_LIGHT_MIN_ACTIVE_PERIOD   200
 
#define BRAKE_SENSOR_PIN   A5
 
#define CURRENT_SENSOR_PIN   A4
 
#define RIGHT_WHEEL_ENCODER_PIN   30
 
#define LEFT_WHEEL_ENCODER_PIN   28
 
#define RPM_PUBLISH_PERIOD   5000
 
#define WPS_PULSES_PER_ROTATION   36
 
#define LIMIT_RPM_INTERVAL   500000
 
#define SENSOR_SAMPLE_PERIOD   20
 
#define CAN_BAUD_RATE   500000
 
#define CAN_TRANSMISSION_PERIOD   100
 
#define C1_ID   0x123
 
#define BRAKE_MSG_1ST_BYTE   0x90
 
#define RR_RPM_MSG_1ST_BYTE   0x11
 
#define RL_RPM_MSG_1ST_BYTE   0x12
 
#define LOGGING_PERIOD   10
 
#define BAMO_SPEED   0x30
 
#define BAMO_RPM_MOTOR   0xCE
 
#define BAMO_ACTUAL_CURRENT   0x5f
 
#define BAMO_MOTOR_TEMP   0x49
 
#define BAMO_POWER_STAGE_TEMP   0x4A
 
#define BAMO_MOTOR_VOLTAGE   0x8A
 
#define BAMO_MOTOR_TORQUE   0xA0
 
#define BAMO_DC_VOLTAGE   0xeb
 

Functions

int average (int *buffer, int n)
 
void bufferInsert (int *buffer, int n, int value)
 
void initMessages ()
 
void canbusSniffer (const CAN_message_t &msg)
 
void canbusSetup ()
 
void sendBrakeVal (uint16_t brake_value)
 
bool brakeLightControl (int brake_val)
 
void setup ()
 
void loop ()
 

Variables

uint16_t brake_val = 0
 
elapsedMicros rpm_publisher_timer
 
elapsedMillis canTimer
 
elapsedMillis brake_sensor_timer
 
elapsedMillis brake_light_active_timer
 
elapsedMillis writeTIMER
 
elapsedMillis CURRENTtimer
 
Logging loggingInstance
 
int current = 0
 
int voltage = 0
 
int mintmp = 0
 
int maxtmp = 0
 
int avgtmp = 0
 
int apps1 = 0
 
int apps2 = 0
 
int brake = 0
 
int speed = 0
 
int rpm_max = 0
 
int I_actual = 0
 
int powerStageTemp = 0
 
int motorTemp = 0
 
int lemos = 0
 
int motorTemp2 = 0
 
int powerStageTemp2 = 0
 
int torque = 0
 
int motor_voltage = 0
 
int battery_voltage = 0
 
float rr_rpm
 
float rl_rpm
 
unsigned long last_wheel_pulse_rr
 
unsigned long last_wheel_pulse_rl
 
unsigned long second_to_last_wheel_pulse_rr
 
unsigned long second_to_last_wheel_pulse_rl
 
FlexCAN_T4< CAN1, RX_SIZE_256, TX_SIZE_16 > can1
 
CAN_message_t brake_sensor_c3
 
CAN_message_t rr_rpm_msg
 
CAN_message_t rl_rpm_msg
 
CAN_message_t current_controll
 
int8_t current_byte1
 
int8_t current_byte2
 
CAN_message_t current_message_bamo
 
bool R2D = false
 
int avgBuffer1 [AVG_SAMPLES] = {0}
 

Macro Definition Documentation

◆ AVG_SAMPLES

#define AVG_SAMPLES   20

Definition at line 9 of file main.cpp.

◆ BAMO_ACTUAL_CURRENT

#define BAMO_ACTUAL_CURRENT   0x5f

Definition at line 40 of file main.cpp.

◆ BAMO_DC_VOLTAGE

#define BAMO_DC_VOLTAGE   0xeb

Definition at line 45 of file main.cpp.

◆ BAMO_MOTOR_TEMP

#define BAMO_MOTOR_TEMP   0x49

Definition at line 41 of file main.cpp.

◆ BAMO_MOTOR_TORQUE

#define BAMO_MOTOR_TORQUE   0xA0

Definition at line 44 of file main.cpp.

◆ BAMO_MOTOR_VOLTAGE

#define BAMO_MOTOR_VOLTAGE   0x8A

Definition at line 43 of file main.cpp.

◆ BAMO_POWER_STAGE_TEMP

#define BAMO_POWER_STAGE_TEMP   0x4A

Definition at line 42 of file main.cpp.

◆ BAMO_RPM_MOTOR

#define BAMO_RPM_MOTOR   0xCE

Definition at line 39 of file main.cpp.

◆ BAMO_SPEED

#define BAMO_SPEED   0x30

Definition at line 38 of file main.cpp.

◆ BRAKE_LIGHT

#define BRAKE_LIGHT   2

Definition at line 11 of file main.cpp.

◆ BRAKE_LIGHT_BRIGHTNESS

#define BRAKE_LIGHT_BRIGHTNESS   150

Definition at line 14 of file main.cpp.

◆ BRAKE_LIGHT_LOWER_THRESH

#define BRAKE_LIGHT_LOWER_THRESH   165

Definition at line 12 of file main.cpp.

◆ BRAKE_LIGHT_MIN_ACTIVE_PERIOD

#define BRAKE_LIGHT_MIN_ACTIVE_PERIOD   200

Definition at line 15 of file main.cpp.

◆ BRAKE_LIGHT_UPPER_THRESH

#define BRAKE_LIGHT_UPPER_THRESH   510

Definition at line 13 of file main.cpp.

◆ BRAKE_MSG_1ST_BYTE

#define BRAKE_MSG_1ST_BYTE   0x90

Definition at line 32 of file main.cpp.

◆ BRAKE_SENSOR_PIN

#define BRAKE_SENSOR_PIN   A5

Definition at line 17 of file main.cpp.

◆ C1_ID

#define C1_ID   0x123

Definition at line 30 of file main.cpp.

◆ CAN_BAUD_RATE

#define CAN_BAUD_RATE   500000

Definition at line 27 of file main.cpp.

◆ CAN_TRANSMISSION_PERIOD

#define CAN_TRANSMISSION_PERIOD   100

Definition at line 28 of file main.cpp.

◆ CURRENT_SENSOR_PIN

#define CURRENT_SENSOR_PIN   A4

Definition at line 18 of file main.cpp.

◆ LEFT_WHEEL_ENCODER_PIN

#define LEFT_WHEEL_ENCODER_PIN   28

Definition at line 20 of file main.cpp.

◆ LIMIT_RPM_INTERVAL

#define LIMIT_RPM_INTERVAL   500000

Definition at line 24 of file main.cpp.

◆ LOGGING_PERIOD

#define LOGGING_PERIOD   10

Definition at line 36 of file main.cpp.

◆ RIGHT_WHEEL_ENCODER_PIN

#define RIGHT_WHEEL_ENCODER_PIN   30

Definition at line 19 of file main.cpp.

◆ RL_RPM_MSG_1ST_BYTE

#define RL_RPM_MSG_1ST_BYTE   0x12

Definition at line 34 of file main.cpp.

◆ RPM_PUBLISH_PERIOD

#define RPM_PUBLISH_PERIOD   5000

Definition at line 22 of file main.cpp.

◆ RR_RPM_MSG_1ST_BYTE

#define RR_RPM_MSG_1ST_BYTE   0x11

Definition at line 33 of file main.cpp.

◆ SENSOR_SAMPLE_PERIOD

#define SENSOR_SAMPLE_PERIOD   20

Definition at line 25 of file main.cpp.

◆ WPS_PULSES_PER_ROTATION

#define WPS_PULSES_PER_ROTATION   36

Definition at line 23 of file main.cpp.

Function Documentation

◆ average()

int average ( int *  buffer,
int  n 
)

Definition at line 102 of file main.cpp.

◆ brakeLightControl()

bool brakeLightControl ( int  brake_val)

Definition at line 220 of file main.cpp.

Here is the caller graph for this function:

◆ bufferInsert()

void bufferInsert ( int *  buffer,
int  n,
int  value 
)

Definition at line 112 of file main.cpp.

Here is the caller graph for this function:

◆ canbusSetup()

void canbusSetup ( )

Definition at line 198 of file main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ canbusSniffer()

void canbusSniffer ( const CAN_message_t &  msg)

Definition at line 139 of file main.cpp.

Here is the caller graph for this function:

◆ initMessages()

void initMessages ( )

Definition at line 121 of file main.cpp.

Here is the caller graph for this function:

◆ loop()

void loop ( )

Definition at line 263 of file main.cpp.

Here is the call graph for this function:

◆ sendBrakeVal()

void sendBrakeVal ( uint16_t  brake_value)

Definition at line 212 of file main.cpp.

Here is the caller graph for this function:

◆ setup()

void setup ( )

Definition at line 236 of file main.cpp.

Here is the call graph for this function:

Variable Documentation

◆ apps1

int apps1 = 0

Definition at line 64 of file main.cpp.

◆ apps2

int apps2 = 0

Definition at line 65 of file main.cpp.

◆ avgBuffer1

int avgBuffer1[AVG_SAMPLES] = {0}

Definition at line 100 of file main.cpp.

◆ avgtmp

int avgtmp = 0

Definition at line 63 of file main.cpp.

◆ battery_voltage

int battery_voltage = 0

Definition at line 78 of file main.cpp.

◆ brake

int brake = 0

Definition at line 66 of file main.cpp.

◆ brake_light_active_timer

elapsedMillis brake_light_active_timer

Definition at line 52 of file main.cpp.

◆ brake_sensor_c3

CAN_message_t brake_sensor_c3

Definition at line 89 of file main.cpp.

◆ brake_sensor_timer

elapsedMillis brake_sensor_timer

Definition at line 51 of file main.cpp.

◆ brake_val

uint16_t brake_val = 0

Definition at line 47 of file main.cpp.

◆ can1

FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> can1

Write CSV fields feature example.

Definition at line 87 of file main.cpp.

◆ canTimer

elapsedMillis canTimer

Definition at line 50 of file main.cpp.

◆ current

int current = 0

Definition at line 59 of file main.cpp.

◆ current_byte1

int8_t current_byte1

Definition at line 94 of file main.cpp.

◆ current_byte2

int8_t current_byte2

Definition at line 95 of file main.cpp.

◆ current_controll

CAN_message_t current_controll

Definition at line 92 of file main.cpp.

◆ current_message_bamo

CAN_message_t current_message_bamo

Definition at line 96 of file main.cpp.

◆ CURRENTtimer

elapsedMillis CURRENTtimer

Definition at line 54 of file main.cpp.

◆ I_actual

int I_actual = 0

Definition at line 70 of file main.cpp.

◆ last_wheel_pulse_rl

unsigned long last_wheel_pulse_rl

Definition at line 83 of file main.cpp.

◆ last_wheel_pulse_rr

unsigned long last_wheel_pulse_rr

Definition at line 82 of file main.cpp.

◆ lemos

int lemos = 0

Definition at line 73 of file main.cpp.

◆ loggingInstance

Logging loggingInstance

Definition at line 56 of file main.cpp.

◆ maxtmp

int maxtmp = 0

Definition at line 62 of file main.cpp.

◆ mintmp

int mintmp = 0

Definition at line 61 of file main.cpp.

◆ motor_voltage

int motor_voltage = 0

Definition at line 77 of file main.cpp.

◆ motorTemp

int motorTemp = 0

Definition at line 72 of file main.cpp.

◆ motorTemp2

int motorTemp2 = 0

Definition at line 74 of file main.cpp.

◆ powerStageTemp

int powerStageTemp = 0

Definition at line 71 of file main.cpp.

◆ powerStageTemp2

int powerStageTemp2 = 0

Definition at line 75 of file main.cpp.

◆ R2D

bool R2D = false

Definition at line 98 of file main.cpp.

◆ rl_rpm

float rl_rpm

Definition at line 81 of file main.cpp.

◆ rl_rpm_msg

CAN_message_t rl_rpm_msg

Definition at line 91 of file main.cpp.

◆ rpm_max

int rpm_max = 0

Definition at line 69 of file main.cpp.

◆ rpm_publisher_timer

elapsedMicros rpm_publisher_timer

Definition at line 49 of file main.cpp.

◆ rr_rpm

float rr_rpm

Definition at line 80 of file main.cpp.

◆ rr_rpm_msg

CAN_message_t rr_rpm_msg

Definition at line 90 of file main.cpp.

◆ second_to_last_wheel_pulse_rl

unsigned long second_to_last_wheel_pulse_rl

Definition at line 85 of file main.cpp.

◆ second_to_last_wheel_pulse_rr

unsigned long second_to_last_wheel_pulse_rr

Definition at line 84 of file main.cpp.

◆ speed

int speed = 0

Definition at line 68 of file main.cpp.

◆ torque

int torque = 0

Definition at line 76 of file main.cpp.

◆ voltage

int voltage = 0

Definition at line 60 of file main.cpp.

◆ writeTIMER

elapsedMillis writeTIMER

Definition at line 53 of file main.cpp.