How do I do a mecanum strafe code?

I cannot strafe with our robot’s mecanum wheels. I have tried countless things, and they simply do not strafe, no matter what. I can grab my code and maybe an image of my robot later, but in the meanwhile can anybody give me suggestions?

Make sure your wheels are in the correct positions. They should be aligned like this:
image

2 Likes

I can check this tomorrow. Also, for clarification, is it different if I use the green mecanum wheels? (see image)
Screenshot 2023-01-11 1.29.31 PM

Whoop, nevermind, I just found an image in our notebook. They’re aligned backwards! I’ll consult my team, I think they’ve been like this the whole time…

Here’s another picture for you to compare your setup to.

7 Likes

For code you probably want this:

 //Drivetrain Control
    Rfront.setVelocity(Controller1.Axis2.position() - (Controller1.Axis1.position() + Controller1.Axis4.position()), percent);
    Lfront.setVelocity(Controller1.Axis2.position() + (Controller1.Axis1.position() + Controller1.Axis4.position()), percent);
    Rback.setVelocity(Controller1.Axis2.position() + (Controller1.Axis1.position() - Controller1.Axis4.position()), percent);
    Lback.setVelocity(Controller1.Axis2.position() - (Controller1.Axis1.position() - Controller1.Axis4.position()), percent);
    Rfront.spin(forward);
    Lfront.spin(forward);
    Rback.spin(forward);
    Lback.spin(forward);

It should work if I haven’t made any mistakes.

3 Likes


Picture of the bot.
The intake generally doesn’t touch the floor, whatever direction. However, since the front wheels are acting strange when strafing, the robot shakes side to side, like it used to when normally turning on normal code before the wheels were fixed.

We fixed our wheels, then we tried this code, and also a code that we were given by a team that formerly used mecanum wheels (same code, but Axis2 was replaced by Axis3)

They didn’t work, so we put them both in a forever loop. Then they started driving. It kept driving in really strange, inconsistent ways, like how it did before we fixed the wheels. Also, we couldn’t strafe either way, even though our wheels would be spinning the correct directions. We don’t know the problem, but we have mostly narrowed it down to either too much weight, bad weight distribution (heavier in the front) or our front wheels locking up. Let me try to get a picture.

Yeah, a picture would help. Are you driving it on the field or are you driving it on a different surface?

Both, it seems. Also, there is a picture, took like 2 hours for the mods to approve it tho lol

1 Like

Also, sorry for the multiple replies, what would each control do? I know some bits of this (and, honestly, can figure it out myself), but knowing what to expect would definitely help determine things, in any case.

So the theory of this sort of code is to set the motor velocities equal to certain joystick values. So the first line

Rfront.setVelocity(Controller1.Axis2.position() - (Controller1.Axis1.position() + Controller1.Axis4.position()), percent);

would set the velocity of the front wheel on the right equal to the total values of Axis 2, minus Axis 1, plus Axis 4. If you try to picture it in your head, it often helps. So for line one you might say, " OK, I want the robot to go forward when I push Axis 2 forward. So when I push Axis 2 forward, I can see that the right front wheel will spin forward." Same deal with strafing and turning. If the wheels are too confusing, imagine that you have an X-drive. It uses identical code, but it is a lot easier to see where the wheels are going. The last 4 lines of code basically tell the motors to spin forward the whole time, but of course, if a motor’s velocity is negative, it will spin in reverse. If its velocity is zero, it will stop. Try using this code. I do not know if it is different, but it is more recent than the other one.

  //Drivetrain Control
    Rfront.setVelocity((Controller1.Axis2.position() - Controller1.Axis1.position() - Controller1.Axis4.position()), percent);
    Lfront.setVelocity((Controller1.Axis2.position() + Controller1.Axis1.position() + Controller1.Axis4.position()), percent);
    Rback.setVelocity((Controller1.Axis2.position() + Controller1.Axis1.position() - Controller1.Axis4.position()), percent);
    Lback.setVelocity((Controller1.Axis2.position() - Controller1.Axis1.position() + Controller1.Axis4.position()), percent);
    Rfront.spin(forward);
    Lfront.spin(forward);
    Rback.spin(forward);
    Lback.spin(forward);
1 Like

The rules for plastics are defined by R7 in the game manual. Since the plastic from which the turning point field element was made is a legal plastic (Polycarbonate), and the thickness is under 0.070" thick, it’s all legal. It doesn’t matter where the plastic comes from, as long as it meets type and dimensional requirements.

4 Likes

This might help also

2 Likes

Could be mecanum wheels aren’t lined up properly too tbh