After completion of wiring up the new components, we had to program the robot to follow a course drawn out on a table with black electrical tape. The following is a sketch of the layout.
The line sensors located on the bar underneath the front end of the platform were to relay data about the location of the robot in regards to the line. We had to program the robot to turn when it strayed to the right or left of the tape. We also had to program it to stop when the platform either left the tape entirely or came across the black stipe that marked the end of the course. One other sensor was also included. It was the IR sensorwe wired in last week. This was supposed to stop the robot if an object was placed in its path.
The following is the do/loop of the program used.
do
readadc A.0, LFright
readadc A.1, LFcenter
readadc A.2, LFleft
readadc A.3, IRvalue
if LFright > 10 then
bit0 = 1
else
bit0 = 0
endif
if LFcenter > 10 then
bit1 = 1
else
bit1 = 0
endif
if LFleft > 10 then
bit2 = 1
else
bit2 = 0
end if
if IRvalue > 60 then
bit3 = 1
else
bit3 = 0
end if
f bit3 = 0 then
select case LFvalue
case = 000000 'stop
gosub stp
case = 000001 'hard right
gosub right
case = 000010 'straight
gosub fwdfll
case = 000100 'hard left
gosub left
case = 000011 'slight right
gosub fwdfll
case = 000101 'stop
gosub stp
case = 000110 'slight left
gosub fwdfll
case = 000111 'stop
gosub stp
end select
else
gosub stp
end if
loop
This program was focused on the readings given by each of the four sensors. You will notice these are grouped together in if/else statements. These if/else statements show what readings on the sensors would cause them to change.
The select case statements had to do with the setting scenarios for each of the three line sensors. The last three digits corresponded with each sensor. The third from the end was the left, the second from the end was the center, and the last one was the right sensor. As you can see, when one of the sensors was set off a 1 would fill its spot. Each of the case statements show what action the platform was to perform in each case. (Keep in mind the sensors were set to read 1 when they picked up the presence of the black electrical tape. That is why the third case comment is "straight." Only the center sensor read the tape. That meant it was directly over the tape.)
Finally, the last if/else statement that surrounded the case statements was for the IR sensor. If an object was in its path and set it off, it would override the other sensor readings and stop the robot. This would occur for the duration of the object remaining in its path. As soon as the object was removed, it would continue with moving forward following the tape.
This, so far, was one of the more demanding programs to write for our platforms. We had a great many variables to include while writing it. Thankfully, after many hours of tests and retests, writes and rewrites, the robot was eventually successful and completed the circuit.
No comments:
Post a Comment