Assignment 3.5: Robots - Visual

Visualizing Robots

Goals

In this lab you will practice the following computer science concepts in a team or small group environment:

  • Creating Objects
  • Using conditional statements and looping statements

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

  • Control Structures
  • If statement
  • Loops
  • Input Manager
  • Infrared Sensor
  • Remote

Overview

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
infraredSensor:SetPort(4) 

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
motor:RotateBackward("B")
motor:RotateBackward("C")

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
else
motor:Stop("B")
motor:Stop("C")//These lines finish the looping and conditional statements
end
end

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 Using Libraries, which describes how to use classes built into Quorum..