Mechanum with XBox Controller

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.

ANY help would be GREATLY appreciated! THANKS!

What template are you using? I could give you Iterative sample code.

Something like this:

float gyroAngle = 0.0; // we don’t have a gyro connected
myRobot->MecanumDrive_Cartesian(stick.GetX(), stick.GetY(), stick.GetZ(), gyroAngle);

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.

Could you use one of the joysticks for forward backward and strafing and the other joystick for rotation.

Im using command base but just any code examples will do - its easy to change over.

Yeah I was thinking about what daniel was saying - using one stick for x and y and the other for rotation - right now only one is being used.

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.

THANKS for the help!

What size mechanum wheels and what gearbox ratio ?

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!

6in and we have not decided on the ratios yet - what is suggested - also should we purchase Heavy Duty or Standard Duty wheels?

Okay thanks Ethan I think im starting to get a picture of what I need to do

Make sure you do the limiting via normalization, not clipping.

And how exactly do I do that?

Search for the word “normalize” in these docs:

http://www.chiefdelphi.com/media/papers/download/2783

Hey LF, Andrew, and Ethan! Just for future reference, it’s spelled mecanum. It’s an easy mistake to make. Good luck this season!

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.:slight_smile:

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?

Okay thanks guys! Ill let you know if I can get it to work;)

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.

You don’t need any “elses”

*
*max=fabs(s1);
if (fabs(s2)>max) max=fabs(s2);
if (fabs(s3)>max) max=fabs(s3);
if (fabs(s4)>max) max=fabs(s4);
if (max>1) {s1/=max; s2/=max; s3/=max; s4/=max;}