So we’re using four wheels, four motors.
We set them up to run through some deadzone code, then perform some calculations, and assign the power to the PWMs in pairs.
The idea is to have the simpliest of holonomic drive code possible.
Here’s the jist of it:
if(!p2_sw_trig) //if not turning
{ //deadzone
if(p2_x<122) //more than 5 below 127
{
deadx = ((p2_x - 122) * 127)/122 + 127; //scaling so we don't just jump from 127 to 121 but can still reach 0
} else if(p2_x>132) //more than 5 above 127
{
deadx = ((p2_x - 132) * 127)/122 + 127; //scaling
} else
{
deadx = 127; //don't move if within 5 of 127
}
printf("deadx=%d\r",(int)deadx);
//same stuff for y axis
if(p2_y<122)
{
deady = ((p2_y - 122) * 127)/122 + 127;
} else if(p2_y>132)
{
deady = ((p2_y - 132) * 127)/122 + 127;
} else
{
deady = 127;
}
printf("deady=%d\r",(int)deady);
pair1 = deady+127-deadx; //holonomictastic
pair2 = deady+deadx-127; //holonomictastic
printf("pair1=%d\r",(int)pair1);
printf("pair2=%d\r\r",(int)pair2);
if(pair1>254) //so moving the controller diagonally does not go outside valid values
pair1 = 254;
else if(pair1<0)
pair1 = 0;
if(pair2>254)
pair2 = 254;
else if(pair2<0)
pair2 = 0;
pwm04 = (pair1 - 127)/2 + 127; //halving
pwm01 = (127 - pair1)/2 + 127; //halving and reversing
pwm03 = (pair2 - 127)/2 + 127; //halving
pwm02 = (127 - pair2)/2 + 127; //halving and reversing
} else //spinning in place
{
pwm01 = pwm02 = 107;
pwm03 = pwm04 = 107;
}
First problem is that it doesn’t drive properly when we move the controller backwards or right. Basically, it considers the y axis neutral for all values below 127 and the x axis neutral for all values above 127. For example, if we moved the controller forward and to the right then it would be the same as just forward. And pulling straight back will not move anything (and the printfs() indicated that the value was 127 being sent to both motors). It went away when we removed the deadzone code, the motors move properly in all directions.
The other problem we’re having is that when we try and go foward the left two wheels (pwm01,pwm02) get up to about 20 or 30 before the right wheels begin responding. When we go backwards the right two wheels (pwm3,pwm4) get up to 20 or 30 before the left two wheels respond. When pressing left the back two wheels (pwm2, pwm4) get up to speed first. When pressing right the front two wheels act similarly.
We know that we could fix this by using four geartooth sensors, but the code behind that would be monstrous and confusing, and require four sensors!
Any help would be appreciated.