Controls
This folder contains the files used in developing the model of the quadcopter.
1. Simulink Flight Simulator
How to Run the Simulator
- In the project folder, open “MicroCART/controls/model”. The “model” folder contains the files needed to run the Simulink simulator. Make sure this folder is the current workspace directory.
- Open “modelParameters.m” in MATLAB and run the script. This will create/update parameters in the MATLAB workspace which are used by the simulator. At this point you should also check that the contents of the “model” folder are displayed in the “Current Folder” window in MATLAB.
- Open “Quadcopter_Model.slx”
- To view the 3D simulator, navigate within the model by clicking on the following blocks: Sensors -> 3D Graphical Simulation -> VR Sink
- Press “Run” in Simulink
Changing Setpoints
-
To change the simulation setpoints, return to the top level of the simulink model and then enter the “Setpoints” block.
-
The default version of the simulator has five step functions which individually instruct the quad to move 1 unit in the x-direction, 1 unit in the y-direction, 1 unit in the z-direction, turn clockwise by 1 unit along the yaw angle, and then return to its starting values. Each step function can be thought of as a setpoint.
-
Open a step function block by double clicking on it. Altering the step time will change when the quad begins to move towards a setpoint. Initial and final value have the format [x-position, y-position, z-position, yaw-angle], and any alterations to these fields will change where the quad starts and where it goes to respectively.
-
Setpoints can be added or removed by adding or removing step functions from the Simulink model diagram.
Note: For this model, negative z values correspond to a position above the starting point [0,0,0,0] and positive z values correspond to a position beneath the starting point. (Example: If the quad is instructed to move from [0,0,-2,0] to [0,0,-1,0], it will be moving from a height of 2 units above the starting point down to a height of 1 unit above the starting point.) This means we will usually only work with negative z-values since our starting point is usually the ground and we cannot fly beneath it :)
Changing Control Models
- To select which controller is used to simulate quad flight, navigate to the top level of the Simulink model and toggle the controller switch to either LQR or PID
Comparing Simulated and Real Motor PWM Signals
With the addtion of the Zybo PCB shield, MicroCART users can now compare motor PWM signals measured from test points on the PCB shield with simulated motor PWM signals created by the Simulink simulator. This is useful for verifying that a controller is behaving as expected without needing to risk damaging the quad during test flights. The physical test points are located on the JE2 header block on the PCB. The simulated signals are contained in the “motorCommands.signals.values” variable. This variable is created in MATLAB's workspace after running a simulation and is updated after each simulation is completed.
To measure the physical motor PWM signals:
- Connect an oscilliscope probe to a motor PWM header pin and a ground pin.
- Calculate the duty cycle of the signal by measuring the time the PWM signal is high and divide it by the period of the PWM signal (~2.2ms).
- The PWM signal should have a duty cycle of ~50% when the quad is on but there is no input sent to the motors.
To measure the simulated motor PWM signals:
- Open and run the simulator as instructed in the sections above.
- Locate the "motorCommands" variable in the MATLAB workspace.
- Open "signals" then open "values" to observe the duty cycle values of each motor PWM signal.
- These signals roughly match the output of the physical system but the user should run tests to observe how accurately the simulation matches the physical results since motors and other components may be switched.
- In the simulink PWM data log, each 1000 data entries corresponds to 5 seconds, which means 0.005 seconds between samples. Ex: 2001 corresponds to 10 seconds into the simulation.
Additional Documents
Measuring Motor Resistance
Simulink Model
Matt Rich's Thesis