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

📄 rcktool.m

📁 航天工程工具箱
💻 M
字号:
function rocket_=rcktool
%RCKTOOL  Create or edit rocket parameters.
%   ROCKET = RCKTOOL  enables the user to create a new rocket or
%   edit or just return a previously saved rocket. The data can then
%   be easily accessed by the RCKSIM simulator. The format of the
%   rocket parameter structure is:
%
%      ROCKET.name     : Name of rocket
%      ROCKET.stages   : Number of stages
%      ROCKET.eng      : The motor for each stage (by LOADENG)
%      ROCKET.Cd       : Drag coefficient for each stage
%      ROCKET.Dr       : Diameter of each stage
%      ROCKET.mr       : Mass of each stage w/o motor
%      ROCKET.dt       : Separation delay between each stage
%
%   Example of usage:
%      rcksim(rcktool)
%
%   See also RCKSIM, LOADENG.

% Copyright (c) 2003-06-14, B. Rasmus Anthin.
% Revisited 2003-06-15, 2003-06-17, 2003-06-19,
%           2003-07-24.

clear global hh mquit h eng
global hh mquit h eng

%%%%% MAIN %%%%%
hh=dialog('name','Rocket Editor','handlevis','on');
xmax=200;
ymax=150;
pos=get(hh,'pos');
set(hh,'pos',[pos(1:2) xmax ymax])
mquit=0;
uicontrol('style','text','string','Action:','pos',[20 120 100 20],'horiz','l')
h(1)=uicontrol('style','popup','string',{'new','load','load & edit'},'val',1,'pos',[20 100 100 20]);
h(2)=uicontrol('style','push','string','Ok','callback','uiresume');
h(3)=uicontrol('style','push','string','Cancel','callback','cb_cancel');
set(h(3),'pos',get(h(2),'pos')+[xmax-100 0 0 0])
uiwait
action=get(h(1),'val');
close
if mquit, rocket_=rquit;return,end

%%%%% LOADING THE ROCKET %%%%%
if action==2 | action==3
   godir(mfilename)
   cd rocket
   [fname,path]=uigetfile('*.rck','Rocket Editor : Load Rocket');
   godir
   if ~ischar(fname), rocket_=rquit;return,end
   file=fullfile(path,fname);
   load(file,'rocket','-mat')
   if action==3
      rocket2=rocket;
      clear rocket;
   end
end

%%%%% BASIC SETTINGS %%%%%
if action==1 | action==3
   hh=dialog('name','Rocket Editor','handlevis','on');
   xmax=300;
   ymax=150;
   pos=get(hh,'pos');
   set(hh,'pos',[pos(1:2) xmax ymax])
   x0=20;
   y0=ymax-30;
   xl=80;
   yl=20;
   dx=xl+20;
   dy=yl+10;
   mquit=0;
   if action==1
      name='<untitled>';
      stages='1';
   elseif action==3
      name=rocket2.name;
      len2=rocket2.stages;
      stages=int2str(len2);
   end
   h(1,1)=uicontrol('style','text','string','Rocket Name:','pos',[x0 y0 xl yl],'horiz','l');
   h(1,2)=uicontrol('style','edit','string',name,'pos',[x0+dx y0 xl yl],'horiz','l');
   h(2,1)=uicontrol('style','text','string','# Stages:','pos',[x0 y0-dy xl yl],'horiz','l');
   h(2,2)=uicontrol('style','edit','string',stages,'pos',[x0+dx y0-dy 40 yl],'horiz','l');
   h(3,2)=uicontrol('style','push','string','Ok','callback','uiresume');
   h(4,2)=uicontrol('style','push','string','Cancel','callback','cb_cancel');
   set(h(4,2),'pos',get(h(3,2),'pos')+[xmax-100 0 0 0])
   uiwait
   rocket.name=get(h(1,2),'string');
   rocket.stages=str2num(get(h(2,2),'string'));
   len=rocket.stages;
   close
   if mquit, rocket_=rquit;return;end
end

%%%%% STAGE SETTINGS %%%%%
if action==1 | action==3
   hh=dialog('name','Rocket Editor : Parameters','handlevis','on');
   pos=get(hh,'pos');
   xmax=500;
   ymax=30*len+200;
   x0=20;
   y0=ymax-20;
   xl=60;
   dx=xl+10;
   set(hh,'pos',[pos(1:2) xmax ymax])
   mquit=0;
   h=zeros(len,6);
   for i=1:len
      eng{i}.name='';
      Cd_str{i}='0.5';
      Dr_str{i}='0.1';
      mr_str{i}='1.0';
      if i<len
         dt_str{i}='0.01';
      end
   end
   if action==3
      for i=1:min(len2,len)
         eng{i}=rocket2.eng(i);
         Cd_str{i}=num2str(rocket2.Cd(i));
         Dr_str{i}=num2str(rocket2.Dr(i));
         mr_str{i}=num2str(rocket2.mr(i));
         if i<min(len2,len)
            dt_str{i}=num2str(rocket2.dt(i));
         end
      end
   end
   uicontrol('style','text','string','Stage #:','pos',[x0 y0 xl yl],'horiz','c')
   uicontrol('style','text','string','Motor:','pos',[x0+dx y0 xl yl],'horiz','c')
   uicontrol('style','text','string','Cd:','pos',[x0+2*dx y0 xl yl],'horiz','c')
   uicontrol('style','text','string','Diameter:','pos',[x0+3*dx y0 xl yl],'horiz','c')
   uicontrol('style','text','string','Empty mass:','pos',[x0+4*dx y0 xl yl],'horiz','c')
   uicontrol('style','text','string','Sep. Delay:','pos',[x0+5*dx y0 xl yl],'horiz','c')
   for i=1:len
      h(i,1)=uicontrol('style','text','string',int2str(i),'pos',[x0 y0-i*dy 40 yl],'horiz','r');
      h(i,2)=uicontrol('style','push','string',eng{i}.name,'pos',[x0+dx y0-i*dy xl yl],'horiz','l');
      set(h(i,2),'userdata',i);
      set(h(i,2),'callback','cb_param_eng');
      h(i,3)=uicontrol('style','edit','string',Cd_str{i},'pos',[x0+2*dx y0-i*dy xl yl],'horiz','c');
      h(i,4)=uicontrol('style','edit','string',Dr_str{i},'pos',[x0+3*dx y0-i*dy xl yl],'horiz','c');
      h(i,5)=uicontrol('style','edit','string',mr_str{i},'pos',[x0+4*dx y0-i*dy xl yl],'horiz','c');
      if i<len
         h(i,6)=uicontrol('style','edit','string',dt_str{i},'pos',[x0+5*dx y0-(i+.5)*dy xl yl],'horiz','c');
      end
   end
   h(len+1,1)=uicontrol('style','push','string','Ok','callback','cb_param_ok');
   h(len+1,2)=uicontrol('style','push','string','Cancel','callback','cb_cancel');
   set(h(len+1,2),'pos',get(h(len+1,1),'pos')+[xmax-100 0 0 0])
   uiwait
   if ~mquit
      for i=1:len
         rocket.eng(i)=eng{i};
         rocket.Cd(i)=str2num(get(h(i,3),'string'));
         rocket.Dr(i)=str2num(get(h(i,4),'string'));
         rocket.mr(i)=str2num(get(h(i,5),'string'));
         if i<len
            rocket.dt(i)=str2num(get(h(i,6),'string'));
         end
      end
   end
   if len==1
      rocket.dt=[];
   end
   close
   if mquit, rocket_=rquit;return;end
end

%%%%% SAVING THE ROCKET %%%%%
if action==1 | action==3
   godir(mfilename)
   cd rocket
   if action==1
      patt='*.rck';
   elseif action==3
      patt=fname;
   end
   [fname,path]=uiputfile(patt,'Rocket Editor : Save Rocket');
   godir
   if ischar(fname)
      file=fullfile(path,fname);
      save(file,'rocket')
   end
end

%%%%% OUTPUT %%%%%
%if action==2 | nargout
   rocket_=rocket;
%end
rquit;

%%%%%%%%%%%%%%%%%%%%%% FUNCTIONS %%%%%%%%%%%%%%%%%%%
function r=rquit;
clear global hh mquit h eng
r=[];

⌨️ 快捷键说明

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