SAE Teensy ECU
IIT SAE Microcontroller programming
Loading...
Searching...
No Matches
libraries/Test/front.cpp
1#include "Log.h"
2#include "Pins.h"
3#include "SerialCommand.h"
4#include "WProgram.h"
5#include "test.h"
6
7static LOG_TAG ID = "Front Teensy";
8
9void full_front_test() {
10 static elapsedMillis timeElapsedHigh;
11 static elapsedMillis timeElapsedMidHigh;
12 static elapsedMillis timeElapsedMidLow;
13 static elapsedMillis timeElapsedLow;
14
15 while (true) {
16 if (timeElapsedHigh >= 20) { // High priority updates
18 timeElapsedHigh = 0;
19 static uint32_t speed = 300;
20 static bool direction = true;
21 if (speed < 50)
22 direction = false;
23 else if (speed > 250)
24 direction = true;
25 speed += (direction ? -1 : 1) * random(10);
26 Log(ID, "Current Motor Speed:", speed);
27 }
28 if (timeElapsedMidHigh >= 200) { // MedHigh priority updates
29 timeElapsedMidHigh = 0;
30 Log(ID, "Current State", 0, 500);
31 }
32 if (timeElapsedMidLow >= 500) { // MedLow priority updates
33 timeElapsedMidLow = 0;
34 static bool on = random(100) > 50;
35 Log(ID, "Start Light", on);
36 }
37 if (timeElapsedLow >= 800) { // Low priority updates
38 timeElapsedLow = 0;
39
40 // Motor controllers
41 Log(ID, "MC0 DC BUS Voltage:", random(200));
42 Log(ID, "MC1 DC BUS Voltage:", random(200));
43 Log(ID, "MC0 DC BUS Current:", random(200));
44 Log(ID, "MC1 DC BUS Current:", random(200));
45 Log(ID, "MC0 Board Temp:", random(200));
46 Log(ID, "MC1 Board Temp:", random(200));
47 Log(ID, "MC0 Motor Temp:", random(200));
48 Log(ID, "MC1 Motor Temp:", random(200));
49 Log(ID, "MC Current Power:", random(200));
50
51 // BMS
52 Log(ID, "BMS State Of Charge:", random(100));
53 Log(ID, "BMS Immediate Voltage:", random(200));
54 Log(ID, "BMS Pack Average Current:", random(200));
55 Log(ID, "BMS Pack Highest Temp:", random(200));
56 Log(ID, "BMS Pack Lowest Temp:", random(200));
57 Log(ID, "BMS Discharge current limit:", random(200));
58 Log(ID, "BMS Charge current limit:", random(200));
59
60 // General
61 Log(ID, "Fault State", random(100) > 50);
62 }
63 }
64}
Special logging functionality.
const char * LOG_TAG
Type definition of logging tags This typedef is necessary to allow for easier manipulation of code by...
Definition Log.h:48
Logging::Log_t Log
The global logging object.
Update, set, and get predefined pin values.
SerialCommand functionality.
Basic functions used for testing.
int receiveCommand(void)
receive any command from serial by matching incoming bytes to a callback