Comments (2)
Make it a subsection of the mecanum drive page, talk about how to use the imu to get heading.
from gm0.
@TeleOp
public class FieldCentric extends LinearOpMode {
@Override public void runOpMode() {
// Declare our motors
// Make sure your ID's match your configuration
DcMotor motorFrontLeft = hardwareMap.dcMotor.get("motorFrontLeft");
DcMotor motorBackLeft = hardwareMap.dcMotor.get("motorBackLeft");
DcMotor motorFrontRight = hardwareMap.dcMotor.get("motorFrontRight");
DcMotor motorBackRight = hardwareMap.dcMotor.get("motorBackRight");
// Reverse the right side motors
// Reverse left motors if you are using NeveRests
motorFrontRight.setDirection(DcMotorSimple.Direction.REVERSE);
motorBackRight.setDirection(DcMotorSimple.Direction.REVERSE);
// Initialize imu
BNO055IMU imu = hardwareMap.get(BNO055IMU.class, "imu");
BNO055IMU.Parameters parameters = new BNO055IMU.Parameters();
parameters.angleUnit = BNO055IMU.AngleUnit.RADIANS;
imu.initialize(parameters);
waitForStart();
while(opModeIsActive()) {
double x = gamepad1.left_stick_x;
double y = -gamepad1.left_stick_y;
double turn = gamepad1.right_stick_x;
// Read inverse imu heading
double botHeading = -imu.getAngularOrientation().firstAngle;
// Rotate gamepad input x/y by hand
// See: https://matthew-brett.github.io/teaching/rotation_2d.html
double rotX = x * Math.cos(botHeading) - y * Math.sin(botHeading);
double rotY = x * Math.sin(botHeading) + y * Math.cos(botHeading);
double frontLeftPower = rotY + rotX + turn;
double backLeftPower = rotY - rotX + turn;
double frontRightPower = rotY - rotX - turn;
double backRightPower = rotY + rotX - turn;
// Put powers in the range of -1 to 1 only if they aren't already
// Not checking would cause us to always drive at full speed
if (Math.abs(frontLeftPower) > 1 || Math.abs(backLeftPower) > 1 ||
Math.abs(frontRightPower) > 1 || Math.abs(backRightPower) > 1) {
// Find the largest power
double max = 0;
max = Math.max(Math.abs(frontLeftPower), Math.abs(backLeftPower));
max = Math.max(Math.abs(frontRightPower), max);
max = Math.max(Math.abs(backRightPower), max);
// Divide everything by max (it's positive so we don't need to worry
// about signs)
frontLeftPower /= max;
backLeftPower /= max;
frontRightPower /= max;
backRightPower /= max;
}
motorFrontLeft.setPower(frontLeftPower);
motorBackLeft.setPower(backLeftPower);
motorFrontRight.setPower(frontRightPower);
motorBackRight.setPower(backRightPower);
}
}
}
from gm0.
Related Issues (20)
- Possible Incorrect Information in the Software Glossary
- Add section for gamepad rumble / LED control
- Driver Hub
- Multiple issues with Finite State Machine page HOT 1
- FSM Useful Implementation Syntax Error
- Mecanum sample code should bind resetYaw() to a button
- Add Laser Cutting Section
- Add images to materials guide
- Revamp Kit and Hardware guide
- Change Github Actions to use Node.js v16 HOT 2
- Add support for Japanese Translation HOT 3
- Arm Kinematics/Feedforward
- Update to the Software/Tutorials/Computer Vision page (SDK 8.2+)
- Add images/CAD to motion mounting page
- Add a translation version of Chinese Translations HOT 4
- Add Purchasing Advice to Belt Page HOT 1
- Add COTS Dead Wheels to Dead Wheels Page HOT 1
- Add a Shaft Retention Page
- Basic IMU Example HOT 6
- RC Phone legality notice is inaccurate
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gm0.