-
Notifications
You must be signed in to change notification settings - Fork 634
/
Copy pathDoubleSolenoidSim.cpp
76 lines (60 loc) · 2.22 KB
/
DoubleSolenoidSim.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
72
73
74
75
76
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/simulation/DoubleSolenoidSim.h"
#include <memory>
#include <utility>
#include "frc/DoubleSolenoid.h"
#include "frc/PneumaticsBase.h"
using namespace frc;
using namespace frc::sim;
DoubleSolenoidSim::DoubleSolenoidSim(
std::shared_ptr<PneumaticsBaseSim> moduleSim, int fwd, int rev)
: m_module{std::move(moduleSim)}, m_fwd{fwd}, m_rev{rev} {}
DoubleSolenoidSim::DoubleSolenoidSim(int module, PneumaticsModuleType type,
int fwd, int rev)
: m_module{PneumaticsBaseSim::GetForType(module, type)},
m_fwd{fwd},
m_rev{rev} {}
DoubleSolenoidSim::DoubleSolenoidSim(PneumaticsModuleType type, int fwd,
int rev)
: m_module{PneumaticsBaseSim::GetForType(
PneumaticsBase::GetDefaultForType(type), type)},
m_fwd{fwd},
m_rev{rev} {}
DoubleSolenoid::Value DoubleSolenoidSim::Get() const {
bool fwdState = m_module->GetSolenoidOutput(m_fwd);
bool revState = m_module->GetSolenoidOutput(m_rev);
if (fwdState && !revState) {
return DoubleSolenoid::Value::kForward;
} else if (!fwdState && revState) {
return DoubleSolenoid::Value::kReverse;
} else {
return DoubleSolenoid::Value::kOff;
}
}
void DoubleSolenoidSim::Set(DoubleSolenoid::Value output) {
m_module->SetSolenoidOutput(m_fwd, output == DoubleSolenoid::Value::kForward);
m_module->SetSolenoidOutput(m_rev, output == DoubleSolenoid::Value::kReverse);
}
bool DoubleSolenoidSim::IsForward() {
return Get() == DoubleSolenoid::Value::kForward;
}
bool DoubleSolenoidSim::IsReverse() {
return Get() == DoubleSolenoid::Value::kReverse;
}
bool DoubleSolenoidSim::IsOff() {
return Get() == DoubleSolenoid::Value::kOff;
}
void DoubleSolenoidSim::SetForward() {
Set(DoubleSolenoid::Value::kForward);
}
void DoubleSolenoidSim::SetReverse() {
Set(DoubleSolenoid::Value::kReverse);
}
void DoubleSolenoidSim::SetOff() {
Set(DoubleSolenoid::Value::kOff);
}
std::shared_ptr<PneumaticsBaseSim> DoubleSolenoidSim::GetModuleSim() const {
return m_module;
}