So we want to make it so when the driver presses forward, it moves away from him rather than the robot going “forward” no matter how it’s rotated.
Correct us if we’re wrong but we think we need to use the gyro to know which way the robot is facing.
We did write some code following the second document of Ether’s documents (Paper: 4 wheel independent drive & independent steering ("swerve")) and were wondering if that is the right path.
Yup, Gyro’s the way to go. All you need to do is create a heading vector from the driver’s controller (for instance, left stick x + y), rotate that vector by the robot’s heading, then use that vector as your translation vector in the swerve math (Vx and Vy, or FWD and STR, in Ether’s derivation).
You’re correct. Your gyro should give you the angle the robot is facing relative to the angle it was at when it was calibrated (let’s assume for now that’s forward). To transform the joystick inputs into field-relative coordinates, follow these steps:
- Convert the joystick cartesian coordinates (x,y) into polar coordinates (r,θ)
- Subtract the gyro angle from the joystick angle
- Convert back to cartesian coordinates
Your new x,y coordinates are now “field-relative” as you described
If you’re using LabView I’m pretty sure you can just plug in the gyro readout to the Holonomic Drive block, making it one thing LabView makes way easier!
Thanks for all your help! It makes a lot of sense- we’ll definitely give it a try.