NI MyRIO Mechatronics and Pneumatics Kit Manual
NI MyRIO Mechatronics and Pneumatics Kit Manual
NI MyRIO Mechatronics and Pneumatics Kit Manual
Manual
1
6 Pneumatic components ......................................................................................................... 29
7 Example Programs.................................................................................................................. 32
8 Helpful links ............................................................................................................................ 35
2
2 Introduction
This document describes the components of the mechatronics and pneumatics kit issued to
students of ME2110 which, most importantly, includes the NI myRIO controller shown in Figure
1. You will not be handed items labeled 2,5,7,8. The controller is a portable reconfigurable I/O
(RIO) device that students can use to design control, robotics, and mechatronics systems. The
controller is programmable with LabVIEW and C languages. There are four electromechanical
actuators provided with the kit: two DC motors, a large solenoid, and a small solenoid. In
addition, a pneumatic system that contains two pneumatic actuators is included. They are
controlled via solenoid valves. There are five sensors included with the kit: two switches, one IR
distance sensor, one potentiometer, banana plugs and one encoder. Included in this document
are explanations of the controller, general LabVIEW programming and operating instructions
for each item in the kit.
3
3 The NI myRIO
In this course you will be using NI myRIO hardware. The NI myRIO is an embedded hardware
device designed specifically to help students design real, complex engineering systems quickly
and affordably. More information can be found at http://www.ni.com/myRIO/what-is/.
3.1 INPUTS-OUTPUTS
The NI myRIO-1900 provides analog input, analog output, digital input and output, audio, and
power output. The NI myRIO-1900 connects to a host computer over USB and wireless
802.11b,g,n.
The MXP ports (the A and B ports), shown on the left side of Figure 1, both have 16 Digital
Input-Output, 2 Analog Output, 4 Analog Input and UART communication channels. The
channels can also be configured to accept an Encoder input, 3 PWM outputs and SPI and I2C
communication. The MSP (the C port) labeled 7 in Figure 1 has 8 Digital Input-Output, 2 Analog
Output, and 2 Analog Input channels. The C port can also accept 2 encoders.
To help students connect their hardware, two custom expansion boards have been made.
These boards will be discussed in the subsequent sections.
When plugging the sensors and actuators into the boards, make sure that the wires are securely
in the sockets and that the stripped parts of the wires are not touching each other (this is
known as a short and is very bad in all applications that deal with electricity). Some common
mistakes on putting wires into sockets are shown in Figure 2. If the wires are inserted correctly
no conductive part of the wire will be exposed even when twisting the wires.
4
3.1.1 The Sensor Board
The Sensor Board in Figure 3 is plugged into the B port. Table 1 shows how the ports on the Sensor
Board correspond with the Channels on the myRIO. All of the sensors are to be connected with the
small (2.5 mm spacing). The sensors are explained in further chapters.
Analog
Inputs
Digital Inputs
Encoder
Figure 3 Sensor Board
5
3.1.2 The Driver Board
The Driver Board in Figure 4 connects the myRIO to the actuators (motors, valves, solenoids).
The Driver Board connects to port A on the myRIO. You can either plug the board straight into
myRIO or use the ribbon cable, shown in Figure 5, to make sure that the board is secure. There
are two holes on the driver board that can be used to secure it to your machine. All of the
actuators are connected to with the larger (5.08 mm spacing) plugs. Table 2 shows which
channel on the myRIO corresponds to the Driver Board outputs.. To use the driver board the
power adapter must be plugged in. Please make sure not to confuse the power adapter for the
myRIO and the Driver Board as shown in Figure 6. If some outputs on the board stop working
try switching the fuses: , if that does not work ask the TAs for help. 630 mA fuses for the
digital outputs and a 4 A fuse for the whole board. Important: Tape the bottom side of the
driver board with electrical tape to avoid shorts.
Power Jack
myRIO Driver Board
Motors Solenoids/Valves
Figure 5 Ribbon Cable
Figure 4 Driver Board Connection Figure 6 Power Adapters
Label on the
Channel Description
Driver Board
Solenoid/Valve Connection
DOUT1 A/DIO1
See Section 5.2.2
6
4 Programming the myRIO
4.1 SETTING UP THE MYRIO
1. Download LabVIEW 2014 for myRIO from here, or ask any of
the TAs for a DVD (You do not need to install DVD 2) or a USB
stick with the installer. If downloading, make sure that the
download does not timeout during the download, check the
size on disk etc. When using studio computers, choose
LabVIEW 2014, and not an earlier version.
2. Install the Software bundle. Use serial number M79X16333 to
activate the product. INSTALL THE SOFTWARE BEFORE
COMING TO THE FIRST MECHATRONICS STUDIO.
3. Connect power to the NI myRIO device
4. Connect the USB cable form NI myRIO to your PC.
5. The NI myRIO USB Monitor appears (Figure 7)
6. Launch the Getting Started Wizard and follow the instructions.
Update to the recommended drivers if prompted. Figure 7 NI myRIO USB monitor
7. Go to the course website and download the ME2110
LabVIEW template. Unzip all of the contents and place them
into a suitable folder. The file must be unzipped.
8. Open LabVIEW
9. Click File->Open Project
10. Open the ME2110 template
11. The LabVIEW Project Explorer opens
12. Right Click on “myRIO-1900 (172.22.11.2)” and right-click
Connect (Figure 8) 1
13. If the process finishes successfully then everything is set up
correctly and you can begin programming the device.
1
If you are using the myRIO over Wi-Fi then click properties and insert the correct IP address and click connect.
2
It is advised, however not compulsory, that the students complete the “Core 1” LabVIEW training by registering
their copy of LabVIEW on ni.com and then choosing the module at http://sine.ni.com/myni/self-paced-
training/app/main.xhtml.
7
LabVIEW is a visual programming language. Execution of the code is determined by a graphical
block diagram where the programmer connects different function-nodes by drawing wires.
These wires propagate variables and any node can execute as soon as all its input data become
available. Since this might be the case for multiple nodes simultaneously, LabVIEW is inherently
capable of parallel execution.
LabVIEW ties the creation of user interfaces, called front panels, into the development cycle.
LabVIEW programs/subroutines are called virtual instruments (VIs). Each VI has two main
components: a block diagram and a front panel. The front panel is built using controls and
indicators. Controls are inputs – they allow a user to supply information to the VI. Indicators are
outputs – they indicate, or display, the results based on the inputs given to the VI.
The block diagram, contains the graphical source code. All of the functional objects placed on
the front panel will appear on the block diagram as terminals (either input or output). The block
diagram also contains structures and functions which perform operations on controls and
supply data to indicators. Examples of the front panel and the block diagram can be seen in
Figure 9.
Figure 9 An Example Block Diagram on the Left and a Front Panel on the Right
The structures and functions are found on the Functions palette which will be visible by right-
clicking on an empty area in either the front panel or the block diagram. Collectively controls,
indicators, structures and functions will be referred to as nodes. Nodes are connected to one
8
another using wires – e.g. two controls and an indicator can be wired to the addition function
so that the indicator displays the sum of the two controls.
The graphical approach also allows non-programmers to build programs by dragging and
dropping virtual representations of lab equipment with which they are already familiar. The
LabVIEW programming environment, with the included examples and documentation, makes it
simple to create small applications compared to traditional text based programming.
VIs are LabVIEW programs, and multiple VIs can be used together to make a LabVIEW
application. To group these related Vis together, use a LabVIEW project, that includes
references to all the LabVIEW files and non-LabVIEW files in the project, configuration
information, build information, and deployment information. When you open a LabVIEW
project, the Project Explorer opens. From there you can open all the files that are linked to the
project and add new ones.
4.2.1 Terminals
You create the front panel with controls and indicators, which are the interactive input and
output terminals of the VI, respectively. Controls are knobs, push buttons, dials, and other input
devices. Indicators are graphs, LEDs and other displays. Controls simulate input devices and
supply data to the block diagram of the VI. Indicators simulate output devices and display data
the block diagram acquires or generates. You can get the Controls Palette as seen in Figure 10
9
by right clicking on an empty area. Objects on the front panel window appear as terminals on
the block diagram. Terminals are entry and exit ports that exchange information between the
front panel and block diagram.
A broken wire appears as a dashed black Line with a red X in the middle . Table 3
shows the most common wire types. To clean up any broken wires press ctrl+b3.
3
All keyboard shortcuts can be found at http://zone.ni.com/reference/en-XX/help/371361H-
01/lvhowto/keyboard_shortcuts/
10
output. To draw a wire hover the mouse over an input or an output until the cursor changes to
the “wiring tool”, then left click to start drawing a wire. This is seen in Figure 11.
11
4.2.3 Basic Loops and structures
The Case Structure has one or more subdiagrams, or cases, exactly one of which executes when
the structure executes. Whether it executes depends on the value of the Boolean, string, or
numeric scalar you wire to the external side of the terminal, labeled selector. A sample Case
Structure is shown in Figure 14.
12
A While Loop executes its subdiagram until a Boolean value you wire to the conditional
terminal is TRUE. A While loop can be seen in Figure 17. Note that you can wire any Boolean
value to the conditional terminal, it does not have to be a button on the Front Panel. As an
option, you can again add shift registers so you can pass information from one iteration to the
next. The value you wire to the shift register on the right side can be read from the shift
register on the left side in the next iteration. In the while loop shown in Figure 17 the numeric
indicator on the front panel is going to display “1” the first iteration of the while loop and “0”
for any consequent because the initial condition is “1” and there is a constant “0” wired to the
right side shift register.
To run the code click on the arrow on the top of the Block diagram or the Front Panel. If the
arrow is broken it means there are errors in your code and you can see the error list by
pressing on it. The abort execution button stops the code regardless where execution of the
code is. Section 4.3 explains how you should terminate the code when using the ME2110
template with the myRIO.
13
IMPORTANT: By default the myRIO will not run a program when you plug it in. To run the code
autonomously, the following steps are necessary :
This was a very brief intro to LabVIEW programming. There is an extensive help section in
LabVIEW. In addition, there is a lot of information and examples on ni.com as well as other
locations on the Internet. If you register your copy of LabVIEW on ni.com you are eligible for
free self-paced trainings offered at http://sine.ni.com/myni/self-paced-
training/app/main.xhtml
An Express VI is a VI with settings that you can configure interactively through a dialog box.
Express VIs appear on the block diagram as expandable nodes with icons surrounded by a blue
field.
14
You can configure an Express VI by setting options in the configuration dialog box that appears
when you place the Express VI on the block diagram. You can double-click the Express VI or
right-click the Express VI and select Properties from the shortcut menu to reopen the
configuration dialog box. You can also configure the Express VI by wiring values to terminals of
the Express VI on the block diagram.
The Express VIs that are going to be used in the ME2110 template are the following:
When you select an Express VI, drag it to the block diagram and a configuration dialog box
appears where you will choose the channels you want to include. Refer to Table 1 and Table 2
for a list of channels used by the Sensor and Driver expansion Board. More details are given in
Section 5.
4
Functionality is the same as compared the Digital Output Express VI
5
Functionality is the same as compared to the Digital Input Express VI
15
4.3 UNDERSTANDING THE ME2110 TEMPLATE
Open Main.vi under the myRIO tree in the Project Manager. The Front panel opens.
TIP: To change between the block diagram and the front panel fast press ctrl+E
16
uncertain on how some of them work, you “help” from the system bar.
Important: When you press the “Stop” button the myRIO will exit the main While loop and will
reset all of the Channels. When you use the Abort Execution button the myRIO will not reset
and will keep the channels at the values that were last written to them. For instance the
Solenoids might be On and the motors running. To fix this You can unplug the power to the
Driver Board and press the “Reset” button on the myRIO. When the program gets stuck in an
infinite loop that it can’t get out of, you must use the Abort Execution button.
previous one has ended. In the “Initialize” frame the initial values are set. The second frame has
a while loop where all of the functional programming is done and is exited once the code tells it
to or the Stop button on the Front Panel is pressed. The while loop has a delay (10 ms in the
template provided) between each iteration. The final frame resets the channels of the myRIO.
17
A more detailed schematic of the main While loop is seen in Figure 21. All of the inputs and the
indicators that are on the Front panel are on the left side of the While loop. Remember you can
find the terminal on the front panel by double clicking on the terminal on the block terminal
and vice versa. There is a case structure that enters the true case when the Control Button on
the Front Panel is in Manual (yellow) and the False case when it is in Program (green) mode. In
the true case you will find code that is behind the control switches and knobs shown in Figure
18. All of the inputs from the sensors are tunneled into the case structure.
Inside the False case of the Case structure you will find another Case structure. Where the
different cases represent the different stages of your code (Start Up, phase 1, phase 2, phase 3
… Stop). This is illustrate in Figure 22. Read about state machines at http://www.ni.com/white-
paper/7595/en/. Remember that the shift registers retain a value to use in the next iteration of
the while loop.
You can change/add states by right clicking on the First state in the initialize frame, and
choosing “Open type def”. There right click on the indicator and choose edit items. When you
are done save it. Right click on the state machine case structure and choose “Add Case For
Every Value”.
18
Remember that you must connect the next case to the output of the structure (it can be the
same case you are in now). You can use “Switch” and other nodes and structures to determine
your next state.
19
7. To program the myRIO and view data over WI-FI right click on the myRIO in the
project explorer in LabVIEW and choose "properties". Then under "general" change IP
address to 172.16.0.1
*To communicate through USB again, you will need to change the IP back
to 172.22.11.2
20
5 Electromechanical Components
This chapter will explain the electromechanical components of the kit, both sensors and
actuators. Sensors include switches, an infrared distance sensor, a potentiometer and an
encoder. Actuators include two DC motors, and solenoids. For each component, its basic
operation will be discussed; then, how to program the myRIO to utilize each component will be
covered.
5.1 SENSORS
5.1.1 Switches
The switches provided are shown in Figure 23. They are simply two wires connected by a
mechanically-triggered attachment. In the relaxed state, the two wires are said to be open, not
connected. When the lever is pressed down, closing the switch, the two wires are shorted and a
current flows. The long-arm switch is momentary, its circuit only remains closed while the lever
is pressed. The pushbutton switch is a toggle switch. Once pressed, it will remain in the
switched position until pressed again. The switches provide an input signal in one of two
possible states. A “LOW” corresponds to a closed circuit, the condition when the switch is
closed, while a “HIGH” corresponds to an open circuit, which is the condition when the switch is
not pressed. “LOW” and “HIGH” can also be interpreted as “FALSE” and “TRUE”. 6
Figure 23 Switches
Each switch is connected to a data channel through the Digital Input Express VI. Choose the
channels you want to use and name them accordingly. Refer to Table 1 for the list channels. In
order for a program to act upon the state of the switch, a case structure (can be used the same
6
It might not seem logical why “LOW” and “HIGH” are interpreted as such but is a common concept in electronics
http://en.wikipedia.org/wiki/Pull-up_resistor.
21
way as “If – Then - Else” in text based programming) can be used. An example of this is show in
Figure 24
The program reads the input from the switch using the Digital Input Express VI, displays it on
the front panel and “tunnels” in to a case structure selector where the user can write routines
for “TRUE” and “FALSE” cases. You will need to add a while loop around this code to read the
digital input more than one time.
22
Figure 25 The IR Distance sensor Figure 26 IR Sensor Wiring
The myRIO reads the voltage that is sent by the sensor. Use the Analog Input Express VI. Refer
to Table 1 to find the channel you are looking for. It is up to the students to convert the voltage
readings to distances. The data you get will be noisy, to handle that you can use the running
average to filter the data. Sample code is shown in Figure 27. This program reads the analog
input, computes the running average, displays it to an indicator on the front panel, and does a
logical comparison with 2(an arbitrary number). The code is left blank in the case structure. The
while loop is stopped when a stop button is pressed on the front panel. Finally the myRIO is
reset.
23
5.1.3 Potentiometer
A potentiometer is a three-terminal resistor with a sliding contact that forms an
adjustable voltage divider. The potentiometers that are included in the kits can be used to
measure the angle of rotation. The correct wiring is shown in Figure 28. The myRIO reads the
voltage the same way as with the IR sensor so an Analog Input Express VI should be used. The
potentiometer you receive in your kit might look a little different but the operation principle is
the same.
The encoder is shown in Figure 29 and is used to measure rotational motion. The encoder and
the potentiometer appear similar but you can tell them apart by how much the shaft turns: the
encoder can rotate freely but the potentiometer has a range of motion of about 270˚. The
rotational motion of the shaft of the encoder is converted to electrical pulses, or counts, that
can be interpreted by a microcontroller. The rotational measurement is based upon the
number of counts. The encoder included in the kit is a relative encoder, meaning it only counts
relative to its starting position for each count command.
24
This piece of code displays the counter value and the direction on the front panel. It also
compares the value to a constant and if the counter is counting up. If both conditions are
“TRUE” the result is displayed on the front panel. You will need to add a while loop to read the
encoder more than one time.
5.2.1 DC Motors
The motors provided are brushed DC motors; the two issued in the kit will be similar to those
shown in Figure 31. The actual motors issued may differ, but their functionality and
programming is the same. The DC motor works by inducing an electromagnetic field using coils
of wire around an armature. Around the inside of the casing are permanent magnets, and as
the shaft turns, the brushes reverse the polarity of the armature, causing the shaft to rotate.
Figure 31 DC Motors
25
For the motors to work you have to enable them by writing true to channel A/DIO 9 using the
Digital Output Express VI. It enables both motor outputs. The direction of the Motor 1 is
determined by channels A/DIO6 and A/DIO7 (A/DIO14, A/DIO15 for Motor 2). When the
direction pins differ the motor turns (you can switch the direction by reversing the pins.) If the
pins are both “HIGH” the motor will break hard and stall (not recommended!) when both are
“LOW” the motor will coast to a stop. The speed of the motors regulated by the Pulse Width
Modulation (PWM) signal which is explained Figure 32. For good form, make sure that you
always provide inputs to both channels to prevent stalling the motor.
The PWM signal can be given to the motor driver through the PWM Express VI. A/PWM2 is for
Motor 1 and A/PWM0 for Motor 2. When configuring the PWM Express VI set Frequency to 20
kHz and Duty cycle to “Set using input to Express VI”. The input for the “Express VI” will have to
be a double from 0 to 1, where 0 will not move the motor, 0.5 will move it at 50% speed and 1
will move the motor at full speed. An example on how to configure the speed and direction can
be seen in Figure 33. If the “double” from the Front Panel (from -1 to 1) is greater than zero
then the “Switch” node will output “TRUE” which will be sent to the first direction pin and the
direction pin will be the inverse of that. This is an easy way to determine the direction and
speed with one control input. The absolute value of the float will be sent to the input of the
PWM Express VI (Remember the input must be from 0 to 1). To stop the motor the user has to
write 0 to the PWM Express VI.
26
Figure 33 Motor Control sample code
5.2.2 Solenoids
A solenoid is essentially a coil of wire around a metallic plunger. When current is run through
the coil of wire, it acts as an electromagnet, pulling in the plunger. Solenoids can be “push”,
“pull”, or both. The solenoids in the kit are “pull” solenoids. The two solenoids issued as part of
the kit are shown in Figure 34. Solenoids should be connected to the digital outputs of the
Driver Board, labeled DOUT1-DOUT4. Refer to Table 2 for the list of channels.
Figure 34 Solenoids
They are controlled using the Boolean (“TRUE”, “FALSE”) inputs. Issuing the “TRUE” command
activates the solenoid, pulling in the plunger. “FALSE” deactivates the solenoid, but will not
return the plunger to its original position. The solenoid are controlled using the Digital Output
Express VI Example code for the solenoids is shown in Figure 35.
27
2 examples are given how to turn two solenoids on and off after 2 seconds.
28
6 Pneumatic components
The pneumatics system, shown in Figure 36, centers around pneumatic actuators, which can be
repeatedly extended. This section will describe the hardware components of the kit and how to
program the controller box to use the system.
29
Figure 39 Pneumatic Valves
Figure 38 Pneumatic Actuators
the cylinder to be achieved before a re-pressurization is needed. However, DO NOT OVER
PRESSURIZE THE SYSTEM. The pump connects to the tank using a 4mm diameter piece of
tubing, through the 4mm one-way coupler on the back of the pressure gauge. After filling the
tank, the 4mm tube should be removed from the tank prior to being removed from the air
source. Leaving the tube in the tank keeps the one-way valve open, allowing the air to escape.
The pneumatic valve controls the airflow of the system; it is a solenoid valve with open and
closed states. In the closed state, ports 1 and 2 of the valve are connected. Because port 2 is
1 2
30
to port 3, which is open. The spring return in the cylinder returns the actuator to un-extended
position, pushing air out the open port 3.
The pneumatic valve is a solenoid and is programmed identically to the solenoids issued in the
kit. Figure 41 shows some sample code on how to use the solenoids (pneumatic valves). Take
note that the “Error Wires” determine the order of execution in this case. The same effect
could be gotten with a Flat Sequence structure and not using the Error wires as in Figure 35.
31
7 Example Programs
In the Example Program shown in Figure 42 the myRIO will turn on a Solenoid once the
Potentiometer value has been greater than 2 at least once (the shift registers will continue to
be true after they have been true once because of the OR block) AND 2 switches has been
pressed together for at least 2 seconds (this will be configured in the Elapsed Time pop-up
window). The elapsed time block will be reset when either of the two switches is not pressed. If
the output from the “And” block is false the solenoid will be turned off, this is not shown in the
diagram. After the stop button has been pressed the while loop will exit and the myRIO is reset.
32
In the program shown in Figure 43 it is desired that the one motor runs and one solenoid is
turned off initially. After two switches have been pressed at the same time the motor should
stop and the solenoid is turned on. Then the motor runs again and the solenoid is turned off
after 1 second has passed. The cycle will be continued until the “Stop” button is pressed on the
front panel. While the program is running the LED 1 and LED 2 will show the states of the
switches (therefore you cannot use any “wait” blocks in your code).
33
“Switch 2” are sent to the case structure and when they are both “true” the selector will output
“1”. This will be sent to the shift register and in the next iteration of the while loop Case “1” will
be selected.
Figure 44 shows the case “1” where the motor is turned off by setting the speed to zero and the
solenoid is turned on. When the “Elapsed Time” Express VI sends a “true” to the selector the
“0” case will used the next iteration of the while loop. Note that in this program the selector
works the same way as a “Not” element. The program is stopped when a “Stop button” is
pressed on the Front panel. This program is very similar to how the ME2110 template works.
34
8 Helpful links
http://www.learnni.com – Learn LabVIEW
http://download.ni.com/support/softlib//labview/labview_myrio/2013/C%20Support%20for%
20NI%20myRIO%20User%20Guide.pdf –How to program the myRIO in C
35