You are on page 1of 7

Trajectory design for single stage vehicle

in gcc
Program
#include <stdio.h>
#include <iostream>
#include <cmath>
// f1(s) is gravity turn equation and f2(s) is its derivative
#define f1(s) (c/g0)*((pow(s,(k-1))-pow(s0,(k-1)))/(k-1)+(pow(s,(k+1))-pow(s0,(k+1)))/(k+1))-.1
#define f2(s) (c/g0)*(pow(s,(k-2))+pow(s,k))
using namespace std;
int main()
{
long int i,j;
long double mi,mf,vb,Isp,CdA,tw,g0,tb,pr,alt,t,vel,range,acce,drag,dp,b,wi,wf,w;
long double density,velx,vely,mt,temp,x,y,accex,accey,thrust,d_acce;
g0=9.81;//m/s^2 Acceleration due to gravity
mi=10000;//kg Initial mass
wi=mi*g0;//N
thrust=2*wi;//N
Isp=280;//sec
CdA=1.62;//m^2
tw=2;//Thrust/Weight
b=2000;// m/s burnout velocity
mf=mi/(exp(b/(g0*Isp)));//kg Final mass
wf=mf*g0;// N Final weight
pr=(mi-mf)/mi;
//Propelent ratio
tb=pr*Isp/tw;//sec Burnout time
vb=(wi-wf)/tb;// N/s
Propelent flow rate
std::cout.precision(10);
//For first 30s vertical liftoff
t=0;
for(i=0;i<=300;i++)
{
alt=Isp*g0*((t-wi/vb)*log(wi/(wi-vb*t))+t)-.5*g0*t*t;// Altitude
vely=g0*Isp*log(wi/(wi-vb*t))-g0*t;
velx=0;
range=0;
acce=thrust*g0/(wi-vb*t)-g0;
drag=0;
d_acce=drag*g0/(wi-vb*t);
vel=sqrt(velx*velx+vely*vely);
density=1.224*exp(-alt/7200);
dp=.5*density*vel*vel;//Dyanamic pressure

cout<<t<<"\t"<<alt<<"\t"<<range<<"\t"<<vel<<"\t"<<acce<<"\t"<<d_acce<<"\t"<<dp<<"\t"<<endl;
t=t+.1;
}
t=t-.1;
//For next 10s Constant Turn over trajectory
for(i=0;i<100;i++)
{
w=wi-t*vb;
temp=g0*(thrust-drag)/w;
accey=temp*sin((-.7*t+111)*M_PI/180)-g0;
accex=temp*cos((-.7*t+111)*M_PI/180);
acce=sqrt(accex*accex+accey*accey);
alt=alt+vely*.1+temp*180*(180*(sin((-.7*t+111)*M_PI/180)-sin((-.7*(t+.1)+111)*M_PI/180))/
(.7*M_PI)-cos((-.7*t+111)*M_PI/180)*.1)/(.7*M_PI)-g0*.005;
range=range+velx*.1+temp*180*(sin((-.7*t+111)*M_PI/180)*.1+180*(cos((-.7*t+111)*M_PI/180)cos((-.7*(t+.1)+111)*M_PI/180))/(.7*M_PI))/(M_PI*.7);
vely=vely+temp*180*(cos((-.7*(t+.1)+111)*M_PI/180)-cos((-.7*t+111)*M_PI/180))/(.7*M_PI)-g0*.1;
velx=velx+temp*180*(sin((-.7*t+111)*M_PI/180)-sin((-.7*(t+.1)+111)*M_PI/180))/(.7*M_PI);
vel=sqrt(velx*velx+vely*vely);
density=1.224*exp(-alt/7200);
dp=.5*density*vel*vel;

//Dyanamic pressure

drag=.5*density*vel*vel*CdA;
d_acce=drag*g0/(wi-vb*t);
t=t+.1;
cout<<t<<"\t"<<alt<<"\t"<<range<<"\t"<<vel<<"\t"<<acce<<"\t"<<d_acce<<"\t"<<dp<<"\t"<<endl;
}
//For remaining time Gravity Turn Trajectory
long double k,s,s0,c,s1,phi0,phi,vel0;
for(i=0;i<(tb-40)*10;i++)
{
temp=((.7*t-21)*M_PI/180)/2;
if(i==0)
s0=tan(temp);
else
s0=s1;
k=(thrust-drag)/w;
c=vel/(pow(s0,(k-1))*(1+s0*s0));
s1=1.7;
//Newton Raphson Method to calculate 's'

while(f1(s1)>1e-10)
{
s=s1-(f1(s1))/(f2(s1));
s1=s;
}
phi0=2*atan(s0);
phi=2*atan(s);
vel0=vel;
vel=c*pow(s,(k-1))*(1+s*s);
velx=(vel0*sin(phi0)+vel*sin(phi))*.5;
vely=(vel0*cos(phi0)+vel*cos(phi))*.5;
range=range+velx*.1;
alt=alt+vely*.1;
vel=sqrt(velx*velx+vely*vely);
acce=sqrt(pow((k*g0-g0*cos(phi0)),2)+pow((g0*sin(phi0)),2));
density=1.224*exp(-alt/7200);
dp=.5*density*vel*vel;

//Dyanamic pressure

drag=.5*density*vel*vel*CdA;
d_acce=drag*g0/(wi-vb*t);
t=t+.1;
cout<<t<<"\t"<<alt<<"\t"<<range<<"\t"<<vel<<"\t"<<acce<<"\t"<<d_acce<<"\t"<<dp<<"\t"<<endl;
}
cout<<"Final mass = "<<mf<<endl;
cout<<"Propellant ratio = "<<pr<<endl;
cout<<"Burnout time = "<<tb<<endl;
cout<<"Propellant flow rate = "<<vb<<endl;
cout<<"Thrust = "<<thrust<<endl;
return 0;
}

Gnuplot file (mission.gnu)


set terminal postscript eps size 3.5,2.62 enhanced color font 'Helvetica,20' lw 2
set noborder
set size 1.2,.721
set output 'mission.eps'
#set key at 3117.057429,20000
set key top right
set key box
set grid
set pointsize .03
set xlabel "Time (sec)"
set ylabel "Dynamic Pressure (N/m^2)"

plot "mission2.dat" using 1:7 title "{/Helvetica=10 T/W=2}" with lines lc rgb "black" ,"mission3.dat"
using 1:7 title "{/Helvetica=10 T/W=3}" with lines lc rgb "black" lt 4,"mission4.dat" using 1:7 title
"{/Helvetica=10 T/W=4}" with lines lc rgb "black" lt 2

To run above program


1.
2.
3.
4.

Go to terminal
Go to the directory of file
Type command g++ -o mission\ design mission\ design.cpp and enter
Type command ./mission ->mission.dat and enter this will generate datafile
i.e solution of pde
Type command gnuplot < mission.gnu and enter this will generate mission.eps file
in which graph is plotted.

Results
T/W

Final mass
(kg)

Propellant
ratio

Burnout
time (s)

Propellant flow
rate (N/s)

Thrust (N)

4828.15834

0.517184166

72.405

700.714

196200

4828.15834

0.517184166

48.270

1051.071

294300

4828.15834

0.517184166

36.202

1401.428

392400

Conclusion

You might also like