-
Notifications
You must be signed in to change notification settings - Fork 0
/
DriveBase.cpp
61 lines (47 loc) · 1.65 KB
/
DriveBase.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
#include "WPILib.h"
#include "DriveBase.h"
#include "Constants.h"
DriveBase* DriveBase::m_instance = NULL;
DriveBase* DriveBase::GetInstance() {
if (m_instance == NULL) {
m_instance = new DriveBase();
}
return m_instance;
}
DriveBase::DriveBase() {
m_controls = Controls::GetInstance();
// Remember to change these to Talons
m_leftDrive = new Victor(LEFT_DRIVE_PWM);
m_rightDrive = new Victor(RIGHT_DRIVE_PWM);
m_leftEncoder = new Encoder(LEFT_ENCODER_A, LEFT_ENCODER_B);
m_rightEncoder = new Encoder(RIGHT_ENCODER_A, RIGHT_ENCODER_B, true);
m_leftEncoder->SetDistancePerPulse(INCHES_PER_COUNT);
m_rightEncoder->SetDistancePerPulse(INCHES_PER_COUNT);
m_leftEncoderController = new PIDController(0.0, 0.0, 0.0, m_leftEncoder, m_leftDrive);
m_rightEncoderController = new PIDController(0.0, 0.0, 0.0, m_rightEncoder, m_rightDrive);
LiveWindow* liveWindow = LiveWindow::GetInstance();
liveWindow->AddComponent("Left Drive", "Left Encoder", m_leftEncoderController);
liveWindow->AddComponent("Right Drive", "Right Encoder", m_rightEncoderController);
}
void DriveBase::EnableTeleopControls() {
m_leftDrive->Set(m_controls->GetLeftY());
m_rightDrive->Set(m_controls->GetRightY());
}
int DriveBase::GetLeftEncoderCount() {
m_leftEncoder->Start();
return m_leftEncoder->Get();
}
int DriveBase::GetRightEncoderCount() {
m_rightEncoder->Start();
return m_rightEncoder->Get();
}
void DriveBase::ResetEncoders() {
m_leftEncoder->Reset();
m_rightEncoder->Reset();
}
PIDController* DriveBase::GetLeftEncoderController() {
return m_leftEncoderController;
}
PIDController* DriveBase::GetRightEncoderController() {
return m_rightEncoderController;
}