User Tools

Site Tools


lego_rip_prog_simulink

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
lego_rip_prog_simulink [2016/04/18 00:18] joaomatoslego_rip_prog_simulink [2016/04/18 22:08] (current) joaomatos
Line 1: Line 1:
 +**Following this tutorial you will be able to make the system balance like this:**
 +
 +{{youtube>CVWS4crfsck?medium}}
 +----
 +
 +**Hardware And Software requirements:**
 +
 +  You will need a NXT Brick and Matlab with Simulink version 2015 or higher. 
 +
 +Follow the step-by-step tutorial to install this ADD-ON on your Matlab provided by MathWorks.
 +
 +[[http://www.mathworks.com/hardware-support/lego-mindstorms-simulink.html?refresh=true|Download and Tutorial Link]]
 +
 +
 +  * Following the tutorial , you will need to update the firmware of your Brick , just click next and it will auto update.However , many times an error can occur when updating for the first time. If your update fail and your brick don't want to turn on again and keep "Clicking" , you will need to recover the Brick and then update again. This "Clicking" is known as "Death Clicking Brick" or "Clicking Syndrome" , and is totally recoverable. Just Hard -reset your Brick and then follow the installation tutorial again and it should work. 
 +
 +
 +{{::simulink_files.rar| Simulink Files}}
 + 
 +To run the model , first run the script on matlab and then deploy the model to the hardware on the Simulink.
 +----
 +
 +
 **Part I) Getting the angles and calculating the velocities from the encoders: ** **Part I) Getting the angles and calculating the velocities from the encoders: **
  
Line 44: Line 67:
  
   * **Input Calculation Logic:**Now that we have our “[x]” matrix with the states of our system , we can calculate the motor input as [K]*[u] , where [K] is our optimal gain matrix from LQR (Can be calculated using Matlab). We just need to do a matrix multiplication and its done.   * **Input Calculation Logic:**Now that we have our “[x]” matrix with the states of our system , we can calculate the motor input as [K]*[u] , where [K] is our optimal gain matrix from LQR (Can be calculated using Matlab). We just need to do a matrix multiplication and its done.
 +
 +**1)Drag the following blocks to the work area: **  1x Mux / 1x  Gain / 1x Output(out1).
 +
 +**2)Double click on the following blocks to modify its parameters:**
 +  * **Mux**:Change the ports number to 4
 +  * **Gain**: Change the gain value to the name of your Optimal Gain matrix stored on your workspace, and the multiplication to matrix.
 +  * **Output**: Change the name to power input.
 +
 +**3) Connections:**Connect the blocks as shown in the picture. After connecting, select all the blocks and create a subsystem.
 +{{::voltagesim.jpg?direct|}}
 +
 +**4)Organizing:** Change the name of your subsystem and the name of input and output to representative names , as shown in the picture:
 +{{::voltage_calculations.jpg?direct|}}
 +
 +
 +----
 +
 +**Part III) Sending the input to the motor **
 +
 +  * **Motor Input Logic:**Now that we have our input calculated, we just need to send it to the motor. As the Lego motors only takes -100 to +100 values, we can use a saturation block to limit the input. For the convenience, we can use a switch block to set a time to start our model (this way we can safely deploy the model to the brick, lift the pendulum to the top position and then the system start balancing).
 +
 +**1) Drag the following blocks to the work area:** 1x Switch / 2x Clock / 1x Constant / 1x Saturation /1x Motor/1x LCD
 +
 +**2)Double click on the following blocks to modify its parameters:**
 +  * **Constant**: Set the Value to 0.
 +  * **Motor**:Change the port to A and the stop action to brake. 
 +  * **Switch:**set the conditional to u2 >= Threshold and Threshold as the time that you want to your system to start (entering 5, after 5 seconds of the program start, it will start balancing).
 +  * **Saturation**:change the values to +100, -100.
 +  * **LCD:**Change the label to "time" and the line to 1.
 +
 +**3) Connections:**Connect the blocks as shown in the picture. No need to create a subsystem.
 +
 +**4) Organizing:**You can add a Clock block and connect to a LCD block to see on the screen the running time. 
 +
 +{{::finalripsim.jpg?direct|}}
 +
 +
 +----
 +
 +**Part IV) Configurations and running the model**
 +
 +**1)** Click on the Simulation tab on the top of the window and then click on Model Configuration Parameters. Change the Solver tab and the Hardware implementation tab as shown in the pictures. The step size can be typed on the tab or can be a variable stored on your Matlab workspace (I'm using 0.010s).
 +
 +{{::config_rip1.jpg?direct|}}
 +{{::config_rip2.jpg?direct|}}
 +
 +**2)Running the Model**: The run the model , click on the Deploy to Hardware buttom , on the right top corner . If you did everything OK , the system will load a little bit and then your brick will start running the program.
 +
 +{{::deployrip.jpg?direct|}}
lego_rip_prog_simulink.1460963896.txt.gz · Last modified: 2016/04/18 00:18 by joaomatos