As of now our team has the XBox controller working using ArcadeDrive. But we now want to use mechanum wheels… I have an okay understanding of how to do this with a joystick using x, y, and twist but how do I do it with an XBox controller. I don’t even know how I would begin to structure the code.
I would just pick one of the sticks for your X and Y axis, and then a good replacement for the joystick twist would be using the analog triggers on the xbox controller. If you need Axis numbers, the input tab on the driver station has live controller readings and axis/button numbers.
Okay here is what I was thinking - use L1 and R1 to turn slow and L2 and R2 to turn fast. Then use left joystick x to move left and right and left joystick y to move up and down - if I push up on the joystick AND move it right the robot should move diagonally - will this work and if so how would I implement it? I also want to be able to have a button - probably the up arrow and down arrow - that I can change the speed with.
for mechanum wheels, our team also uses a Xbox controller. We have the right joystick axis mapped to the linear movement of the robot, and the the left joystick x axis mapped to the rotation.
Here’s a simplified version of our code:
//FLMotor = Front Left Motor
//FRMotor = Front Right Motor
//BLMotor = Back Left Motor
//BRMotor = Back Right Motor
//x = right joystick, x axis
//y = right joystick, y axis
//yaw = left joystick, x axis
FLMotor = y + x + yaw
FRMotor = y - x - yaw
BLMotor = y - x + yaw
BRMotor = y + x - yaw
The values will have to be limited, other-wise it will go beyond the accepted values (-1 to 1). Make sure the wheels are set up properly, and good luck!
I would start here. https://wpilib.screenstepslive.com/s/4485/m/13809/l/241862-driving-a-robot-using-mecanum-drive
Our team did our first mecanum over off season and found out that it was better to replace the “Get Z Axis” and “Get X Axis” and “Get Y Axis” with get raw axis with which ever ones you want. We put the X Axis to strafe left and right on axis 0 (left joystick X Axis). The Y Axis to go forwards and backwards on axis 1 (left joystick Y Axis). And for rotation, we put axis on the right X Axis on axis 4 (right joystick X Axis). Also make sure they your motor controllers are set up in the correct order when you set it up. Hopefully that helps some.
We do something very similar to this. I don’t want to hijack this thread but how are you limiting the values? Right now in our rough code we have a mess of if-elses determining if the values are over 1. I imagine that there is a better way to do this?
Our team uses mecanum with a Logitech F310 gamepad. The way we map the controls is that we use tank drive with the joysticks to control forwards, backwards, and rotation. For strafing we use the back triggers because they are analog. I believe they translate to twist on the flight sticks. Hope this helps.