Onbot Archives - The Fire Wires FTC Team 12014 https://www.firewires.org/category/onbot/ A spark is about to ignite Sun, 23 Apr 2023 03:50:52 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.2 https://www.firewires.org/wp-content/uploads/2022/03/cropped-Full-Logo-512-1-32x32.png Onbot Archives - The Fire Wires FTC Team 12014 https://www.firewires.org/category/onbot/ 32 32 204565980 A Beginner’s Guide to Mecanum Teleop in Onbot Java https://www.firewires.org/a-beginners-guide-to-mecanum-teleop-in-onbot-java/ https://www.firewires.org/a-beginners-guide-to-mecanum-teleop-in-onbot-java/#respond Thu, 20 Apr 2023 13:56:42 +0000 https://firewires.org/?p=2305 Open the Onbot Java IDE. Create a new project. In

The post A Beginner’s Guide to Mecanum Teleop in Onbot Java appeared first on The Fire Wires FTC Team 12014.

]]>
  1. Open the Onbot Java IDE.
  2. Create a new project.
  3. In the project, create a new class called MecanumTeleop.
  4. In the MecanumTeleop class, add the following imports:
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.util.ElapsedTime;

  1. In the MecanumTeleop class, declare the following variables:
private ElapsedTime runtime = new ElapsedTime();
private DcMotor leftFrontMotor;
private DcMotor rightFrontMotor;
private DcMotor leftBackMotor;
private DcMotor rightBackMotor;

  1. In the MecanumTeleop class, override the init() method. In this method, initialize the motors:
@Override
public void init() {
  leftFrontMotor = hardwareMap.get(DcMotor.class, "left_front_motor");
  rightFrontMotor = hardwareMap.get(DcMotor.class, "right_front_motor");
  leftBackMotor = hardwareMap.get(DcMotor.class, "left_back_motor");
  rightBackMotor = hardwareMap.get(DcMotor.class, "right_back_motor");

  leftFrontMotor.setMode(DcMotor.Mode.RUN_WITHOUT_ENCODER);
  rightFrontMotor.setMode(DcMotor.Mode.RUN_WITHOUT_ENCODER);
  leftBackMotor.setMode(DcMotor.Mode.RUN_WITHOUT_ENCODER);
  rightBackMotor.setMode(DcMotor.Mode.RUN_WITHOUT_ENCODER);
}

  1. In the MecanumTeleop class, override the loop() method. In this method, read the gamepad inputs and drive the robot:
@Override
public void loop() {
  // Read the gamepad inputs
  double x = gamepad1.left_stick_x;
  double y = gamepad1.left_stick_y;
  double rotation = gamepad1.right_stick_x;

  // Drive the robot
  leftFrontMotor.setPower(x + y + rotation);
  rightFrontMotor.setPower(x - y - rotation);
  leftBackMotor.setPower(x - y + rotation);
  rightBackMotor.setPower(x + y - rotation);

  // Display the runtime
  telemetry.addData("Runtime", runtime.seconds());
  telemetry.update();
}

  1. To run the code, click the “Play” button in the Onbot Java IDE.
  2. The robot should now drive in all directions in response to the gamepad inputs.

Here are some additional tips for creating a mecanum teleop code in Onbot Java:

  • Use the ElapsedTime class to keep track of the robot’s runtime. This can be useful for debugging and for timing events.
  • Use the telemetry class to display information about the robot’s state on the Driver Station. This can be useful for debugging and for monitoring the robot’s performance.
  • Use the Scheduler class to schedule periodic tasks. This can be useful for tasks that need to be run at regular intervals, such as updating the odometry or checking the battery level.

I hope this tutorial has been helpful. If you have any questions, please feel free to ask in the comments.

The post A Beginner’s Guide to Mecanum Teleop in Onbot Java appeared first on The Fire Wires FTC Team 12014.

]]>
https://www.firewires.org/a-beginners-guide-to-mecanum-teleop-in-onbot-java/feed/ 0 2305