Advertisement
Guest User

Field Centric Code

a guest
Dec 9th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1.         robot.updateGyro();
  2.         //Changes the angle of the robot's motion with respect to the driver to the robot's current
  3.         //heading when the Y button is pressed
  4.         if(gamepad1.y)
  5.             angleFromDriver = robot.heading;
  6.         //This is the angle that the right joystick is pointing in
  7.         double inputAngle = Math.atan2(-gamepad1.right_stick_y, gamepad1.right_stick_x);
  8.         //This is the magnitude of how far the joystick is pushed
  9.         double inputPower = Math.sqrt(gamepad1.right_stick_x * gamepad1.right_stick_x + gamepad1.right_stick_y *                     
  10.         gamepad1.right_stick_y);
  11.         telemetry.addData("Joystick Magnitude", inputPower);
  12.         if (inputPower > 1)
  13.             inputPower = 1;
  14.         //This is the angle at which the robot should translate
  15.         double moveAngle = inputAngle + (angleFromDriver - robot.heading);
  16.         //Drives the robot in a field centric fashion, ordering frontLeft,frontRight,backLeft,backRight
  17.         robot.drive(
  18.                 (Math.sin(moveAngle) + Math.cos(moveAngle)) * inputPower * robot.currentDrivePower + (gamepad1.left_stick_x) *  
  19.                 robot.currentDrivePower,
  20.                 (Math.sin(moveAngle) - Math.cos(moveAngle)) * inputPower * robot.currentDrivePower + (- gamepad1.left_stick_x) *    
  21.                 robot.currentDrivePower,
  22.                 (Math.sin(moveAngle) - Math.cos(moveAngle)) * inputPower * robot.currentDrivePower + (gamepad1.left_stick_x) *       
  23.                 robot.currentDrivePower,
  24.                 (Math.sin(moveAngle) + Math.cos(moveAngle)) * inputPower * robot.currentDrivePower + (- gamepad1.left_stick_x) *     
  25.                 robot.currentDrivePower
  26.         );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement