Robo-G!RL
1 2
X
3 4
NOTE: X must be in the center, but I don't know how to fix it 😔
and for Black=1, White=0
and I'll have a table like this
1 2 3 4
-------------
1 0 1 0 Turn Right (means I have a triangle pointing to the right)
0 1 0 1 Turn Left
0 0 0 0 Stop
Shouldn't stop be 1 1 1 1? Since you'll be on top of the black hexagon right. Anywayz, you didnt take into account about actually following the line. If the robot was following the line and it detects 1 0 1 0, it would get confused whether its on the triangle pointing to the right, or whether the left sensors are detecting the line itself. Do you understand my point? Thats why I thought of using 8 of them so it can differentiate from a shape and a line entirely. I modified the shape a little. For example:
1 2 3
4 5
6 7 8
1 2 3 4 5 6 7 8
--------------
1 0 0 1 1 1 0 0 Triangle pointing right
0 0 1 1 1 0 0 1 Triangle pointing left
0 1 0 1 1 0 1 0 Hexagon (stop)
Sensors 4 & 5 are a little indented inwards to the center so that the pointed part of the triangle can be detected (since its a 2" equilateral triangle). Also, you could just use sensor 4 & 5 to detect the line too. Lots of possibilities! 😀
In line of what silverscorpion said about optimizing the position of the sensors, the distance from the front sensors to the back sensors whould be the length of the triangle (2"). But, using 8 sensors though goes against my "keep it simple" philosophy. If you do plan to use a voltage divider technique for all 8, thats alot of wiring.. plus sensor readings could get a little saturated since all are sharing a common voltage and ground. If you do choose this route of 8 sensors, try it out first on a prototype board. Try checking out the links I posted about different sensor circuit configurations! The one using the demultiplexer could prove handy.
Hey preeste, your welcome! Anyway, I did not use phototransistors on my robot, perhaps only in the 2nd version I plan to use them. I used 3 LEDs and 3 LDRs. I described it here:
#-Link-Snipped-#
I dont think you'll suffer the same problem about the incorrect readings, as long as you properly isolate the LEDs and sensors from each other and also solder the components carefully. Check out the links I posted before for phototransistor sensor layouts.. I hope its there somewhere 😛
The structure of the code is pretty basic, but if your competition layout has many conditions, the hard thing is to optimize it as the PIC has limited memory. I'll give you some head start. If you want to read a value from a sensor connected to pin A0 and print it out to the Bootloader software:
#include <16f877a.h>
#device adc=8
#use delay(clock=20000000) //oscilator frequency
#fuses hs,noprotect,nowdt,nolvp
#use rs232(baud=56000,xmit=PIN_C6,rcv=PIN_C7,parity=N)
main()
{
int value;
setup_port_a(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
do
{
set_adc_channel(0);
value=read_adc();
delay_ms(300);
printf("\nan0:%u",value);
}while(1);
}
That code sets port A as analog and gets values from the sensor connected to it. If you want to set other ports like Port B as digital I/0, then its like:
main()
{
set_tris_b(0)//set all pins of port B as input
set_tris_b(1)// set all pins of port B as output
...
ouput_high(PIN_B0); //output high on pin B0
Also, I did use a differential drive to move the robot. If you look at the schematic, we only used 2 motors.. one for the right and one for the left. You'd have to refer to the L293 datasheet for more info. Please try to do some research for the coding on google. I can't give ALL of it just like that 😛 If you get stuck, then just post what you've found and then we CEans can help you through understanding it!