Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ReturnToHeading(int MinHeading, int MaxHeading) {
- ForwardLeft.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
- BackLeft.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
- ForwardRight.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
- BackRight.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
- angles = imu.getAngularOrientation(AxesReference.INTRINSIC, AxesOrder.ZYX, AngleUnit.DEGREES);
- float zAxis = angles.firstAngle;
- //If this is a positive number, it means the inside distance from the right to the 0 heading
- while (zAxis < MinHeading) {
- angles = imu.getAngularOrientation(AxesReference.INTRINSIC, AxesOrder.ZYX, AngleUnit.DEGREES);
- zAxis = angles.firstAngle;
- ForwardLeft.setPower(.3); //These powers will make it turn to the left
- ForwardRight.setPower(-.3);
- BackLeft.setPower(.3);
- BackRight.setPower(-.3);
- }
- //if this is a negative number, it means the inside distance from the left to the 0 heading
- while (zAxis > MaxHeading) {
- angles = imu.getAngularOrientation(AxesReference.INTRINSIC, AxesOrder.ZYX, AngleUnit.DEGREES);
- zAxis = angles.firstAngle;
- ForwardLeft.setPower(-.3); //And these make it turn to the right
- ForwardRight.setPower(.3);
- BackLeft.setPower(-.3);
- BackRight.setPower(.3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement