Mecanum Wheels

Hi All

I am building a robot and I want to use mecanum wheels. I want to deploy one joystick with click button to toggle between two modes.
Mode 1. Forward, Backwards, Left turn and right turn (as a normal car would drive.)
Mode2. Forward, Backwards, Left strafe, Right strafe (typical mecanum wheels arrangement.)

I know the basic understanding of how mecanum wheels work but I am unable to put a one general mathematical equation based on the joystick value so that I can implement programming code based on that equation to move the robot using mecanum wheels.
I intend to use a basic 2 axis joystick used in xbox or playstation controllers.

Could anyone help me with it please.

Thanks

It actually easier than you think, especially with the numerous topics on skid steering and single joysticks. However, because you want to strafe left and right, this would mean you need two motor driver controllers. one for the front wheels and the other for the back wheels.

What parts do you have already?

I have currently 4 dc geared motors with encoders connected to all four wheels. Two kangaroo motor controllers, each for two motors. Everything connected to Arduino Mega 2560.

Correction:
I have 4 motors connected to 2 sabertooth motor controllers and Kangaroo motion controllers.

Good, now how do you plan on controlling it, what have you decided on? Both Xbox and Ps3 controllers will need the USB host shield and Bluetooth dongles to work. Or you can go with either paired bluetooth modules or RF modules. The "modules" are easier to learn and use, but are not compatible with a xbox or Ps3 controllers. The downside of these module is you would need a second arduino to act as a controller.

Two kangaroo motor controllers

Kangaroo makes motor controllers? Never mind

Alternative:
If you want, you can use a wireless Ps2 controller, which would give you the same range as a Ps3 or Xbox, and you won't need to buy a USB host shield or a second arduino. Also they are VERY cheap now, gamestop probably has them for $5 on the clearance rack.

I do not intend to use xbox or playstation controllers as is. I am only using 2 axis joystick. for example parallax 2 axis joystick hardwired to arduino mega on two analog inputs.
maybe in future I will in future get a wifi shield and control via wifi but thats not I am worried about that for the time being.

For now I am just concentrating on getting the programming done for simple driving mode I explained earlier.

I am only using 2 axis joystick. for example parallax 2 axis joystick hardwired to arduino mega on two analog inputs.

You want to hardwire the joystick to the same arduino, or make it wireless?

Either way you would need to convert the 0-1023 range from the joysticks to values for your motors. I used the map() function and a few IF/ELSE statements for my RC truck.

Here is my drive code(not the full code). My controller outputs 0 - 20 for both Forward/Reverse and Left/Right, then from those values, drive the motors accordingly.

void move(int z, int y, int s)
{  
  //Movement varibles
  int DRV2 = map(z, 0, 10, 255, 0); //Reverse
  int DRV1 = map(z, 10, 20, 0, 255); // Forward
  int STRL = map(y, 0, 10, 255, 0); // Left
  int STRR = map(y, 10, 20, 0, 255);// Right

  if(z > 10)//forwards, Center point is 10, so if z is greater than 10, go forward, else reverse.           
  {
    //Serial.println("Forward with turning"); 
    analogWrite(LMF, constrain(abs(DRV1 - STRL),0,255)); 
    analogWrite(RMF, constrain(abs(DRV1 - STRR),0,255));   
    digitalWrite(LMR, LOW); 
    digitalWrite(RMR, LOW);   
  }
  else if(z < 10)//backwards               
  {
    //Serial.println("Reverse with turning"); 
    digitalWrite(LMF, LOW); 
    digitalWrite(RMF, LOW);   
    analogWrite(LMR, constrain(abs(DRV2 - STRL),0,255)); 
    analogWrite(RMR, constrain(abs(DRV2 - STRR),0,255));   
  }
  else if(z == 10 && y > 10)//Right               
  {
    //Serial.println("360 left"); 
    digitalWrite(LMR, LOW); 
    analogWrite(RMR, STRR);   
    analogWrite(LMF, STRR); 
    digitalWrite(RMF, LOW);
  }
  else if(z == 10 && y < 10)//Left              
  {
    //Serial.println("360 right"); 
    analogWrite(LMR, STRL); 
    digitalWrite(RMR, LOW);   
    digitalWrite(LMF, LOW); 
    analogWrite(RMF, STRL);   
  }

  else //full stop
  { 
    digitalWrite(LMF, LOW); 
    digitalWrite(RMF, LOW);        
    digitalWrite(LMR, LOW); 
    digitalWrite(RMR, LOW);    
  }
  y=0; z=0; s=0;
}

Have you tested your motors with some simple code? Forward, reverse, left, right ?

Yes I have tried that. they run perfectly

The output from my controller is 0 to 255.

Did you use mecanum wheels to drive your RC truck ?

This is my truck. - YouTube which original started from this (code wise) - YouTube

I saw the videos. Good work.

How did you live stream the video feed. Was it wireless or wired.

Anyways. I still could find any proper implementation to drive mecanum wheels or found any mathematical equations so that I can use that as a basis of writing of code.

Wireless video stream.

The code snippet I gave is basically your Mode 1.
Mode 2 is a bit different, to strafe left and right, the wheels need to rotate opposite of each other.

Like so, F = forward, R = reverse
Left: Right:
F R : (front wheels)
R F : (rear wheels)

Okay thanks, i will try that.

Did you use off the shelf IP camera for wireless stream.
I have searched and found out that using a simple camera a plugging it to arduino with wifi shield does not give good fps and there is a noticeable lag. All in all it is not "real time". What type of camera did you use.

This is the camera I am using Mini Wireless Security Camera with this mount Arduino Servo Mount