It's time to bring everything together so to have a fully mobile robot! Returning to our HelloRobot_TeleOp program we can add our arm control to our loop below the drivetrain code.
Full Program
This program uses the same configuration file created at the start of Hello Robot. Some hardware may not be used during this section.
packageorg.firstinspires.ftc.teamcode;importcom.qualcomm.robotcore.eventloop.opmode.LinearOpMode;importcom.qualcomm.robotcore.hardware.Blinker;importcom.qualcomm.robotcore.hardware.Servo;importcom.qualcomm.robotcore.hardware.TouchSensor;importcom.qualcomm.robotcore.eventloop.opmode.TeleOp;importcom.qualcomm.robotcore.eventloop.opmode.Disabled;importcom.qualcomm.robotcore.hardware.DcMotor;importcom.qualcomm.robotcore.hardware.DcMotorSimple;importcom.qualcomm.robotcore.util.ElapsedTime;@TeleOppublicclassHelloRobot_TeleOpextendsLinearOpMode {privateBlinker control_Hub;privateDcMotor arm;privateDcMotor leftmotor;privateDcMotor rightmotor;privateDcMotor test_motor;privateServo test_servo;privateTouchSensor test_touch; @OverridepublicvoidrunOpMode() { control_Hub =hardwareMap.get(Blinker.class,"Control Hub"); arm =hardwareMap.get(DcMotor.class,"arm"); leftmotor =hardwareMap.get(DcMotor.class,"leftmotor"); rightmotor =hardwareMap.get(DcMotor.class,"rightmotor"); test_motor =hardwareMap.get(DcMotor.class,"test_motor"); test_servo =hardwareMap.get(Servo.class,"test_servo"); test_touch =hardwareMap.get(TouchSensor.class,"test_touch");rightmotor.setDirection(DcMotorSimple.Direction.REVERSE);double x;double y;telemetry.addData("Status","Initialized");telemetry.update();// Wait for the game to start (driver presses PLAY)waitForStart();// run until the end of the match (driver presses STOP)while (opModeIsActive()) {//Drivetrain Control x =gamepad1.right_stick_x; y =-gamepad1.right_stick_y;rightmotor.setPower(y-x);leftmotor.setPower(y+x);//Arm Control with Limit Switchif(test_touch.isPressed()){if(gamepad1.dpad_up){arm.setPower(0.2); }else{arm.setPower(0); } }else {if(gamepad1.dpad_up){arm.setPower(0.2); }elseif (gamepad1.dpad_down){arm.setPower(-0.2); } else { arm.setPower(0); } } telemetry.addData("Status","Running");telemetry.update(); } }}
Right Stick vs. Left?
Which joystick is used for driving the robot is largely based on driver preference.
For Hello Robot, we will be referencing using the right stick due to the arm control using the Dpad. This can be changed at any time by changing from right to left in your x = gamepad1.right_stick_x; lines.
Downloads
These premade programs do not include control of the Class Bot V2's "claw" servo. To learn about programming a servo visit Programming Servos.
Class Bot V2 / Hello Robot Configuration File:
Class Bot V2 / Hello Robot Full TeleOp:
Class Bot V2 / Hello Robot Arm Control no Limit Switch: