-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTribot.java0
117 lines (95 loc) · 4.34 KB
/
Tribot.java0
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
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.hardware.DcMotor;
import org.firstinspires.ftc.robotcore.external.navigation.AxesReference;
import org.firstinspires.ftc.robotcore.external.navigation.AxesOrder;
import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
import com.qualcomm.hardware.bosch.BNO055IMU;
import org.firstinspires.ftc.robotcore.external.navigation.Orientation;
import org.firstinspires.ftc.robotcore.external.navigation.Acceleration;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
import com.qualcomm.robotcore.hardware.HardwareMap;
import com.qualcomm.hardware.bosch.JustLoggingAccelerationIntegrator;
/**
* This is NOT an opmode.
*
* This class is the hardware map of the robot.
*/
public class Tribot
{
/* Public OpMode members. */
public DcMotor one = null;
public DcMotor two = null;
public DcMotor three = null;
public BNO055IMU imu;
public Orientation angles;
public Acceleration gravity;
public float dangles[] = new float[3];
/* local OpMode members. */
HardwareMap hwMap = null;
//private ElapsedTime period = new ElapsedTime();
/* Constructor */
public Tribot(){
}
/* Initialize standard Hardware interfaces */
public void init(HardwareMap ahwMap) {
// Save reference to Hardware map
hwMap = ahwMap;
// Define and Initialize Motors
one = ahwMap.dcMotor.get("one");
two = ahwMap.dcMotor.get("two");
three = ahwMap.dcMotor.get("three");
// Set all motors to zero power
one.setPower(0);
two.setPower(0);
three.setPower(0);
// Set all motors to run using encoders.
// May want to use RUN_USING_ENCODERS if encoders are installed.
/*one.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
two.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
three.setMode(DcMotor.RunMode.RUN_USING_ENCODER);*/
one.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
two.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
three.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
BNO055IMU.Parameters parameters = new BNO055IMU.Parameters();
parameters.angleUnit = BNO055IMU.AngleUnit.DEGREES;
parameters.accelUnit = BNO055IMU.AccelUnit.METERS_PERSEC_PERSEC;
parameters.calibrationDataFile = "BNO055IMUCalibration.json"; // see the calibration sample opmode
parameters.loggingEnabled = true;
parameters.loggingTag = "IMU";
parameters.accelerationIntegrationAlgorithm = new JustLoggingAccelerationIntegrator();
imu = ahwMap.get(BNO055IMU.class, "imu");
imu.initialize(parameters);
angles = imu.getAngularOrientation(AxesReference.INTRINSIC, AxesOrder.XYZ, AngleUnit.DEGREES);
gravity = imu.getGravity();
dangles[0] = angles.firstAngle;
dangles[1] = angles.secondAngle;
dangles[2] = angles.thirdAngle;
}
public void updateGyro(int damping) {
float origX = angles.firstAngle;
float origY = angles.secondAngle;
float origZ = angles.thirdAngle;
angles = imu.getAngularOrientation(AxesReference.INTRINSIC, AxesOrder.XYZ, AngleUnit.DEGREES);
dangles[0] = ((dangles[0] * damping) + angles.firstAngle) / (damping + 1);
dangles[1] = ((dangles[1] * damping) + angles.secondAngle) / (damping + 1);
dangles[2] = ((dangles[2] * damping) + angles.thirdAngle) / (damping + 1);
gravity = imu.getGravity();
}
/***
*
* 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.
* @throws InterruptedException
*/
/*public void waitForTick(long periodMs) throws InterruptedException {
long remaining = periodMs - (long)period.milliseconds();
// sleep for the remaining portion of the regular cycle period.
if (remaining > 0)
Thread.sleep(remaining);
// Reset the cycle clock for the next pass.
period.reset();
}*/
}