Sign in:

Tutorial #8: Braitenblocks

Introduction:

“If/else statements” are similar to if statements but allow for two possible responses. Think of them as a coding tool that allows you to create an action if something occurs and perform a different action in all other cases.

A simple example is if I see you wave “hello” while looking in my direction then I will wave hello in response. Otherwise, I will continue walking down the street.

Instructions:

  1. Begin by building the robot using the onscreen instructions. This is the same robot design you built in Tutorial #7.
  2. Download the cubelets_tutorial_8a.cubelet and cubelets_tutorial_8b.cubelet starter files.

  3. Power on your robot and be aware that your Drive Cubelets may still be running custom programs. Be sure that your robot won’t drive away when you power it on!
  4. If you need to pair with your Bluetooth Cubelet, click the connection icon and complete the Bluetooth pairing process.
  5. In this tutorial we will complete two different programs, one for each Drive Cubelet. As you complete this tutorial you will notice that these programs have a seemingly strange conditional statement that isn’t used in this tutorial, but is needed for Tutorial #9.
Cubelet Tutorial 8a.cubelet
  1. First, you’ll need to load the “cubelets_tutorial_8a.cubelet” file. Click the load icon in the toolbar. Then follow the system dialogue to select the proper file.

  2. We’ve arrange the blocks in this file into groups to help you as you work your way through this tutorial. Starting at the top of the “loose” blocks and working your way down will help you identify which blocks are needed in any given step.
  3. In line one of this program, you need to set a variable that we can use in our conditional statement. This allows us to know if a very specific event has occurred.
  4. Drag the blocks so that the first line in the forever block reads “set block value to weighted average.” Tip: use the dropdown menu to select “block value.”
  5. Next you are going to set up the if/else statement. Use the animation below to guide you as you switch an if statement into an if/else statement. Position the if/else block in the forever block below your variable definition.

  6. Look for the big orange conditionals block and connect it to your if/else statement. It reads “if blank equals 0 and blank equals 0.” This block will help you identify a specific event for the robot to respond to.
  7. Adjust the variables and conditional symbols so that it reads if “block value is less than 255 and block value is greater than 180.”

  8. Use the next group of “loose” blocks and arrange them inside the if/else block so that if the conditional is met your robot will change directions at full speed (255) for half a second. Don’t forget the final “toggle motor direction” command to return your Drive Cubelet to the proper direction of travel!
  9. If you want to double check your progress, click here for a code comparison.
  10. Nicely done! If your code is correct, there should be a group of three more blocks on the canvas. Arrange them in the else cutout so that the Drive Cubelet action is equal to the inverse of the Block Value.
  11. Now you’re ready to program the first Drive Cubelet! Select the Drive Cubelet that is directly attached to the Bluetooth and Distance Cubelets, then click “Program Selected Cubelet.”
  12. Once your Cubelet has been successfully updated, it is time to start building the 2nd program.
Cubelet Tutorial 8b.cubelet
  1. First, you’ll need to load the “cubelets_tutorial_8b.cubelet” file. Click the load icon in the toolbar. Then follow the system dialogue to select the proper file.

  2. Arrange the code blocks to create a one line program that tells the Drive Cubelet to set the action value to the inverse of the weighted average. When you’re finished click continue.
  3. If you’re having difficulties completing this section, click here for a hint.

    HINT: Place the “set actuator value to” block inside the “forever” block. Connect the “inverse of” block to the open puzzle position on the right side of the “set actuator value to block.” Finally, connect the “weighted average” block to the right hand side of the “inverse of” block.

  4. Select the Drive Cubelet that is directly attached to the Battery Cubelet then click “Program Selected Cubelet.”
  5. Now that you’ve completed your robot, take a moment to write down a prediction about what this robot will do once you turn it on. Think about the parts and the rules you set up. What sort of behaviors should this robot show?
  6. Take your robot somewhere flat with plenty of room to explore. Grab a couple of obstacles like some books at stand them up so that your robot can detect them. Turn on your robot and observe the behaviors it shows. When you’ve finished observing your robot take a moment to compare your prediction to the robot you built.
  7. How did your robot hypothesis compare to your your robot’s behavior? Were you able to accurately predict what sort of behavior you would see?
  8. If you’re ready to move to Tutorial #9 be sure to save your robot! You’ll be expanding on this exact same robot in Tutorial #9.

Tutorial Summary:

Congratulations on completing the eighth tutorial! Did you see how much your little robot looked like it was trying to avoid objects? With a few simple parts and two modified rules you’ve created a robot that avoids objects! It is pretty amazing to see how seemingly complex lifelike behaviors can come from systems with simple parts and rules.

The rules you created don’t tell the robot to avoid objects. That behavior is simply is a result of the parts and rules interacting!