Introduction to Robotics Teachers Notes Activity 7: USER FUNCTIONS and the DRIVE function

Activity 7: USER FUNCTIONS and the DRIVE function

Activity Setup 10 Minutes Calculations Simple Reliability Good Interest Good Activity Time 60 Minutes

Objective: Students will be able to:

1. Find where the USER FUNCTIONS are located.

2. Create a forward, reverse, 90° right pivot, 90° left pivot, and stop functions

3. Import LIBRARIES into a project.

4. Explain what the DRIVE FUNCTION does.

5. Use the DRIVE FUNCTION to create a program to go forward, reverse, 90° left pivot, 90° right pivot, and stop.

Materials (Per Group): BaseBot with Vex Controller

Computer Workstation with Easy C™ installed.

Orange Serial interface cable.

Hazards: Make sure students are wearing their safety glasses when working on the robot.

Make sure the robot is propped up so that the wheels are not touching the table.

Always make sure the controller is turned off when plugging in or removing cables!

Never plug the orange interface cable into the Rx1 or Rx2 Port!

Make sure that the battery is plugged in properly. Teaching Strategies: It is very important that the power switch on the controller is in the OFF position when plugging cables into the controller. If the controller is ON, a static charge may burn out the controller while the cable is being plugged in.

Make sure the robot is propped up off the table so that the wheels are not touching. Many times there is an old program in the controller and when it is turn on it starts moving. It could roll right off the table top. The top cover of a 50 pack CD spindle works well for propping up the robot as do the four larger extra wheels in the kit.

In this activity the students will learn how to make their own functions to make the robot go forward, reverse, turn, and pivot. They will also learn how to load a pre-built function from a library. These functions will be useful in the next activity where they will be used to create a program that navigates the robot through a maze.

To set up for this activity, use blue painter’s masking tap to tape out the following shapes.

When students are trying to get the robot to move forward and stop, point out to them that the robot has momentum, even though the motors stop moving it takes some time for the robot to stop. It is important that robot comes to a complete stop before making a 90° turn, if one wants the turn to be precise. This will become apparent in the Maze activity and the Optical Encoder Activity.

2 The most common mistake encountered in this activity it that students forget to change the motor numbers in their MOTOR MODULES. As a result, the controller gets confused and the motors do not exhibit the desired behavior. For example, to make the robot got forward the Modules should look like this:

Instead of this:

The second diagram is incorrect because the program is giving the same motor two different commands.

A WAIT statement continues the preceding commands for a specified amount of time. The time unit is milliseconds. So if a student wants the robot to move forward for 4 seconds, they would enter 4000 for the time in the Wait statement.

The program for a pivot should contain the WAIT statement within the PIVOT function. However, for FORWARD, REVERSE, and TURN the WAIT statement should not be placed inside the function but in the main program instead. This allows them to use those functions to travel a variety of distances.

3 SAMPLE USER FUNCTIONS

4 SAMPLE USER FUNCTIONS USING THE DRIVE FUNCTION

To use these functions, TwoWheelDrive or FourWheelDrive must be called at the beginning of the main program!!!

Must call TwoWheelDrive or FourWheelDrive.

5 Assessment:

Student Worksheet Answers: 1. A USER FUNCTION is program that contains a set of frequently used commands. By placing these commands in a USER FUNCTION, the programmer can save time and space.

2. Select PRO from the menu bar at the top of the screen. Right click on USER FUNCTIONS on the left side of the screen. Name you program and click OK. Drag and drop the required commands. When finished, select MAIN from window in the upper right portion of the screen.

3. Sketch your program that contains a 5 second wait, forward (2sec), stop (2sec), a 90° right pivot, stop (2sec), a 90° left pivot, stop (2sec), 180° pivot, and reverse (1sec).

4. Examine the following DRIVE function. What do the numbers represent? 127: Speed 0: Direction

6 5. Explain what the following program does.

Sets motor numbers for drive function

Waits five seconds before starting

Full speed forward for five seconds

Stop

7 6. Examine the following DRIVE functions. If MOTOR #1 is the right motor and MOTOR #2 is the left motor, what will the robot do?

Full speed reverse

Full speed forward

Right pivot

Left pivot

Turning left while going reverse

Turning right while going forward

Turning left while going forward

Turning right while going backwards

Complete stop

7. The robot will travel backwards or in the reverse direction.

8. When the second number is negative the robot will turn or pivot left.

8