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

Computer Science Principles Curriculum

Common Core Standards



This lab demonstrates the use of theLego library in Quorum. The Lego library can be used to control every part of the robot but in this lab we’re going to use just the motor part. You will write a program that moves forward the robot and rotate the robot 360 degrees while the third motor not connected to the wheels will keep working the whole time. Before you start with the programming part you need to build the robot, in all the lessons we use the EV3MEG, you can find the tutorial on "Lego website". If you never worked with robots or if you don't remember how it works you should read this tutorial before start:

Goal 1: Accessing the Quorum Standard Library

You will start by creating a new blank Robot project. Name the project Lab2_6. Open the main.quorum file in the editor.

This assignment makes use of the Quorum Motor Library in the Quorum Lego Library. You will need to type code at the beginning of the main.quorum file that lets Quorum know you want to use this library. Begin by typing the appropriate code to use the Quorum Lego Library in your project. The Lego Library is called Libraries.Robots.Lego. To use the Motor Library inside the Lego Library you add .Motor add the end.

Example: Tell Quorum we want access to Motor.

// this line tells Quorum to use the Motor library
use Libraries.Robots.Lego.Motor

You must include a statement like this at the top of the file every time you want to use a Quorum library.

Goal 2: Creating Objects and Calling Actions on Objects

To be able to call actions that are in the Motor library, instantiate a new Motor object, calling it motorControl.

Example: Instantiate a Motor object.

// this line creates (instantiates) a new Motor object called motor
Motor motorControl

Now you can call actions to send commands to the motors. To do that you will use the RotateByDegrees command that has two parameters, the name of the motor you want to activate and the number of degrees you want to rotate the motor. After you send a movement command to a motor you should use the Wait command after to allow the motor time to complete its action before the next action begins.

Large Motors

We will start with the large motors, which are most frequently used for moving the wheels. For these examples we have the right motor plugged into port "B" and the left motor plugged into port "C." This simple example code will move the robot forward 5 turns and then move it backward 5 turns.

Example: Moving the Robot Forward and Backward.

// We use our motorControl object to issue instructions to the motor
//First, set the speed of the motor as a number between 0 and 100, which represents the 
//percentage of power applied to the motor. If your robot is 
//low on power, or doing too many other things, speed may be affected.
motorControl:SetSpeed("B", 50)
motorControl:SetSpeed("C", 50)
//Next, tell the motors to move forward using degrees.
//Use a variable to represent one full revolution of 360 degrees.
integer turn = 360
motorControl:RotateByDegrees("B", turn * 5)
motorControl:RotateByDegrees("C", turn * 5)
//After a motor instruction, you must also tell Quorum to wait to complete the movement.

Activity: Move the robot backward

Expand the program you started to move the robot back to its starting position.

(Hint: a positive number moved the motors forward.)

Small Motor

We can use the small motor with the same basic commands. For this example, the small motor is in port "A". Our robot is configured to raise and lower an arm, but the basic code concept will work on other robot builds.

// First set the speed of the motor
motorControl:SetSpeed("A", 50)
// Move the small motor 90 degrees (one quarter turn)
motorControl:RotateByDegrees("A", 90)

Activity: Move the small motor on your own

Experiment with ways to move your motor by changing speeds, degrees, and executing several commands in a row. For example, raise and then lower an arm, or open or close pincers, if that is how your robot is built.

Next Tutorial

In the next tutorial, we will discuss Assignment 2.1, which describes how work Ramp Experiment and Implicit Type Casting in Quorum..