6DOF Quaternion Block initial conditions are dependent on output of another subsystem

3 visualizaciones (últimos 30 días)
I am trying to simulate a UAV being lanuched from a rail launcher and then flying. The initial conditions of the 6DOF quaternion block are thus dependent on the UAV state as it leaves the launcher. How do I assigned the required initial conditions in the 6DOF quaternion block when these conditions need to still be computed by the launcher subsystem? Any help would be appreciated.

Respuestas (1)

Saurav
Saurav el 3 de Oct. de 2024
Editada: Saurav el 3 de Oct. de 2024
For simulating a UAV launch from a rail launcher and setting the initial conditions of the 6DOF quaternion block based on values coming from output of another subsystem, MATLAB scripting within a Simulink model can be used that dynamically manipulates the model parameters. Here's how MATLAB scripting can be utilized in conjunction with Simulink:
  1. Create a MATLAB Script: Write a MATLAB script (.m file) to calculate the initial conditions for the UAV based on outputs from the launcher subsystem.
  2. Set Parameters in the Base Workspace: Store these initial conditions in variables within the MATLAB base workspace, allowing Simulink to access them directly.
% Example script to calculate initial conditions
initialPosition = [0; 0; 0];
initialVelocity = [10; 0; 0];
initialOrientation = [1; 0; 0; 0];
initialAngularVelocity = [0; 0; 0];
% Save these variables to the base workspace
assignin('base', 'initialPosition', initialPosition);
assignin('base', 'initialVelocity', initialVelocity);
assignin('base', 'initialOrientation', initialOrientation);
assignin('base', 'initialAngularVelocity', initialAngularVelocity);
For more information on “assignin”, refer to this documentation: https://www.mathworks.com/help/matlab/ref/assignin.html
3. Use "From Workspace" Blocks: In Simulink, use “From Workspace” blocks to import these variables into the model. Set the ‘Data parameter’ to the variable name in the MATLAB workspace (e.g., ‘initialPosition’) and connect the output of each block to the corresponding input of the 6DOF block.
4. Model Callbacks: Use the model’s “InitFcn” callback to run the MATLAB script before the simulation starts, ensuring that the initial conditions are computed and available. More details can be found here:
5. "MATLAB Function" Block: For the initial conditions requiring complex calculations based on simulation data, utilize a “MATLAB Function” block within Simulink. This block can perform calculations and output results during the simulation. Example function for computing initial conditions:
function [pos, vel, orient, angVel] = computeInitialConditions()
% Example calculations for initial conditions
pos = [0; 0; 0]; % Initial position (x, y, z)
vel = [10; 0; 0]; % Initial velocity (vx, vy, vz)
orient = [1; 0; 0; 0]; % Initial quaternion (qw, qx, qy, qz)
angVel = [0; 0; 0]; % Initial angular velocity (wx, wy, wz)
end
Connect the outputs of the “MATLAB Function” block to subsequent blocks that require the computed data. For more details on using “MATLAB Function” blocks, refer this example:
Additional Methods for Setting Initial Conditions:
  • Using Initial Condition Blocks: Use the “IC” (Initial Condition) block to specify initial values for signals. Connect the output from the launcher subsystem to the IC block, which then feeds into the 6DOF block.
  • https://www.mathworks.com/help/simulink/slref/ic.html
  • Data Store Blocks: Utilize “Data Store Memory”, “Data Store Read”, and “Data Store Write” blocks. The launcher subsystem writes the computed initial conditions to the data store, and the 6DOF block reads from it. For more information on using these ““Data Store Memory”, “Data Store Read”, and “Data Store Write” blocks, refer these documentation links:
Hope these resources help in simulating the UAV launch scenario.

Productos


Versión

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by