-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobot.java
More file actions
147 lines (134 loc) · 4.16 KB
/
Copy pathRobot.java
File metadata and controls
147 lines (134 loc) · 4.16 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
package org.usfirst.frc.team3647.robot;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
public class Robot extends IterativeRobot
{
Encoders encodersObject;
Joysticks joystickObject;
//This function is run whenever the robot starts. This function is used for any initialization of code
@Override
public void robotInit()
{
encodersObject = new Encoders();
joystickObject = new Joysticks();
}
//This function runs once, right before autonomous period starts.
@Override
public void autonomousInit()
{
}
//This is the function that is called during the autonomous period
//This function runs periodically, meaning it acts as an infinite loop
@Override
public void autonomousPeriodic()
{
}
double RightJoyValueY;
double RightJoyValueX;
double rightSpeed;
double leftSpeed;
//This is the function that is called during the Tele-operated period
//This function runs periodically, meaning it acts as an infinite loop
@Override
public void teleopPeriodic()
{
RightJoyValueY = joystickObject.fixController(Joysticks.rightJoySticky);
RightJoyValueX = joystickObject.fixController(Joysticks.rightJoyStickx);
rightSpeed = -RightJoyValueY;
leftSpeed = RightJoyValueY;
if(RightJoyValueY <= 1 && RightJoyValueY >= 0.15)
{
if(RightJoyValueX >= 0.15 && RightJoyValueX <= 1)
{
joystickObject.updateMainController();
rightSpeed = rightSpeed + 0.2;
Motors.rightMotor.set(rightSpeed);
Motors.leftMotor.set(leftSpeed);
}
else if(RightJoyValueX >= -1 && RightJoyValueX <= -0.15)
{
joystickObject.updateMainController();
leftSpeed = leftSpeed - 0.2;
Motors.rightMotor.set(rightSpeed);
Motors.leftMotor.set(leftSpeed);
}
else if(RightJoyValueX == 0)
{
if(encodersObject.getRightEncoder() > encodersObject.getLeftEncoder())
{
joystickObject.updateMainController();
rightSpeed = rightSpeed + 0.05;
Motors.leftMotor.set(leftSpeed);
Motors.rightMotor.set(rightSpeed);
}
else if(encodersObject.getRightEncoder() < encodersObject.getLeftEncoder())
{
joystickObject.updateMainController();
leftSpeed = leftSpeed - 0.05;
Motors.leftMotor.set(leftSpeed);
Motors.rightMotor.set(rightSpeed);
}
else if(encodersObject.getRightEncoder() == encodersObject.getLeftEncoder())
{
joystickObject.updateMainController();
Motors.leftMotor.set(leftSpeed);
Motors.rightMotor.set(rightSpeed);
}
}
}
else if(RightJoyValueY >= -1 && RightJoyValueY <= -0.15)
{
if(RightJoyValueX >= 0.15 && RightJoyValueX <= 1)
{
joystickObject.updateMainController();
rightSpeed = rightSpeed - 0.2;
Motors.rightMotor.set(rightSpeed);
Motors.leftMotor.set(leftSpeed);
}
else if(RightJoyValueX >= -1 && RightJoyValueX <= -0.15)
{
joystickObject.updateMainController();
leftSpeed = leftSpeed + 0.2;
Motors.rightMotor.set(rightSpeed);
Motors.leftMotor.set(leftSpeed);
}
else if(RightJoyValueX == 0)
{
if(encodersObject.getRightEncoder() < encodersObject.getLeftEncoder())
{
joystickObject.updateMainController();
rightSpeed = rightSpeed - 0.05;
Motors.leftMotor.set(leftSpeed);
Motors.rightMotor.set(rightSpeed);
}
else if(encodersObject.getRightEncoder() > encodersObject.getLeftEncoder())
{
joystickObject.updateMainController();
leftSpeed = leftSpeed + 0.05;
Motors.leftMotor.set(leftSpeed);
Motors.rightMotor.set(rightSpeed);
}
else if(encodersObject.getRightEncoder() == encodersObject.getLeftEncoder())
{
joystickObject.updateMainController();
Motors.leftMotor.set(leftSpeed);
Motors.rightMotor.set(rightSpeed);
}
}
}
else if(RightJoyValueY == 0)
{
encodersObject.resetEncoders();
Motors.leftMotor.set(0);
Motors.rightMotor.set(0);
}
}
//This is the function that is called during the test
//Test is an option available in the driver station and can be used to test specific pieces of code.
//This function runs periodically, meaning it acts like an infinite loop
@Override
public void testPeriodic()
{
}
}