User Guide

Recuerda siempre al crear código con funciones de poner el fichero de cabecera! Si no tienes
otra solución, crea diferente copias separadas de cada fichero de código que incluya las
cabeceras.
el mismo código que en el seguimiento de línea analizado en la sección 6, pero con
ill be following a line. The code below is
follower-pid example, but the maximum
60 for reliability.
ion of the line.
int sensors[5];
um) of the
ll turn
will
itude of the number determines
e*3/2;
fference);
s (1, 2, and 3) for
a line straight ahead, and the
to the left and
nsors[3] < 100)
cciones, en la actualidad hay alrededor de seis
an ajustar. Hemos recogido aquí los valores que permiten a 3pi
con seguridad, control de velocidad, intento de aumentar la velocidad y que
der Files”. Botón derecho en cada uno y tienes la opción de remover o añadir a la
El fichero follow-segment.c también contiene una simple función follow_segment(), la cual lleva
al 3pi recto a lo largo de una línea de segmento mientas busca una intersección o un fin de línea.
Esta es casi
más controles para las intersecciones y los extremos de línea. Aquí está la función:
1. void follow_segment()
2. {
3. int last_proportional = 0;
4. long integral=0;
5. while(1)
6. {
// Normally, we w7.
8. // similar to the 3pi-line
ned down to9. // speed is tur
the posit10. // Get
unsigned11.
12. unsigned int position = read_line(sensors,IR_EMITTERS_ON);
13. // The “proportional” term should be 0 when we are on the line.
14. int proportional = ((int)position) - 2000;
and integral (s15. // Compute the derivative (change)
16. // position.
17. int derivative = proportional - last_proportional;
18. integral += proportional;
19. // Remember the last position.
20. last_proportional = proportional;
difference between the two motor power settings, 21. // Compute the
22. // m1 - m2. If this is a positive number the robot wi
negative number, the robot23. // to the left. If it is a
24. // turn to the right, and the magn
25. // the sharpness of the turn.
26. int power_difference = proportional/20 + integral/10000 + derivativ
27. // Compute the actual motor settings. We never set either motor
28. // to a negative value.
29. const int max = 60; // the maximum speed
30. if(power_difference > max)
31.
power_difference = max;
32. if(power_difference < -max)
x; 33. power_difference = -ma
34. if(power_difference < 0)
erence,max); 35. set_motors(max+power_diff
36. else
37. set_motors(max,max-power_di
38. // We use the inner three sensor
e is 39. // determining whether ther
40. // sensors 0 and 4 for detecting lines going
t. 41. // righ
42. if(sensors[1] < 100 && sensors[2] < 100 && se
43. {
44. // There is no line visible ahead, and we didn’t see any
45. // intersection. Must be a dead end.
46. return;
47. }
if(sensors[0] > 200 || sensors[4] > 200) 48. else
49. {
50. // Found an intersection.
51. return;
52. }
53. }
54. }
Entre el código PID y la detección de interse
parámetros más qu
into
e se podrí
resolver el laber
se ejecute con rapidez a los muchos de los problemas que tendría que manejar con un código
complicado.
Poner los ficheros C y los ficheros de cabecera en tu proyecto es fácil en AVR Studio. En la
columna de la izquierda de la pantalla puedes ver varias opciones para los ficheros de “Source
Files” y “Hea