Sign in:

Tutorial #5: Random wandering

Introduction:

In this lesson you’ll be using a new math/numbers block called “random integer.” An integer is just a whole number greater than zero (1, 2, 3, etc.). So a random integer means a random number that is chosen from a range of numbers where all numbers in the range have an equal chance of being chosen.

For example a random integer between 1 and 10 could be any number 1-10. Numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10 all have the same likelihood of being selected.

Instructions:

  1. Follow the on-screen instructions to complete your robot.
  2. If you haven’t already paired with your Bluetooth Cubelet, click the connection icon and complete the Bluetooth pairing process.
  3. In this tutorial you will create two programs, one for each Drive Cubelet.
  4. Begin by downloading the “cubelets_tutorial_5a.cubelet” and “cubelets_tutorial_5b.cubelet” starter files.

  5. Load the “cubelets_tutorial_5a.cubelet” file. Click the load icon in the toolbar. Then follow the system dialogue to select the proper file.

    Load a .cubelet file.

  6. The first program is for the Drive Cubelet that is directly connected to the Distance Cubelet and Battery Cubelet.
  7. For this Drive Cubelet, arrange the blocks to create a one line program that sets the motor (action) to the inverse of the weighted average.
  8. If you’re having difficulties completing this program, click here for a hint.

    HINT: Drag the “Set actuator value to” into the “forever” block. Connect the “inverse of” to the right edge of the “Set actuator value to” block. Connect the “weighted average” bock to the right edge of the “inverse of” block.

  9. Once you’ve finished creating your program, select the Drive Cubelet that is directly connected to the Distance Cubelet and Battery Cubelet then click “Program Selected Cubelet.” Remember to place your robot in a safe position so it doesn’t accidentally drive off a table or desk!
  10. Next you’ll need to load the “cubelets_tutorial_5b.cubelet” file. Click the load icon in the toolbar. Then follow the system dialogue to select the proper file.

    Load a .cubelet file.

  11. In this program we are going to set our Drive action value to a random integer between 0 and 255 every half second. Arrange the blocks so that the program will set the Drive action value to a random integer between 0 and 255 every half second
  12. If you’re having difficulties completing this program, click here for a hint.

    HINT: Position the “set actuator value to” inside the “forever” block. Then connect the “random integer from 1 to 100” block to the right edge of the “set actuator value to” block. Adjust the values to match the maximum range of Cubelets’ block values, 0 and 255. Next, position the “wait” block in the “forever” block. It should go just below the line of code that sets the actuator value. Change the number field so that you are only waiting 500 milliseconds.

  13. The program you just created tells your Drive Cubelet to set the action value to a random number for half a second before repeating the process over and over again.
  14. Time to program your Cubelet! Make sure that the tab named “cubelets_tutorial_5b.cubelet” is active by clicking on it. Then select the Drive Cubelet that is directly attached to the Bluetooth Cubelet in the Block Map and click “Program Selected Cubelet.”
  15. Once Cubelets Blockly has finished updating your Drive Cubelet, take your robot to a safe play space and observe what new behavior you have created!
  16. How is this robot different than the other driving robots you’ve built and programmed?
  17. When you’re ready to finish this tutorial, power down your robot and read through the Tutorial Summary!

Tutorial Summary:

Changing two rules in the robot has produced more complex behavior, making it harder to determine what is happening inside the robot. Random behavior is difficult to understand. Humans have a tendency to see patterns in things. Pattern recognition is actually one of our biggest strengths as a species! When we see patterns it is natural for us to sometimes think that we are seeing intention or intelligence. However, this robot’s behavior is simply a result of the parts and the rules you’ve created!