-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBarRocketVisualizer.m
66 lines (50 loc) · 1.89 KB
/
BarRocketVisualizer.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
classdef BarRocketVisualizer < Visualizer
% Implements the draw function for the Bar Rocket (Planar Quadrotor) model
properties
L=.25; % moment arm
kx = 0;
end
methods
function obj = BarRocketVisualizer(plant)
typecheck(plant,'BarRocketPlant');
obj = obj@Visualizer(plant.getOutputFrame);
obj.L = plant.L;
obj.kx = plant.kx;
end
function draw(obj,t,x)
% Draw the quadrotor.
persistent hFig base pin prop;
if (isempty(hFig))
hFig = sfigure(25);
set(hFig,'DoubleBuffer', 'on');
base = [1.2*obj.L*[1 -1 -1 1]; .025*[1 1 -1 -1]];
pin = [.005*[1 1 -1 -1]; .1*[1 0 0 1]];
a = linspace(0,2*pi,50);
prop = [obj.L/1.5*cos(a);.1+.02*sin(2*a)];
end
sfigure(hFig); cla; hold on; view(0,90);
r = [cos(x(3)), -sin(x(3)); sin(x(3)), cos(x(3))];
%spring?
if obj.kx > 0
spring_width = 0.03;
spring_x = [0; 0; x(1); x(1)];
spring_z = [spring_width; -spring_width; -spring_width; spring_width] + x(2);
patch(spring_x, spring_z, [0.4, 0.4, 0.4]);
end
p = r*base;
patch(x(1)+p(1,:), x(2)+p(2,:),1+0*p(1,:),'b','FaceColor',[0 0 0])
p = r*[obj.L+pin(1,:);pin(2,:)];
patch(x(1)+p(1,:),x(2)+p(2,:),0*p(1,:),'b','FaceColor',[0 0 0]);
p = r*[-obj.L+pin(1,:);pin(2,:)];
patch(x(1)+p(1,:),x(2)+p(2,:),0*p(1,:),'b','FaceColor',[0 0 0]);
p = r*[obj.L+prop(1,:);prop(2,:)];
patch(x(1)+p(1,:),x(2)+p(2,:),0*p(1,:),'b','FaceColor',[0 0 1]);
p = r*[-obj.L+prop(1,:);prop(2,:)];
patch(x(1)+p(1,:),x(2)+p(2,:),0*p(1,:),'b','FaceColor',[0 0 1]);
title(['t = ', num2str(t(1),'%.2f') ' sec']);
set(gca,'XTick',[],'YTick',[])
axis image; axis([-2.0 2.0 -1.0 1.0]);
drawnow;
end
end
end