Mechanum Program

I have been searching around on the internet, looking up some code for mechanum wheels,stuff like this

//Create "deadzone" variables. Adjust threshold value to increase/decrease deadzone
int X2 = 0, Y1 = 0, X1 = 0, threshold = 15;

//Loop Forever
while(1 == 1)
{
//Create "deadzone" for Y1/Ch3
if(abs(vexRT[Ch3]) > threshold)
Y1 = vexRT[Ch3];
else
Y1 = 0;
//Create "deadzone" for X1/Ch4
if(abs(vexRT[Ch4]) > threshold)
X1 = vexRT[Ch4];
else
X1 = 0;
//Create "deadzone" for X2/Ch1
if(abs(vexRT[Ch1]) > threshold)
X2 = vexRT[Ch1];
else
X2 = 0;

//Remote Control Commands
motor[frontRight] = Y1 - X2 - X1;
motor[backRight] = Y1 - X2 + X1;
motor[frontLeft] = Y1 + X2 + X1;
motor[backLeft] = Y1 + X2 - X1

But I am unsure of what some of the stuff is. I am an amateur programer, and have no idea what some of this stuff means. Particularly the deadzone,the X and Y and Channels. Please help!
I realize that this code will not strafe, and if someone could help me with that too that would be great!!

Thank you sooo much!

I am by no means a professional, but I can read the code.

Dead zone is the feature frequently used in any joystick programming. Basically, the way we program a joystick to motor is giving the reading of the joystick to the motor. When we do not want motors to move, we allow the joystick to go back to its original position. However the original position is usually not a precise 0 reading. Without dead zone, your motor may possibly keep drifing when the joystick is not moved. So dead zone is a command saying that if joystick reading is under a certain value, just stop the motors. And in the program sample the programmer used absolute value to simplify the code, but basically it is the same principle.

The addition and subtraction below is the command for holonomic mecanum drive. Basically a mecanum drive uses same driver code as an X drive. Easy c does this for you in one block, but giving addition and subtraction values of joystick channel readings to motors is the principle programming an arcade holonomic drive.

Edit: if you are using easy c, joystick deadzone is automatically prepared and holonomic drive has an easy setup block. This is just the bare-bone code behind it.

That definitely clears it up! Thank you so much! I’m trying to make sure that I understand the code before actually trying to use it (and or fix what ever happened when I tested it).

the deadzone can be implemented with a single for loop for all motors at once, this is what i use


for (int i=0;i<9;i++) {
  if (abs(motor*)<20) {
    motor*=0;
  }
}

**

You’re welcome! Glad I can help. Have fun programming!

Thank you again to everyone who posted, but can anyone help me with the strafing? Omni wheels is ok too, but my team has been talking and we are sure that strafing is something we definitely want to at least attempt. Thanks for the help!

This code (I believe) will strafe as is as long as you set up the motors and mecanum wheels correctly.

Uhhhhh… not a method I would use and I never considered about it… how does it theoretically work? Could you please explain this?

This will set all motors which have a low power to zero, even if you want them to be set to a low value (ie. arm hold code in lifts). Also, it will not check the last motor which could cause one side of a lift to hold, while the other goes down (resulting in a tipped robot and/or bent metal).

Yes, basically correct. Consider this code.

task main()
{
    while(1)
        {
        // Ch1 ontrols arm
        if( abs(vexRT Ch1 ]) > 15 )
            { 
            motor[port1]  = vexRT Ch1 ];
            motor[port10] = vexRT Ch1 ];
            }
        else
            {
            // Hold power
            motor[port1]  = 19;
            motor[port10] = 19;
            }
        
        // Other code in here
        // That takes time to execute
          
        // unfortunate deadband
        for (int i=0;i<9;i++) {
            if (abs(motor*)<20) {
                motor*=0;
            }
        }
        
        wait1Msec(25);
      }
}

There are two potential issues.

  1. As you said, if you want some small value sent to the motors then this code will override that.

  2. It may cause the motors to “jitter” if other small values are sent. The operating system is using the values in the “motor” array and sends them out to the motors approximately every 20mS. If you set in your code values between 1 and 19, these may be sent before the deadband code changes them back to 0. Values higher than 10 to so can cause the motor to move, in other words, the motor may turn quickly on and off.

These are minor issues and may not be noticeable. Better solution if you want to do this is to use an intermediate variable for motor values and then send those once to the motors at the end of the while loop.**

Thanks for the explanation. Good to know.