⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rckcad.m

📁 航天工程工具箱
💻 M
📖 第 1 页 / 共 2 页
字号:
   rpos=rck.comp{sidx}(idx,10);
   w=rck.comp{sidx}(idx,11);
else
   idx=size(rck.comp{sidx},1)+1;
   pos=0;
   L=500;
   d=50;
   rpos=250;
   w=100;
end
hold on
rckplot([2 nan 40 100 0 20 nan nan nan 50 100],0,0)
load cgico
marker(90,0,double(cdata),[0 0 1;1 1 1],7)
%[x0 y0 xsc ysc]=winscale(gca);
set(findobj('type','line'),'color','k')
plot([0 40],[0 0],'r:')
plot([40 140],[5 5],'r:')
plot([40 40 90 90],[-10 -20 -20 0],'r:')
eval(get(gcf,'resizefcn'))
axis([0 140 -20 20])
axis equal off
h(1,1)=uicontrol('style','text','string','x','pos',[100 110 10 20],'horiz','l');
h(1,2)=uicontrol('style','edit','string',num2str(pos),'pos',[115 110 40 20]);
set(h(1,2),'callback','rckcad(21)')
h(2,1)=uicontrol('style','text','string','L','pos',[200 120 10 20],'horiz','l');
h(2,2)=uicontrol('style','edit','string',num2str(L),'pos',[215 120 40 20]);
set(h(2,2),'callback','rckcad(22)')
h(3,1)=uicontrol('style','text','string','d','pos',[420 105 10 20],'horiz','l');
h(3,2)=uicontrol('style','edit','string',num2str(d),'pos',[435 105 40 20]);
set(h(3,2),'callback','rckcad(23)')
h(4,1)=uicontrol('style','text','string','CG','pos',[210 55 20 20],'horiz','l');
h(4,2)=uicontrol('style','edit','string',num2str(rpos),'pos',[235 55 40 20]);
set(h(4,2),'callback','rckcad(24)')
h(5,1)=uicontrol('style','text','string','Mass:','pos',[20 155 50 20],'horiz','l');
h(5,2)=uicontrol('style','edit','string',num2str(w),'pos',[75 155 40 20]);
set(h(5,2),'callback','rckcad(25)')
h(6,2)=uicontrol('style','push','string','Ok','callback','global hh, close(hh)');
rck.comp{sidx}(idx,:)=[2 nan pos L 0 d nan nan nan rpos w];
figure(hfig)
rckplot(rck.comp{sidx})


function cb_coupler
global rck h hfig idx hh sidx
hh=dialog('name','Coupler','handlevis','on');
xmax=400;
ymax=300;
pos=get(hh,'pos');
set(hh,'pos',[pos(1:2) xmax ymax])
if idx
   pos=rck.comp{sidx}(idx,3);
   L=rck.comp{sidx}(idx,4);
   d1=rck.comp{sidx}(idx,5);
   d2=rck.comp{sidx}(idx,6);
   rpos=rck.comp{sidx}(idx,10);
   w=rck.comp{sidx}(idx,11);
else
   idx=size(rck.comp{sidx},1)+1;
   pos=0;
   L=50;
   d1=50;
   d2=d1+50;
   rpos=25;
   w=20;
end
hold on
plot([40 40 100 100 40],[30 70 80 20 30],'k')
load cgico
marker(70,50,double(cdata),[0 0 1;1 1 1],7)
plot([40 100],[60 60],'r:')
plot([0 40],[50 50],'r:')
plot([40 40 70 70],[30 20 20 50],'r:')
eval(get(gcf,'resizefcn'))
axis([0 100 0 100])
axis equal off
h(1,1)=uicontrol('style','text','string','x','pos',[80 145 10 20],'horiz','l');
h(1,2)=uicontrol('style','edit','string',num2str(pos),'pos',[95 145 40 20]);
set(h(1,2),'callback','rckcad(31)')
h(2,1)=uicontrol('style','text','string','L','pos',[240 180 10 20],'horiz','l');
h(2,2)=uicontrol('style','edit','string',num2str(L),'pos',[255 180 40 20]);
set(h(2,2),'callback','rckcad(32)')
h(3,1)=uicontrol('style','text','string','d1','pos',[140 120 20 20],'horiz','l');
h(3,2)=uicontrol('style','edit','string',num2str(d1),'pos',[165 120 40 20]);
set(h(3,2),'callback','rckcad(33)')
h(4,1)=uicontrol('style','text','string','d2','pos',[320 120 20 20],'horiz','l');
h(4,2)=uicontrol('style','edit','string',num2str(d2),'pos',[345 120 40 20]);
set(h(4,2),'callback','rckcad(34)')
h(5,1)=uicontrol('style','text','string','CG','pos',[190 55 20 20],'horiz','l');
h(5,2)=uicontrol('style','edit','string',num2str(rpos),'pos',[215 55 40 20]);
set(h(5,2),'callback','rckcad(35)')
h(6,1)=uicontrol('style','text','string','Mass:','pos',[20 220 50 20],'horiz','l');
h(6,2)=uicontrol('style','edit','string',num2str(w),'pos',[75 220 40 20]);
set(h(6,2),'callback','rckcad(36)')
h(7,2)=uicontrol('style','push','string','Ok','callback','global hh, close(hh)');
rck.comp{sidx}(idx,:)=[3 (d1<d2)+2*(d1>d2) pos L d1 d2 nan nan nan rpos w];
figure(hfig)
rckplot(rck.comp{sidx})


function cb_fins
global rck h hfig idx hh sidx
hh=dialog('name','Fins','handlevis','on');
xmax=400;
ymax=400;
pos=get(hh,'pos');
set(hh,'pos',[pos(1:2) xmax ymax])
if idx
   pos=rck.comp{sidx}(idx,3);
   a=rck.comp{sidx}(idx,4);
   b=rck.comp{sidx}(idx,5);
   R=rck.comp{sidx}(idx,6);
   S=rck.comp{sidx}(idx,7);
   m=rck.comp{sidx}(idx,8);
   n=rck.comp{sidx}(idx,9);
   rpos=rck.comp{sidx}(idx,10);
   w=rck.comp{sidx}(idx,11);
else
   idx=size(rck.comp{sidx},1)+1;
   pos=0;
   a=200;
   b=100;
   R=25;
   S=2*R;
   m=100;
   n=3;
   rpos=100;
   w=10;
end
nval=find(n==[3 4 6]);
hold on
patch([30 75 100 80 30],[40 80 80 40 40],[.7 .7 .7])
h=plot(0,0);set(h,'color',[.8 .8 .8])
load cgico
marker(70,60,double(cdata),[0 0 1;1 1 1],7)
plot([30 30 80 80 30],[0 40 40 0 0],'k')
plot([0 30],[20 20],'r:')
plot([30 30 75],[40 80 80],'r:')
plot([100 100 80],[80 20 20],'r:')
plot([80 100],[40 40],'r:')
plot([30 70 70],[10 10 60],'r:')
eval(get(gcf,'resizefcn'))
axis([0 100 -40 100])
axis equal tight off
typestr={'3','4','6'};
h(1,1)=uicontrol('style','text','string','# Fins:','pos',[20 370 50 20],'horiz','l');
h(1,2)=uicontrol('style','popup','string',typestr,'val',nval,'pos',[75 370 80 20]);
set(h(1,2),'callback','rckcad(41)')
h(2,1)=uicontrol('style','text','string','x','pos',[80 135 10 20],'horiz','l');
h(2,2)=uicontrol('style','edit','string',num2str(pos),'pos',[90 135 40 20]);
set(h(2,2),'callback','rckcad(42)')
h(3,1)=uicontrol('style','text','string','a','pos',[200 195 10 20],'horiz','l');
h(3,2)=uicontrol('style','edit','string',num2str(a),'pos',[210 195 40 20]);
set(h(3,2),'callback','rckcad(43)')
h(4,1)=uicontrol('style','text','string','b','pos',[300 320 10 20],'horiz','l');
h(4,2)=uicontrol('style','edit','string',num2str(b),'pos',[310 320 40 20]);
set(h(4,2),'callback','rckcad(44)')
h(5,1)=uicontrol('style','text','string','R','pos',[330 170 10 20],'horiz','l');
h(5,2)=uicontrol('style','edit','string',num2str(R),'pos',[340 170 40 20]);
set(h(5,2),'callback','rckcad(45)')
h(6,1)=uicontrol('style','text','string','S','pos',[330 230 10 20],'horiz','l');
h(6,2)=uicontrol('style','edit','string',num2str(S),'pos',[340 230 40 20]);
set(h(6,2),'callback','rckcad(46)')
h(7,1)=uicontrol('style','text','string','m','pos',[180 320 10 20],'horiz','l');
h(7,2)=uicontrol('style','edit','string',num2str(m),'pos',[190 320 40 20]);
set(h(7,2),'callback','rckcad(47)')
h(8,1)=uicontrol('style','text','string','CG','pos',[180 105 20 20],'horiz','l');
h(8,2)=uicontrol('style','edit','string',num2str(rpos),'pos',[205 105 40 20]);
set(h(8,2),'callback','rckcad(48)')
h(9,1)=uicontrol('style','text','string','Mass:','pos',[20 340 50 20],'horiz','l');
h(9,2)=uicontrol('style','edit','string',num2str(w),'pos',[75 340 40 20]);
set(h(9,2),'callback','rckcad(49)')
h(10,2)=uicontrol('style','push','string','Ok','callback','global hh, close(hh)');
rck.comp{sidx}(idx,:)=[4 nan pos a b R S m n rpos w];
figure(hfig)
rckplot(rck.comp{sidx})


function cb_motor
global rck h hfig idx hh sidx motorh
warndlg('Under construction')
return
hh=dialog('name','Motor','handlevis','on');
xmax=300;
ymax=200;
pos=get(hh,'pos');
set(hh,'pos',[pos(1:2) xmax ymax])
if idx
   ud=get(motorh,'userdata'); eng=ud{2};
   pos=rck.comp{sidx}(idx,3);
   L=rck.comp{sidx}(idx,4);
   d=rck.comp{sidx}(idx,6);
   n=rck.comp{sidx}(idx,9);
   rpos=rck.comp{sidx}(idx,10);
   w=rck.comp{sidx}(idx,11);
else
   idx=size(rck.comp{sidx},1)+1;
   eng=loadeng('estes\d12');
   pos=0;
   L=eng.L;     %Estes D12 (mm)
   d=eng.D;     %Estes D12 (mm)
   n=1;
   rpos=L/2;  %Estes D12 (mm)
   w=(eng.mm+eng.mf)*1e3;   %Estes D12 (g)
end
h(1,1)=uicontrol('style','text','string','# Motors:','pos',[20 170 50 20],'horiz','l');
h(1,2)=uicontrol('style','edit','string',num2str(n),'pos',[75 170 80 20]);
set(h(1,2),'callback','rckcad(51)')
h(2,1)=uicontrol('style','text','string','x','pos',[60 140 10 20],'horiz','l');
h(2,2)=uicontrol('style','edit','string',num2str(pos),'pos',[75 140 40 20]);
set(h(2,2),'callback','rckcad(52)')
% Use the objects UserData to store the motor-data (append to existing COMP in UserData)
h(3,1)=uicontrol('style','text','string','Motor:','pos',[20 110 50 20],'horiz','l');
h(3,2)=uicontrol('style','push','string',eng.name,'pos',[75 110 60 20],'horiz','l');
set(h(3,2),'callback','rckcad(53)');
h(4,2)=uicontrol('style','push','string','Ok','callback','global hh, close(hh)');
rck.comp{sidx}(idx,:)=[5 nan pos L nan d nan nan n rpos w];
figure(hfig)
rckplot(rck.comp{sidx})
drawnow
motorh=findobj('type','patch');
figure(hh)
motorh=motorh(end);
userdata(motorh,eng,2)
get(motorh,'type')
get(motorh,'userdata')


function cb_edit
global rck hfig idx sidx
set(hfig,'windowstyle','modal')         %seems to work now
figure(hfig)
while 1
   ginput(1);
   if ~isempty(gco)
      comp=get(gco,'userdata');
      if iscell(comp), comp=comp{1};end
      if all(size(comp)==[1 11]), break,end
   end
   if ~strcmp(get(gcf,'selectiontype'),'normal')
      set(hfig,'windowstyle','normal')
      return
   end
end
a=rck.comp{sidx}; a(find(isnan(a)))=inf;
b=repmat(comp,[size(rck.comp{sidx},1) 1]); b(find(isnan(b)))=inf;
idx=find(all(a==b,2));
set(hfig,'windowstyle','normal')
switch(comp(1))
case 1
   cb_nose
case 2
   cb_tube
case 3
   cb_coupler
case 4
   cb_fins
case 5
   cb_motor
end


function cb_delete
global rck hfig idx sidx
set(hfig,'windowstyle','modal')
figure(hfig)
ginput(1);
if isempty(gco)
   set(hfig,'windowstyle','normal')
   return
else
   comp=get(gco,'userdata');
   set(hfig,'windowstyle','normal')
   if iscell(comp), comp=comp{1};end
   if ~all(size(comp)==[1 11]), return,end
end
a=rck.comp{sidx}; a(isnan(a))=inf;
b=repmat(comp,[size(rck.comp{sidx},1) 1]); b(isnan(b))=inf;
idx=find(all(a==b,2));
rck.comp{sidx}=delrows(rck.comp{sidx},idx);
set(hfig,'windowstyle','modal')
figure(hfig)
rckplot(rck.comp{sidx})
set(hfig,'windowstyle','normal')


function cb_save
global rck deffname
godir(mfilename)
cd rocket
if isempty(deffname)
   patt='*.cad';
else
   patt=deffname;
end
[fname,path]=uiputfile(patt,'Load Rocket');
godir
if ischar(fname)
   file=fullfile(path,fname);
   save(file,'rck','-mat')
   deffname=file;
end


function cb_quit
global hmain hfig
btn=questdlg('Really quit?','Quit');
if strcmp(btn,'Yes')
   close(hmain)
   close(hfig)
   rquit
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


function rquit
clear global mquit hfig idx h rck hh hmain deffname hs sidx


function scopy
%copy parts from upper stages down to all lower stages
%changes made to components in upper stages at a lower stage will
%remain unaffected.
global rck sidx
for i=1:length(rck.comp)
   if i<sidx
      %items to add or replace
      for j=1:size(rck.comp{sidx},1)
         a=rck.comp{i};
         b=rck.comp{sidx}(j,:);
         k=[find(a(:,1)==b(1) & b(1)==1) ...
               find(a(:,1)==b(1) & a(:,3)==b(3) & b(1)>1)];
         if ~isempty(k)
            rck.comp{i}(k,:)=rck.comp{sidx}(j,:);
         end
         if isempty(a) | max([a(a(:,1)>1,3);a(a(:,1)==1,2)])<b(3)
            rck.comp{i}=[rck.comp{i}; rck.comp{sidx}(j,:)];
         end
      end
      %items to remove
      %k=[];
      %for j=1:size(rck.comp{i},1)
      %   a=rck.comp{sidx};
      %   a(isnan(a))=inf;
      %   b=repmat(rck.comp{i}(j,:),[size(a,1) 1]);
      %   b(isnan(b))=inf;
      %   if ~any(all(a==b,2))
      %      k=[k j];
      %   end
      %end
      %rck.comp{i}=delrows(rck.comp{i},k);
   end
end


function B=delrows(A,i)
n=size(A,1);
ninv=setdiff(1:n,i);
B=A(ninv,:);


function [x0,y0,xsc,ysc]=winscale(ah)
axes(ah)
u=get(gca,'units');
set(gca,'units','pix');
ppos=get(gca,'pos');
set(gca,'units',u);
ax=axis;
% x0 [pixels]
x0=ppos(1);
% y0 [pixels]
y0=ppos(2);
% xsc [pixels/tick]
xsc=ppos(3)/diff(ax(1:2));
% ysc [pixels/tick]
ysc=ppos(4)/diff(ax(3:4));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -