-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUSAKIRA2
157 lines (133 loc) · 3.54 KB
/
GUSAKIRA2
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
153
154
155
156
157
package frc.robot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.motorcontrol.Spark;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
public class Robot extends TimedRobot {
private String m_autoSelected;
private final SendableChooser<String> m_chooser = new SendableChooser<>();
private Spark leftMotor1 = new Spark(0);
private Spark leftMotor2 = new Spark(1);
private Spark rightMotor1 = new Spark(2);
private Spark rightMotor2 = new Spark(3);
private Spark coletorMotor1 = new Spark(4);
private Spark shooterMotor1 = new Spark(5);
private Spark shooterMotor2 = new Spark(6);
private Spark shooterMotor3 = new Spark(8);
private Joystick joy1 = new Joystick(0);
private Joystick joy2 = new Joystick(1);
double velocidade1 = -1;
double autonomo = 1;
double giro1 = 1.1;
protected void execute(){
SmartDashboard.putNumber(drivetrain.get(velocidade1), velocidade1);
}
@Override
public void robotInit() {
leftMotor1.addFollower(leftMotor2);
rightMotor1.addFollower(rightMotor2);
}
@Override
public void robotPeriodic() {
}
@Override
public void autonomousInit() {
m_autoSelected = m_chooser.getSelected();
System.out.println("Auto selected: " + m_autoSelected);
autonomo = 1;
}
@Override
public void autonomousPeriodic() {
if (autonomo == 1) {
rightMotor1.set(0.3);
leftMotor1.set(-0.265);
try {
Thread.sleep(1500);
} catch (Exception erro) {
}
rightMotor1.set(0.4);
leftMotor1.set(0.4);
try {
Thread.sleep(1710);
} catch (Exception erro) {
}
rightMotor1.set(-0.29);
leftMotor1.set(0.3);
coletorMotor1.set(1);
try {
Thread.sleep(2500);
} catch (Exception erro) {
}
coletorMotor1.set(0);
rightMotor1.set(0.4);
leftMotor1.set(0.4);
try {
Thread.sleep(1500);
} catch (Exception erro) {
}
rightMotor1.set(-0.3);
leftMotor1.set(0.29);
try {
Thread.sleep(3000);
} catch (Exception erro) {
}
rightMotor1.set(0);
leftMotor1.set(0);
try {
Thread.sleep(999999999);
} catch (Exception erro) {
}
}
}
public void teleopInit() {
coletorMotor1.set(0);
leftMotor1.set(0);
leftMotor2.set(0);
rightMotor1.set(0);
rightMotor2.set(0);
}
public void teleopPeriodic() {
double velocidade = joy1.getRawAxis(1) * velocidade1;
double giro = joy1.getRawAxis(2) * giro1;
double esquerda = -velocidade + giro;
double direita = -velocidade - giro;
leftMotor1.set(-esquerda/1.35);
leftMotor2.set(-esquerda/1.32);
rightMotor1.set(direita);
rightMotor2.set(direita);
if (joy1.getRawButtonPressed(6)) {
velocidade1 = velocidade1 - 0.25;
giro1 = giro1 + 0.25;
}
if (joy1.getRawButtonPressed(5)) {
velocidade1 = velocidade1 + 0.25;
giro1 = giro1 - 0.25;
}
System.out.println(velocidade1);
if (joy2.getRawButtonPressed(2)){
coletorMotor1.set(1);
}
if (joy2.getRawButtonReleased(2)) {
coletorMotor1.set(0);
}
if (joy2.getRawButtonPressed(1)){
shooterMotor3.set(-1);
}
if (joy2.getRawButtonPressed(1)){
shooterMotor2.set(-1);
}
if (joy2.getRawButtonPressed(1)){
shooterMotor1.set(-1);
}
if (joy2.getRawButtonReleased(1)) {
shooterMotor3.set(0);
}
if (joy2.getRawButtonReleased(1)) {
shooterMotor2.set(0);
}
if (joy2.getRawButtonPressed(1)){
shooterMotor1.set(0);
}
}
}