Advertisement
Golden_Dragoon

Return to heading FTC

Jan 24th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1.  void ReturnToHeading(int MinHeading, int MaxHeading) {
  2.         ForwardLeft.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
  3.         BackLeft.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
  4.         ForwardRight.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
  5.         BackRight.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
  6.  
  7.         angles = imu.getAngularOrientation(AxesReference.INTRINSIC, AxesOrder.ZYX, AngleUnit.DEGREES);
  8.         float zAxis = angles.firstAngle;
  9.  
  10.         //If this is a positive number, it means the inside distance from the right to the 0 heading
  11.         while (zAxis < MinHeading) {
  12.             angles = imu.getAngularOrientation(AxesReference.INTRINSIC, AxesOrder.ZYX, AngleUnit.DEGREES);
  13.             zAxis = angles.firstAngle;
  14.             ForwardLeft.setPower(.3); //These powers will make it turn to the left
  15.             ForwardRight.setPower(-.3);
  16.             BackLeft.setPower(.3);
  17.             BackRight.setPower(-.3);
  18.         }
  19.  
  20.         //if this is a negative number, it means the inside distance from the left to the 0 heading
  21.         while (zAxis > MaxHeading) {
  22.             angles = imu.getAngularOrientation(AxesReference.INTRINSIC, AxesOrder.ZYX, AngleUnit.DEGREES);
  23.             zAxis = angles.firstAngle;
  24.             ForwardLeft.setPower(-.3); //And these make it turn to the right
  25.             ForwardRight.setPower(.3);
  26.             BackLeft.setPower(-.3);
  27.             BackRight.setPower(.3);
  28.         }
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement