Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.firstinspires.ftc.robotcontroller.external.samples;
- import com.qualcomm.robotcore.hardware.ColorSensor;
- import com.qualcomm.robotcore.hardware.DcMotor;
- import com.qualcomm.robotcore.hardware.HardwareMap;
- import com.qualcomm.robotcore.hardware.Servo;
- import com.qualcomm.robotcore.util.ElapsedTime;
- /**
- * 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 HardwarePushbot
- {
- /* Public OpMode members. */
- public DcMotor leftMotor = null;
- public DcMotor rightMotor = null;
- public DcMotor armMotor = null;
- public DcMotor arm2Motor = null;
- public DcMotor leftShooter = null; //This is for the shooter motors
- public DcMotor rightShooter = null; //This is for the shooter motors
- public DcMotor liftLeft = null; //This is for the left side that moves the yoga ball lift
- public DcMotor liftRight = null; //This is for the right side that moves the yoga ball lift
- public Servo ballPusher = null; //This is for the pusher thing that pushes the ball into the shooter
- public Servo liftHolder = null; //This is for the servo that pushes the button on the beacon
- public Servo liftArmLeft = null; //This is for the left arm connected to the servo to grab onto the yoga ball
- public Servo liftArmRight = null; //This is for the right arm connected to the servo to grab onto the yoga ball.
- public ColorSensor beaconSensor = null;
- public static final double MID_SERVO = 1.0 ;
- 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 HardwarePushbot(){
- }
- /* Initialize standard Hardware interfaces */
- public void init(HardwareMap ahwMap) {
- // Save reference to Hardware map
- hwMap = ahwMap;
- // Define and Initialize Motors
- leftMotor = hwMap.dcMotor.get("left_drive");
- rightMotor = hwMap.dcMotor.get("right_drive");
- armMotor = hwMap.dcMotor.get("left_arm");
- //arm2Motor = hwMap.dcMotor.get("right_arm");
- leftShooter = hwMap.dcMotor.get("left_drive2");
- rightShooter = hwMap.dcMotor.get("right_drive2");
- liftLeft = hwMap.dcMotor.get("lift_left");
- liftRight = hwMap.dcMotor.get("lift_right");
- // Define and Initialize Servos
- ballPusher = hwMap.servo.get("left_hand");
- liftHolder = hwMap.servo.get("right_hand");
- //Define and Initialize Sensors
- beaconSensor = hwMap.colorSensor.get("colorSensor");
- leftMotor.setDirection(DcMotor.Direction.FORWARD); // Set to REVERSE if using AndyMark motors
- rightMotor.setDirection(DcMotor.Direction.REVERSE);// Set to FORWARD if using AndyMark motors
- // Set all motors to zero power
- leftMotor.setPower(0);
- rightMotor.setPower(0);
- armMotor.setPower(0);
- leftShooter.setPower(0);
- rightShooter.setPower(0);
- // Set all motors to run without encoders.
- // May want to use RUN_USING_ENCODERS if encoders are installed.
- leftMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
- rightMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
- //armMotor.setMode(DcMotor.RunMode.RUN_USING_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();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement