-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrive.cpp
114 lines (97 loc) · 3.04 KB
/
Drive.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "Subsystem.h"
#include "WPIObjMgr.h"
#include "Config.h"
#include <math.h>
#include <iostream>
class Drive : public Spyder::Subsystem
{
private:
//demo comment
Spyder::TwoIntConfig leftJoystick;
Spyder::TwoIntConfig rightJoystick;
Spyder::ConfigVar<UINT32> leftMotor;
Spyder::ConfigVar<UINT32> rightMotor;
Spyder::ConfigVar<bool> leftMotorInv;
Spyder::ConfigVar<bool> rightMotorInv;
Spyder::TwoIntConfig halfSpeed;
bool reversed;
bool lastRevBtnVal;
Spyder::TwoIntConfig reverseBtn;
Spyder::ConfigVar<float> curvature;
public:
Drive() : Spyder::Subsystem("Drive"), leftJoystick("bind_leftDrive", 1, 2),
rightJoystick("bind_rightDrive", 2, 2), leftMotor("leftDriveMotor", 2),
rightMotor("rightDriveMotor", 1), leftMotorInv("leftDriveInverted", true),
rightMotorInv("rightDriveInverted", false), halfSpeed("bind_halfSpeedDrive", 1, 1),
reversed(false), lastRevBtnVal(false), reverseBtn("bind_driveReverse", 2, 3),
curvature("drive_controlCurvature", 0.351563f)
{
}
virtual ~Drive()
{
}
virtual void Init(Spyder::RunModes runmode)
{
}
virtual void Periodic(Spyder::RunModes runmode)
{
float curve = 0.0f;
float right = 0.0f;
float left = 0.0f;
Joystick *leftJoy = Spyder::GetJoystick(leftJoystick.GetVar(1));
Joystick *rightJoy = Spyder::GetJoystick(rightJoystick.GetVar(1));
switch(runmode)
{
case Spyder::M_DISABLED:
Spyder::GetVictor(leftMotor.GetVal())->Set(0);
Spyder::GetVictor(rightMotor.GetVal())->Set(0);
break;
case Spyder::M_TELEOP:
//Joystick *leftJoy = Spyder::GetJoystick(leftJoystick.GetVar(1));
//Joystick *rightJoy = Spyder::GetJoystick(rightJoystick.GetVar(1));
left = leftJoy->GetRawAxis(leftJoystick.GetVar(2));
right = rightJoy->GetRawAxis(rightJoystick.GetVar(2));
left = fabs(left) > Spyder::GetDeadzone() ? left : 0;
right = fabs(right) > Spyder::GetDeadzone() ? right : 0;
curve = curvature.GetVal();
left = ((left*left*left)*curve) + (left*(1.f-curve));
right = ((right*right*right)*curve) + (right*(1.f-curve));
if(leftMotorInv.GetVal())
{
left *= -1;
}
if(rightMotorInv.GetVal())
{
right*= -1;
}
if(Spyder::GetJoystick(halfSpeed.GetVar(1))->GetRawButton(halfSpeed.GetVar(2)))
{
left /= 2.f;
right /= 2.f;
}
if(Spyder::GetJoystick(reverseBtn.GetVar(1))->GetRawButton(reverseBtn.GetVar(2)) && !lastRevBtnVal)
{
lastRevBtnVal = true;
reversed = !reversed;
}
lastRevBtnVal = Spyder::GetJoystick(reverseBtn.GetVar(1))->GetRawButton(reverseBtn.GetVar(2));
if(reversed)
{
float temp = left;
left = right;
right = temp;
}
Spyder::GetVictor(leftMotor.GetVal())->Set(left);
Spyder::GetVictor(rightMotor.GetVal())->Set(right);
break;
default:
Spyder::GetVictor(leftMotor.GetVal())->Set(0);
Spyder::GetVictor(rightMotor.GetVal())->Set(0);
break;
};
}
virtual void RobotInit()
{
}
};
Drive drive;