-
Notifications
You must be signed in to change notification settings - Fork 0
/
Robot.cpp
133 lines (107 loc) · 3.64 KB
/
Robot.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include <iostream>
#include <string>
#include "WPILib.h"
#include <LiveWindow/LiveWindow.h>
#include <SmartDashboard/SendableChooser.h>
#include <SmartDashboard/SmartDashboard.h>
class Robot : public frc::IterativeRobot {
public:
// drive train
frc::Spark leftMots{0};
frc::Spark rightMots{1};
frc::Spark armMot{3};
frc::DifferentialDrive drive{leftMots, rightMots};
// gyro
ADXRS450_Gyro gyro; // get angles and stuff
// xbox controller
frc::Joystick xbox{0};
// pneumatics
frc::DoubleSolenoid dumper{0, 1};
// autonomous chooser code
frc::LiveWindow& lw = *LiveWindow::GetInstance();
frc::SendableChooser<std::string> autoChooser;
const std::string autoNameDefault = "Default";
const std::string autoDriveStraight = "drive straight";
std::string autoSelected;
void RobotInit() {
autoChooser.AddDefault(autoNameDefault, autoNameDefault);
autoChooser.AddObject(autoDriveStraight, autoDriveStraight);
frc::SmartDashboard::PutData("Auto Modes", &autoChooser);
}
/*
* This autonomous (along with the chooser code above) shows how to
* select
* between different autonomous modes using the dashboard. The sendable
* chooser code works with the Java SmartDashboard. If you prefer the
* LabVIEW Dashboard, remove all of the chooser code and uncomment the
* GetString line to get the auto name from the text box below the Gyro.
*
* You can add additional auto modes by adding additional comparisons to
* the
* if-else structure below with additional strings. If using the
* SendableChooser make sure to add them to the chooser code above as
* well.
*/
void AutonomousInit() override {
autoSelected = autoChooser.GetSelected();
// m_autoSelected = SmartDashboard::GetString(
// "Auto Selector", kAutoNameDefault);
std::cout << "Auto selected: " << autoSelected << std::endl;
if (autoSelected == autoDriveStraight) {
const double TURNINGCONST = 0.03;
gyro.Reset();
double offset = gyro.GetAngle();
for (int i = 0; i < 160; i++){
Wait (0.05 / 4);
drive.ArcadeDrive(-.5, (offset - gyro.GetAngle()) * TURNINGCONST);
}
drive.ArcadeDrive(0,0);
} else {
// do nothing
}
}
void AutonomousPeriodic() {
if (autoSelected == autoDriveStraight) {
// Custom Auto goes here
} else {
// Default Auto goes here
}
}
void TeleopInit() {}
void TeleopPeriodic() {
// make it so we can switch directions with button 3
static bool switchable = true;
static float direction = 1;
if (switchable && xbox.GetRawButton(3)) {
switchable = false;
direction = -direction;
} else if(!switchable && !xbox.GetRawButton(3))
switchable = true;
// drive based on controller input
drive.ArcadeDrive(direction * xbox.GetRawAxis(1), xbox.GetRawAxis(4) * 0.8);
// control pneumatics
if (xbox.GetRawButton(1)) {
dumper.Set(frc::DoubleSolenoid::kForward);
} else if (xbox.GetRawButton(2)) {
dumper.Set(frc::DoubleSolenoid::kReverse);
} else {
dumper.Set(frc::DoubleSolenoid::kOff);
}
// Control front arm motor
if (xbox.GetRawButton(5)) {
armMot.Set(1);
} else if (xbox.GetRawButton(6)) {
armMot.Set(-1);
} else {
armMot.Set(0);
}
}
void TestPeriodic() {}
};
START_ROBOT_CLASS(Robot)