Shop OBEX P1 Docs P2 Docs Learn Events
Routines — Parallax Forums

Routines

I thought it would go unnoticed, and tried to gloss over it, but there's always one student....

In the boe-bot book we used subroutines. I understand those.

Now we are modifying the sumobot book for the boe-bot. In this book, it has what seems like subroutines, but they are never defined as such, and they aren't called with GOSUB but GOTO. Also, they don't end in RETURN. Are these main routines? And why would there be more than one main routine? Why would you use this rather than subroutines?

Please help me answer my student.

Thanks,
Diane

Comments

  • bmcnicho wrote: »
    I thought it would go unnoticed, and tried to gloss over it, but there's always one student....

    In the boe-bot book we used subroutines. I understand those.

    Now we are modifying the sumobot book for the boe-bot. In this book, it has what seems like subroutines, but they are never defined as such, and they aren't called with GOSUB but GOTO. Also, they don't end in RETURN. Are these main routines? And why would there be more than one main routine? Why would you use this rather than subroutines?

    Please help me answer my student.

    Thanks,
    Diane

    Diane,

    Could you post one of the programs in question? Or a page in a book to look at?

  • bmcnichobmcnicho Posts: 40
    edited 2017-02-01 23:49
    This is from the SumoBot manual. I've tweaked it a bit to make it work on a boe-bot.

    Thank you for your help. I'm just a mom trying to teach at my homeschool co-op. I'm not a trained programmer or computer person.
  • tomcrawfordtomcrawford Posts: 1,126
    edited 2017-02-02 16:32
    Diane, sometimes a picture IS worth a thousand words. Beginning at MAIN, the program is an infinite loop. You call Read_Line_Sensors to determine where you are with respect the the line. It can be one of four cases. The BRANCH goes to one of four little programs which controls the motors appropriately. The GOTO Main at the end of each little program just goes back to the top.

    Edit: and nobody is "just" a mom. EndEdit
    1700 x 2338 - 1M
  • This is essentially just a set of logic choices. The code looks at the values being read from the line sensors and makes a decision as to what to do based on those inputs. The code could easily have been written as four subroutines, but the author chose to write it this way, likely because the four actions were very simple, so keeping them "in-line" with the main routine doesn't sacrifice readability. Read_Line_Sensors is a little larger, so it was broken out into a subroutine. The choice is largely stylistic.
  • Thanks very much Jason, Tom and Jim for helping Diane with your detailed answer to her question.

    Ken Gracey
  • Thank you so much for your simple explanations. When things get into stylistic choices, I get a little hesitant. This does seem much easier to read than subroutines.

    It did take me forever to figure out what was going on with the Branch. But I really like how it's done.

    My kids are loving this class. We've only had 1 day, and one kid has already designed a scoop out of a switch cover, and several others have e-mailed me saying how much fun they're having.

    Thanks again for your help!

    Here's a pic that the student sent me. Within 24 hours of the first class... I love when kids are excited about learning.

    874 x 654 - 135K
Sign In or Register to comment.