In the last assignment, we had to navigate our robots through a maze. This maze was the same as the first maze assignment. The only difference in this assignment was the starting and ending positions. The professor randomly doled out different starting positions to each of the students. From the start, each student had to write a program in which the robot had seven straight commands before the end. The following photographs show the path my robot had to follow and the list of the direction commands I used.
The program was very similar to the program written for the earlier maze and intitials assignment except for a few lines of code.
At the beginning of the program, the symbols were created as follows:
symbol molcont = C.1
symbol moldir = D.1
symbol morcont = C.2
symbol mordir = D.2
In this case, mol stood for left motor and mor stood for right motor. Cont and dir stood for control and direction respectively. Finally C.1, D.1, C.2, D.2 represented the pins on the chip the motors were wired to.
In this exercise we learned how to change directions of the motors. In all of the previous assignments the motors were always programmed to move forward and the speed they were given was contolled by the program. An example of this is: pwmout mor, 99, 400. In that example the 400 was the motor speed command. In order to write a command to change a motor's direction we used a set of high and low commands. When written in at the correct spot (mordir or moldir), a high command would cause the motor to move forward. The following subroutine shows this.
fwdfll: low morcont
high mordir
low molcont
high moldir
return
To program the motor to run in reverse, a high had to be in the mordir/moldir line. This is shown in the left and right turn subroutines below. We wanted a zero turning radius, so that meant that one wheel went forward and the other reverse.
left: low morcont
high mordir
high molcont
low moldir
return
right: high morcont
low mordir
low molcont
high moldir
return
Another part of the program was stopping the motors. This was accomplished by either writing both high or low for both cont and dir. The following example from my program used the low command in the cont and dir lines.
stp: low morcont
low mordir
low molcont
low moldir
return
This assignment was fun for me. It was not difficult to complete. It took probably twenty minutes to write the program and test it. I wrote separate subroutine programs for fwdfll, left, and right. I would test each individually before putting them into my final program. This allowed me to figure out 90 degree and 180 degree turns at my computer. The straight stretches were tested by running the fwdfll subroutine a certain length of time until the platform went the proper distance. Upon completion of testing each subroutine, they were put into the final program. I was extremely excited when the robot ran the entire maze in my first full test run.
No comments:
Post a Comment