User Tools

Site Tools


labview_nxt_tutorial

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
labview_nxt_tutorial [2017/07/31 13:24] – [NXT Module Basics] yuhanghelabview_nxt_tutorial [2017/08/15 15:47] (current) – [LabVIEW and LEGO MINDSTORMS NXT] yuhanghe
Line 3: Line 3:
 **Author:** Yu Hang He **Email:** <hey6@unlv.nevada.edu>  **Author:** Yu Hang He **Email:** <hey6@unlv.nevada.edu> 
 \\ \\
-**Date:** Last modified on 7/28/17+**Date:** Last modified on <8/1/17>
 \\ \\
 **Keywords:** LabVIEW, LEGO MINDSTORMS, NXT, NXT Motor **Keywords:** LabVIEW, LEGO MINDSTORMS, NXT, NXT Motor
Line 27: Line 27:
   * [[labview_nxt_tutorial#installation_guide|Installation Guide]]   * [[labview_nxt_tutorial#installation_guide|Installation Guide]]
   * [[labview_nxt_tutorial#nxt_module_basics|NXT Module Basics]]   * [[labview_nxt_tutorial#nxt_module_basics|NXT Module Basics]]
-  * [[labview_nxt_tutorial#examples_and_exercises|Examples and Exercises]]+  * [[labview_nxt_tutorial#examples|Examples]]
   * [[labview_nxt_tutorial#final_words|Final Words]]   * [[labview_nxt_tutorial#final_words|Final Words]]
  
-==== Installation Guide ====+===== Installation Guide =====
  
 If you have not download LabVIEW yet, [[labview_tutorial#installation_guide|follow this tutorial]] to install LabVIEW. **LabVIEW module for LEGO MINDSTORMS is currently only compatible with LabVIEW 2016 and previous editions.**  If you have not download LabVIEW yet, [[labview_tutorial#installation_guide|follow this tutorial]] to install LabVIEW. **LabVIEW module for LEGO MINDSTORMS is currently only compatible with LabVIEW 2016 and previous editions.** 
Line 37: Line 37:
 \\  \\ 
  
-==== NXT Module Basics ====+===== NXT Module Basics =====
  
-=== Section 1.1: Robot Project Center ===+==== Section 1.1: Robot Project Center ====
  
 The Robot Project Center is a central hub for your robot project. To create a robot project, click on ''File'' in the upper left corner of LabVIEW Getting Started window-> ''New NXT/EV3'' -> ''Robot Project'' The Robot Project Center is a central hub for your robot project. To create a robot project, click on ''File'' in the upper left corner of LabVIEW Getting Started window-> ''New NXT/EV3'' -> ''Robot Project''
Line 61: Line 61:
  
  
-=== Section 1.2: Connect NXT and NXT motor ===+==== Section 1.2: Connect NXT and NXT motor ====
  
 Use a USB cable to connect your NXT brick to your computer. Turn on your NXT brick. Under ''Choose NXT/EV3'', select ''Find NXT/EV3'' to display the Find NXT/EV3 dialog box. Use a USB cable to connect your NXT brick to your computer. Turn on your NXT brick. Under ''Choose NXT/EV3'', select ''Find NXT/EV3'' to display the Find NXT/EV3 dialog box.
Line 75: Line 75:
 You can test your motor by change the power level and then press ''Go'' button. Power level determines the speed and direction that NXT motor will turn. When unloaded, NXT motor's power level is proportional to its rotational speed, around 160 RPM at 100% power. NXT motor also has built-in encoder that has 360 counts per single revolution of motor.  You can test your motor by change the power level and then press ''Go'' button. Power level determines the speed and direction that NXT motor will turn. When unloaded, NXT motor's power level is proportional to its rotational speed, around 160 RPM at 100% power. NXT motor also has built-in encoder that has 360 counts per single revolution of motor. 
  
-=== Section 1.3: Hello World ===+==== Section 1.3: Hello World ====
  
 This example will show you how to display ''Hello World!'' message on the NXT brick screen.  This example will show you how to display ''Hello World!'' message on the NXT brick screen. 
Line 93: Line 93:
 {{ :yuhang:labview_nxt_motor:change_visible_palettes.png?400 |Change Visible Palettes}} {{ :yuhang:labview_nxt_motor:change_visible_palettes.png?400 |Change Visible Palettes}}
 \\ \\  \\ \\ 
-Block diagram has its own sets of palettes in MINDSTORMS Robotics section and you must use them to work with NXT brick. Follow the same steps to access these palettes.+Block diagram has its own sets of function palettes in MINDSTORMS Robotics section and you must use them to work with NXT brick. Follow the same steps to access these palettes.
 \\ \\  \\ \\ 
 {{ :yuhang:labview_nxt_motor:function_palettes.png?400 | Function Palettes}} {{ :yuhang:labview_nxt_motor:function_palettes.png?400 | Function Palettes}}
Line 109: Line 109:
 {{ :yuhang:labview_nxt_motor:hello_world.png | Hello World!}} {{ :yuhang:labview_nxt_motor:hello_world.png | Hello World!}}
  
-=== Section 1.4: Executing Programs ===+==== Section 1.4: Executing Programs ====
  
 There are two different modes you can use to run your program: Direct mode and Remote mode. In Direct mode, you run the program from the computer and communicate with the NXT brick with either USB or Bluetooth. In Remote mode, you download the program to the NXT brick with USB or Bluetooth and the program runs directly on the NXT brick without any communication from the computer. There are two different modes you can use to run your program: Direct mode and Remote mode. In Direct mode, you run the program from the computer and communicate with the NXT brick with either USB or Bluetooth. In Remote mode, you download the program to the NXT brick with USB or Bluetooth and the program runs directly on the NXT brick without any communication from the computer.
Line 123: Line 123:
 To run a program, turn on your NXT brick and connect it to your computer with USB cable. On Robot Project Center, under ''Choose NXT/EV3'', choose your NXT brick or use ''Find NXT/EV3'' to connect to your NXT brick. Check you are in Direct mode, then click run command on front panel or block diagram tool bar. The ''Hello World!'' message should display on your NXT brick screen for 1 second. To run a program, turn on your NXT brick and connect it to your computer with USB cable. On Robot Project Center, under ''Choose NXT/EV3'', choose your NXT brick or use ''Find NXT/EV3'' to connect to your NXT brick. Check you are in Direct mode, then click run command on front panel or block diagram tool bar. The ''Hello World!'' message should display on your NXT brick screen for 1 second.
  
-=== Section 1.5: Running NXT motor ===+==== Section 1.5: Running NXT motor ====
  
-In this section, you will learn how to use LabVIEW to program a NXT motor to run for 5 seconds then brake. Create a new VI through Robot Project Center. On the block diagram, right click to open function palettes -> ''I/O'' -> ''Move Moters''.+In this section, you will learn how to use LabVIEW to program a NXT motor to run for 5 seconds then brake. Create a new VI through Robot Project Center. On the block diagram, right click to open function palettes -> ''I/O'' -> ''Move Motors''.
 \\ \\  \\ \\ 
 {{ :yuhang:labview_nxt_motor:move_motor.png | Move Motors}} {{ :yuhang:labview_nxt_motor:move_motor.png | Move Motors}}
 \\ \\  \\ \\ 
-The ''Move Motors'' function is also a polymorphic VI. Click on the text box below function and you can choose between ''Constant Power'' or ''Constant Speed''. To set the power for motor, right click on bottom left connector of function -> ''Create'' -> ''Constant''. The default speed of motor is set at 75%.+The ''Move Motors'' function is also a polymorphic VI. Click on the text box below function and you can choose between ''Constant Power'' or ''Constant Speed''. To set the power for motor, right click on bottom left connector of function -> ''Create'' -> ''Constant''. The default speed of motor is set at 75.
 \\ \\  \\ \\ 
 {{ :yuhang:labview_nxt_motor:motor_power.png | Motor Power}} {{ :yuhang:labview_nxt_motor:motor_power.png | Motor Power}}
 \\ \\  \\ \\ 
 +Now, you need a function to tell NXT brick how long NXT motor should run for. Open functions palettes -> ''I/O'' -> ''Wait For''. The ''Wait For'' function is also a polymorphic VI. Click on the text box below function to check the different instances you can create. You need the function to wait for 5 seconds.
 +\\ \\ 
 +{{ :yuhang:labview_nxt_motor:wait_for.png | Wait For}}
 +\\ \\ 
 +Finally you need the motor to stop. Open functions palettes -> ''I/O'' -> ''Stop Motors'' to create a brake function. Without specifying the motor, NXT brick will send these commands to every motor port. To choose a motor port, right click on the top connector of motor function -> ''Create'' -> ''Constant'', then click on constant box.
 +\\ \\ 
 +{{ :yuhang:labview_nxt_motor:motor_port.png | Motor Port}}
 +\\ \\ 
 +You will need to specify the sequence in which functions will be executed. To specify order, use ''NXT/EV3'' connector to wire the functions together.
 +\\ \\ 
 +{{ :yuhang:labview_nxt_motor:run_nxt_motor.png | Run NXT Motor}}
 +\\ \\
 +The program will set motor power at 75, wait for 5 seconds, then brake all motors.
  
 +===== Examples =====
  
-==== Examples and Exercises ====+==== Section 2.1: Synchronizing Two Motors ====
  
 +Slight differences in NXT motors will cause them to rotate at different rates. This issue become apparent when using two NXT motors to drive in straight line. To solve this problem, you can implement a feedback control. NXT motors have built-in encoders. You can write a program that adjusts power levels to reflect the difference between two encoder readings.
 +\\ \\ 
 +Encoder values can be accessed through ''Motor Status'' function. Open functions palette -> ''I/O'' -> ''Advanced Motors'' -> ''Motor Status''. You will also need ''Reset Encoder'' function, which right next to ''Motor Status'' function
 +\\ \\ 
 +If your motors are connected to ports A and B, then the power input of motors can be adjusted according to this:
 +\\ \\ 
 +''Motor A Power = constant - gain * (Motor A Encoder - Motor B Encoder)''
 +\\ 
 +''Motor B Power = constant + gain * (Motor A Encoder - Motor B Encoder)''
 +\\ \\ 
 +The constant represent the target motor power you want to achieve, the difference between encoder values represent the possible errors, and the gain represent how much weight you want to place on the error, which is called proportional gain.
 +\\ \\ 
 +Here is an example of how to implement proportional controller to synchronize two motors.
 +\\ \\ 
 +{{ :yuhang:labview_nxt_motor:p_controller3.png | Proportional Controller}}
 +\\ \\ 
 +If motor B encoder is greater than motor A encoder that means motor B is running faster than motor A and the difference between 2 encoder values will be positive. After multiplying the proportional gain, this positive value will be added to power of motor A and subtract from power of motor B. Otherwise, power of motor A will be decreased and power of motor B will be increased instead. Through feedback control, the power of motors will constantly adjusting to reflect the difference in encoder readings.
  
-==== Final Words ====+==== Section 2.2: Proportional Integral (PI) Controller ==== 
 + 
 +Encoder function can be used to program NXT motors to rotate to desired position. However, at high power level, motor will overshoot desired position. Proportional integral controller can be implemented to accurately rotate NXT motors to desired position. Here is an exmple of PI controller. 
 +\\ \\  
 +{{ :yuhang:labview_nxt_motor:pi_controller.png | PI Controller}} 
 +\\ \\  
 +Desired position from user input is the setpoint and encoder values are measured process variable. The difference between setpoint and encoder values represent error. The controller constantly adjust motor power, the control variable, to minimize error based on proportional and integral term. 
 +===== Final Words =====
  
-This tutorial's objective was to <fill in the blank>Complete <choose: construction detailssource code and program descriptions> for <fill in the blank>. Once the concepts were conveyed the reader could <fill in the blank>.+This tutorial's objective was to introduce LabVIEW module for LEGO MINDSTORMS and demonstrate how to program NXT motorThe tutorial covers installation of LabVIEW modulehow to write program for NXT brick, and how to control NXT motor. Once the concepts were conveyed the reader could use LabVIEW module for LEGO MINDSTORMS to program NXT brick and motor.
 \\ \\
 \\ \\
-Speculating future work derived from this tutorialincludes <fill in the blank>In the big picture, the problem of <fill in the blankcan be solved with this tutorial.+LabVIEW module for LEGO MINDSTORMS included help manual and examplesyou can access them through toolbar on top of front panel or block diagramGo to ''Help'' -''Find Examples'' or ''MINDSTORMS Module Help''.
 \\ \\
 \\ \\
labview_nxt_tutorial.1501532691.txt.gz · Last modified: (external edit)