This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNathanPushboat.java
More file actions
227 lines (196 loc) · 9.53 KB
/
NathanPushboat.java
File metadata and controls
227 lines (196 loc) · 9.53 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package org.firstinspires.ftc.teamcode;
import com.qualcomm.hardware.bosch.BNO055IMU;
import com.qualcomm.hardware.bosch.JustLoggingAccelerationIntegrator;
import com.qualcomm.robotcore.hardware.AnalogInput;
import com.qualcomm.robotcore.hardware.CRServo;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
import com.qualcomm.robotcore.hardware.DigitalChannel;
import com.qualcomm.robotcore.hardware.DistanceSensor;
import com.qualcomm.robotcore.hardware.ColorSensor;
import com.qualcomm.robotcore.hardware.HardwareMap;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.hardware.ServoControllerEx;
import com.qualcomm.robotcore.hardware.TouchSensor;
import com.qualcomm.robotcore.util.ElapsedTime;
//import org.firstinspires.ftc.robotcontroller.external.samples.SensorREVColorDistance; Commented out doopadoo
//Most code taken from HardwarePushbot.java in the FTC samples
/**
* This is NOT an opmode.
*
* This class can be used to define all the specific hardware for a single robot.
* In this case that robot is a Pushbot.
* See PushbotTeleopTank_Iterative and others classes starting with "Pushbot" for usage examples.
*
* This hardware class assumes the following device names have been configured on the robot:
* Note: All names are lower case and some have single spaces between words.
*
* Motor channel: Left drive motor: "left_drive"
* Motor channel: Right drive motor: "right_drive"
* Motor channel: Manipulator drive motor: "left_arm"
* Servo channel: Servo to open left claw: "left_hand"
* Servo channel: Servo to open right claw: "right_hand"
*/
public class NathanPushboat
{
//////////////////
/* DECLARATIONS */
//////////////////
//(Expansion Hub Number, Number)
//DRIVE//
public DcMotor front_left_motor = null; //(9, 0)
public DcMotor front_right_motor = null; //(6, 0)
public DcMotor back_left_motor = null; //(9, 1)
public DcMotor back_right_motor = null; //(6, 1)
//INTAKE//
public DcMotor right_intake = null; //(6, 2)
public DcMotor left_intake = null; //(9, 2)
public DistanceSensor wall_distance_sensor = null;
//public DcMotor intake_aligner = null;
// public AnalogInput intakePotentiometer = null;
public CRServo winch = null;
//GLYPH//
public DcMotor glyph_flipper = null; //(9, 3)
public Servo glyph_aligner = null; //(9, 0)
public Servo glyph_aligner2 = null;
public Servo glyph_grabber = null; //(9, 1)
public AnalogInput armPotentiometer = null;
public Servo glyph_stacker = null;
public DigitalChannel glyphswitch = null;
public DistanceSensor glyph_distance_sensor = null;
//JEWEL//
public Servo jewel_arm = null; //(6, 0)
public DistanceSensor distance_sensor = null;
public ColorSensor color_sensor = null;
//RELIC//
public DcMotor relic_extender = null;
public Servo relic_flipper = null;
public Servo relic_grabber = null;
//IMU//
BNO055IMU imu;
/* local OpMode members. */
HardwareMap hwMap = null;
private ElapsedTime period = new ElapsedTime();
private ElapsedTime runtime = new ElapsedTime();
/* Constructor */
public NathanPushboat(){
}
/* Initialize standard Hardware interfaces */
public void init(HardwareMap hwMap) {
//////////////////////////////////
/* RETRIEVING STUFF FROM PHONES */
//////////////////////////////////
//DRIVE//
front_left_motor = hwMap.dcMotor.get("front_left_wheel");
front_right_motor = hwMap.dcMotor.get("front_right_wheel");
back_left_motor = hwMap.dcMotor.get("back_left_wheel");
back_right_motor = hwMap.dcMotor.get("back_right_wheel");
glyph_distance_sensor = hwMap.get(DistanceSensor.class,"glyph_sensor");
//INTAKE//
right_intake = hwMap.dcMotor.get("right_intake");
left_intake = hwMap.dcMotor.get("left_intake");
wall_distance_sensor = hwMap.get(DistanceSensor.class,"wall_sensor");
//intake_aligner = hwMap.dcMotor.get("intake_aligner");
winch = hwMap.crservo.get("winch");
//intakePotentiometer = hwMap.analogInput.get("intakePotentiometer");
//GLYPH//
glyph_flipper = hwMap.dcMotor.get("glyph_flipper"); //positive power increases pot position
glyph_aligner = hwMap.servo.get("glyph_fixer");
glyph_aligner2 = hwMap.servo.get("glyph_fixer2");
glyph_aligner2.setDirection(Servo.Direction.REVERSE);
glyph_grabber = hwMap.servo.get("glyph_grabber");
armPotentiometer = hwMap.analogInput.get("armPotentiometer");
glyph_stacker = hwMap.servo.get("glyph_stacker");
glyphswitch = hwMap.get(DigitalChannel.class , "glyphswitch");
glyphswitch.setMode(DigitalChannel.Mode.INPUT);
//JEWEL//
jewel_arm = hwMap.servo.get("jewel_arm");//.2 for STRAIGHT UP, .76 JEWEL DOWN
color_sensor = hwMap.get(ColorSensor.class, "color_sensor");
distance_sensor = hwMap.get(DistanceSensor.class,"color_sensor");
jewel_arm.setDirection(Servo.Direction.REVERSE);
// //RELIC//
relic_extender = hwMap.dcMotor.get("relic_extender");
relic_flipper = hwMap.servo.get("relic_flipper");
relic_grabber = hwMap.servo.get("relic_grabber");
relic_extender.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
relic_extender.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
relic_extender.setDirection(DcMotorSimple.Direction.REVERSE);
//IMU//
imu = hwMap.get(BNO055IMU.class, "imu");
//////////////////
/* STUFFY STUFF */
//////////////////
/* DRIVING STUFF */
front_left_motor.setDirection(DcMotor.Direction.REVERSE); // Set to REVERSE if using AndyMark motors
back_left_motor.setDirection(DcMotor.Direction.REVERSE);
front_right_motor.setDirection(DcMotor.Direction.FORWARD);// Set to FORWARD if using AndyMark motors
back_right_motor.setDirection(DcMotor.Direction.FORWARD);
// front_left_motor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.FLOAT);
// front_right_motor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.FLOAT);
// back_left_motor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.FLOAT);
// back_right_motor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.FLOAT);
front_left_motor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
front_right_motor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
back_left_motor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
back_right_motor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
front_left_motor.setPower(0);
front_right_motor.setPower(0);
back_left_motor.setPower(0);
back_right_motor.setPower(0);
front_left_motor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
front_right_motor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
back_left_motor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
back_right_motor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
front_left_motor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
front_right_motor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
back_left_motor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
back_right_motor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
/* GLYPH STUFF */
glyph_flipper.setDirection(DcMotor.Direction.REVERSE);
glyph_flipper.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
glyph_flipper.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
/* INTAKE STUFF */
right_intake.setDirection(DcMotor.Direction.REVERSE);
left_intake.setDirection(DcMotor.Direction.REVERSE);
right_intake.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.FLOAT);
left_intake.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.FLOAT);
// intake_aligner.setDirection(DcMotor.Direction.REVERSE);
// intake_aligner.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
// intake_aligner.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
}
public void imu(){
/* IMU STUFF */
BNO055IMU.Parameters parameters = new BNO055IMU.Parameters();
parameters.mode = BNO055IMU.SensorMode.IMU;
parameters.angleUnit = BNO055IMU.AngleUnit.DEGREES;
parameters.accelUnit = BNO055IMU.AccelUnit.METERS_PERSEC_PERSEC;
parameters.loggingEnabled = false;
imu.initialize(parameters);
}
/***
*
* waitForTick implements a periodic delay. However, this acts like a metronome with a regular
* periodic tick. This is used to compensate for varying processing times for each cycle.
* The function looks at the elapsed cycle time, and sleeps for the remaining time interval.
*
*/
public void delay (double time){
double desiredRunTime = time;
double currentTime = runtime.milliseconds();
while (runtime.milliseconds() > currentTime && runtime.milliseconds() < currentTime + desiredRunTime ) {
}
}
public void waitForTick(long periodMs) {
long remaining = periodMs - (long)period.milliseconds();
// sleep for the remaining portion of the regular cycle period.
if (remaining > 0) {
try {
Thread.sleep(remaining);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
// Reset the cycle clock for the next pass.
period.reset();
}
}