Quadrotor Control Co-Simulation with Twin Activate
In this tutorial, you will learn how to use MotionSolve and Twin Activate in a co-simulation to control a Quadrotor model.
A quadrotor model is a multirotor helicopter that uses 2 sets of identical fixed pitched propellers (2 clockwise and 2 counter-clockwise) to control lift and torque.
Control of vehicle motion is achieved by altering the rotation rate of one or more rotor discs, thereby changing its torque load and thrust or lift characteristics.
In MotionView you will create the quadrotor frame with 4 superblades and add the rotors motions. A set of forces will be used to represent the wind disturbance.
Twin Activate, through co-simulation with MotionSolve, will implement a controller to impose altitude and direction in quadrotor trying to compensate against the wind effect.
Twin Activate is a software solution for multi-disciplinary, dynamic system modeling and simulation. The software is especially useful for signal-processing and controller design that requires both continuous-time and discrete-time components.
A co-simulation enables MotionSolve and Twin Activate models to communicate with each other during simulation. An ideal use case for co-simulation is the development of a control system for a multibody dynamics model.
Review the Model
- Start a new MotionView session.
- Select File Open model to load the Quadrotor_start.mdl file from your working directory.
-
Review the model.
The Quadrotor model has 9 bodies, one frame called vehicle, 4 propellers and 4 rotors. Associated with them are their respective graphics.
To connect these 9 bodies there are 4 fixed joints connecting the rotors with the vehicle and 4 revolute joints connecting the propellers with the rotors.
Specify the Propeller's Motion
-
Select the Model Ribbon and click
Motions
, to display the Motions guide bar.
-
Click on the ellipsis
next to the Joint collector to access the advanced
selections dialog. Select Propeller_Left and click
OK.
- Click on the Create icon in the Motions microdialog to add the motion.
-
In the Entity Editor, for Label
and Variable, enter
Prop_Left_Rotation and
mot_Prop_Left_Rotation respectively.
-
In the General section, change the Property to Velocity
and click on on the guide bar to finish
editing.
Observe that the guide bar remains open to create new motions.
-
Repeat the steps 1-5 to create motion in the other propellers. When complete,
click on the Cancel icon to exit the Motions guide bar.
Label Variable On Joint Property Prop_Right_Rotation mot_Prop_Right_Rotation Propeller_Right Velocity Prop_Front_Rotation mot_Prop_Front_Rotation Propeller_Front Velocity Prop_Rear_Rotation mot_Prop_Rear_Rotation Propeller_Rear Velocity In a quadrotor, the velocity of the propeller is defined by the controller of pitch and roll of the vehicle.
To define the velocity value of each propeller motion, create three solver variables in the next step that are used further in the co-simulation.
Specify the Velocity of the Propellers
-
Before you can specify the velocity, you must first create the solver
variables.
-
Now you can update the propeller motion velocity.
Add Wind Disturbance Forces
To represent the wind effect and thrust of the quadrotor, a set of forces and moments must be defined.
The wind disturbance is represented as a combination of torques in the X and Y axle applied at the vehicle center.
The thrust of each propeller is represented as a Z force following this equation:
Where,
= Thrust force
= Thrust factor (Defined considering the propeller geometry, air density, m and spin area. For this analysis Tf= 2.1998e-5).
= Propeller Angular velocity
-
Create the wind disturbance force.
-
Create the thrust force.
- To save your model, click Save As and save it with the name Quadrotor_tutorial.mdl.
Create Control Inputs and Plant Outputs
To modify the MBS model to work in a Co-Simulation Mode you need to add solver arrays and solver variables entities in MotionView model. The solver variables contain the individual plant input and output values. The solver arrays define the plant input and output to communicate with Twin Activate.
-
Adding solver variables.
- The individual plant input solver variables were already defined with the propellers motion in Specify the Velocity of the Propellers. They are Throttle_Command, Roll_Command and Pitch_Command.
-
Next, you will define the individual plant output values, which are Altitude,
Roll Angle, Pitch Angle, X position, Y position, X velocity and Y
velocity.
-
Create two solver arrays, ControlInput and PlantOutput, to communicate with
Twin Activate.
- Save your model .
Run the MBS Model in MotionSolve for Verification
-
From the Analyze ribbon, click on Analysis settings
next to Run, to open the Run
Motion Analysis dialog.
- Select the Run offline option.
- Rename the Run name input to Quadrotor_tutorial.
- Select an Output directory folder, where the results will be save and click on the Run button.
-
Click Results to animate the simulation results and
confirm that the model works as intended before continuing to the next
step.
Note: The controller is not yet connected to the model, so the input force and torque are zero.
Connect MotionSolve with Twin Activate
- From the All Programs menu, launch Twin Activate.
- From the menu bar, select Quadrotor_Control_Start .scm file from your working directory. to load the
-
Review the model.
The system has 3 sections of control: Altitude of the quadrotor, X position and Y position. The X and Y position control is defined by a target path, for this model it is a slope of 0.025.
These three sections of controls defined by seven PIDs are the plant input for the MBS model. In MotionView, it's defined as Roll_Command, Throttle_Command and Pitch_Command.
The plant output, Roll_Angle, Altitude, Pitch_Angle, PosX, PosY, VX, and VY, are input for the PID controls.
For example, in the X position target control, you will see three inputs which come from the plant output (PosX, VX, and Roll Angle). -
To enable co-simulation between Twin Activate and
MotionSolve, from Twin Activate, select . In the dialog that is displayed, define the MotionSolve and MotionView
license paths.
-
From the Palette Browser, select , and drag-and-drop the MotionSolve
block into the current diagram and connect the blocks.
-
From the diagram, double-click the MotionSolve block. From the dialog that
is displayed, define the following block properties:
The following parameters are populated automatically after you load the input model, *.mdl or *.xml:
- Inputs Row Size: The value 3 indicates that three signals are supplied from Twin Activate to the MotionSolve model. These signals correspond to the solver array PlantInput, with variables Roll_Command, Throttle_Command and Pitch_Command.
- Outputs Row Size: The value 7 indicates that the MotionSolve model is sending out seven signals from one port, which is why the Demux block is added to separate the signals. The signals correspond to the solver array PlantOutput with variables Roll_Angle, Altitude, Pitch_Angle, PosX, PosY, VX and VY.
Co-simulation with Twin Activate can be done in two ways:- Local co-simulation
- In this case, both MotionSolve and Twin Activate are installed on the same machine. You do not need any additional setup and the fields “MotionSolve server IP address” and “MotionSolve server port number” can be left at their default values as shown in the figure above. Upon starting the co-simulation from Twin Activate, the connection between the two solvers is made automatically, based on the paths specified in Step 4.
- Remote co-simulation between Twin Activate and MotionSolve
- In this case, MotionSolve and Twin Activate can be located on different machines that are accessible over the network. The following section describes how remote co-simulation can be accomplished.
To co-simulate, continue following the rest of this tutorial.
-
Click and drag to connect the output of the block Mux to
Control Input of the MS Plant. Similarly, connect the Plant Output end of the MS
Plant to the input end of Dmux. All required blocks are
now present and connected in the modeling window.
-
From the ribbon's Simulate tool group, select the Setup
tool. From the
Simulation Parameters dialog, in the Final Time field,
enter 12 so that your simulation runs for twelve
seconds.
Note: Since Twin Activate is the main, or calling, solver in this co-simulation scenario, if the simulation end time in Twin Activate is different than the MotionSolve simulation end time, the MotionSolve simulation end time will be modified at run time to match the end time specified in the Twin Activate dialog above.
-
From the ribbon, click Run
.
The Scope blocks in the model generate the following plots, which illustrate the altitude, roll, pitch, x position, y position, and the path.
-
Launch HyperView and animate the
Quadrotor_tutorial.h3d file to see the quadrotor
behavior.
- Before exiting the applications, save your work in Twin Activate as quadrotor_complete.scm.