Latest Entries »

Day 31

Today’s class will be the last with the Boe-Bot . Last class we made our Boe-Bot navigate with the whiskers on and today we were assigned a project that will mark us for our understanding in this interesting and joy able journey 🙂 :). Mrs.Thompson gave us a list of ideas that and from there onward we can up with an idea of what kind of program we want to write. For example: we can write a program that will make our Boe-Bot perform a dead reckoning around the class, we can do a maze and make our Boe-Bot navigate through it….etc. There were many ideas on the list that were all fun and exciting to do. I couldn’t make up my mind, so I went to YouTube and researched some videos maybe that would give an idea. In the end I chose to create my own maze with the help of the program (Subroutines). That was just the main plan and I am usually known for my exceeding perfection and I might spice things up concerning my program. By perfection, I mean I would make my boe-bot go in a neat and precise pattern. Since the idea was set on …..I started to draw the maze that I wanted my Boe-Bot to navigate through. At first I decided to make a big maze but then I changed my mind and worked on a small instead. The reason behind this huge change in plan was because I have already kept the distance measurements that I would like my Boe-Bot to move and they were big, so that meant building a maze which was more than 5 meters long. After I have designed the maze, I wrote up a program using subroutines based on the distance in the maze and the ones that I would use to make my Boe-Bot move. Writing the program was easy because I used subroutine which is the simplest program, it’s less complicated than EEPROM.  Here is what the program looks like:

‘ Robotics with the Boe-Bot – MovementsWithSubroutines.bs2

‘ Make forward, left, right, and backward movements in reusable   subroutines.

‘ {$STAMP BS2}

‘ {$PBASIC 2.5}

DEBUG “Program Running!”

counter VAR Word

FREQOUT 4, 2000, 3000              ‘ Signal program start/reset.

GOSUB Forward_a

GOSUB Right

GOSUB Forward_q

GOSUB Left

GOSUB Forward_w

GOSUB Left_s

GOSUB Forward_b

GOSUB Left_s

GOSUB Forward_b

GOSUB Right_b

GOSUB Forward_w

GOSUB Left

GOSUB Forward_w

GOSUB Right

GOSUB Forward_b

GOSUB Right_c

GOSUB Forward_d

GOSUB Forward_e

GOSUB Circle_n

END

Forward_a:

FOR counter = 1 TO 97

PULSOUT 13, 850

PULSOUT 12, 650

PAUSE 20

NEXT

PAUSE 200

RETURN

Forward_q:

FOR counter = 1 TO 106

PULSOUT 13, 850

PULSOUT 12, 650

PAUSE 20

NEXT

PAUSE 200

RETURN

Forward_w:

FOR counter = 1 TO 111

PULSOUT 13, 850

PULSOUT 12, 650

PAUSE 20

NEXT

PAUSE 200

RETURN

Forward_b:

FOR counter = 1 TO 48

PULSOUT 13, 850

PULSOUT 12, 650

PAUSE 20

NEXT

PAUSE 200

RETURN

Forward_d:

FOR counter = 1 TO 121

PULSOUT 13, 850

PULSOUT 12, 650

PAUSE 20

NEXT

PAUSE 200

RETURN

Forward_e:

FOR counter = 1 TO 73

PULSOUT 13, 850

PULSOUT 12, 850

PAUSE 20

NEXT

PAUSE 200

RETURN

 Left:

FOR counter = 1 TO 17

PULSOUT 13, 650

PULSOUT 12, 650

PAUSE 20

NEXT

PAUSE 200

RETURN

Left_s:

FOR counter = 1 TO 17

PULSOUT 13, 650

PULSOUT 12, 650

PAUSE 20

NEXT

PAUSE 200

RETURN

 Left_z:

FOR counter = 1 TO 19

PULSOUT 13, 650

PULSOUT 12, 650

PAUSE 20

NEXT

PAUSE 200

RETURN

Right:

FOR counter = 1 TO 16

PULSOUT 13, 850

PULSOUT 12, 850

PAUSE 20

NEXT

PAUSE 200

RETURN

Right_b:

FOR counter = 1 TO 17

PULSOUT 13, 850

PULSOUT 12, 850

PAUSE 20

NEXT

PAUSE 200

RETURN

Right_c:

FOR counter = 1 TO 18

PULSOUT 13, 850

PULSOUT 12, 850

PAUSE 20

NEXT

PAUSE 200

RETURN

Circle_n:

‘ —–[ Main Routine ]————————————————

Main:

DO

PULSOUT 13, 850 ‘ Veer right

PULSOUT 12, 750

PAUSE 20

LOOP

END

After I have written down the program …..It was time to buildup the maze. After I have finished building up the maze, it is the crunch time to see whether all that hard work and long night staying up was worth it. The Boe-Bot went through the maze just perfectly; the only problem that I faced was the turns. They were not exactly 90 degrees, so I just went back to the problem and applied some of my magic. Later on Mrs.Thompson came in and she was eager to see our progress. I told her that it was ready and set it out in the maze and BAMMM!!!!! It went through it just fine but then there was a left turn where my Boe-Bot would just come in contact with the wall and it would cause it walk on the wall and then turn upside down. I keep asking myself where the problem was because before Mrs. Thompson came it worked fine and then I realized that the position you kept in at the start point of the maze would affect it if it was not straight.  I think we tried like 5 times more and then finally I took my time and placed the Boe-Bot in a straight position. I ran the program and then it finally worked. And when it reached the end of the maze it celebrated its victory with a circular dance. I have another theory for what might have caused the boe-bot to hit the wall, because when I first tried it I kept my cell phone with music on, so that it can give a special effect. The time it actually did work, my cell phone wasn’t there and maybe the cell phone has increased some weight on the Boe-bot making it hard for her to turn. Well I was jumping when it went through that maze. It felt I have accomplished something big. This was the first time that I actually on such projects. I have to admit it was frustrating when it didn’t turn exactly 90 degrees and at one point I even cried but my happiness covered up these too unpleasant memories. Our last mission in this wonderful journey was dissembling the Boe-Bot. I felt so bad when I was disassembling it, because I worked so hard to build up. Well that was Mrs. Thompson wish and we just went on with the verdict. It was an experience of a life time. Now I can go and brag in front of people that I built a robot and that I created a program and made my Boe-Bot work based on it. I really enjoyed it and if they asked me to do it again ….I would certainly agree too but that does not mean I would be more patient with it but I try to be more understanding. Anyways that was my “EPIC BOE-BOT JOUNEY” and now its time to say goodbye to my baby boe-bot. (I LOVE YOU) 🙂 🙂 🙂 ❤

Last class was a joy able class. We have fixed our whiskers onto our Boe-Bots and we even checked if they work by making them perform a series of tests. Today we will field test the whiskers. Since we are going to test them on the ground, we wouldn’t be able to tell if it works because we wouldn’t have the DEBUG Terminal. So, this can be done with a pair of LED circuits and a program that turns the LEDs on and off based on the whisker inputs.

So we will use the same program we have used before with tiny changes in it. We will insert these two IFTHEN statements between the PAUSE 50 and LOOP

commands.

IF (IN7 = 0) THEN

HIGH 1

ELSE

LOW 1

ENDIF

IF (IN5 = 0) THEN

HIGH 10

ELSE

LOW 10

ENDIF

These are called IF…THEN statements. These statements are used to make decisions in PBASIC. The first of the two IF…THEN statements sets P1 high, which turns the LED on when the whisker connected to

P7 is pressed (IN7 = 0). The ELSE portion of the statement makes P1 go low, which turns the LED off when the whisker is not pressed. The second IF…THEN statement does the same thing for the whisker connected to P5 and the LED connected to P10.

Now that we know how this program works we just have to test it and see. I ran the program and I pressed the whiskers gently onto the 3-pin headers and they worked, both of the red LEDs had light up. Next we will type down a program that we will make our Boe-Bot navigate with the help of the whiskers. Whenever the LEDs light up that means the Boe-Bot has bumped into an object. As soon as the obstacle is detected by the whiskers, the navigation routines and subroutines developed in Chapter 4 will make the Boe-Bot back up and turn. Then the Boe-Bot resumes forward motion until it bumps into another obstacle. BASIC has a command called an IF…..THEN statement that makes decisions.

 IF (condition) THEN…{ELSEIF (condition)}…{ELSE}…ENDIF

 

You can place a code block of one or more commands between the keywords. This means if you want it to roll forward, just write down the command between the keywords and when you run the program it would perform the specified maneuver. This program makes decision based on the whiskers input.

These are

IF (IN5 = 0) AND (IN7 = 0) THEN

GOSUB Back_Up       ‘ Both whiskers detect obstacle,

GOSUB Turn_Left     ‘ back up & U-turn (left twice)

GOSUB Turn_Left

ELSEIF (IN5 = 0) THEN ‘ Left whisker contacts

GOSUB Back_Up ‘ Back up & turn right

GOSUB Turn_Right

ELSEIF (IN7 = 0) THEN ‘ Right whisker contacts

GOSUB Back_Up ‘ Back up & turn left

GOSUB Turn_Left

ELSE ‘ Both whiskers 1, no contacts

GOSUB Forward_Pulse ‘ Apply a forward pulse &

ENDIF ‘ check again

After that just run the program and test it. I kept obstacles on the ground with books as walls. I pressed the reset button and it began rolling forward, then as soon as the tip of the whisker touched the book it went on to perform the next maneuver in the program. It was so cool to watch it bump into every obstacle that comes ahead. It looked like a blind driver was driving the Boe-Bot.


Today we started a new chapter, which is chapter 5 Tactile Navigation with Whiskers. In this chapter we will learn programs that will make our Boe-Bots navigate on what it can touch. So first we start by assembling our whiskers on to our Boe-Bots. These are the parts that will be needed :

Parts List:(2) Whisker wires (2) 7/8″ pan head 4-40Phillips screws (2) ½″ round spacer(2) Nylon washers – size #4 (2) 3-pin m/m headers (2) Resistors, 220 Ω(red-red-brown) (2) Resistors, 10 kΩ(brown-black-orange).

Now we will have to build it up. First remove the two front screws that hold your board to the front standoffs. Thread a nylon washer and then a ½″ round spacer on each of the 7/8″ screws. Then Attach the screws through the holes in your board and into the standoffs below. Slip the hooked ends of the whisker wires around the screws, one above thewasher and the other below the washer, positioning them so they cross over eachother without touching.

This is how it would like after you fix it on to your Boe-Bot:

Awwwwwwwwwww doesn’t it look so cute, just like a robot with Butterfly antenna’s. Then we were asked to put in some jumpers and resistors. This is so much fun but you have to be careful because not inserting the resistors or jumpers in the right pins, would not make the program run.

Then we wrote a program that will test our whiskers and check whether they really work or not. By displaying the binary digits stored in the P7 and P5 input registers (IN7 and IN5), the program will show you whether the BASIC Stamp detects contact with a whisker. When the value stored in a given input register is 1, the whiskeris not pressed. When it is 0, the whisker is pressed.

When you run the program the DEBUG Terminal should display that both P7 and P5 are equal to 1. Now let’s see if the whiskers do work. Press the right whisker into its three-pin header, and check the values displayed inthe Debug Terminal, they should  read : P5 = 1 P7 = 0. Now press the left whisker into its three-pin header, and check the value displayed inthe Debug Terminal again, this time it should be the opposite, it should read like this P5 = 0 P7 = 1. Finally last but not least, press both whiskers against both three-pin headers, so that they can read as P5 = 0 P7 = 0. Me and Julia went through all th tests and they indicated that out latest epic edition (WHISKERS) works just fine.

Today’s class we really fun especially building the fixing the whiskers onto out Boe-Bots. I think when it comes to the building part, I am actually more better at it then the programming one. Yes, I can program a Boe-Bot to do a specific thing but the building is something that is more like a telnet. :D. I hope next class we will be able to test our whiskers while they are actually navigating. 🙂 😀

Today’s class was new and it seemed to be interesting. The truth is, it was interesting but we only felt that way after we had almost banged our heads into the walls from frustration :( . I don’t know about my other classmates but for me it was a bit challenging. We had to write two programs that would make our Boe-Bots go in a circle and in a triangular shape. It was kind of a new thing to learn, because usually we wrote programs that involved our Boe-Bots performing maneuvers in a straight path or turns of exact 90 degrees. I started working with the easy one first, which was the circle. I started to type down the program and here it is:

‘ Robotics with the Boe-Bot – Circle.bs2

‘ Boe-Bot navigates a circle of 1 yard diameter.

‘{$STAMP BS2}

‘{$PBASIC 2.5}

DEBUG “Program running!”

pulseCount      VAR         Word                                                                                            ’ Pulse count to servos

FREQOUT 4, 2000, 3000                                                                                                    ’ Signal program start/reset.

‘ —–[ Main Routine ]————————————————

Main:

DO

PULSOUT 13, 850                                                                                                                  ’ Veer right

PULSOUT 12, 716

PAUSE 20

LOOP

Of course when you write down the program, you will have to to change the the right PULSOUT  Value, so that right wheel can increase speed or decrease according to the distance you kept as the circles diameter. For example: If you wanted it to go round and round with a diameter distance of 4 inches, then you will have to increase the right PULSOUT Value but if you want it to go for like turn round for like 12 inches then you will decrease the right PULSOUT Value. For my self I chose to make my Boe-Bot go round and round with a diameter distance of 36 inches which is 1 yard, so i decreased my right PULSOUT Value to 716. After that I ran the program, it went in a really huge circle which had a diameter of 36 inches. This means whenever you want your Boe-Bot to perform a circle, first you have to chose  how big the circle you want it to be and from that point onwards you can alter the right PULSOUT Value making the Boe-Bot go in big circles(decrease value) or small ones(increase value).

Then I started off to finish my one and last program in this chapter, which was making my Boe-bit perform a triangle. This program was a bit hard because making the Boe-Bot go in exact equal turns was hard. I wanted my Boe-Bot to turn an angel of 60 degrees, which means the other turns would be also a 60 degree (An Equilateral Triangle). Yes, you would say whats hard about that, whenever its a left or right turn just keep the same pulseCount EndValue in the right. Well, it didn’t work for me when I tried the 60 degree angel, so I went for the one that my other classmates used which was the 120 right turn degree angel. When you type down the program, first you have  to calculate the number of pulses required for a one meter, or 1 yard straight line. I used 36 inches which is = 1 yard. I found the distance that my Boe-Bot would roll straight for and then I Adjusted the pulseCount EndValue in the Right_Rotate120 subroutine to get a precise 120 degree turn.

When I ran the program it went just fine, I don’t know what was the problem for the 60 degrees turn. Either I didn’t spend enough tome working on it or the fact that there  was something fishy about this 60 degree turn. I wanted to go back and try again and see where I did a mistake but the class already has ended. I had to admit that it was fun but then when typing down these kind of programs, a person should have lots of patience, because all this journey is about errors and trials. You have to keep on trying again and again until it finally works :) :) .

 

Today we resumed with the second part of the EEPROM program, which was EepromNavigationWithWordValues.bs2. This program looks way complicated and I knew from the first look that I would encounter difficulties. Lucky me I had Julia assigned as my partner, so maybe if she understood they way this program would work, she would be able to explain it to me. This example program uses EEPROM data storage, but does not use subroutines. Instead, a single code block is used, with variables in place of the FOR…NEXT loop’s EndValue and PULSOUT Duration arguments. To store wordsized data items, you can add the Word modifier to the DATA directive, before each data item in your string. When using more than one DATA directive, it is most convenient to assign a label to each one, this way you won’t get messed up. The addressOffset is  the location of each byte in the EEPROM. This address will be stored in the READ command’s variable argument and the READ command will then get the correct code block out of the EEPROM while the program runs.

Here is the program me and Julia wrote that was in the guide book:

 

When we played the program, it went forward, left, right and backward.The first time through the loop our Boe-Bot ran  according the the addressOffset column with a value of 0. The first READ command willretrieve a value of 64 from the first address at the Pulses_Count label, and place it in thepulseCount variable. The second READ command retrieves a value of 850 from the firstaddress specified by the Pulses_Left label, and places it in the pulseLeft variable.The third READ command retrieves a value of 650 from the first address specified by thePulses_Right label and places it in the pulseRight variable. I didn’t quite understand this program the way I understood the others.  Me and Julia had to go over it one more to really digest the program!!!!! 😦 I think this is complicated one by far)

Day 26

 

Today’s class we started a new program, EEPROM (Electrically Erasable Programmable Read Only Memory). From the beginning of our Boe-Bot journey till now we have tried three different programming approaches to make our Boe-Bot drive forward, turn left, turn right, and drive back again. Each technique we have experienced has it own way in working. The interesting thing about this program is that it is capable of storing 2048 bytes of information.This program uses the now-familiar code blocks in subroutines for each basic maneuver. Each maneuver in this program has a given label. For example for forward the code will be “F”, for backward “B”, for left turn “L”, for right turn “R”. Long lists of these code letters can be stored in EEPROMand then read and decoded during program execution.This avoids the boredom of repeating long lists of subroutines, or having to change the variables before each GOSUB command. Wile going through the program will be introduced to new PBASIC instructions that would be required to run the program. Here are the instructions : the DATA directive,and READ and SELECT…CASE…ENDSELECT commands. Each of the basic maneuvers is given a single letter code that will correspond to its subroutine: F for Forward, B for Backward, L for Left_Turn, and R for Right_Turn. The last letter in the string is Q, which means to “quite” when the movements are over. Then the list is saved in EEPROM and heres what it would look like:

DATA “FLFFRBLBBQ”

The READ command is used to get the list of letter codes out of EEPROM while the program is running. The last command, SELECT…CASE…ENDSELECT  is used to select variable and evaluate.

After I typed down  the program, I tried to run it but I kept on getting this window message that said that there is a Label error. So, I scan the whole program with the one in the book but nothing seem to be different. I look at my friends (Atiqa) program but whatever program she wrote to make hers run successfully is the same one I have. I couldn’t figure out what was going wrong, so I asked Atiqa to give me her program which was an exact copycat from mine, so that I can try it may be it works. When I ran the program, it actually worked which was a shock O_o because we had the exact same program. Anyways, after it have worked, me and Atiqa have decided to play the two Boe-Bots at the same time and see if they perform the same maneuvers. When we both pressed the reset button on our Boe-Bots, both of the them started to perform the specified moves and they looked as if they were doing a partner dance. It was so EPIC!!!! :D….. Me and Atiqa found it so cool, that we shows Mrs.Thompson and then we told the rest of our classmates to run their programs so that we can play altogether at the same and see whether they perform a groupie dance. While running their programs some of my classmates had problems like they would have a HardwareCommuication problem and some would have the same message that used to appear for me. So, they kept trying and the ones that looked like they would never work, we just gave them a copy of Atiqa’s program and made them run it. It actually worked when they tried it on. After all the trials, we have decided to see their groupie dance. We have all of the Boe-Bots beside each other and then we pressed the reset button. All of the Boe-Bots moved the same maneuvers but kind of different. Some were really slow, some where fast, some would have their turns off the track but mine and Atiqa’s were like two twin sisters dancing down the street. Next we were asked to change the order of the maneuvers, which was quite simple. Instead of having them start to roll forward, this time make them go backward. Me and Atiqa did the same set of orders, so that our  movements would be the  same and may be we can witness another dual dance . By the end of the class me and Atiqa were thinking how cool it would be if we were able to make a Boe-Bot dance or even better a parade of Boe-Bots. That sounds extremely fun but unfortunately it would have to wait for next class.

 

Day 25

What’s the first thing that comes up to your mind when you hear the words ” Dead Reckoning.” You either think of Tom Cruise and his movie Mission Impossible or you can act nerdy and say that its a technological phrase. When Mrs.Thompson first told us about it, I was WOW, my Boe-Bot would finally perform this twisted maneuver just like we see in the movies. Well, Dead Reckoning is pretty similar to that but its way simple and less dangerous 😀 :D. You will have to modify your MovementWithVariablesAndOneSubroutine.bs2 program to make your Boe-Bot drive in a square, facing forwards on the first two sides and backwards on the second two sides. I decided to use MovementsWithSubroutines.bs2 because I felt more comfortable with it then the other one. Okay, a key point in order this program would work is that, you will have to use your own PULSOUT  EndValue argument that you have found it and used in chapter 2.

Here is what my program looked like:

‘ Robotics with the Boe-Bot – MovementsWithSubroutines.bs2

‘ Make forward, left, right, and backward movements in reusable   subroutines.

‘ {$STAMP BS2}

‘ {$PBASIC 2.5}

DEBUG “Program Running!”

counter VAR Word

FREQOUT 4, 2000, 3000              ‘ Signal program start/reset.

GOSUB Forward

GOSUB Left

GOSUB Forward

GOSUB Left

GOSUB Forward

GOSUB Left

GOSUB Forward

END

Forward:

FOR counter = 1 TO 64

PULSOUT 13, 850

PULSOUT 12, 650

PAUSE 20

NEXT

PAUSE 200

RETURN

Left:

FOR counter = 1 TO 18

PULSOUT 13, 650

PULSOUT 12, 650

PAUSE 20

NEXT

PAUSE 200

RETURN

END

In my program I simply made my Boe-Bot roll forward and make a left turn but of course it carried out these commands in a specific sequence made by me. So, first it would roll forward in a straight path then it would turn left at 90 degrees and then again moves Forward and then turns Left at 90 degrees and so on, until it performs a complete circle and end up at the same exact point where it began in the first place.  You can the know the sequence that the Boe-Bot performs by simply looking at this:

GOSUB Forward

GOSUB Left

GOSUB Forward

GOSUB Left

GOSUB Forward

GOSUB Left

GOSUB Forward

I wasn’t able to show Mrs.Thompson my “Epic Dead Reckoning ” but I am sure she would approve of it because it took me a while until I made my Boe-Bot go in a straight line, which I think was the challenge in this activity. That was everything for today’s class, it was really fun today, especially the Dead Reckoning!!! I enjoyed it 😀 😀

 

Last class I ran out of time and  I couldn’t finish the last program related to the Subroutines. This program is another example that causes your Boe-Bot to perform the same maneuvers but instead of using more then one subroutine, this actually uses one subroutine and some variables to do it. Instead of using separate subroutines with specific PULSOUT Duration arguments for each maneuver, the program below uses the same subroutine over and over.

‘ Robotics with the Boe-Bot – MovementsWithVariablesAndOneSubroutine.bs2

‘ Make a navigation routine that accepts parameters.

‘ {$STAMP BS2}

‘ {$PBASIC 2.5}

DEBUG “Program Running!”

counter        VAR               Word

pulseLeft      VAR               Word

pulseRight     VAR               Word

pulseCount     VAR               Byte

FREQOUT 4, 2000, 3000                    ‘ Signal program start/reset.

‘ Forward

pulseLeft = 850: pulseRight = 650: pulseCount = 64: GOSUB Navigate

‘ Left turn

pulseLeft = 650: pulseRight = 650: pulseCount = 24: GOSUB Navigate

‘ Right turn

pulseLeft = 850: pulseRight = 850: pulseCount = 24: GOSUB Navigate

‘ Backward

pulseLeft = 650: pulseRight = 850: pulseCount = 64: GOSUB Navigate

END

Navigate:

FOR counter = 1 TO pulseCount

PULSOUT 13, pulseLeft

PULSOUT 12, pulseRight

PAUSE 20

NEXT

PAUSE 200

RETURN

I know that it looks hard to understand but its actually simple. 🙂 Instead of writing it like this  :

GOSUB Forward

GOSUB Right

GOSUB Left

GOSUB Backward

They are  simply grouped together on the same line and separated by colons. Colons function as a carriage return to separate each PBASIC instruction. In the end this program would perform the familiar Forward-Left-Right-Backward sequence.  Then Mrs.Thompson kept an small assignment on moodle. She had assigned each one of us with different Subroutine commands and we had to type them up and check out if the Boe-Bot performs them.Here is my assignment:

    Anay

  1. Go forward 12″
  2. Turn left 90
  3. Go backward 24″
  4. Turn right 90
  5. Go backward 8″

 

So. I wrote down the program and I ran it and it did exactly like it was supposed to do. That was a nice and  quick assignment. No one seemed to have a problem running it. this whole thing is  pretty easy once you understand they way things function out, but I recall some of my classmates having problems with the program. They would have the same program but for some reason it wouldn’t work . It would always show them a Hardware Communication Failure, which honestly we are still trying to figure out why is that so. Sometimes you would have to run the program like more then 3o times and then if you were lucky enough it would run and sometimes you would sit there with that message constantly appearing on your screen. I hope we can find an answer for this problem because some of us in class are actually beginning to lose their patience including me!!!! 😦

Day 23

Last class we weren’t able to start with the subroutines, so today without any further delay I quickly got my Boe-Bot and started the work. Today my Boe-Bot will perform maneuvers to avoid obstacles and in order to avoid obstacles it will have to execute preprogrammed maneuvers. One way of executing pre-programmed maneuvers is with subroutines. There are two parts of a PBASIC Subroutine.  One part is the subroutine call and its the command in the program that tells it to jump to the reusable part of code, then come backwhen it’s done. The other part is the actual subroutine and it starts with a label that servesas its name and ends with a RETURN command.The commands between the label andthe RETURN command make up the code block that does the job you want the subroutine to do.

‘ Robotics with the Boe-Bot- OneSubroutine.bs2

‘ This program demonstrates a simple subroutine call.

‘ {$STAMP BS2}

‘ {$PBASIC 2.5}

DEBUG “Before subroutine” , CR

PAUSE 1000

GOSUB My_Subroutine

DEBUG “After subroutine” , CR

END

My_Subroutine:

DEBUG “Command in Subroutine” , CR

PAUSE 1000

RETURN

Now, it took me some time to figure out how it works  but in the end th program made sense to me.  It says DEBUG “Before subroutine”, CR this means that on the DEBUG terminal it will say “Before subroutine”, then will go to the next line. It will pause for a second then it says  GOSUB My_Subroutine, so then you go down where it says “My_Subroutine:” and it says DEBUG “Command in Subroutine”, CR so on the debug terminal it will say Command in Subroutine, then will go to the next line  and pause for  a second.Then it says RETURN, and you go back to where you stopped, after the GOSUB Subroutine, and it says DEBUG “After Subroutine” and this is what will say on the debug terminal after a pause of a second. So, when you run the program you should get the same set of three messages in the right order each time.

The second program I wrote has two subroutines.

‘  Robotics with the Boe-Bot – TwoSubroutines.bs2

‘  This program demonstrate that a subroutine is a reusable block of commands.

‘ {$STAMP BS2}

‘ {$PBASIC 2.5}

DO

GOSUB High_Pitch

DEBUG “Back in main”, CR

PAUSE 1000

GOSUB Low_Pitch

DEBUG “Back in main again”, CR

PAUSE 1000

DEBUG “Repeat…”, CR, CR

LOOP

High_Pitch:

DEBUG “High pitch”, CR

FREQOUT 4, 2000, 3500

RETURN

Low_Pitch:

DEBUG “Low pitch”, CR

FREQOUT 4, 2000, 2000

RETURN

After you run the program, you will see in the DEBUG Terminal that it says  “High Pitch” and then will go to next line, and you will hear a high pitched tone.Then it says RETURN, so you return back and do what it says after GOSUB High_Pitch, it says DEBUG “Back in main,” CR now on the debug terminal it will say Back in main and then will go to a different line pause for a second and then it says GOSUB Low_Pitch. Then you will see in the DEBUG Terminal “Low Pitch” and then will go to the nest line, and you will hear a low pitched tone. Then it says RETURN and then you go back again, and keeps on doing this again and again because the program is written between DO and LOOP. 😀

Then I wrote another program that will make my Boe-Bot move in a pattern similar to that it did when I ran the program ForwardLeftRightBackward.bs2. Check it out :

‘ Robotics with the Boe-Bot – MovementsWithSubroutines.bs2

‘ Make forward, left, right, and backward movements in reusable subroutines.

‘ {$STAMP BS2}

‘ {$PBASIC 2.5}

DEBUG “Program Running!”

counter VAR Word

FREQOUT 4, 2000, 3000 ‘ Signal program start/reset.

GOSUB Forward

GOSUB Left

GOSUB Right

GOSUB Backward

END

Forward:

FOR counter = 1 TO 64

PULSOUT 13, 850

PULSOUT 12, 650

PAUSE 20

NEXT

PAUSE 200

RETURN

Left:

FOR counter = 1 TO 24

PULSOUT 13, 650

PULSOUT 12, 650

PAUSE 20

NEXT

PAUSE 200

RETURN

Right:

FOR counter = 1 TO 24

PULSOUT 13, 850

PULSOUT 12, 850

PAUSE 20

NEXT

PAUSE 200

RETURN

Backward:

FOR counter = 1 TO 64

PULSOUT 13, 650

PULSOUT 12, 850

PAUSE 20

NEXT

RETURN

The was another program leftto do, that will  cause your Boe-Bot to perform the same maneuvers, but it only uses one subroutine and some variables to do it but unfortunately I will have to do that next time in class. Today was hectic, it seemed that we did alot of work . The subroutine programs were easy to understand and no one in class faced any program running them including me 😀 :D.


 

 

Last class  we wrote a program called (Ramping) and we tested it. Today we are going to work a bit more on ramping, creating routines to combine ramping up or down with the other maneuvers and we will start a new program called Subroutines.  Okay, first I started with changing some variables in my Ramping program. Instead of ramping up to full speed going forward, this time I did it backwards.The only difference between this routine and the forward ramping routine is that thevalue of pulseCount is subtracted from 750 in the PULSOUT 13 command, where beforeit was added. Likewise, pulseCount is added to the value of 750 in the PULSOUT 12command, where before it was subtracted.

‘ Ramp up to full speed going backwards

FOR pulseCount = 1 TO 100

PULSOUT 13, 750 – pulseCount

PULSOUT 12, 750+ pulseCount

PAUSE 20

NEXT

I have also added another routine as well, making my Boe-Bot ramp into a turn. You can do this by adding the value of pulseCount to 750 in both PULSOUT commands. To make it ramp into a turn the other direction, just subtract pulseCount from 750 in bothPULSOUT commands.

‘ Ramp up right rotate.

FOR pulseCount = 0 TO 30

PULSOUT 13, 750 + pulseCount

PULSOUT 12, 750 + pulseCount

PAUSE 20

NEXT

‘ Ramp down right rotate

FOR pulseCount = 30 TO 0

PULSOUT 13, 750 + pulseCount

PULSOUT 12, 750 + pulseCount

PAUSE 20

NEXT

Now just modify your the new program so that your Boe-Bot will ramp in and out of each maneuver, save it and run the program. When I did run the program, my Boe-Bot went backwards just like it was supposed to do but when it came to turn 90 degrees right , it went more then that value. I didn’t know where the problem might be, so I asked my friend who was sitting next to me (Atiqa) and she told me to keep the same value that I kept for my FOR pulseCount, when we made our Boe-Bot turn exact 90 degrees (In previous classes). So, I changed my FOR pulseCount from 30 to 18 and I ran the program. It went great, my turn was exact 90 degrees,  and it went backwards in a straight path with no funky turns and unassigned routines. 🙂 🙂

As I said we were going to work on subroutines in today’s class but the ramping thingy took me the whole class. So, I think I would keep the Subroutines pleasure for next class and we shall see what it is. 😀