Goals

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

Computer Science Principles Curriculum

Common Core Standards

Vocabulary

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:


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.

//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)

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.

Next Tutorial

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