Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Programming a Mechatronic System: LEGO Mindstorms RCX for Two-Second Motor Function, Study Guides, Projects, Research of Mechanical Engineering

Instructions for creating a program using lego mindstorms rcx to control a motor that turns on for two seconds when a switch is pressed and then turns off. How to use the rcx controller, switches, and dc motors, and provides details on how to create and modify programs using the functions palette and context help. It also covers the use of modifiers and the importance of saving each program created.

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 08/07/2009

koofers-user-z2q
koofers-user-z2q 🇺🇸

3.5

(2)

10 documents

1 / 18

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MECH-311
INTRODUCTION TO MECHATRONIC CONTROLS
The control of our mechatronic projects will be accomplished using the LEGOTM RCX.
This is a microcontroller driven control system that is conveniently housed in a single unit.
Each unit features the following:
A liquid crystal display (LCD) to give visual feedback
Pushbutton switches for controlling program selection and execution
A series of three (3) input ports for attaching sensors to the system
A series of three (3) output ports for attaching actuators to the system
An infrared (IR) communications interface for programming
Battery housing for six (6) AA batteries
An external power supply jack
These devices will be programmed to run the mechatronic systems we develop in
this course.
As we all know, mechatronics devices feature the use of sensors, controls and actuators
to enhance system functionality. Let's say, for example, that we desire a mechatronic
system to function in a way that a motor (actuator) that is part of that system turns on for
two seconds when a switch (sensor) is pressed, and then turns off. Let's say that we
desire this to only happen once in the operation of that system (just to complicate things).
In this example, we have already identified the mechatronic needs:
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download Programming a Mechatronic System: LEGO Mindstorms RCX for Two-Second Motor Function and more Study Guides, Projects, Research Mechanical Engineering in PDF only on Docsity!

MECH-

INTRODUCTION TO MECHATRONIC CONTROLS

The control of our mechatronic projects will be accomplished using the LEGOTM RCX.This is a microcontroller driven control system that is conveniently housed in a single unit.Each unit features the following:^ •^

A liquid crystal display (LCD) to give visual feedback • Pushbutton switches for controlling program selection and execution • A series of three (3) input ports for attaching sensors to the system • A series of three (3) output ports for attaching actuators to the system • An infrared (IR) communications interface for programming • Battery housing for six (6) AA batteries • An external power supply jack These devices will be programmed to run the mechatronic systems we develop inthis course

As we all know, mechatronics devices feature the use of sensors, controls and actuatorsto enhance system functionality. Let's say, for example, that we desire a mechatronicsystem to function in a way that a motor (actuator) that is part of that system turns on fortwo seconds when a switch (sensor) is pressed, and then turns off. Let's say that wedesire this to only happen once in the operation of that system (just to complicate things). In this example, we have already identified the mechatronic needs:

An actuator is needed: the motor A sensor is needed: the switch A controller is needed because the functionality requirements are much more than justturning on the motor when the switch is pressed. So in the development of this mechatronic system, we have several tasks: 1. We must

INTERFACE

the sensors and actuators to the controller. 2. We must

PROGRAM

the controller to accomplish the functionality desired. 3. We must integrate

the sensor, actuator and controller into our mechatronic system. Today's laboratory exercises will help you develop the skills needed to accomplish tasks 1and 2 using the LEGOTM RCX controller. INTERFACING SENSORS AND ACTUATORS This is the easy part. Observe your RCX controller (from here on we'll just call it the"RCX"). On the top side of the LCD is three INPUT PORTS to plug in sensors. In this lab,switches will be provided to you that have connectors like any typical LEGO piece: theysimply SNAP ON to the input ports. Once you have connected the sensor to an input port,all you have to keep track of is which port it's plugged into. Note that the input ports arenumbered 1, 2 or 3. Thus, a switch plugged into the leftmost input port will be associatedwith input number 1.

This is the entry screen to create programs. Notice that there are two sections, the PILOTsection and the INVENTOR section. The Pilot section provides a number of exampleprograms that are ready to download to the RCX. You may find these useful in futurework, but it is not necessary to explore this. You will write your programs in the Inventor section. Notice that there are multiple levelsof “Inventor” levels. Inventor 1 provides only the most basic programming functionality.Inventor 4 provides the full range of capabilities. We will work out of Inventor 4. Noticethat if you click Inventor 4 just ONCE you will see different “Themes” listed. NOTE: IT IS STRONGLY RECOMMENDED THAT YOU MAKE BACKUP COPIES OFYOUR PROGRAMS TO FLOPPY DISK. THERE IS NO SECURITY ON PROGRAMS

STORED ON THE HARD DRIVES, AND SO YOUR PROGRAM CAN EASILY BEERASED! We will return to this shortly. For now, let’s open an example program from one of themore basic levels. Click once on Inventor 2, then once on Starter Set, and then TWICEon “Bug Step3.vi”. The following three windows should open: The top left-most window is the “vi” (Virtual Instrument) window. For our work, this reallyhas little purpose. Below that is the “Diagram” window. This window shows the ICONS

Diagram window and then click “

Show Context Help

”. A help window opens. Now, click

on the Motor reverse icon on the Diagram window. Your screen should look somethinglike this: Notice that the Context Help screen shows all of the connections to the icon, and what themodifiers are for. Notice too that if you want, you can click at the bottom of the ContextHelp window for more detailed help if you need it. Here we see that the modifiers for the Motor reverse icon are PORTS and POWERLEVEL modifiers. Thus, the two diamond-shaped icons that have an A and C in them aremodifiers telling the system that you want to operate on the motors attached to ports Aand C. The number 5 in the other modifier icon is the power level, which is a control ofhow much power is actually sent to the motor (this is useful for controlling speed andtorque!!) Can you find where these modifier icons are on the Functions palette? HINT: move

your mouse pointer around until you see a description called “Modifiers”, then clickthat icon. Notice how the line color-coding matches the border colors of the modifier icons? Keepthis in mind as you learn what modifiers are used and where they belong! NOTE:

On the Functions palette you can always return to the previous palette by clicking the “up arrow” at the top of the window. So now, in terms of what this program is going to do, when it starts we should expect thatthe motors attached to ports A and C will begin turning in the reverse direction at a powerlevel of 5. What next? Well first of all, what is the next icon in the program sequence? Click on the “Wait for”icon from the main Function palette to see that this is the icon for the “Wait for push”command. NOTE: This icon references a “touch sensor”, which is actually just a switch. Whenwe “wait for a push” we are waiting for the switch to be closed! Your Context Help window should show the modifier possibilities for this sensor. In thisexample, the only modifier used is the diamond-shaped number “1”.

What is that telling

us? The next icon in the programming line is a stop sign. Use what you have learned alreadyin terms of utilizing Context Help to determine what this icon is and what modifiers are

Your Functions palette should be visible, and if needed, use the up arrow button to returnto the basic palette. We need to open just one more window, and that’s the Tools Palette.This palette gives us the ability to connect (wire) icons, input parameter values, edit text,and a number of other things we’ll encounter as needed. To view it, simply click Windowon the Diagram screen and then click “

Show Tools Palette

We’re ready to program …

Now, we know that we are going to need a switch (push) icon and a motor icon for thisprogram. Before we get them, think about which should come first. Since our motor is not supposed to start until the switch is pressed, then the switch mustcome before the motor in the progression of the program. Thus, we may go ahead andbring in the switch (Wait for push) icon from the Function palette. NOTICE

that if you move the switch icon close enough to the green light, it will automatically wire itself to the green light. However if you don’t and the icons appearseparate, don’t worry, we can wire them later. Did you notice that you have a LOT MORE icons available to you at the Inventor 4level? Whether you add the modifiers now or add them later is up to you. It’s a matter ofpreference. You may wish to get the basic functionality of the program in line beforeadding modifiers. That is the approach we will use here. Now, bring in an icon for the motor. Which motor icon? Well, remember that our motor isattached to Port A, so we will use either “Motor A forward” or “Motor A reverse” (on themain palette). It really does not matter for this exercise. Move this icon onto the screenclose to the switch icon, but DON’T LET THEM AUTOMATICALLY WIRE TOGETHER.We will do this manually to illustrate how it’s done. NOTE:

if it does accidentally get wired together, simply click the arrow icon on the Tools Palette. This is the Position/Size/Select icon. You can now click on icons and wires to

stop the motor until AFTER the two seconds has elapsed! Now, since our objective calls for this to only occur once, we want to stop the program.Simply wire the red light icon into the Stop Outputs icon. When you are done, yourprogram should look something like this: We now have the basic flow of our program.

All that remains is to add the modifiers.

First, we must identify the switch as the one attached to Port 1. On the Functions palette,click the Modifiers icon and then click the diamond-shaped 1. Drag this into the Diagram

window and place it below the switch icon. Place it so that it automatically wires to theswitch icon. If it does not, use the wiring tool to finish the connection. Now, is it necessary to tell the motor icon that you want to address the motor on Port A?NO, not if you used the icon for Motor A. The only modifier we might want to consider is apower-level modifier. Look for the power-level modifiers on the “Modifiers” Functionpalette. Choose either Power Level 4 or Power Level 5, and attach it to the motor icon inthe Diagram window. At this point, your program should look something like this:

MUST FIX THE ERROR FIRST. If an error occurs, simply click on the broken arrow. A window will open up with advice tohelp you find your error. On the other hand, if no error exists then you can go ahead and send the program to theRCX. After clicking the arrow button you should see a progress bar on the screen, andwithin a few seconds the program will be sent to the RCX. A sound plays to let you knowthat the process is done. NOTE:

you should not move the RCX during programming! NOTE:

this process will only take a few seconds

UNLESS

the firmware needs to be

loaded on your RCX (this only occurs on new RCX modules or sometimes if power hasbeen completely lost by removal of batteries). If your firmware needs to load, it will take afew minutes. Now all that is left is to run your program on the RCX. At this point, press the Run buttonon the RCX. Nothing should happen except you should see the icon of the person on theLCD appear to be walking. This lets you know that the program is running. Note that thenumber next to this icon is the number of the program running. Now press the switch. Your motor should run for two seconds and then stop. Pressingthe switch again should do nothing. Thus, the objectives of our control have been met! For the remainder of the laboratory today you will work on developing a number of other

example controls and programming the RCX. IT IS HIGHLY RECOMMENDED THAT YOU SAVE EACH PROGRAM YOU CREATE

as

example code that you might find useful later in the course!! Other exercises for you to complete TODAY: 1. Write a program so that the motor runs 2 seconds one way, then 4 seconds theother way. 2. Write a program so that the 2-second run process repeats (HINT: Look in theStructures icon for the Jump / Land commands, or possibly consider using a Loopicon) 3. Write a program so that the motor runs in one direction as long as the switch isheld down (HINT: Consider the “Loop while touch sensor is pushed” icon in theStructures set - but MAKE SURE to check out the "additional help" link for all theinformation you need to make it work!) 4. Write a program so that the motor is running all the time but switches directionas long as a switch is pressed 5. Write a program to use a photosensor to detect a black stripe which in turn, turnsa motor on for 4 seconds. (Note: The light detector default number 55 may need tobe adjusted.)