Assignment 2.5: More Movement, Tones and L.E.D.

More Movement, Tones and L.E.D.

Goals

In this assignment you will practice the following computer science concepts:

  • Creating Objects and Calling Actions on Objects
  • Using the Quorum Lego Library to play tones and turn on the L.E.D.

Computer Science Principles Curriculum

  • Big Idea: Creativity: EU 1.2, LO 1.2.3, EK 1.2.3A, EU 1.3, LO 1.3.1, EK 1.3.1A
  • Big Idea: Algorithms: EU 4.1, LO 4.1.1, EK 4.1.1B
  • Big Idea: Programming: EU 5.1, LO 5.1.1, EK 5.1.1B, EU 5.2, LO 5.2.1, EK 5.2.1C, EK 5.2.1D

Common Core Standards

  • English Language Arts Standards » Science & Technical Subjects: CCSS.ELA-Literacy.RST.9-10.2, CCSS.ELA-Literacy.RST.9-10.3, CCSS.ELA-Literacy.RST.9-10.4, CCSS.ELA-Literacy.RST.9-10.5, CCSS.ELA-Literacy.RST.9-10.6, CCSS.ELA-Literacy.RST.11-12.2, CCSS.ELA-Literacy.RST.11-12.3, CCSS.ELA-Literacy.RST.9-10.1, CCSS.ELA-Literacy.RST.9-10.2, CCSS.ELA-Literacy.RST.9-10.7, CCSS.ELA-Literacy.RST.9-10.8, CCSS.ELA-Literacy.RST.9-10.9
  • Standards For Mathmatical Practice: CCSS.Math.Practice.MP1, CCSS.Math.Practice.MP2, CCSS.Math.Practice.MP5, CCSS.Math.Practice.MP6, CCSS.Math.Practice.MP7, CCSS.Math.Practice.MP8, CCSS.Math.Content.HSF.IF.A.1

Vocabulary

  • Library
  • Object
  • Instantiation
  • Action Call
  • Parameters
  • Parameter Passing
  • Robot
  • Motor
  • Brick
  • Port

Overview

In this assignment you will write a program that combines the RotateByDegreesand the RotateToDegree statements to make the robot move in a L shape and come back. At the same time you will make the tone and the L.E.D. color change when moving forward or rotating.

Goal 1: Calling Actions on Objects

Begin by typing the appropriate code to use the Motor library in the Quorum Lego Library at the top of the file. Don’t forget to instantiate a new Motor object called motorControl.

To move the robot in this assignment you will combine the RotateToDegree and the RotateByDegrees statements. Both of these actions work with two parameters, the name of the motor you want to rotate and the amount of degrees you want to rotate to, or rotate by. You will also need to remember to use the Wait statement.

The difference between how these two actions work is:

  • RotateByDegrees will add the new rotation on to it's current position and turn the motor as far as you specify. For example, if your motor has already been rotated one quarter turn and you issue a RotateByDegrees(90) instruction, the motor will now be rotated 180 degrees from it's original position.
  • RotateToDegree will rotate the motor to an absolute position like a compass heading, regardless of its last position. For example, no matter what the position of the motor, a RotateToDegree(180) will move the motor to the due south position (one half turn from it's base position).

Example: Turn the robot

//This line sets the speed of the motor
//This value goes from 0 to 100 and max speed indicates two rotations per second with a full battery
//Let's set it to 50, or one rotation per second.
motorControl:SetSpeed("B", 50)
//This line of code tells the Motor object named motorControl
//that it should rotate the motor one full rotation (backward)
//Note: This does NOT turn the robot by 360 degrees backward, it turns the motor.
motorControl:RotateToDegree("B",-360)
//This line tells the program to wait the motor to finish the action
motorControl:Wait("B")

Activity 1: Lift the robot arm using the small motor

After the robot is in it's position, use the RotateToDegree() action to raise the arm. Experiment with different positions.

Activity 2: Turn the robot around and return to the starting position

In this activity, our goal is to tell the motor object that you want to move the motor C in the same way that we are moving motor B. We do this by using the RotateToDegree command. After the turn, rotate your robot to head back over the same path it came from. When the robot is "home" turn it back around to prepare to run it again. You can put tape or a mark on the floor to remember the position if it helps. You can use a whichever Rotate action you prefer to use. Lower the arm to it's starting position.

Goal 2: Using the Quorum Lego Library to play tones and to turn on the L.E.D.

To play tones you will need to use the Sound library in Libraries.Lego, so you need to include the use statement at the top of the file. The full path of the library is Libraries.Robots.Lego.Sound. After the library inclusion, you will need to instantiate a new Sound object called soundControl.

Instantiate a new Sound object called soundControl.

Sound soundControl

To turn on the L.E.D. you will need to include the Button library and instantiate a Button object called buttonControl.

Example: Play a tone

Once you have done this, you will use the PlayTone statement to play the tones. The PlayTone statement takes two parameters, frequency and duration.

You can change the frequency and duration of the tone. The frequency is between 200 and 20000 and different values will have different tones. You won't be able to hear differences between values that are too close to each other. Experiment with different tones to understand how they change.

Example: Turn the L.E.D. green and solid

Use the SetLightPattern statement to turn on the L.E.D. The SetLightPattern statement takes one parameter, the pattern. The pattern that represents an orange and solid pattern is number 3. A list of the patterns for the LED lights is located here.

// This line turns on the L.E.D. 
buttonControl:SetLightPattern(1)

Activity: Insert some sounds and lights into your code from Goal 1

Insert lines like these to play the tones and change lights at different points while your robot is moving. The instruction to play a tone when the robot is moving forward must be on the line before the commands to move forward and the line with a different tone must be on the line before of the commands to rotate.

To complete the activity, you must move the robot in the L shape again but now with the tones and the L.E.D. You can use the sounds and lights to mark the times when the robot is changing to a new instruction.

//This line plays a tone in a frequency of 820 Hertz with a duration of 200 milliseconds
//To give a reference, a frequency of 440 would be an "A" in music.
soundControl:PlayTone(820, 200)

Next Tutorial

In the next tutorial, we will discuss Assignment 2.6, which describes how work Atmospheric Calculations in Quorum..