classdef QuadPlot < handle
%QUADPLOT Visualization class for quad
properties (SetAccess = public)
k = 0;
qn; % quad number
time = 0; % time
state; % state
des_state; % desried state [x; y; z; xdot; ydot; zdot];
rot; % rotation matrix body to world
color; % color of quad
wingspan; % wingspan
height; % height of quad
motor; % motor position
state_hist % position history
state_des_hist; % desired position history
time_hist; % time history
max_iter; % max iteration
end
properties (SetAccess = private)
h_3d
h_m13; % motor 1 and 3 handle
h_m24; % motor 2 and 4 handle
h_qz; % z axis of quad handle
h_qn; % quad number handle
h_pos_hist; % position history handle
h_pos_des_hist; % desired position history handle
text_dist; % distance of quad number to quad
end
methods
% Constructor
function Q = QuadPlot(qn, state, wingspan, height, color, max_iter, h_3d)
Q.qn = qn;
Q.state = state;
Q.wingspan = wingspan;
Q.color = color;
Q.height = height;
Q.rot = QuatToRot(Q.state(7:10));
Q.motor = quad_pos(Q.state(1:3), Q.rot, Q.wingspan, Q.height);
Q.text_dist = Q.wingspan / 3;
Q.des_state = Q.state(1:6);
Q.max_iter = max_iter;
Q.state_hist = zeros(6, max_iter);
Q.state_des_hist = zeros(6, max_iter);
Q.time_hist = zeros(1, max_iter);
% Initialize plot handle
if nargin < 7, h_3d = gca; end
Q.h_3d = h_3d;
hold(Q.h_3d, 'on')
Q.h_pos_hist = plot3(Q.h_3d, Q.state(1), Q.state(2), Q.state(3), 'r.');
Q.h_pos_des_hist = plot3(Q.h_3d, Q.des_state(1), Q.des_state(2), Q.des_state(3), 'b.');
Q.h_m13 = plot3(Q.h_3d, ...
Q.motor(1,[1 3]), ...
Q.motor(2,[1 3]), ...
Q.motor(3,[1 3]), ...
'-ko', 'MarkerFaceColor', Q.color, 'MarkerSize', 5);
Q.h_m24 = plot3(Q.h_3d, ...
Q.motor(1,[2 4]), ...
Q.motor(2,[2 4]), ...
Q.motor(3,[2 4]), ...
'-ko', 'MarkerFaceColor', Q.color, 'MarkerSize', 5);
Q.h_qz = plot3(Q.h_3d, ...
Q.motor(1,[5 6]), ...
Q.motor(2,[5 6]), ...
Q.motor(3,[5 6]), ...
'Color', Q.color, 'LineWidth', 2);
Q.h_qn = text(...
Q.motor(1,5) + Q.text_dist, ...
Q.motor(2,5) + Q.text_dist, ...
Q.motor(3,5) + Q.text_dist, num2str(qn));
hold(Q.h_3d, 'off')
end
% Update quad state
function UpdateQuadState(Q, state, time)
Q.state = state;
Q.time = time;
Q.rot = QuatToRot(state(7:10))'; % Q.rot needs to be body-to-world
end
% Update desired quad state
function UpdateDesiredQuadState(Q, des_state)
Q.des_state = des_state;
end
% Update quad history
function UpdateQuadHist(Q)
Q.k = Q.k + 1;
Q.time_hist(Q.k) = Q.time;
Q.state_hist(:,Q.k) = Q.state(1:6);
Q.state_des_hist(:,Q.k) = Q.des_state(1:6);
end
% Update motor position
function UpdateMotorPos(Q)
Q.motor = quad_pos(Q.state(1:3), Q.rot, Q.wingspan, Q.height);
end
% Truncate history
function TruncateHist(Q)
Q.time_hist = Q.time_hist(1:Q.k);
Q.state_hist = Q.state_hist(:, 1:Q.k);
Q.state_des_hist = Q.state_des_hist(:, 1:Q.k);
end
% Update quad plot
function UpdateQuadPlot(Q, state, des_state, time)
Q.UpdateQuadState(state, time);
Q.UpdateDesiredQuadState(des_state);
Q.UpdateQuadHist();
Q.UpdateMotorPos();
set(Q.h_m13, ...
'XData', Q.motor(1,[1 3]), ...
'YData', Q.motor(2,[1 3]), ...
'ZData', Q.motor(3,[1 3]));
set(Q.h_m24, ...
'XData', Q.motor(1,[2 4]), ...
'YData', Q.motor(2,[2 4]), ...
'ZData', Q.motor(3,[2 4]));
set(Q.h_qz, ...
'XData', Q.motor(1,[5 6]), ...
'YData', Q.motor(2,[5 6]), ...
'ZData', Q.motor(3,[5 6]))
set(Q.h_qn, 'Position', ...
[Q.motor(1,5) + Q.text_dist, ...
Q.motor(2,5) + Q.text_dist, ...
Q.motor(3,5) + Q.text_dist]);
set(Q.h_pos_hist, ...
'XData', Q.state_hist(1,1:Q.k), ...
'YData', Q.state_hist(2,1:Q.k), ...
'ZData', Q.state_hist(3,1:Q.k));
set(Q.h_pos_des_hist, ...
'XData', Q.state_des_hist(1,1:Q.k), ...
'YData', Q.state_des_hist(2,1:Q.k), ...
'ZData', Q.state_des_hist(3,1:Q.k));
drawnow;
end
end
end
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![mp4](https://img-home.csdnimg.cn/images/20210720083504.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 21 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/1ad39e95093044228d03f0d7ce161a82_zy_dreamer.jpg!1)
![avatar-vip](https://csdnimg.cn/release/downloadcmsfe/public/img/user-vip.1c89f3c5.png)
白话机器学习
- 粉丝: 9974
- 资源: 7681
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)