In this lab, we will learn the following computer science concepts:

Computer Science Principles Curriculum

Common Core Standards



In this assignment you will use the InfraredSensor Library to control the robot using the remote.

Goal 1: Creating objects

Create a new Robot project. Name it properly and open the main.quorum file. In the top of the file type the appropriate code to use the Quorum InfraredSensor and Motor libraries inside the Lego library.

Activity: Instantiate the Motor and InfraredSensor objects.

Call the Motor object motor and the InfraredSensor object infraredSensor.

Now you must set the port to work with. That will be the port that the Infrared Sensor is connected to on the robot. You will do that using the SetPort statement.

Example: Set the port your Infrared Sensor is connected.

// This line of code will set the port to work with

After that you should set the speed of the motors. This will affect the speed of your robot during turns and while moving straight.

Activity: Write the proper code to set the speed of the motors 'B' and 'C'.

Again you should have some lines of code before the conditions:

//This first line is just giving a value for the loop to start with but it’s going to change once the loop starts so the value doesn’t matter
integer command = 0
//This line is the looping condition, once the condition doesn’t match anymore the program stops
repeat while true
// This line is giving “command” the value that comes back from the GetRemoteCommand statement, that takes as parameter the channel you’re using in the remote
command = infraredSensor:GetRemoteCommand(1)

Goal 2: Using conditional and looping statements

In this assignment we’re going to use the left part of the remote to control the robot's forward movement (top left button) or backwards movement (bottom left button). The right part of the remote will control if the robot turns right (top right button) or left (bottom right button).

Let’s do the conditions now. In this assignment it is clear what the conditions are: when pressed, each button should tell the motors what they should do. The top left button is represented by the number 1, the bottom left is the number 2, the top right the number 3, and the bottom right the number 4.

Example: Create the condition in which the top left button is pressed.

//This line creates the condition in which the top left button is pressed
if command = 1
//These lines tell the robot to move forward

Activity: Use elseif statements to create the other conditions.

Create the other conditions now: elseif the command is equal to 2, elseif the command is equal to 3, and elseif the command is equal to 4. Remember you are making the robot go backwards, turn right, or turn left based on what button is pressed. To finish you will do the last condition: if no buttons are pressed.

Example: Condition in which no buttons are pressed.

//This line tells the robot what to do in case none of the above is true
motor:Stop("C")//These lines finish the looping and conditional statements

Congrats! You are finished with this assignment! Run your program and see if you get any errors. If you do, go back and fix them. Make sure your robot is doing what you expect it to. Did you assign everything as you intended to?

Next Tutorial

In the next tutorial, we will discuss Challenge 3.1, which describes how work Updated Travel Reservation in Quorum..