Monday, April 9, 2012

When the last assignment (the line following sensors) was complete, we received a new assignment.  This time we were using an ultrasonic sensor to guide our robot.  This assignment seemed simple at first, but it was much more difficult than expected.  Our platform had to travel forward until it encountered an obstacle.  At this point, it had to look left.  If no obstacle blocked the left, it was to turn left and continue onward.  If there was an obstacle, it had to look right.  Once again, if no obstacle there it was to turn right and move on.  Now if both were blocked, it had to make a 180 degree turn and move out in the opposite direction.

This was our first time using the ultrasonic sensor.  First we had to construct it from a kit.  Once that was complete, it was then mounted on a servo motor so it could turn.  The following pictures show the sensor and the servo respectively.



The wiring for this set up was fairly simple.  The sensor was wired into A.3, and the servo was wired into B.6.  Aside from that the motors were wired the same as from two projects ago.  The following picture shows the setup on the bread board.

The following program is one of the shorter programs, but it was difficult to write correctly.

do
 
                gosub ultraread                              'read ultrasonic sensor

             if inchdist > 5 then                           'if greater than 5 inches, go forward
                gosub fwdfll    
  
             else
                gosub stp                                       'if less than 5 inches, look left  
                gosub lft
 
           endif
 
loop
           ultraread: pulsout A.3, 1                    'read the ultrasonic sensor
           pulsin A.3, 1, rawdist
           inchdist = rawdist * 5
           inchdist = inchdist / 2
           inchdist = inchdist / convert
           return
 
        lft:  servopos serv, 225                        'turn ultrasonic sensor left
               pause 500
               gosub ultraread                             'take reading
               gosub ctr                                       'center servo
               pause 1000
    
      if inchdist > 5 then
              gosub left                                      'turn robot left
              pause 1000
              gosub stp
              return
            
      else gosub rgt                                       'if not go look to right
    
      end if
    
      return

     rgt:  servopos serv, 75                          'turn ultrasonic sensor right
            pause 500
            gosub ultraread                              'take reading
            gosub ctr                                        'center servo
            pause 1000
    
      if inchdist > 5 then
            gosub right                                   'turn robot right
            pause 1000
            gosub stp
            return
      
      else
           gosub left                                     'if not do a u-turn
           pause 2000
           gosub stp
      
      end if
           
      return

The comments on the right hand side pretty much explain the process the platform followed.  The do/loop had the sensor centered and reading what was ahead as it moved forward.  Once it encountered an obstacle.  the program jumped down the the "lft" commands.  These commands told it to look left, take a reading, then turn left if it was clear.  On the other hand, if the sensor encountered something there it took the platform to the "rgt" statements.  These followed the same order as the "lft" commands did.  Once again, it was to turn right if the area was clear, but if it was not the program told the robot to then make a u-turn and return from the direction it came.  At this point, and at all points where "return" appears in the program, the program would begin again at the top and move forward until another obstacle appeared.

The frustrations with this assignment came from getting the program written correctly.  I had the correct line of reasoning, but kept sending the program to the wrong commands to continue correctly.  After completion of the program another problem arose.  The platform appeared to be stuck in a loop that it was not programmed to do.  This was due to a low battery.  Once a fresh battery was in place, it was finally successful.

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.

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.

Tuesday, February 28, 2012

The entry from last week had the class completing a transition.  We had to remove the servo motors from the maze project and install brush motors.  Upon completion of that, we then were assigned to program the platform to drive the pattern of our initials on the floor.

This was a simple program to write.  Initially a diagram of the letters was needed.  Seeing as two of my initials are the same (JJM), all I needed was two diagrams listing all the steps.  These diagrams are shown below.

 


The programming was very similar to the maze assignment.  Most of the program was written in subroutines.  The difference was in how these subroutines were written.  The following is an example of the forward full speed subroutine:       fwdfll:               pwmout mol, 99, 400
                                                                                           pwmout mor, 99, 400
                                                                                           return
In the last assignment the motors were identified using "servopos."  This time, that command was replaced by "pwmout."  The 400 at the end is full power to the motor in this program.  After each subroutine a pause command was added with a time ("pause 2000").  This was how the program was written.  Each step was either a straight command or a turn command.  Each was written as a subroutine, then placed in the program in the proper order, and assigned a time limit to accomplish the goal.

I had the program completed and was ready to test it out, but I had a major problem.  On Sunday afternoon, while I was putting the robot away, I forgot to unplug the battery pack.  It caught fire and comlpletely melted.  The pictures below show the results of this fire.  The first is the remains of the battery pack and the second is the damage the fire did to the wiring.



Thankfully, the fire did not damage anything on the board itself.  Only the wires pictured above incurred damage.  The wires were easily fixed by cutting and resoldering them together with new pieces.  The results are visible below.  The blue sleeves are where the wires were rejoined.


If you look closely at the picture below, there is a blue housing where the black and red power cable attaches to the platform.  This is why the battery pack overheated and melted down.  Where the wires are attached the ends there were very short, but loose wires hanging free.  These crossed over and touched.  This shorted the battery pack out.  The reason for the frays is because of how the cable was created.  It was a thick bundle of wire that did not fit into the housing correctly.  We had to trim away excess strands until the core of the strands would fit in.  What remained were these very short frays.  They would not have been a problem except if the cable were jostled around.  As the cable moved around, the wires would pull out slightly.  After so long, the wires would pull out to far and the strands could touch.  This problem was fixed by the professor.  He had smaller cables that he gave out to the class.  These smaller cables slid directly into the housing and attached snuggly.  Important rule of thumb:  ALWAYS UNPLUG THE BATTERY PACK WHEN DONE USING!


As a final note, when all repairs were completed.  The program was finally reloaded into the platform, and the robot was successful in writing my initials.

Monday, February 20, 2012

The last assignment had us using servo motors to drive our platforms. Today we transferred over to brushed DC motors in class.  The first step in today's process was soldering foot long wires to the tabs on the motors.  Also, we had to attach a capacitor between the tabs.  This was accomplished simultaneously by slipping the wires through the tab holes, wrapping them around themselves and the tabs, laying the capacitor between the tab/wire combination, then soldering everything together at once.  The final results are visible below.


The next step was attaching the motor to the platform.  The following picture shows a side view of the motor with the wheel removed.


At this point, only one small piece remained.  To the ends of the wires tips had to be crimped on.  These tips were then placed in a plastic sleeve that acts like a plug for adding the motors to the bread board.  This picture shows the final results of both plugs.


This final picture shows a side view of the platform with the motor and wheel in place.



Saturday, February 18, 2012

This entry will be about the first full assignment with the built robot platform. 

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.