Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.usfirst.ftc.exampleteam.yourcodehere;
- import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
- import com.qualcomm.robotcore.hardware.DcMotor;
- import com.qualcomm.robotcore.hardware.Servo;
- import org.swerverobotics.library.SynchronousOpMode;
- /**
- * A skeletal example of a do-nothing first OpMode. Go ahead and change this code
- * to suit your needs, or create sibling OpModes adjacent to this one in the same
- * Java package.
- */
- @TeleOp(name = "My First OpMode")
- public class MyFirstOpMode extends SynchronousOpMode {
- /* Declare here any fields you might find useful. */
- public DcMotor motorLeft = null;
- public DcMotor motorRight = null;
- public DcMotor slide2 = null;
- public Servo pusher = null;
- public Servo P1 = null;
- public Servo P2 = null;
- public DcMotor carry = null;
- public Servo buttonPusher = null;
- @Override
- public void main() throws InterruptedException {
- /* Initialize our hardware variables. Note that the strings used here as parameters
- * to 'get' must correspond to the names you assigned during the robot configuration
- * step you did in the FTC Robot Controller app on the phone.
- */
- motorLeft = this.hardwareMap.dcMotor.get("motorLeft");
- motorRight = this.hardwareMap.dcMotor.get("motorRight");
- pusher = hardwareMap.servo.get("pusher");
- slide2 = hardwareMap.dcMotor.get("slide2");
- P1 = hardwareMap.servo.get("P1");
- P2 = hardwareMap.servo.get("P2");
- carry = hardwareMap.dcMotor.get("carry");
- buttonPusher = hardwareMap.servo.get("buttonPusher");
- motorRight.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
- motorLeft.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
- slide2.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
- carry.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
- boolean direction = true;
- double powerM = 5.5;
- double powerRight = 0;
- double powerLeft = 0;
- boolean pusherIn = true;
- waitForStart();
- // Go go gadget robot!
- while (opModeIsActive()) {
- if (updateGamepads()) {
- if (gamepad1.a){
- direction = !direction;
- }
- if (gamepad1.y){
- powerM = .55;
- }
- if (gamepad1.x){
- powerM = .2;
- }
- powerLeft = gamepad1.left_stick_y;
- powerRight = gamepad1.right_stick_y;
- //reverse direction
- if (direction){
- this.motorLeft.setPower(powerLeft * powerM);
- this.motorRight.setPower(-powerRight * powerM);
- }
- else {
- this.motorLeft.setPower(-powerRight * powerM);
- this.motorRight.setPower(powerLeft * powerM);
- }
- // pusher
- if (gamepad1.dpad_up) {
- pusher.setPosition(100);
- }
- else if (gamepad1.dpad_down) {
- pusher.setPosition(0.5);
- }
- //buttonPusher
- if (gamepad1.b){
- if (pusherIn){
- buttonPusher.setPosition(0.5);
- pusherIn = !pusherIn;
- }
- else{
- buttonPusher.setPosition(100);
- pusherIn = !pusherIn;
- }
- }
- //higher slide bar
- if (gamepad2.left_bumper) {
- slide2.setPower(-15);
- } else if (gamepad2.left_trigger > 0) {
- slide2.setPower(15);
- } else {
- slide2.setPower(0);
- }
- //pincers
- if(gamepad2.a){
- P1.setPosition(0);
- P2.setPosition(1);
- }
- if(gamepad2.b){
- P1.setPosition(1);
- P2.setPosition(0);
- }
- //lower pinser code
- if (gamepad2.dpad_down){
- carry.setPower(25);
- }
- else if (gamepad2.dpad_up){
- carry.setPower(-25);
- }
- else {
- carry.setPower(0);
- }
- }
- telemetry.update();
- idle();
- }
- }
- }
- //auto
- package org.usfirst.ftc.exampleteam.yourcodehere;
- import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
- import com.qualcomm.robotcore.eventloop.opmode.Disabled;
- import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
- import com.qualcomm.robotcore.hardware.DcMotor;
- import com.qualcomm.robotcore.hardware.Servo;
- import org.swerverobotics.library.SynchronousOpMode;
- /**
- * A skeletal example of a do-nothing first OpMode. Go ahead and change this code
- * to suit your needs, or create sibling OpModes adjacent to this one in the same
- * Java package.
- */
- @Autonomous(name = "Auto")
- public class Auto extends SynchronousOpMode {
- /* Declare here any fields you might find useful. */
- public DcMotor motorLeft = null;
- public DcMotor motorRight = null;
- public DcMotor slide1 = null;
- public DcMotor slide2 = null;
- public Servo pusher = null;
- @Override
- public void main() throws InterruptedException {
- /* Initialize our hardware variables. Note that the strings used here as parameters
- * to 'get' must correspond to the names you assigned during the robot configuration
- * step you did in the FTC Robot Controller app on the phone.
- */
- motorLeft = this.hardwareMap.dcMotor.get("motorLeft");
- motorRight = this.hardwareMap.dcMotor.get("motorRight");
- pusher = hardwareMap.servo.get("pusher");
- slide2 = hardwareMap.dcMotor.get("slide2");
- motorRight.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
- motorLeft.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
- slide2.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
- waitForStart();
- // Go go gadget robot!
- motorLeft.setPower(-35);
- motorRight.setPower(35);
- Thread.sleep(2000);
- motorLeft.setPower(0);
- motorRight.setPower(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement