When using holonomic drive, one must remember that left/right strafing has to be coded. This can be done taking three values: the vertical axis, horizontal axis, and turning axis. We wi;l refer to the frontleft, frontright, backleft, and backright motors as fl, fr, bl, and br respectively.
- Get the values and put them into variables. I’ll use x, y, and z (turning) for my axes.
- Reverse the motors, this will make your life easier.
- Vertical movment should stay positive for each motor, so let’s give each motor “y”:
- Figure out how each motor strafes. For Omni, you can get a good idea using this simulator we made (takes a while to load): Omni Simulator. A good idea is to figure out max speed in the right direction. For our wheels’ Mecanum drive, to strafe right at max speed the motor values must be as follows (when using reversed motors! don’t forget this bit! simply setDirection(Direction.REVERSE) will do!):
Basically, the diagonals must fight each other to strafe. This means that they can’t move forward or backward, so the wheels move side to side. So diagonal pairs are positive and negative respectively to strafe. You must test this if you don’t know the force vectors of the wheels to figure out which configuration is left/right. Based on this and the knowledge that the rightmost point of the joystick x axis is +1, we come to this:
And compiling this with our previous conclusion:
- Figure out how to turn. If you reversed correctly, and are using a conventional holonomic drive, this should be when the left and right wheels move in opposite directions – just like tank! Meaning the motors for left/right should be reversed. To rotate right (again, we use right because the rightmost point on the joystick x axis is +1) the left side is positive and right side is negative, as follows:
And using our joystick values:
Compiling with our previous conclusions:
- Write the code! Disclaimer: under TeleOp, you’ll find a conversion of our teleop. That won’t match with this even though it’s Mecanum – that’s because turning is reversed!
Java123456//DONT FORGET TO RANGE.CLIP BECAUSE IT'S POSSIBLE TO GO OVER 1!!!!!!!!!//Range.clip(value, minimum value, maximum value) is the syntax, but we wrote our own method to scale our input, manage deadzones, and make sure we don't burn out our neverest-40's which have a max scalar power of .78, usage scale(value). We encourage writing this type of method, but using Range.clip also worksfrontright.setPower(scale(y+x-z));frontleft.setPower(scale(y-x+z));backright.setPower(scale(y-x-z));backleft.setPower(scale(y+x+z));