View difference between Paste ID: sEH5QCak and jBMMjgf8
SHOW: | | - or go back to the newest paste.
1
package org.firstinspires.ftc.teamcode;
2
3
import com.qualcomm.hardware.lynx.LynxI2cColorRangeSensor;
4
import com.qualcomm.robotcore.hardware.ColorSensor;
5
import com.qualcomm.robotcore.hardware.DcMotor;
6
import com.qualcomm.robotcore.hardware.HardwareMap;
7
import com.qualcomm.robotcore.hardware.Servo;
8
import com.qualcomm.robotcore.util.ElapsedTime;
9
10
/**
11
 * This is NOT an opmode.
12
 *
13
 * This class can be used to define all the specific hardware for a single robot.
14
 * In this case that robot is a Pushbot.
15
 * See PushbotTeleopTank_Iterative and others classes starting with "Pushbot" for usage examples.
16
 *
17
 * This hardware class assumes the following device names have been configured on the robot:
18
 * Note:  All names are lower case and some have single spaces between words.
19
 * Motor channel:  Manipulator drive motor:  " arm"
20
 * Servo channel:  Servo to open left claw:  "left_hand"
21
 * Servo channel:  Servo to open right claw: "right_hand"t
22
 */
23
public class TestBotNN
24
{
25
    /* Public OpMode members. */
26
    public DcMotor  leftMotor   = null;
27
    public DcMotor  rightMotor  = null;
28-
    public LynxI2cColorRangeSensor colorSensor;
28+
29
    //changed the linx to the rev sensor
30
    ColorSensor colorSensor;
31
    DistanceSensor sensorDistance;
32
33
    public Servo grabberServo;
34
35
    /* local OpMode members. */
36
    HardwareMap hwMap           =  null;
37
    private ElapsedTime period  = new ElapsedTime();
38
39
    /* Constructor */
40
    public TestBotNN(){
41
42
    }
43
44
    /* Initialize standard Hardware interfaces */
45
    public void init(HardwareMap ahwMap) {
46
        // Save reference to Hardware map
47
        hwMap = ahwMap;
48
49-
        colorSensor = hwMap.get(LynxI2cColorRangeSensor.class, "color sensor");
49+
50
        leftMotor   = hwMap.dcMotor.get("left motor");
51
        rightMotor  = hwMap.dcMotor.get("right motor");
52
        grabberServo = hwMap.servo.get("grabber servo");
53
54
        //initialize the rev sensors
55
        // get a reference to the color sensor.
56
        colorSensor = hwMap.get(ColorSensor.class, "sensor_color_distance");
57
58
        // get a reference to the distance sensor that shares the same name.
59
        sensorDistance = hwMap.get(DistanceSensor.class, "sensor_color_distance");
60
61
62
        colorSensor.enableLed(false);
63-
       // rightMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
63+
64
        colorSensor.blue();
65
        leftMotor.setDirection(DcMotor.Direction.REVERSE); // Set to REVERSE if using AndyMark motors
66
        rightMotor.setDirection(DcMotor.Direction.FORWARD);// Set to FORWARD if using AndyMark motors
67
68
        // Set all motors to zero power
69
        leftMotor.setPower(0);
70
        rightMotor.setPower(0);
71
        // Set all motors to run without encoders.
72
        // May want to use RUN_USING_ENCODERS if encoders are installed.
73
        leftMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
74
        rightMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);;
75
        // rightMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
76
        //leftMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
77
    }
78
79
    /***
80
     *
81
     * waitForTick implements a periodic delay. However, this acts like a metronome with a regular
82
     * periodic tick.  This is used to compensate for varying processing times for each cycle.
83
     * The function looks at the elapsed cycle time, and sleeps for the remaining time interval.
84
     *
85
     * @param periodMs  Length of wait cycle in mSec.
86
     */
87
    public void waitForTick(long periodMs) {
88
89
        long  remaining = periodMs - (long)period.milliseconds();
90
91
        // sleep for the remaining portion of the regular cycle period.
92
        if (remaining > 0) {
93
            try {
94
                Thread.sleep(remaining);
95
            } catch (InterruptedException e) {
96
                Thread.currentThread().interrupt();
97
            }
98
        }
99
100
        // Reset the cycle clock for the next pass.
101
        period.reset();
102
    }
103
}