# Holonomic Drive Code problem

I have no idea if it’s my code that’s wrong or the motors on the robot. I looked up how to do the code for a holonomic drive and I pretty much wrote the same thing as the other codes I saw. I only changed the variables. When I test it, two wheels would run but the other two won’t. And, from time to time, one of the two wheels working would stop or jerk, leaving one wheel running nicely. Can someone please check and tell me what’s wrong? Thanks!!!

#pragma config(Motor, port2, LeftTop, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port3, RightTop, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port4, RightBack, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port5, LeftBack, tmotorServoContinuousRotation, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

{
int joy_x;
int joy_y;
int rot;

int m1 = 0;
int m2 = 0;
int m3 = 0;
int m4 = 0;

while(1)
{
joy_x = vexRT[Ch2];
joy_y = vexRT[Ch3];
rot = vexRT[Ch1];

``````m1 = (joy_y) + (-1 * joy_x) + (-1 * rot);
m2 = (-1 * joy_y) + (-1 * joy_x) + (-1 * rot);
m3 = (-1 * joy_y) + (joy_x) + (-1 * rot);
m4 = (joy_y) + (joy_x) + (-1 * rot);

if (m1 >= 127)
{
m1 = 127;
}
else if (m1 <= -127)
{
m1 = -127;
}

if (m2 >= 127)
{
m2 = 127;
}
else if (m2 <= -127)
{
m2 = -127;
}

if (m3 >= 127)
{
m3 = 127;
}
else if (m3 <= -127)
{
m3 = -127;
}

if (m4 >= 127)
{
m4 = 127;
}
else if (m4 <= -127)
{
m4 = -127;
}

motor[port2] = m1;
motor[port3] = m2;
motor[port4] = m3;
motor[port5] = m4;
``````

}
}

Could you tell me which motors run and which ones don’t? Could you also diagram which motors correspond to which wheels on the drive train?

Run my code and see if it works:

``````  int joy_1_x = 0;
int joy_2_x = 0;
int joy_2_y = 0;
joy_1_x = vexRT[Ch4];
joy_1_y = vexRT[Ch3];
joy_2_x = (vexRT[Ch1]/2);

if(joy_1_x <= 50 && joy_1_x >= -50){joy_1_x = 0;}
if(joy_1_y <= 30 && joy_1_y >= -30){joy_1_y = 0;}
if(joy_2_x <= 30 && joy_2_x >= -30){joy_2_x = 0;}

motor[one] = (-1*joy_1_y) + (-1*joy_1_x) + (joy_2_x);
motor[two] = (1 * joy_1_y) + (-1*joy_1_x) + (joy_2_x);
motor[three] = (1 * joy_1_y) + (1 * joy_1_x)  +(joy_2_x);
motor[four] = (-1*joy_1_y) + (1 * joy_1_x) + (joy_2_x);

if (motor[one] >= 127)
{
motor[one] = 127;
}
else if(motor[one] <= -127)
{
motor[one] = -127;
}

if (motor[two] >= 127)
{
motor[two] = 127;
}
else if(motor[two] <= -127)
{
motor[two] = -127;
}

if (motor[three] >= 127)
{
motor[three] = 127;
}
else if(motor[three] <= -127)
{
motor[three] = -127;
}

if (motor[four] >= 127)
{
motor[four] = 127;
}
else if(motor[four] <= -127)
{
motor[four] = -127;
}``````

I set some deadzones, but that should not effect how the motors turn. When looking at your robot from the top the motors go clockwise, but i forget which wheel is motor 1. I believe it is top left but it could be bottom left or bottom right (its been over a year since I used holonomic sorry) Tell me how this works out. There were some small differences but I think that would only effect the direction the motors turn not necessarily whether they turn at all. For some reason I have this vague memory of encountering the same problem you had so I wonder if those small differences actually matter. BTW next time wrap your program in the

[CODE]
tags

Well, the code runs and the motors turn, nothing jumps, but I don’t actually have a holonomic drive here. The code follows smartkid’s original example and I don’t see any typos. Are all the motor directions set correctly? When I push ch1 left, “rot” decreases and all the motors turn forwards. Test each motor individually with the robot supported off the ground, perhaps there is a wiring issue.

Thorondor. The code you sent was a big help. We were able to tell what the problem was. One of the wheels wouldn’t turn and when we checked, we found out the wheel was stripped. My code was probably ok, but yours was better since it runs all wheels now (and my code only ran 2 1/2 wheels LOL:D). Thanks alot for your help.

Ya stripped wheels are never good. Glad I could help

It looks like you had channel 2 and 3 being considered versus 4 and 3 respectively for X and Y. Sorry for the big picture but that’s how it plopped in. It looks like you can see the channels easily on this guy to see where you coded it one channel off.

Channels 1 & 2 are on the right joystick and channels 3 & 4 are on the left one. Your code was trying to pick up the left joystick x control from the right joystick while Y direction joy_y was looking at the left joystick correctly. Or in other words, you were one channel off.

So I could see while you thought you were rotating the robot, you were really sending in signal for the x direction from whatever you were off the x axis. Since that value was probably pretty small it made it seem it was only going one direction. You had the Y right, just the X value was wrong.

Well, I think this could be done in a shorter code with tweaks in the way the controller would control. Ch3 and Ch4 would control a 45 degree holonomic drive [forward, backward, strafting, diagonal]. Ch2 would control the right side of the drive. If Ch3 is positive, Ch2 is negative and vice versa, it rotates respectively. That means a controller used to tank who simply push both joystick forward would make the robot forward. Here’s my code, hopefully it works for you
[HTML]
int ch2Value = vexRT(Ch2);
int ch3Value = vexRT(Ch3);
int ch4Value = vexRT(Ch4);
if (ch2Value <= -10 || ch2Value >= 10) {
setMotorValues(ch3Value, ch3Value, ch2Value, ch2Value);
}
else if (ch2Value >= -10 && ch2Value <= 10) {
setMotorValues(ch3Value + ch4Value,
ch3Value - ch4Value,
ch3Value - ch4Value,
ch3Value + ch4Value);
}[/HTML]

Here’s how I map my motors:
1 /// 3
2 /// 4