Skip to content

Instantly share code, notes, and snippets.

@erinzm
Last active October 6, 2015 21:40
Show Gist options
  • Save erinzm/dfdac631fbe2dd73ebe9 to your computer and use it in GitHub Desktop.
Save erinzm/dfdac631fbe2dd73ebe9 to your computer and use it in GitHub Desktop.
Theodore Teleop
package com.qualcomm.ftcrobotcontroller.opmodes;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorController;
// everything before this line IntelliJ writes out for you automatically as you use stuff.
/**
* Created by liam on 9/19/2015.
*/
public class TheodoreTeleop extends OpMode { // declares a new opmode. IntelliJ does this automatically for you.
// these are /kind of/ like the #pragmas in RobotC
private DcMotorController drive_motor_controller;
private DcMotor drive_left;
private DcMotor drive_right;
@Override
public void init() {
// here we get a reference to the motor controller called "drive_controller" in the config file
drive_motor_controller = hardwareMap.dcMotorController.get("drive_controller");
// then let's get references to the motors "left_drive" and "right_drive"
drive_left = hardwareMap.dcMotor.get("left_drive");
drive_right = hardwareMap.dcMotor.get("right_drive");
// reverse one of the motors (because it's a tank drive)
drive_left.setDirection(DcMotor.Direction.REVERSE);
// set both of the motors to use a bit of PID to keep them running at a constant speed
drive_left.setChannelMode(DcMotorController.RunMode.RUN_USING_ENCODERS);
drive_right.setChannelMode(DcMotorController.RunMode.RUN_USING_ENCODERS);
}
@Override
public void loop() { // this gets run again and again and again
// and every time around, we grab the stick value, negate them (because they come in with the wrong sign),
// and then set the power of the drivetrain motors.
drive_left.setPower(gamepad1.left_stick_y);
drive_right.setPower(gamepad1.right_stick_y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment