Time varying data to workspace
3 views (last 30 days)
Show older comments
I need to load a time varying vector to workspace. At each instant the vector should get updated with new values. ie; a 3x1 vector should be obtained at each instant for both position and orienation. Code is attached.
duration = 5; % seconds
fs = 10; % Hz
N = duration*fs; % number of samples
radius = 2; % meters
speed = 2; % meters per second
climbRate = 2; % meters per second
initialYaw = 90; % degrees
pitch = 20; % degrees
initPos = [radius, 0, 0];
initVel = [0, speed, climbRate];
initOrientation = quaternion([initialYaw,pitch,0],'eulerd','zyx','frame');
trajectory = kinematicTrajectory('SampleRate',fs, ...
'Velocity',initVel, ...
'Position',initPos, ...
'Orientation',initOrientation);
accBody = zeros(N,3);
accBody(:,2) = speed^2/radius;
accBody(:,3) = 0.2;
angVelBody = zeros(N,3);
angVelBody(:,3) = speed/radius;
pitchRotation = quaternion([0,pitch,0],'eulerd','zyx','frame');
angVelBody = rotateframe(pitchRotation,angVelBody);
accBody = rotateframe(pitchRotation,accBody);
[position, orientation, velocity] = trajectory(accBody,angVelBody);
eulerAngles = eulerd(orientation,'ZYX','frame');
speed = sqrt(sum(velocity.^2,2));
timeVector = (0:(N-1))/fs;
% pb=angVelBody(:,1);qb=angVelBody(:,1);rb=angVelBody(:,1);
% ub=velocity(:,1);vb=velocity(:,2);wb=velocity(:,2);
% xb=position(:,1);yb=position(:,2);zb=position(:,3);
% phi=eulerAngles(:,1);theta=eulerAngles(:,2);psi=eulerAngles(:,3);
% Vref=[ub vb wb pb qb rb]';
% V=diff(position);
% posi=position'
figure(1)
plot3(position(:,1),position(:,2),position(:,3))
xlabel('North (m)')
ylabel('East (m)')
zlabel('Down (m)')
title('Position')
grid on
figure(2)
plot(timeVector,eulerAngles(:,1),...
timeVector,eulerAngles(:,2),...
timeVector,eulerAngles(:,3))
axis([0,duration,-180,180])
legend('Yaw (Rotation Around Down)','Pitch (Rotation Around East)','Roll (Rotation Around North)')
xlabel('Time (s)')
ylabel('Rotation (degrees)')
title('Orientation')
0 Comments
Answers (0)
See Also
Categories
Find more on Simulation, Tuning, and Visualization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!