Repository navigation
Expand file tree
/
Copy pathVCU.ino
More file actions
84 lines (74 loc) · 2.49 KB
/
Copy pathVCU.ino
File metadata and controls
84 lines (74 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* @file VCU.ino
* @author Arella Matteo <br/>
* (mail: arella.1646983@studenti.uniroma1.it)
* @date 2018
* @brief Main module file
*/
#include "common.h"
#include "CO_can.h"
#include "can_servizi.h"
#include "model.h"
#include "states.h"
/**
* @mainpage FastChargeSAE VCU firmware
*
* VCU is an embedded system employeed to control the functional operations of the vehicle.
* It takes care of the management of the state of drive according to the @ref FSM_page
* section.
*/
/**
* @defgroup Main_group_module Main module
* @{
*/
/**
* @brief This function perform basic board setup.
* - It starts initializing both CAN funzionale (with inverter) and
* CAN servizi (with the two SCUs and TCS); if the comunication
* between inverter and VCU can't be established via CAN bus
* then the VCU is configured to request torque value to inverter
* by analog signal.
*
* - It initializes board hardware (@ref Board_model_group)
*
* - If the configuration over CAN servizi with the frontal SCU was
* successful then VCU (master) send an NMT request to go in
* 'Operational' state.
*
* @image html setup_activity.svg
* @image latex setup_activity.eps "Setup Activity" width=10cm
*
* @author Arella Matteo <br/>
* (mail: arella.1646983@studenti.uniroma1.it)
*/
void setup() {
volatile uint16_t timeout = 10;
while (!can_init()) // initialize CAN bus baudrate & configure mailboxes
if (timeout--) break;
model_init();
if (can_servizi_online())
can_servizi_go_operational();
}
/**
* @brief This function is called into endless while main loop.
* It takes care of dispatching states of the @ref FSM_page
*
* @author Arella Matteo <br/>
* (mail: arella.1646983@studenti.uniroma1.it)
*/
__attribute__((__inline__))
void loop() {
uint16_t apps_percentage;
Serial.print("CURRENT_STATE: ");
Serial.print(getState());
Serial.print(", SC : ");
Serial.print(get_SC_value());
Serial.print(", RTD = ");
Serial.print(digitalRead(RTDB));
apps_percentage = (get_tps1_percentage() + get_tps2_percentage()) / 2;
Serial.print(", APPS: "); Serial.print(apps_percentage); Serial.print(" BRAKE: "); Serial.println(get_brake_percentage());
state_dispatch();
}
/**
* @}
*/