Hola, pues eso me presento: soy jose, un novato autodidacta, y estoy empezando (despues de hacer ejercicios con los led), a controlar un robot con la direccion tipo tanque, con un joystick, he encontrado un codigo, que lo he probado y si que leo las lecturas del joystick's pero no veo la forma de pasar esta esta lectura a los motores, por favor una ayudita diciendome donde mirar (pero que sea muy sencillo que estoy empezando) o explicarme como crear el motor cc y governarlo, a ver si tengo mas suerte que con otro post que dejé nadie me pudo contestar (ya esta borrado). por favor contestarme aunque sea para decirme que me olvide de este proyecto, muchas gracias.
el codigo es para enviarlo via xbee, pero primero quiero empezar en la misma placa y mas adelante me complicare os dejo el codigo:
//this code reads from the inputshield's joystics, and forwards the message to the xbee sensor on the remote
//Remote Arduino Reads the analog values of the joystick->
//Remote Arduino translates the signal meaning and creates commands ->
//Remote Arduino Serial Port ->
//Remote Xbee Shield ->
//Tank Xbee Shield ->
//Tank Arduino Forwards the signal to pins 12,13 ->
//TankShield pin 12, 13 reads command and controls motors
void setup()
{
Serial.begin(9600);
digitalWrite(4, HIGH); pinMode(4, INPUT);
digitalWrite(5, HIGH); pinMode(5, INPUT);
}
unsigned int V1;
unsigned int L1;
long LEFT = 255;
long RIGHT = 255;
long Throttle; //forwards is positive, reverse is negative
long Percent; //percentage of power given to the right side
void loop()
{
///////////////////////////////////////////////////////////////
//Read JOY Position
///////////////////////////////////////////////////////////////
L1 = analogRead(5);//Joy latteral read analog value (1023 is the most left position and 0 is the most right position
V1 = analogRead(4);//Joy vertical read analog value (1023 is the most up/forward position and 0 is the most down/reverse position)
Percent = L1 + 1; //add 1 so I never have to divide by zero 0
Percent = Percent * 100; //scale up the value to apply a ratio to the "RIGHT" and "LEFT"
Percent = (Percent/1024); //divide by the most possible value (all the way right)
///////////////////////////////////////////////////////////////
//TEST JOY Position and calculate respective direction
///////////////////////////////////////////////////////////////
if (V1>600 & Percent<60 & Percent>40)//Forward
{
RIGHT = 255;
LEFT = 255;
}
else if (V1>600 & Percent<96 & Percent>59)//Forward but left
{
RIGHT = 255;
LEFT = (150-Percent)255;
LEFT = LEFT/100;
}
else if (V1>600 & Percent<41 & Percent>4)//Forward but right
{
RIGHT = (Percent+50)255;
RIGHT = RIGHT/100;
LEFT = 255;
}
else if (V1<400 & Percent<60 & Percent>40)//Reverse
{
RIGHT = -255;
LEFT = -255;
}
else if (V1<400 & Percent<96 & Percent>59)//Reverse but left
{
RIGHT = -255;
LEFT = (150-Percent)(-255);
LEFT = LEFT/100;
}
else if (V1<400 & Percent<41 & Percent>4)//Reverse but right
{
RIGHT = (Percent+50)(-255);
RIGHT = RIGHT/100;
LEFT = -255;
}
else if (V1>399 & V1<601 & Percent>80)//Sharp left turn
{
RIGHT = +255;
LEFT = -255;
}
else if (V1>399 & V1<601 & Percent<20)//Sharp right turn
{
RIGHT = -255;
LEFT = +255;
}
else //stop
{
RIGHT = 0;
LEFT = 0;
}
// Remote Arduino Serial Port ->
//Remote Xbee Shield ->
//Tank Xbee Shield ->
//Tank Arduino ->
//TankShield pin 12, 13
// command structure is:
//"THROTTLE|left-gear-box|right-gear-box;"
Serial.print("THROTTLE|"); //print the throttle command to the serial port
Serial.print(RIGHT);
Serial.print("|");
Serial.print(LEFT);
Serial.print(";");
delay(100);//give time for the XBee transfer
}