Code doesn't work
i've got differential drive code doesn't seem work.
i've sent prospective outputs serial monitor,, confirming if statements sending data, sends 0's.
i want have joystick control 2 motorspeeds based on angular velocity derived mapping x,y of joystick velocity y, , distance center of turn radius x.
is there common way sort of simplified test? produce rc type control (granted joystick hooked car).
i've sent prospective outputs serial monitor,, confirming if statements sending data, sends 0's.
i want have joystick control 2 motorspeeds based on angular velocity derived mapping x,y of joystick velocity y, , distance center of turn radius x.
is there common way sort of simplified test? produce rc type control (granted joystick hooked car).
code: [select]
int rightmotorpinf = 3;
int rightmotorpinb = 5;
int leftmotorpinf = 6 ;
int leftmotorpinb = 7 ;
int joyturnangle = a0;
int joyvelocity = a1;
void setup() {
// put setup code here, run once
pinmode (joyturnangle, input);
pinmode (joyvelocity, input);
pinmode (rightmotorpinf, output);
pinmode (leftmotorpinf, output);
pinmode (rightmotorpinb, output);
pinmode (leftmotorpinb, output);
serial.begin (9600);
}
void loop() {
// put main code here, run repeatedly:
float angularvelocity,velocityright, velocityleft;
joyturnangle = analogread(a0);
joyvelocity = analogread(a1);
map (joyvelocity, 0, 1023, -200, 200);
map (joyturnangle, 0, 1023, -32000, 32000);
float (angularvelocity = (joyvelocity/joyturnangle));
int (velocityright = angularvelocity * (joyturnangle + 5));
int (velocityleft = angularvelocity * (joyturnangle - 5));
if (velocityright >= 10 && velocityright <= 200 && velocityleft >= 10 && velocityleft <= 200)
{
analogwrite (rightmotorpinf, velocityright);
analogwrite (leftmotorpinf, velocityleft);
analogwrite (rightmotorpinb, 0);
analogwrite (leftmotorpinb, 0);
serial.print (velocityleft);
serial.print (" ");
serial.println (velocityright);
}
if (velocityright >= -200 && velocityright <= -10&&velocityleft >= -200 && velocityleft <= -10)
{
analogwrite (rightmotorpinb, -velocityright);
analogwrite ( leftmotorpinb, -velocityleft);
analogwrite (rightmotorpinf, 0);
analogwrite (leftmotorpinf, 0);
serial.print (velocityleft);
serial.print (" ");
serial.println (velocityright);
}
if (velocityleft >= -10 && velocityleft <= 10 && velocityright >= -10 && velocityright <= 10)
{
analogwrite (leftmotorpinf, 0);
analogwrite (rightmotorpinf, 0);
analogwrite (leftmotorpinb, 0);
analogwrite (rightmotorpinb, 0);
serial.print (velocityleft);
serial.print (" ");
serial.println (velocityright);
}
delay (50);
}
Arduino Forum > Using Arduino > Programming Questions > Code doesn't work
arduino
Comments
Post a Comment