Formula Student Electronics & Software
The code for the embedded software
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1
#include "
model/systemData.hpp
"
2
#include "
comm/communicator.hpp
"
3
#include "
embedded/digitalReceiver.hpp
"
4
#include "
embedded/digitalSender.hpp
"
5
#include "
logic/stateLogic.hpp
"
6
#include "
timings.hpp
"
7
#include "
debugUtils.hpp
"
8
9
SystemData
systemData
;
// Model
10
Communicator
communicator
=
Communicator
(&
systemData
);
// CAN
11
DigitalReceiver
digitalReceiver
=
DigitalReceiver
(&
systemData
.
digitalData
, &
systemData
.
mission
);
// Digital inputs
12
DigitalSender
digitalSender
=
DigitalSender
();
// Digital outputs
13
ASState
as_state
=
ASState
(&
systemData
, &
communicator
, &
digitalSender
);
14
15
Metro
rl_rpm_timer
=
Metro
{
LEFT_WHEEL_PUBLISH_INTERVAL
};
16
Metro
mission_timer
=
Metro
(
MISSION_PUBLISH_INTERVAL
);
17
Metro
state_timer
=
Metro
(
STATE_PUBLISH_INTERVAL
);
18
IntervalTimer
state_calculation_timer
;
19
20
void
setup
() {
21
Serial.begin(9600);
22
DEBUG_PRINT
(
"Starting up..."
);
23
Communicator::_systemData
= &
systemData
;
24
communicator
.
init
();
25
// state_calculation_timer.begin([]() {
26
// noInterrupts();
27
// digitalReceiver.digitalReads();
28
// as_state.calculateState();
29
// interrupts();
30
// }, STATE_CALCULATION_INTERVAL); // Ensuring 50ms intervals beween state calculations
31
32
rl_rpm_timer
.
reset
();
33
mission_timer
.
reset
();
34
state_timer
.
reset
();
35
}
36
37
void
loop
() {
38
digitalReceiver
.
digitalReads
();
39
as_state
.
calculateState
();
40
41
if
(
mission_timer
.
check
()) {
42
Communicator::publish_mission
(
systemData
.
mission
);
43
mission_timer
.
reset
();
44
}
45
if
(
state_timer
.
check
()) {
46
Communicator::publish_state
(
as_state
.
state
);
47
state_timer
.
reset
();
48
}
49
}
ASState
The ASState class manages and transitions between different states of the vehicle system.
Definition
stateLogic.hpp:14
ASState::calculateState
void calculateState()
Calculates the state of the vehicle.
Definition
stateLogic.hpp:39
ASState::state
State state
Current state of the vehicle system, initialized to OFF.
Definition
stateLogic.hpp:21
Communicator
Class that contains definitions of typical messages to send via CAN It serves only as an example of t...
Definition
communicator.hpp:40
Communicator::publish_mission
static int publish_mission(int mission_id)
Publish AS Mission to CAN.
Definition
communicator.hpp:289
Communicator::init
void init()
Initializes the CAN bus.
Definition
communicator.hpp:127
Communicator::_systemData
static SystemData * _systemData
Definition
communicator.hpp:47
Communicator::publish_state
static int publish_state(int state_id)
Publish AS State to CAN.
Definition
communicator.hpp:281
DigitalReceiver
Class responsible for the reading of the digital inputs into the Master teensy.
Definition
digitalReceiver.hpp:15
DigitalReceiver::digitalReads
void digitalReads()
read all digital inputs
Definition
digitalReceiver.hpp:106
DigitalSender
Class responsible for controlling digital outputs in the Master Teensy.
Definition
digitalSender.hpp:14
Metro
Our own implementation of Metro class.
Definition
metro.h:13
Metro::reset
void reset()
Resets the timer to the current time.
Definition
metro.h:125
Metro::check
bool check()
Checks if the interval has passed and resets the timer if true.
Definition
metro.h:91
communicator.hpp
debugUtils.hpp
DEBUG_PRINT
#define DEBUG_PRINT(str)
Definition
debugUtils.hpp:30
digitalReceiver.hpp
digitalSender.hpp
mission_timer
Metro mission_timer
Definition
main.cpp:16
communicator
Communicator communicator
Definition
main.cpp:10
as_state
ASState as_state
Definition
main.cpp:13
setup
void setup()
Definition
main.cpp:20
digitalSender
DigitalSender digitalSender
Definition
main.cpp:12
rl_rpm_timer
Metro rl_rpm_timer
Definition
main.cpp:15
digitalReceiver
DigitalReceiver digitalReceiver
Definition
main.cpp:11
state_timer
Metro state_timer
Definition
main.cpp:17
systemData
SystemData systemData
Definition
main.cpp:9
state_calculation_timer
IntervalTimer state_calculation_timer
Definition
main.cpp:18
loop
void loop()
Definition
main.cpp:37
stateLogic.hpp
SystemData
The whole model of the system: holds all the data necessary.
Definition
systemData.hpp:12
SystemData::digitalData
DigitalData digitalData
Definition
systemData.hpp:17
SystemData::mission
Mission mission
Definition
systemData.hpp:18
systemData.hpp
timings.hpp
MISSION_PUBLISH_INTERVAL
constexpr auto MISSION_PUBLISH_INTERVAL
Definition
timings.hpp:6
LEFT_WHEEL_PUBLISH_INTERVAL
constexpr auto LEFT_WHEEL_PUBLISH_INTERVAL
Definition
timings.hpp:4
STATE_PUBLISH_INTERVAL
constexpr auto STATE_PUBLISH_INTERVAL
Definition
timings.hpp:5
master
src
main.cpp
Generated by
1.9.8