RobotBASIC Robots For Beginners: Building Inexpensive RROS-Based Robots by John Blankenship

RobotBASIC Robots For Beginners: Building Inexpensive RROS-Based Robots by John Blankenship

Author:John Blankenship [Blankenship, John]
Language: eng
Format: epub, azw3, pdf
Publisher: CreateSpace
Published: 2017-10-12T07:00:00+00:00


Coding vs Developing Algorithms

Notice that the discussion above did not talk about how to program the robot to do anything. Instead, it simply expressed an idea of what the robot should do. In general, programmers should decide what has to be done first, then decide how to write the code to do it. As you become more and more proficient in a computer language the difference between the above two ideas will blur, but in the beginning, you should certainly see them as distinct processes.

The plan for what needs to happen is called an algorithm. Writing a program to implement the plan is called coding. Programming is really the process of creating an algorithm and implementing that using the code required for the language you are using. If you learn how to create algorithms, then you can program with many language by just studying their instructions.

Our next step is to see how we can make the robot change between right and left turns for a random amount of time. Look at Figure 6.9. The actual rTurn statement uses dir*10 to control the turn itself. If the value of dir is +1 the robot will turn right. A value of -1 will turn the robot left. At the beginning of the module, the variable dir is set equal to 1. Inside the loop, a random statement multiplies dir by -1 about 5% of the time.

If dir is 1, multiplying it by -1 will make it a -1. If it is already -1, multiplying it by -1 will make it positive again. This means the robot will change the style of its turns about 5% of the time and that should eliminate the vibrating movements seen in the last module used. Make these modification to your Roam module and verify the program now works as expected.

This program is not necessarily perfect, but it does seem to perform fairly well based on our original goals. It certainly is possible though that the robot, if it runs long enough, might eventually bump into an object for some unusual position of the robot in the room. And since our robot moves with some randomness, it should eventually find itself in every possible situation (given enough time).



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.