Setting up and Modifying RADA Simulations: Difference between revisions

From Distributed Autonomous and Networked Control Lab
Jump to navigation Jump to search
Pfuhing (talk | contribs)
Pfuhing (talk | contribs)
Line 69: Line 69:


==== System commands ====
==== System commands ====
The system commands block is fairly strait forward. This subsystem just uses the From_Workspace Simulink blocks, step inputs and other Simulink source blocks to create the input reference commands for the simulation.


====  Body velocity calculations ====
====  Body velocity calculations ====

Revision as of 17:56, 8 August 2016

Simulink Setup

In order to use Simulink effectively you need to setup a few things. Iowa State will allow you download MATLAB and use a site license for free as a student. For more information about installing MATLAB using this site license look here. Simulink comes with MATLAB. You should get MATLAB 2014b or latter to ensure the Simulink files from Paul Uhing's research repository will work with your installation of MATLAB.

Once the install is complete and MATLAB is registered you can open MATLAB up. Then change the folder MATLAB will work out of to a directory you will want to work form. It would be best to copy a few files from Paul Uhing's repository to help you get started. Inside of the RADA Research Repository go to MATLAB/RADA and copy modelParams_smallWheels_RADA.m, Hbrigeest.mat, Kvw_calc.mat, Hmu_r_erisLargeWheels.mat, LQI_recalc.m, and RADA_ctrlSep.m from this directory to you new diectroy as these files will allow you to load the model parameters and controller designs used in Paul Uhing's thesis or find the most recent version of these files an copy them instead. It would also be good to copy and of the RADA_psiCtrl_v2.slx or RADA_psiCtrl_LQGsep.slx files here to sever as the base RADA simulation in your new directory. Finally, open te DataSets directory below the RADA directory can copy one of the RADA_LQG_compPID.mat files or RADA_LQG_sep.mat files because it will allow you to have input vector for the copied .slx Simulink file.

Setting up the MATLAB Workspace

Now in MATLAB with you working directory set to you new directory for test RADA simulations run modelParams_smallWheels_RADA.m from the MATLAB command line ten load the RADA .mat data file. Now in the Current Folder screen in MATLAB double click on the .slx and wait for it to open.

Settings in Simulink

When running a simulation RADA in simulink always make sure your solver is set to ode23t! The RADA model is a moderately stiff set of differential equations and ode45 the default solver will take an extremely long time to run simulaitons of RADA. You can set the run length to any length you want and then run the simulation.

Store Data from Simulink

All of the Simulink files in Paul Uhing's Research Repository output simulation data MATLAB structures contain the time and value arrays for important variables. After a simulation finishes these will show up as variables in the MATLAB Workspace. If you want to save any of these values for latter use select them in the MATLAB Workspace and right-click and select save or press ctrl+s to save these variables to a .mat file.

Understanding and Modifying RADA Simulations

The Simulink models of RADA for Paul Uhing's Thesis is built to be fairly easy to understand. Normal Simulink blocks are used for routing signals and completing simple calculations. For more difficult calculations MATLAB Function blocks are used. These blocks allow you to write MATLAB code to complete some calculation. They can have inputs from the Simulink simulation and parameter inputs from the MATLAB Workspace. This makes complex calculations much easier to understand. The goal of using all of these tricks is to avoid creating a model that is a rat's nest of interconnecting blocks that is impossible trace any errors in the simulation. Understanding how the RADA model was put together wil help you understand how to modify this model and how to build your own models.

Components of the Model

The model is broken down into subsystems based off of sub-components of the actual system. There is a block for calculating the accelerations of RADA's body, two blocks for calculating the different actuator sets, producing commands to the system, and calculating intermediate values used by other blocks.

Body dynamics calculations

The body dynamics block (RADA_BodyDynamcis_v2) takes in Euler angle position and velocity of the pendulum (including yaw), the global velocity of the ground vehicle, the force produced by the propellers in the x body direction of the pendulum, the force produced by the propellers in the y body direction of the pendulum, and the force produced by each wheel. This block is a MATLAB Function block so it also has parameter inputs. For using MATLAB Function block is is important to never delete:

%#codegen

because this allows the MATLAB code to function in Simulink.

The code inside the block is just the implementation of the final equation in Chapter 3.4 of Paul Uhing's Thesis. The outputs of the block are the acceleration of the pendulum's in pitch and roll, the acceleration of the yaw of the system, and the x and y global acceleration of the ground robot. Then MATLAB continuous time integrator blocks are used to get the corresponding velocities and positions. MATLAB function blocks do not do integration very well so it is easier just to calculate the accelerations and then use the Simulink blocks to integrate.

Simulink Setup

In order to use Simulink effectively you need to setup a few things. Iowa State will allow you download MATLAB and use a site license for free as a student. For more information about installing MATLAB using this site license look here. Simulink comes with MATLAB. You should get MATLAB 2014b or latter to ensure the Simulink files from Paul Uhing's research repository will work with your installation of MATLAB.

Once the install is complete and MATLAB is registered you can open MATLAB up. Then change the folder MATLAB will work out of to a directory you will want to work form. It would be best to copy a few files from Paul Uhing's repository to help you get started. Inside of the RADA Research Repository go to MATLAB/RADA and copy modelParams_smallWheels_RADA.m, Hbrigeest.mat, Kvw_calc.mat, Hmu_r_erisLargeWheels.mat, LQI_recalc.m, and RADA_ctrlSep.m from this directory to you new diectroy as these files will allow you to load the model parameters and controller designs used in Paul Uhing's thesis or find the most recent version of these files an copy them instead. It would also be good to copy and of the RADA_psiCtrl_v2.slx or RADA_psiCtrl_LQGsep.slx files here to sever as the base RADA simulation in your new directory. Finally, open te DataSets directory below the RADA directory can copy one of the RADA_LQG_compPID.mat files or RADA_LQG_sep.mat files because it will allow you to have input vector for the copied .slx Simulink file.

Setting up the MATLAB Workspace

Now in MATLAB with you working directory set to you new directory for test RADA simulations run modelParams_smallWheels_RADA.m from the MATLAB command line ten load the RADA .mat data file. Now in the Current Folder screen in MATLAB double click on the .slx and wait for it to open.

Settings in Simulink

When running a simulation RADA in simulink always make sure your solver is set to ode23t! The RADA model is a moderately stiff set of differential equations and ode45 the default solver will take an extremely long time to run simulaitons of RADA. You can set the run length to any length you want and then run the simulation.

Store Data from Simulink

All of the Simulink files in Paul Uhing's Research Repository output simulation data MATLAB structures contain the time and value arrays for important variables. After a simulation finishes these will show up as variables in the MATLAB Workspace. If you want to save any of these values for latter use select them in the MATLAB Workspace and right-click and select save or press ctrl+s to save these variables to a .mat file.

Understanding and Modifying RADA Simulations

The Simulink models of RADA for Paul Uhing's Thesis is built to be fairly easy to understand. Normal Simulink blocks are used for routing signals and completing simple calculations. For more difficult calculations MATLAB Function blocks are used. These blocks allow you to write MATLAB code to complete some calculation. They can have inputs from the Simulink simulation and parameter inputs from the MATLAB Workspace. This makes complex calculations much easier to understand. The goal of using all of these tricks is to avoid creating a model that is a rat's nest of interconnecting blocks that is impossible trace any errors in the simulation. Understanding how the RADA model was put together wil help you understand how to modify this model and how to build your own models.

Components of the Model

The model is broken down into subsystems based off of sub-components of the actual system. There is a block for calculating the accelerations of RADA's body, two blocks for calculating the different actuator sets, producing commands to the system, and calculating intermediate values used by other blocks.

Body dynamics calculations

The body dynamics block (RADA_BodyDynamcis_v2) takes in Euler angle position and velocity of the pendulum (including yaw), the global velocity of the ground vehicle, the force produced by the propellers in the x body direction of the pendulum, the force produced by the propellers in the y body direction of the pendulum, and the force produced by each wheel. This block is a MATLAB Function block so it also has parameter inputs. For using MATLAB Function block is is important to never delete:

%#codegen

because this allows the MATLAB code to function in Simulink.

The code inside the block is just the implementation of the final equation in Chapter 3.4 and 3.5 of Paul Uhing's Thesis. The outputs of the block are the acceleration of the pendulum's in pitch and roll, the acceleration of the yaw of the system, and the x and y global acceleration of the ground robot. Then MATLAB continuous time integrator blocks are used to get the corresponding velocities and positions. MATLAB function blocks do not do integration very well so it is easier just to calculate the accelerations and then use the Simulink blocks to integrate.

Actuator dynamics calculations

The actuator dynamics in general take in commands from the controller, mix them into individual motor commands and then calculate the force outputs of the motors. There are two actuator dynamics calculation subsystems. One for the propellers and one for the wheels. The controller output is calculated before these blocks and after the input command block. You just put whatever controller you want to use.

Propellers

The propeller subsystem takes in the the pitch and roll commands, the Euler angle velocities, the cart body velocities and the pitch and roll position. The pitch and roll inputs are mixed into actual motor commands using the Pitch_mixer and Roll_mixer. These two MATLAB function blocks transform the command into something that can be used by the motor normalized between zero and one. Then the motor command, battery voltage and current motor velocity is passed into the motor MATLAB function blocks. These blocks calculate the acceleration of the propeller motors. That acceleration is integrated and the motor velocity is feedback into the motor block and then sent to the motor to force block. This MATLAB Function block uses the four propeller velocities, the angular velocities of the pendulum, and the body velocities of the cart. The output of the block is the total force output in the x and y pendulum axis. Finally there is a MATLAB function block, localAngleVel will calculate convert the global Euler angle velocities to to local body angular velocities. For how the model is generally used this last block isn't necessary but if you are going to have the pendulum do any maneuvers with large angular changes in both pitch and roll using this block will give you better results.

The calculations for all of this blocks come from Chapters 2.2, 3.6 and 3.7 of Paul Uhing's Thesis.

Wheels

The WheelForce subsystem of the RADA model takes in the heading, x and y controller outputs, the body linear velocities of the cart, the yaw velocity of the cart, the heading of the cart and finally takes in the x and y reference commands. This block then outputs the force produced by each of the four wheels.

The heading controller output command, the x and y velocity commands, the heading of the robot, and finally the x and y reference velocities are put into the wheel command mixing matrix, Wheel input mixer. If you are using PIDs you will want to force this heading input to be zero all the time. This block calculate the command that should be sent to each wheel. These wheel commands pass though some saturation and scaling blocks and then are passed into the H-bridge model MATLAB Function block. This converts the controller output to a command for the motor between -1 and 1. This command is passed into the motor subsystems. These blocks take in this command the battery voltage and the velocity of the wheel which was summed from the body linear velocities of the cart and yaw velocity. This subsystem uses Simulink blocks to calculate the force produced by each wheel. The calcaultions done in this subsystem can be found in Chapters 3.5 and 3.7 of Paul Uhing's Thesis.

System commands

The system commands block is fairly strait forward. This subsystem just uses the From_Workspace Simulink blocks, step inputs and other Simulink source blocks to create the input reference commands for the simulation.

Body velocity calculations

Modifying Simulink

Creating a new simulation

Modifying existing files