I was wondering if anyone had any resources on the best way to make a mecanum drive robot turn left and right. This is currently the best I came up with, but this is based on Arcade Drive turn logic. I was wondering if this code would function / any ways that were more effective.
The leftTurn and rightTurn methods are unnecessary. In the second snippet you posted replace leftStickZ (an axis that doesn’t exist) with rightStickX and your robot should rotate in place the way you want.
That’s actually the method in charge of of using the left stick to drive the robot. The reason that I’m using the right stick to turn the robot is because the X axis on the left stick determines how much the robot strafes by.
I can provide a larger snippet of code if that helps. Or if I misunderstood what you were saying please correct me.
So I can feel for ya - I’ve been in this position before, many times. The critical thing I’ve learned from those positions - Getting a yes/no answer on whether a given piece of code works will not actually be useful.
To be able to be flexible and grow your codebase as needed, you need to be able to generate the answer yourself, and more importantly know why the answer is yes or no.
I think your analysis is a good start, but I have some feedback:
1 seems reasonable
2 is already talking about “setting motors” - this sounds like writing to an output to me
Additionally, you’ve not addressed the logic inside driveCartesian cartisian. Do you know which of the three steps it takes care of? Or if it takes care of more than one? In particular, look into its source code if you like - this may be helpful.
The above questions look into more “depth” of your particular chosen implementation. I do have another, more “high level” question about your choice in code though:
WPILib provides an example for a mechanum drivetrain. Your code looks like you have chosen to add more functionality. Can you describe if you intended to diverge from their example? And, if the divergence was expected, can you describe why you chose to go this route?
Knowing what you’re attempting to accomplish above and beyond the example could be helpful in advising on the best solution.
I realized that I had been misunderstanding the way the .driveCartasian worked. When I read the variables it requires it listed an Z axis, which I assumed meant a third z axis on the joystick.
But after thinking about it properly (and some research) I found that the Z axis was meant to represent the rotation you wanted the robot to make meaning this value can be set to the right stick x axis.
The .driveCartasian function will run all the background math equations to make the mecanum drive move 360 and rotate, you just need to provide the proper axis from your joy stick.