Sunday, March 25, 2012

This past week, we began a new assignment that utilizes sensors to guide our robot.  The first sensor we added was on Monday.  It was an infrared sensor (IR sensor).  Below is a picture of it mounted to the platform.


The following is the program used for the IR sensor.

symbol IRValue = b0
adcsetup = 2

do
  gosub IRSensor
loop

IRSensor:
  readadc A.1, IRValue
  sertxd ("IR Value = ", #IRValue, CR, LF)
  pause 500
  return

Once we were done programming the IR sensor on Monday, we had to solder some wires onto three line following sensors (LF sensors).  Plugs were then added to the other end of the wires so we could attach these sensors to our bread boards.  Below are pictures of one of the LF sensors and how they were plugged into the bread board.




The next step was to write a program for these sensors.  What follows is that program.

symbol StoreLF1 = b0
adcsetup = 3   'A.0, A.1, A.2

do
  gosub LFleft                                                                  'left sensor
 
  gosub LFcenter                                                              'center sensor
 
  gosub LFright                                                                'right sensor
  loop

LFleft:
  readadc A.0, StoreLF1
  sertxd ("LFleft = ", #StoreLF1, CR, LF)
  pause 500
  return

LFcenter:
  readadc A.1, StoreLF1
  sertxd ("LFcenter = ", #StoreLF1, CR, LF)
  pause 500
  return
 
LFright:
  readadc A.2, StoreLF1
  sertxd ("LFright = ", #StoreLF1, CR, LF)
  pause 500
  return

As you can see, each sensor is attached to a separate pin (A.0, A.1, A.2).  They run independently from each other.  Another thing that should become apparent is that this program is almost identical to the IR sensor program.  Upon completion of the programming, the LF sensors were mounted underneath the front end of the platform.  This is shown in the following pictures.



The next class we are supposed to program our robots to follow a line using these LF sensors.

Friday, March 16, 2012

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.