-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobot.java
More file actions
executable file
·152 lines (128 loc) · 3.71 KB
/
Robot.java
File metadata and controls
executable file
·152 lines (128 loc) · 3.71 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package org.usfirst.frc.team3238.robot;
import java.util.ArrayList;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Talon;
/**
* Crab drive uses 2 sets of Wheels(Mecanum Drive, High Traction) Pnuematics can
* cycle between the two different drives
*
* @author Nick Sorensen
*/
public class Robot extends IterativeRobot
{
Autonomous autonomous;
Chassis chassis;
Talon leftFrontTalon, rightFrontTalon, leftRearTalon, rightRearTalon;
Joystick joystickZero;
Encoder leftFront, rightFront;
DoubleSolenoid frontSolenoid, backSolenoid;
ArrayList<String> fileContents;
public void robotInit()
{
final int CHASSISLEFTFRONTTALONID = 3;
final int CHASSISLEFTREARTALONID = 2;
final int CHASSISRIGHTFRONTTALONID = 1;
final int CHASSISRIGHTREARTALONID = 0;
final int JOYSTICKPORT = 0;
final int LEFTFRONTENCODERA = 3;
final int LEFTFRONTENCODERB = 2;
final int RIGHTFRONTENCODERA = 0;
final int RIGHTFRONTENCODERB = 1;
final int FRONTUPSOLENOID = 2;
final int FRONTDOWNSOLENOID = 0;
final int BACKUPSOLENOID = 3;
final int BACKDOWNSOLENOID = 1;
joystickZero = new Joystick(JOYSTICKPORT);
leftFrontTalon = new Talon(CHASSISLEFTFRONTTALONID);
rightFrontTalon = new Talon(CHASSISRIGHTFRONTTALONID);
leftRearTalon = new Talon(CHASSISLEFTREARTALONID);
rightRearTalon = new Talon(CHASSISRIGHTREARTALONID);
frontSolenoid = new DoubleSolenoid(FRONTUPSOLENOID, FRONTDOWNSOLENOID);
backSolenoid = new DoubleSolenoid(BACKUPSOLENOID, BACKDOWNSOLENOID);
leftFront = new Encoder(LEFTFRONTENCODERA, LEFTFRONTENCODERB);
rightFront = new Encoder(RIGHTFRONTENCODERA, RIGHTFRONTENCODERB);
chassis = new Chassis(leftFrontTalon, leftRearTalon, rightFrontTalon, rightRearTalon);
autonomous = new Autonomous(chassis);
}
public void autonomousInit()
{
autonomous.init();
leftFront.reset();
rightFront.reset();
}
public void autonomousPeriodic()
{
autonomous.idle(chassis, frontSolenoid, backSolenoid, leftFront, rightFront);
chassis.idle();
}
public void teleopPeriodic()
{
System.out.println("Right " + rightFront.get() + " Left: " + leftFront.get());
if (joystickZero.getRawButton(1))
{
frontSolenoid.set(DoubleSolenoid.Value.kForward);
backSolenoid.set(DoubleSolenoid.Value.kForward);
}
else if (joystickZero.getRawButton(2))
{
frontSolenoid.set(DoubleSolenoid.Value.kReverse);
backSolenoid.set(DoubleSolenoid.Value.kReverse);
}
else if (joystickZero.getRawButton(3))
{
frontSolenoid.set(DoubleSolenoid.Value.kForward);
backSolenoid.set(DoubleSolenoid.Value.kReverse);
}
else if (joystickZero.getRawButton(4))
{
frontSolenoid.set(DoubleSolenoid.Value.kReverse);
backSolenoid.set(DoubleSolenoid.Value.kForward);
}
else
{
frontSolenoid.set(DoubleSolenoid.Value.kOff);
backSolenoid.set(DoubleSolenoid.Value.kOff);
}
double x = joystickZero.getX();
double y = joystickZero.getY();
double twist = joystickZero.getTwist();
double deadzone = 0.15;
if (twist < 0)
{
if (twist > -deadzone)
{
twist = 0;
}
else
{
twist += deadzone;
twist = twist * (1 / (1 - deadzone));
}
}
else
{
if (twist < deadzone)
{
twist = 0;
}
else
{
twist -= deadzone;
twist = twist * (1 / (1 - deadzone));
}
}
/*
* Maps the value of the joystick using the current position of the
* throttle slider for safety and ease of driver control.
*/
double throttleMapping = Math.abs((joystickZero.getThrottle() - 1));
chassis.setJoystickData(x * throttleMapping * -1, y * throttleMapping * -1, twist * -1);
chassis.idle();
}
public void testPeriodic()
{
}
}