-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSNRobotHardware.java
More file actions
92 lines (73 loc) · 3.29 KB
/
SNRobotHardware.java
File metadata and controls
92 lines (73 loc) · 3.29 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
package org.firstinspires.ftc.teamcode.etrobot;
import com.qualcomm.hardware.modernrobotics.ModernRoboticsI2cGyro;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.HardwareMap;
import com.qualcomm.robotcore.util.ElapsedTime;
/**
* Created by RobotChicken on 11/1/2016.
*/
public class SNRobotHardware {
/* Public OpMode members. */
public DcMotor leftFrontMotor = null;
public DcMotor rightFrontMotor = null;
public DcMotor armMotor = null;
public ModernRoboticsI2cGyro gyro = null; //
//public Servo leftClaw = null;
// public Servo rightClaw = null;
// public static final double MID_SERVO = 0.5 ;
public static final double ARM_UP_POWER = 0.45 ;
public static final double ARM_DOWN_POWER = -0.45 ;
/* local OpMode members. */
HardwareMap hwMap = null;
private ElapsedTime period = new ElapsedTime();
/* Constructor */
public SNRobotHardware(){
}
/* Initialize standard Hardware interfaces */
public void init(HardwareMap ahwMap) {
// Save reference to Hardware map
hwMap = ahwMap;
// Define and Initialize Motors
leftFrontMotor = hwMap.dcMotor.get("left_front_drive");
rightFrontMotor = hwMap.dcMotor.get("right_front_drive");
armMotor = hwMap.dcMotor.get("left_arm");
gyro = (ModernRoboticsI2cGyro)hwMap.gyroSensor.get("gyro");
//leftFrontMotor.setDirection(DcMotor.Direction.FORWARD); // Set to REVERSE if using AndyMark motors
//rightFrontMotor.setDirection(DcMotor.Direction.REVERSE);// Set to FORWARD if using AndyMark motors
// Set all motors to zero power
leftFrontMotor.setPower(0.0);
rightFrontMotor.setPower(0.0);
armMotor.setPower(0);
// Set all motors to run without encoders.
// May want to use RUN_USING_ENCODERS if encoders are installed.
leftFrontMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
rightFrontMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
armMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
// Define and initialize ALL installed servos.
// leftClaw = hwMap.servo.get("left_hand");
// rightClaw = hwMap.servo.get("right_hand");
//leftClaw.setPosition(MID_SERVO);
// rightClaw.setPosition(MID_SERVO);
}
/***
*
* 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.
*
* @param periodMs Length of wait cycle in mSec.
*/
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();
}
}