0

How do I create an animation for a rocket using xyz, roll, pitch, yaw and time in MATLAB Aerospace Toolbox?

Here is some sample data:

x = 1.0e+06 .*[3.0138, 3.1345, 3.7675, 4.7347,6.1352];
y = 1.0e+07 .*[-1.8160,-1.8244,-1.8326,-1.8232,-1.7877];
z = 1.0e+07 .*[0.9917,0.9980,1.0119,1.0218,1.0261];
r =[ 0,0,0.0046,0.0046,0.0046];
p =[ 89.9900,26.6402,22.4665,16.0608,3.6879];
y =[86.7370,86.7370,86.7810,86.7810,86.7810];
t =[0,95,186,282,380];

Here is what I have tried so far:

data = [x',y',z',r',p',y',t'];
h=Aero.Animation;
f=figure;
h.Figure=f;
h.initialize();
h.FramesPerSecond=10
h.TimeScaling = 5;
idx1=h.createBody('delta2.ac','ac');
h.show()
h.bodies{1}.TimeseriesSourceType='Array6DoF';
h.bodies{1}.timeseriesSource=data;
h.Camera.offset=[-150 -150 0];
h.show()
h.VideoRecord = 'on';
h.VideoQuality = 50;
h.VideoCompression = 'Motion JPEG AVI'
h.VideoFilename = 'rocket trajectory';
h.play()
h.VideoRecord='off';

However when I try to run the data, the rocket doesnt rotate or translate.

Alko
  • 57
  • 2
  • 8
  • Can you [edit] your question to include example values for these variables so others can run your code? Might get you better assistance. – SecretAgentMan Oct 30 '19 at 20:47
  • What is the best way to post data on here? – Alko Nov 05 '19 at 20:33
  • If you have a minimal example, you could just do it in the code formatting like [this](https://stackoverflow.com/q/53517842/8239061) or [this](https://stackoverflow.com/q/56994963/8239061) or [this](https://stackoverflow.com/q/58631801/8239061)). The trick is to identify where to give users a *jumping off point* on your code. What about example `xyz = [x,y,z]`? Could users run your code from that point on? – SecretAgentMan Nov 05 '19 at 21:05
  • 1
    Thanks for the tips. I added a short data set and modified the code above so that a copy paste should work out. – Alko Nov 05 '19 at 23:33
  • You should also make clear that this is using the MATLAB [Aerospace Toolbox](https://uk.mathworks.com/products/aerospace-toolbox.html). Users who don't have this toolbox cannot help you and don't need to spend time analysing your problem to find that out later. – Hoki Nov 06 '19 at 09:19
  • When I run your code, I get the following errors: (1) `Error using Aero.Body` ... `TimeseriesSource must be n-by-7.`, (2) `Error in Aero.Body/findstartstoptimes`, (3) `Error in Aero.Animation`, and (4) `Error in Aero.Animation/play` – SecretAgentMan Nov 06 '19 at 14:01
  • @Hoki I specified the Aerospace Toolbox in the question, but not in the description – Alko Nov 07 '19 at 15:53
  • 1
    @SecretAgentMan I was able to fix issue 1 by removing `data_ts = ...` and rewrite data vector as `data = [t',x',y',z',r',p',y']` . Also need to change `h.bodies{1}.timeseriesSource=data` – Alko Nov 07 '19 at 16:11
  • However after making these changes, the rocket still doesnt rotate or translate in the animation. – Alko Nov 07 '19 at 16:18

1 Answers1

0

Created a working animation using the code below:

6dof data should be in this format as an array: [ time, lat, lon, alt, phi , theta, psi]

Make sure that phi, theta, psi are in radians not degrees.

%sixdof_data = [time,lat,long,alt,phi,theta,psi]; % This is if you have data saved as variables
h = Aero.Animation;
h.FramesPerSecond = 20;
h.TimeScaling = 10;
h.createBody('delta2.ac');
h.bodies{1}.TimeseriesSourceType='Array6DoF';
h.Bodies{1}.TimeSeriesSource = sixdof_data;
h.Camera.PositionFcn = @staticCameraPosition;
h.Camera.ViewAngle = 6;
h.show();
h.VideoRecord = 'on';
h.VideoQuality = 50;
h.VideoCompression = 'Motion JPEG AVI';
h.VideoFilename = 'rocket trajectory'
h.play();

useful docs: https://www.mathworks.com/help/aerotbx/ug/playaero.flightgearanimation.html

Here is some sample data that should work:

sixdof_data =[
        0       28.534       279.43   2.8871e-09            0       1.5706       1.6397
       73       28.529       279.51        23057            0      0.88894       1.6397
      148       28.478        280.3   1.6241e+05            0      0.70976       1.6397
      220        28.36       281.87   3.8062e+05   8.3012e-05      0.44196       1.6405
      294       28.185       283.85    5.206e+05   8.3012e-05      0.38282       1.6405
      368       27.936        286.3   5.9145e+05   8.3012e-05      0.32057       1.6405
      443       27.575       289.41    6.137e+05   8.3012e-05      0.20756       1.6405
      517       27.055       293.39   6.0892e+05   8.3012e-05     0.094718       1.6405]
Alko
  • 57
  • 2
  • 8