lunes, 27 de agosto de 2012

Controlling Robot with Cell Phone, Second Part


In this part I'm going to explain how the robot works with distance sensor. The arduino program is the same to the first part, but now I add one menu, this menu allows select the work function of the robot.
Now in this moment we have two function, the first is Bluetooth control and the second is semi autonomous robot. I said semi, because the robot only do evade object or obstacle.
For this part we´ve needed a distance sensor.In my case I use three sensor Sharp with a max distance of 150 cm, using the ADC convert to acquire the signal.

When I have the signal the sensor acquired, we need to calculate the distance, to do this I implemented the next code:
 int Cal_Dis_0(){
Dis_0 = analogRead(3);
volts = (float)Dis_0 * VOLTS_PER_UNIT; // ("proxSens" is from analog read)
inches = 23.897 * pow(volts,-1.1907); //calc inches using "power" trend line from Excel
cm = 60.495 * pow(volts,-1.1904); // same in cm
if (volts < .2) inches = -1.0;
return cm;
}
The result of this operation, is sending to the mobile. when I want to send this data is necessary a encoding. We need a beginning byte and a end byte, as show below.
 void Send(){
Serial2.print("@");
Serial2.print(cm_0);
Serial2.print(",");
Serial2.print(cm_1);
Serial2.print(",");
Serial2.print(cm_2);
Serial2.print(",");
Serial2.print('&');
Serial2.print(':');
//delay(200);
}
 The second step is to capture and decode data. The data is store in a list and then decrypted. Then we will have to make the implementation of actions. This is shown below:
class RobotAction:
def Robot(self, dis0,dis1,dis2):
Distancia = 20
if(dis0<Dist):# and dis1<Dist and dis2<Dist):
# backward
app.SendArduino('$')
app.SendArduino(0)
app.SendArduino(',')
app.SendArduino(17)
app.SendArduino('&')
elif(dis0>Dist and dis1>Dist and dis2>Dist):
# forward
app.SendArduino('$')
app.SendArduino(0)
app.SendArduino(',')
app.SendArduino(16)
app.SendArduino('&')
elif(dis1<Dist):
# right
app.SendArduino('$')
app.SendArduino(0)
app.SendArduino(',')
app.SendArduino(15)
app.SendArduino('&')
elif(dis2<Dist):
# left
app.SendArduino('$')
app.SendArduino(0)
app.SendArduino(',')
app.SendArduino(14)
app.SendArduino('&')
else:
# stop
app.SendArduino('$')
app.SendArduino(0)
app.SendArduino(',')
app.SendArduino(167)
app.SendArduino('&')
That´s it!!!
Material:
In the third part I will show how to make the robot move with the accelerometer of the phone.
 thanks

video


No hay comentarios:

Publicar un comentario