On Monday, during class, we began a project. This project was to program our robot to make its way through a maze. The layout of the maze is below.
This was a task where it was primarily programming. The following is the program that was written.
init: servo B.6, 150 ;right motor starts from zero
servo B.7, 150 ;left motor starts from zero
symbol mor = B.6 ;change servo in B.6 to right motor
symbol mol = B.7 ;change servo in B.7 to left motor
main: gosub fwd ;1 move forward
pause 3500
gosub stp
gosub rgt ;2 turn right
pause 1300
gosub stp
gosub fwd ;3 move forward
pause 3500
gosub stp
gosub lft ;4 turn left
pause 1450
gosub stp
gosub fwd ;5 move forward
pause 1600
gosub stp
gosub lft ;6 turn left
pause 1450
gosub stp
gosub fwd ;7 move forward
pause 4000
gosub stp
gosub rgt ;8 turn right
pause 1400
gosub stp
gosub fwd ;9 move forward
pause 1600
gosub stp
gosub rgt ;10 turn right
pause 1350
gosub stp
gosub fwd ;11 move forward
pause 1300
gosub stp
gosub lft ;12 turn left
pause 1500
gosub stp
gosub fwd ;13 move forward
pause 4250
gosub stp
sound A.1,(100,150) ;piezzo buzzer
stop ;stop at end
fwd: servopos mor, 75 ;right motor forward (rev) full
servopos mol, 225 ;left motor forward full
return
lft: servopos mor, 75 ;right motor full forward
servopos mol, 150 ;left motor stop
return
rgt: servopos mor, 150 ;right motor stop
servopos mol, 225 ;left motor full forward
return
stp: servopos mor, 150 ;right motor stop
servopos mol, 150 ;left motor stop
pause 1000 ;wait 1 second
return
The right hand side, in green, is where the programming comments are. These allow me to keep track of what the program should be doing at that point. The blue words are the commands for the program. If you read the program, you will notice a command: "gosub." This command sends the program down to a subroutine. These are the four segments at the very end. They each have a designated job. These jobs are to move forward, turn left, turn right, and stop respectively. These subroutines are very nice in that you do not have to repeatedly type the same commands over and over. Instead, all you need to do is send the program to that portion over and over. If you contiue to inspect the program, you should notice the command "pause." This tells the program to continue the previous action for that length of time. For example: gosub lft ;12 turn left pause 1500
gosub stp
This tells the robot to turn left for 1.5 seconds. 1000 is equal to 1 second. One final addition that was made to the program was the second to last line. sound A.1,(100,150) ;piezzo buzzer
This line was added to make the piezzo buzzer sound when the robot completed the maze. This time, the numbers indicated two things. The 100 indicates the tone the buzzer is to sound, and the 150 indicates the duration. This means that if you wanted to, you could have your buzzer play an entire song.
The program was to be written on Monday and it was to be tested on Wednesday. My personal side to this was one of major upset. I had the entire program written on Monday, but my laptop died before I saved it. This meant that I had to rewrite the program from scratch. Happily, it did make the run on Wednesday after I rewrote it.
Another item we worked on on Wednesday was adding LED lights to our bread board. This exercise was designed to show us how we can control multiple components at the same time. Below is the program that I wrote for this assignment.
dirsD=000111
main: pinsD=000001
pause 100
pinsD=000011
pause 100
pinsD=000111
pause 100
pinsD=000110
pause 100
pinsD=000100
pause 100
pinsD=000000
pause 100
goto main
With this program, I was able to make the LEDs come on and turn off in sequence. The first line of the program designates which pins attached to the chip will be turned on. The final three (where the ones are) designate pins 2, 1, and 0 respectively. Each LED was plugged into one of those pins (see picture below). In the program as a 1 appears it means that that pin is turned on. When a 0 appears it is turned off.
The following is a movie of the LEDs in operation.
No comments:
Post a Comment