The final code that was used in the working model of the buggy is written below. Group and I noticed that it was possible to look at other peoples code, and in reflection others could look at ours, through any followers on our blog. With that in mind, since the evaluation was completed this morning I am now putting on the code as my work could have been used for other buggies.
Richard bay and I created this code through joint effort on the circuitry.
symbol ledstate = b0
mainswitch:
high 1
debug
if pin7 = 1 then ' has button been pressed?
if ledstate = 0 then 'if it has then if we are off (ledstate = 0) then tell system we will
ledstate = 1 'want update the status so we know LED is on.
goto start2
else
ledstate = 0 'if on, then update status to off
goto start
endif
endif
if pin7 = 0 then
if ledstate = 1 then
goto start2
elseif ledstate = 0 then
goto start
endif
endif
GOTO mainswitch
start:
readadc 1, b1 'read the analogue values from
readadc 0, b2 'left LDR (b1), and right LDR (b2)
if b1 > 110 then 'This is allocates values to b3 and b4 depending
b3 = 1 'on the input coming from the LDR
else b3 = 0
end if
if b2 < b4 =" 1" b4 =" 0" b5 =" b4"> 140 then 'This is allocates values to b3 and b4 depending
b4 = 1 'on the input coming from the LDR
else b4 = 0
end if
if b2 > 120 then
b3 = 1
else b3 = 0
endif
b5 = b4 * 2 + b3 'Arithmic condition that will allow the PICAXE
'to decide whach case to choose.
select case b5
case 0
low 3
high 4
low 6
high 5
case 1
low 3
low 4
high 5
low 6
pause 5000
low 3
high 4
low 6
high 5
pause 3000
low 3
low 4
low 5
low 6
case 2
low 3
high 4
low 6
low 5
pause 5000
low 3
high 4
low 6
high 5
pause 3000
low 3
low 4
low 5
low 6
case 3
low 3
low 4
low 5
low 6
high 3
low 4
high 6
low 5
pause 2000
endselect
goto mainswitch
When the buggy was doing the track following set of commands (start sub routine) the LDR's were acting wuite strangely as one would increase and the other would decrease. We could see nothing wrong in the wiring of the system so we just altered the clause statements so that the appropiate case was chosen.
From the past lectures we had decided that a select case format was probably the simplest and safest choice to pick for a couple of reasons:
1) The program would be very easy to cnofigure and debug
2) It cut down on the amount of code needed to be executed for each repeat
3) Reduced that amount of places where confusion would arise.
Without the coding before the cases, where it gave b3 and b4 set values we would have had to create two different sets of cases which would have nearly doubled the processing time for each repeat. Also with the set up we designed if any problem s arose it was very easy to see where.
The design also worked for the instruction side of the assignment so a simple clone was made of the original code and then the cases were altered so that they followed set routines and did not simply repeat in a rapid fashion.
When it came to switching between the two sets of code, we decided that using the simple routine that was taught when looking at switches would work and whatever the value that was on ledstate would decide which subroutine the program would skip to.
Through the simulations the program worked as expected however in the real life result the coding was either running too fast for the buggy operation or too slow depending on what output was coming out of the weak motors, which were very unreliable.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment