-
Notifications
You must be signed in to change notification settings - Fork 1
/
Pedals.cpp
60 lines (54 loc) · 1.37 KB
/
Pedals.cpp
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
#include "Pedals.h"
Pedals::Pedals(){
throttleVal = 0;
brakeVal = 0;
}
//Pedals::~Pedals(){}
float Pedals::getThrottle(){
checkWatchdog();
return throttleVal;
}
float Pedals::getBrake(){
checkWatchdog();
return brakeVal;
}
bool Pedals::getReverse(){
checkWatchdog();
return reverse;
}
bool Pedals::getSDfront(){
checkWatchdog();
return SDfront;
}
bool Pedals::getSDrear(){
checkWatchdog();
return SDrear;
}
bool Pedals::getEstop(){
checkWatchdog();
return Estop;
}
bool Pedals::processMessage(CAN_message_t &message){
patWatchdog();
throttleVal = message.buf[0]/255.0;
brakeVal = message.buf[1]/255.0;
reverse = (((1<<reverseSwBit) & (message.buf[2]))!=0);
SDfront = (((1<<frontSDBit) & (message.buf[2]))!=0);
SDrear = (((1<<rearSDBit) & (message.buf[2]))!=0);
Estop = (((1<<estopBit) & (message.buf[2]))!=0);
brakesOK = (((1<<brakeWarnBit) & (message.buf[2]))!=0);
throttleOK = (((1<<throttleWarnBit) & (message.buf[2]))!=0);
return true;
}
void Pedals::patWatchdog(){
watchdogTimer = micros(); //pat the watchdog
}
bool Pedals::checkWatchdog(){
if(micros() - watchdogTimer >= watchdogPeriod){
//we haven't had an update in too long.
throttleVal = 0;
brakeVal = 0;
return false; //timed out
}
return true;
}