-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathPneumatics.cpp
executable file
·71 lines (65 loc) · 1.79 KB
/
Pneumatics.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
61
62
63
64
65
66
67
68
69
70
71
#include <vector>
#include <IterativeRobot.h>
#include <DigitalInput.h>
#include <Relay.h>
#include <Timer.h>
#include <DoubleSolenoid.h>
#include "Pneumatics.h"
#include "DriveTrain.h"
#include "612.h"
#include "main.h"
Pneumatics::Pneumatics(main_robot* r,
uint8_t digitalMod, uint32_t digitalChannel,
uint8_t compModuleNumber, uint32_t compChannel)
{
robot = r;
switchObject = new DigitalInput(digitalMod, digitalChannel);
compressor = new Relay(compModuleNumber, compChannel, Relay::kForwardOnly);
robot -> update -> addFunctions(&updateHelper, (void*) this);
}
void Pneumatics::checkPressure()
{
if(switchObject->Get() == 1)
{
compressor->Set(Relay::kOff);
}
else
{
compressor->Set(Relay::kForward);
}
}
void Pneumatics::updateSolenoid()
{
//This function checks if the solenoid has expired
for(unsigned int i = 0; i < time.size();)
{
Timer* timerObj = timerObject[i];
if(timerObj->Get() >= time[i])
{
delete timerObj;
solenoid[i]->Set(DoubleSolenoid::kOff);
solenoid.erase(solenoid.begin()+i);
time.erase(time.begin()+i);
timerObject.erase(timerObject.begin()+i);
}
else
{
i++;
}
}
}
void Pneumatics::setVectorValues(double timerValue, DoubleSolenoid* startSolenoid, DoubleSolenoid::Value value)
{
Timer* solenoidTimer = new Timer();
time.push_back(timerValue);
timerObject.push_back(solenoidTimer);
solenoid.push_back(startSolenoid);
startSolenoid->Set(value);
solenoidTimer->Start();
}
void Pneumatics::updateHelper(void* instName)
{
Pneumatics* pnumObj = (Pneumatics*)instName;
pnumObj -> checkPressure();
pnumObj -> updateSolenoid();
}