forked from FIRST-Tech-Challenge/FtcRobotController
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobotHardware.java
More file actions
135 lines (120 loc) · 6.09 KB
/
Copy pathRobotHardware.java
File metadata and controls
135 lines (120 loc) · 6.09 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
/* Copyright (c) 2022 FIRST. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted (subject to the limitations in the disclaimer below) provided that
* the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* Neither the name of FIRST nor the names of its contributors may be used to endorse or
* promote products derived from this software without specific prior written permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS
* LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.util.Range;
public class RobotHardware {
/* Declare OpMode members. */
private LinearOpMode myOpMode = null; // gain access to methods in the calling OpMode.
// Define Motor and Servo objects (Make them private so they can't be accessed externally)
protected DcMotor frontLeft = null;
protected DcMotor frontRight = null;
protected DcMotor backLeft = null;
protected DcMotor backRight = null;
// Define Drive constants. Make them public so they CAN be used by the calling OpMode
public static final double MID_SERVO = 0.5 ;
public static final double HAND_SPEED = 0.02 ; // sets rate to move servo
public static final double ARM_UP_POWER = 0.45 ;
public static final double ARM_DOWN_POWER = -0.45 ;
// Define a constructor that allows the OpMode to pass a reference to itself.
public RobotHardware(LinearOpMode opmode) {
myOpMode = opmode;
}
/**
* Initialize all the robot's hardware.
* This method must be called ONCE when the OpMode is initialized.
* <p>
* All of the hardware devices are accessed via the hardware map, and initialized.
*/
public void init() {
// Define and Initialize Motors (note: need to use reference to actual OpMode).
frontLeft = myOpMode.hardwareMap.get(DcMotor.class, "front_left");
frontRight = myOpMode.hardwareMap.get(DcMotor.class, "front_right");
backLeft = myOpMode.hardwareMap.get(DcMotor.class, "back_left");
backRight = myOpMode.hardwareMap.get(DcMotor.class, "back_right");
// To drive forward, most robots need the motor on one side to be reversed, because the axles point in opposite directions.
// Pushing the left stick forward MUST make robot go forward. So adjust these two lines based on your first test drive.
// Note: The settings here assume direct drive on left and right wheels. Gear Reduction or 90 Deg drives may require direction flips
// // AP: As long as all the left motors' directions are different from the right ones it should be fine
frontLeft.setDirection(DcMotor.Direction.REVERSE);
backLeft.setDirection(DcMotor.Direction.FORWARD);
frontRight.setDirection(DcMotor.Direction.REVERSE);
backRight.setDirection(DcMotor.Direction.REVERSE);
//
// // If there are encoders connected, switch to RUN_USING_ENCODER mode for greater accuracy
//
// // AP: We have encoders but I'm not sure if we're gonna use them
// frontLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
// frontRight.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
// backLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
// backRight.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
// Define and initialize ALL installed servos.
// leftHand = myOpMode.hardwareMap.get(Servo.class, "left_hand");
// rightHand = myOpMode.hardwareMap.get(Servo.class, "right_hand");
// leftHand.setPosition(MID_SERVO);
// rightHand.setPosition(MID_SERVO);
myOpMode.telemetry.addLine("Hardware Initialized");
myOpMode.telemetry.update();
}
// AP: We don't need this because we have fancy wheels
// public void driveRobot(double Drive, double Turn) {
// // Combine drive and turn for blended motion.
// double left = Drive + Turn;
// double right = Drive - Turn;
//
// // Scale the values so neither exceed +/- 1.0
// double max = Math.max(Math.abs(left), Math.abs(right));
// if (max > 1.0)
// {
// left /= max;
// right /= max;
// }
//
// // Use existing function to drive both wheels.
// setDrivePower(left, right);
// }
//AP: This is all servo stuff that we can't make use of yet
// public void setArmPower(double power) {
// armMotor.setPower(power);
// }
//
// /**
// * Send the two hand-servos to opposing (mirrored) positions, based on the passed offset.
// *
// * @param offset
// */
// public void setHandPositions(double offset) {
// offset = Range.clip(offset, -0.5, 0.5);
// leftHand.setPosition(MID_SERVO + offset);
// rightHand.setPosition(MID_SERVO - offset);
// }
}