Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.firstinspires.ftc.teamcode;
- import com.qualcomm.hardware.lynx.LynxI2cColorRangeSensor;
- 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: Manipulator drive motor: " arm"
- * Servo channel: Servo to open left claw: "left_hand"
- * Servo channel: Servo to open right claw: "right_hand"t
- */
- public class TestBotNN
- {
- /* Public OpMode members. */
- public DcMotor leftMotor = null;
- public DcMotor rightMotor = null;
- public LynxI2cColorRangeSensor colorSensor;
- public Servo grabberServo;
- /* local OpMode members. */
- HardwareMap hwMap = null;
- private ElapsedTime period = new ElapsedTime();
- /* Constructor */
- public TestBotNN(){
- }
- /* 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 motor");
- rightMotor = hwMap.dcMotor.get("right motor");
- grabberServo = hwMap.servo.get("grabber servo");
- colorSensor = hwMap.get(LynxI2cColorRangeSensor.class, "color sensor");
- colorSensor.enableLed(false);
- colorSensor.red();
- colorSensor.blue();
- leftMotor.setDirection(DcMotor.Direction.REVERSE); // Set to REVERSE if using AndyMark motors
- rightMotor.setDirection(DcMotor.Direction.FORWARD);// Set to FORWARD if using AndyMark motors
- // Set all motors to zero power
- leftMotor.setPower(0);
- rightMotor.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);;
- // rightMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- //leftMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- }
- /***
- *
- * 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