This repository has been archived by the owner on Apr 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Robot.java-3-1-17(2)
135 lines (114 loc) · 3.61 KB
/
Robot.java-3-1-17(2)
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
package org.usfirst.frc.team6763.robot;
import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.Encoder;
//Imports the other files needed by the program
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Spark;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.buttons.Button;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import edu.wpi.first.wpilibj.command.Command;
public class Robot extends IterativeRobot {
RobotDrive myRobot = new RobotDrive(0, 2);
Joystick stick = new Joystick(0);
Timer timer = new Timer();
Jaguar ArmMotor = new Jaguar(9);
SpeedController Climber = new Spark(7);
Joystick mXboxController = new Joystick(1);
Encoder slaveEncoder; // Right Side Encoder
Encoder masterEncoder; // Left Side Encoder
float TicksPerInch = 108.333333F; // Number of Encoder Ticks per Inch
int InchesPerFoot = 12;
double masterPower = 0.475;
double slavePower = 0.5;
double error = 0.0;
double kp = 0.05;
double maxEncoderError = TicksPerInch * 85;
@Override
public void robotInit() {
slaveEncoder = new Encoder(3, 2);
slaveEncoder.setReverseDirection(false);
masterEncoder = new Encoder (1, 0);
masterEncoder.setReverseDirection(true);
CameraServer.getInstance().startAutomaticCapture();
}
@Override
public void autonomousInit() {
timer.reset();
timer.start();
System.out.println("Master Count,Slave Count,Error,KP,MasterPower,SlavePower");
masterEncoder.reset();
slaveEncoder.reset();
}
@Override
public void autonomousPeriodic() {
if (masterEncoder.get() < (TicksPerInch * InchesPerFoot * 12)) {
masterPower = -0.533;
slavePower = -0.5;
error = masterEncoder.get() - slaveEncoder.get();
if (error > 50){
masterPower = -0.531;
}
else if (error < -50){
masterPower = -0.535;
}
else if (error > -50 && error < 50){
masterPower = -0.533;
}
}
else {
masterPower = 0;
slavePower = 0;
}
myRobot.tankDrive(masterPower, slavePower);
System.out.println(masterEncoder.get() + " , " + slaveEncoder.get() + " , " + error);
/*
if (masterEncoder.get() > 10500 && masterEncoder.get() < 11000){
slavePower = -.6;
masterPower = -.47;
}
else {
myRobot.tankDrive(masterPower, slavePower);
error = masterEncoder.get() - slaveEncoder.get();
slavePower += error / maxEncoderError;
if (slavePower < .55){
slavePower = -.55;
}
else if (slavePower > .45){
slavePower = -.45;
}
}
if (masterEncoder.get() < 11000) {
myRobot.tankDrive(0, 0);
}
*/
//System.out.println(masterEncoder.get() + "," + slaveEncoder.get() + "," + error + "," + kp + "," + masterPower + "," + slavePower);
//System.out.println(masterEncoder.get() + "," + slaveEncoder.get());
}
@Override
public void teleopInit() {
}
@Override
public void teleopPeriodic() {
myRobot.arcadeDrive(mXboxController);
Climber.set(mXboxController.getRawAxis(5));
ArmMotor.set(stick.getRawAxis(1)*.25);
}
@Override
public void testPeriodic() {
LiveWindow.run();
}
public void disabledPeriodic(){
//System.out.println("RightEncoder (slave) = " + slaveEncoder.get());
//System.out.println("LeftEncoder (master) = " + masterEncoder.get());
//System.out.println(masterEncoder.get() + " , " + slaveEncoder.get());
}
}h