Initial commit of "Rocket Workbench".
Taken from sources in CVS at:
https://sourceforge.net/projects/rocketworkbench/
Sources extracted in two steps:
1. Pull entire project tree into a subdir "rwb" via "rsync":
rsync -a a.cvs.sourceforge.net::cvsroot/rocketworkbench/ rwb/.
2. Export sources:
export CVSROOT=$(pwd)/rwb
SUBDIRS="analyser cpropep cpropep-web CVSROOT data libcompat libcpropep libnum libsimulation libthermo prop rocketworkbench rockflight"
mkdir rwbx; cd rwbx
cvs export -D now ${SUBDIRS}
After this (and some backups for safety), the directory content was
added to a Git repo:
git init .
git add *
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
ROOT = ../../..
|
||||
include $(ROOT)/config/presrc.mk
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
CC = gcc
|
||||
COPT = -g -Wall -O3 #-pg
|
||||
|
||||
ROOT = ../..
|
||||
|
||||
LIB = -lMagick -lrockflight -lnum -lm
|
||||
|
||||
LIBDIR = -L$(ROOT)/libnum/lib -L/usr/X11R6/lib/ -L../lib/
|
||||
|
||||
INCDIR = -I$(ROOT)/libnum/include -I../src/ \
|
||||
-I/usr/X11R6/include/magick -I/usr/X11R6/include/
|
||||
|
||||
DEF =
|
||||
|
||||
PROG = viewer
|
||||
|
||||
OBJS = viewer.o
|
||||
|
||||
all: $(PROG) $(PROG2)
|
||||
|
||||
.c.o:
|
||||
$(CC) $(DEF) $(INCDIR) $(COPT) -c $*.c -o $*.o
|
||||
|
||||
$(PROG): $(OBJS) $(LIBNAME)
|
||||
$(CC) $(COPT) $(OBJS) $(LIBDIR) $(LIB) -o $@
|
||||
|
||||
clean:
|
||||
rm -f *.o *~
|
||||
|
||||
deep-clean: clean
|
||||
rm -f $(PROG)
|
||||
@@ -0,0 +1,454 @@
|
||||
|
||||
#include <X11/Xlib.h> // Every Xlib program must include this
|
||||
#include <linux/mc146818rtc.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h> // So we got the profile for 10 seconds
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "rocflight.h"
|
||||
#include "num.h"
|
||||
#include "state.h"
|
||||
|
||||
|
||||
#define PIXEL_M 15
|
||||
#define PIXEL_M_S 15
|
||||
|
||||
#define H 40
|
||||
#define L 40
|
||||
#define SCALEY 1
|
||||
|
||||
#define WIDTH L * PIXEL_M
|
||||
#define HEIGHT (int)(H * PIXEL_M * SCALEY)
|
||||
|
||||
#define MAX_HISTORY 200
|
||||
#define FREQ 32
|
||||
#define STEP (1.0/FREQ)
|
||||
|
||||
#define POSX_TO_PIXEL(x) (WIDTH/2 + (int)((x) * PIXEL_M))
|
||||
#define POSY_TO_PIXEL(y) (HEIGHT - (int)((y) * PIXEL_M * SCALEY))
|
||||
|
||||
|
||||
struct rocketAnim_t
|
||||
{
|
||||
int width, height;
|
||||
|
||||
GC gc;
|
||||
GC tmpgc;
|
||||
Display *display;
|
||||
Window window;
|
||||
Pixmap pixmap;
|
||||
unsigned long red, blue, white, green;
|
||||
|
||||
XFontStruct *font_info;
|
||||
int font_height;
|
||||
|
||||
} rocket;
|
||||
|
||||
|
||||
|
||||
int eom(int neq, double time, double *y, double *dy, void *data);
|
||||
|
||||
|
||||
|
||||
unsigned long AllocColor(char *colName)
|
||||
{
|
||||
Colormap cmap;
|
||||
XColor c0, c1;
|
||||
cmap = DefaultColormap(rocket.display, 0);
|
||||
XAllocNamedColor(rocket.display, cmap, colName, &c1, &c0);
|
||||
return(c1.pixel);
|
||||
}
|
||||
|
||||
void ExposeScreen(void)
|
||||
{
|
||||
XCopyArea(rocket.display, rocket.pixmap,
|
||||
rocket.window, rocket.tmpgc,
|
||||
0, 0, rocket.width, rocket.height, 0, 0);
|
||||
}
|
||||
|
||||
void rocketInit(void)
|
||||
{
|
||||
Display *d;
|
||||
Window w;
|
||||
Pixmap p;
|
||||
XEvent e;
|
||||
|
||||
d = rocket.display = XOpenDisplay(NULL);
|
||||
|
||||
w = rocket.window = XCreateSimpleWindow(d, DefaultRootWindow(d),
|
||||
0, 0,
|
||||
rocket.width, rocket.height,
|
||||
2, BlackPixel(d, 0),
|
||||
WhitePixel(d, 0));
|
||||
|
||||
p = rocket.pixmap = XCreatePixmap(d, DefaultRootWindow(d),
|
||||
rocket.width, rocket.height,
|
||||
DefaultDepth(d, 0));
|
||||
|
||||
rocket.gc = XCreateGC(d, w, 0, 0);
|
||||
rocket.tmpgc = XCreateGC(d, w, 0, 0);
|
||||
rocket.red = AllocColor("red");
|
||||
rocket.blue = AllocColor("blue");
|
||||
rocket.white = AllocColor("white");
|
||||
rocket.green = AllocColor("green");
|
||||
|
||||
rocket.font_info = XQueryFont(d, XGContextFromGC(rocket.gc));
|
||||
rocket.font_height = rocket.font_info->ascent + rocket.font_info->descent;
|
||||
|
||||
XSetForeground(rocket.display, rocket.gc, rocket.white);
|
||||
XFillRectangle(d, p, rocket.gc, 0, 0, rocket.width, rocket.height);
|
||||
XMapWindow(d, w);
|
||||
XSelectInput(d, w, StructureNotifyMask);
|
||||
|
||||
for(;;) {
|
||||
XNextEvent(d, &e);
|
||||
if (e.type == MapNotify)
|
||||
break;
|
||||
}
|
||||
XFlush(d);
|
||||
}
|
||||
|
||||
void DrawLine(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
/* Draw the new line */
|
||||
XDrawLine(rocket.display, rocket.pixmap, rocket.gc, x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
void DrawPoint(int x, int y)
|
||||
{
|
||||
/* draw the point */
|
||||
XSetForeground(rocket.display, rocket.gc, rocket.red);
|
||||
XDrawPoint(rocket.display, rocket.pixmap, rocket.gc, x, y);
|
||||
}
|
||||
|
||||
void DrawFillCircle(int x, int y, int r)
|
||||
{
|
||||
/* Draw the circle */
|
||||
XSetForeground(rocket.display, rocket.gc, rocket.red);
|
||||
XFillArc(rocket.display, rocket.pixmap, rocket.gc,
|
||||
x - r, y - r, 2*r, 2*r, 0, 360*64);
|
||||
}
|
||||
|
||||
void DrawSystem(double *y)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
double x1, y1;
|
||||
|
||||
double theta;
|
||||
double vitesse_tot;
|
||||
|
||||
char vitessex[32];
|
||||
char vitessey[32];
|
||||
char vitesset[32];
|
||||
|
||||
char alpha_str[32];
|
||||
|
||||
char theta_str[32];
|
||||
char velocity_str[32];
|
||||
|
||||
double velocity;
|
||||
|
||||
theta = y[10];
|
||||
|
||||
velocity = sqrt(y[0]*y[0] + y[1]*y[1] + y[2]*y[2]);
|
||||
|
||||
vitesse_tot =
|
||||
sqrt(pow(y[0], 2) + pow(y[2], 2));
|
||||
|
||||
sprintf(velocity_str, "Velocity : % .2f m/s", velocity);
|
||||
sprintf(alpha_str, "Angle of attack : % 6.2f deg", atan(y[2]/y[0])*180/M_PI);
|
||||
sprintf(theta_str, "Theta : % .2f deg", theta*180/M_PI);
|
||||
|
||||
sprintf(vitessex, "Vitesse axe x : % .2f", y[0]);
|
||||
sprintf(vitessey, "Vitesse axe y : % .2f", y[2]);
|
||||
sprintf(vitesset, "Vitesse absolue: % .2f", vitesse_tot);
|
||||
|
||||
/* Clear the screen */
|
||||
XSetForeground(rocket.display, rocket.gc, rocket.white);
|
||||
XFillRectangle(rocket.display, rocket.pixmap,
|
||||
rocket.gc, 0, 0, rocket.width, rocket.height);
|
||||
|
||||
//DrawFillCircle(POSX_TO_PIXEL(x), POSY_TO_PIXEL(y), 10);
|
||||
//printf("%f\n", y[10]);
|
||||
|
||||
|
||||
/* Draw the rocket */
|
||||
XSetForeground(rocket.display, rocket.gc, rocket.red);
|
||||
|
||||
x1 = 0 + 8*cos(theta);
|
||||
y1 = 20 + 8*sin(theta);
|
||||
|
||||
DrawLine(POSX_TO_PIXEL(0 - sin(theta)), POSY_TO_PIXEL(20 + cos(theta)),
|
||||
POSX_TO_PIXEL(x1 - sin(theta)), POSY_TO_PIXEL(y1 + cos(theta)));
|
||||
DrawLine(POSX_TO_PIXEL(0 + sin(theta)), POSY_TO_PIXEL(20 - cos(theta)),
|
||||
POSX_TO_PIXEL(x1 + sin(theta)), POSY_TO_PIXEL(y1 - cos(theta)));
|
||||
DrawLine(POSX_TO_PIXEL(x1 - sin(theta)), POSY_TO_PIXEL(y1 + cos(theta)),
|
||||
POSX_TO_PIXEL(x1 + 4*cos(theta)), POSY_TO_PIXEL(y1 + 4*sin(theta)));
|
||||
DrawLine(POSX_TO_PIXEL(x1 + sin(theta)), POSY_TO_PIXEL(y1 - cos(theta)),
|
||||
POSX_TO_PIXEL(x1 + 4*cos(theta)), POSY_TO_PIXEL(y1 + 4*sin(theta)));
|
||||
|
||||
|
||||
XSetForeground(rocket.display, rocket.gc, rocket.blue);
|
||||
|
||||
|
||||
x1 = (y[0]*cos(theta) - y[2]*sin(theta))/50;
|
||||
y1 = 20 + (y[0]*sin(theta) + y[2]*cos(theta))/50;
|
||||
|
||||
DrawLine(POSX_TO_PIXEL(0), POSY_TO_PIXEL(20),
|
||||
POSX_TO_PIXEL(x1), POSY_TO_PIXEL(y1));
|
||||
|
||||
//DrawLine(x, y,
|
||||
|
||||
/*
|
||||
if (modeleInfo.full)
|
||||
j = MAX_HISTORY;
|
||||
else
|
||||
j = modeleInfo.lasthistory;
|
||||
|
||||
for (i = 0; i < j; i++)
|
||||
DrawPoint(POSX_TO_PIXEL(modeleInfo.pointhistory[i][0]),
|
||||
POSY_TO_PIXEL(modeleInfo.pointhistory[i][1]));
|
||||
*/
|
||||
|
||||
|
||||
XDrawString(rocket.display, rocket.pixmap, rocket.gc, 10,
|
||||
HEIGHT - 3*rocket.font_height, velocity_str,
|
||||
strlen(velocity_str));
|
||||
|
||||
XDrawString(rocket.display, rocket.pixmap, rocket.gc, 10,
|
||||
HEIGHT - 2*rocket.font_height, alpha_str, strlen(alpha_str));
|
||||
|
||||
XDrawString(rocket.display, rocket.pixmap, rocket.gc, 10,
|
||||
HEIGHT - rocket.font_height, theta_str, strlen(theta_str));
|
||||
|
||||
XDrawString(rocket.display, rocket.pixmap, rocket.gc, 100,
|
||||
HEIGHT - 3*rocket.font_height, vitessex,
|
||||
strlen(vitessex));
|
||||
XDrawString(rocket.display, rocket.pixmap, rocket.gc, 100,
|
||||
HEIGHT - 2*rocket.font_height, vitessey,
|
||||
strlen(vitessey));
|
||||
XDrawString(rocket.display, rocket.pixmap, rocket.gc, 100,
|
||||
HEIGHT - 1*rocket.font_height, vitesset,
|
||||
strlen(vitesset));
|
||||
|
||||
|
||||
|
||||
/* XFillRectangle(rocket.display, rocket.pixmap, rocket.gc, 140,
|
||||
HEIGHT - 4*rocket.font_height + rocket.font_info->ascent/2,
|
||||
(int)(PIXEL_M_S * fabs(modeleInfo.state[2])),
|
||||
rocket.font_height/2);
|
||||
|
||||
XFillRectangle(rocket.display, rocket.pixmap, rocket.gc, 140,
|
||||
HEIGHT - 3*rocket.font_height + rocket.font_info->ascent/2,
|
||||
(int)(PIXEL_M_S * fabs(modeleInfo.state[3])),
|
||||
rocket.font_height/2);
|
||||
|
||||
XFillRectangle(rocket.display, rocket.pixmap, rocket.gc, 140,
|
||||
HEIGHT - 2*rocket.font_height + rocket.font_info->ascent/2,
|
||||
(int)(PIXEL_M_S * vitesse_tot),
|
||||
rocket.font_height/2);
|
||||
|
||||
*/
|
||||
|
||||
ExposeScreen();
|
||||
XFlush(rocket.display);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
int i, n;
|
||||
int neq = 12;
|
||||
|
||||
double time;
|
||||
double res[12];
|
||||
|
||||
double *ans;
|
||||
double *init_cond;
|
||||
|
||||
double u = 100; /* velocity component in x */
|
||||
double v = 0; /* velocity component in y */
|
||||
double w = 0; /* velocity component in z */
|
||||
|
||||
double P = 0; /* angular velocity */
|
||||
double Q = 0; /* */
|
||||
double R = 0; /* */
|
||||
|
||||
double lambda = 0*(M_PI/180); /* latitude (positive north) */
|
||||
double mu = 0*(M_PI/180); /* longitude (positive east) */
|
||||
double Re = EARTH_RAD + 5000; /* distance from earth center */
|
||||
double phi = 0*(M_PI/180); /* */
|
||||
double theta = 45*(M_PI/180); /* positive up */
|
||||
double psi = 0*(M_PI/180); /* positive cw*/
|
||||
|
||||
|
||||
// double dt = 0.05;
|
||||
double duration = 10;
|
||||
|
||||
state_t s;
|
||||
|
||||
|
||||
int fd, retval;
|
||||
unsigned long tmp, data;
|
||||
struct rtc_time rtc_tm;
|
||||
|
||||
/* Initialize the window */
|
||||
rocket.width = WIDTH;
|
||||
rocket.height = HEIGHT;
|
||||
rocketInit();
|
||||
|
||||
|
||||
/* open and configure the realtime clock */
|
||||
fd = open ("/dev/rtc", O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
perror("/dev/rtc");
|
||||
exit(errno);
|
||||
}
|
||||
|
||||
/* Set the periodic IRQ rate to FREQ Hz */
|
||||
retval = ioctl(fd, RTC_IRQP_SET, FREQ);
|
||||
if (retval == -1)
|
||||
{
|
||||
perror("ioctl");
|
||||
exit(errno);
|
||||
}
|
||||
|
||||
/* Enable periodic interrupts */
|
||||
retval = ioctl(fd, RTC_PIE_ON, 0);
|
||||
if (retval == -1)
|
||||
{
|
||||
perror("ioctl");
|
||||
exit(errno);
|
||||
}
|
||||
|
||||
//initModele();
|
||||
|
||||
|
||||
s.m = 10.0;
|
||||
|
||||
s.Ix = 25e-3;
|
||||
s.Iy = 3;
|
||||
s.Iz = 3;
|
||||
|
||||
s.Faero[0] = 0;
|
||||
s.Faero[1] = 0;
|
||||
s.Faero[2] = 0;
|
||||
|
||||
s.Maero[0] = 0;
|
||||
s.Maero[1] = 0;
|
||||
s.Maero[2] = 0;
|
||||
|
||||
init_cond = (double *) malloc(sizeof(double) * neq);
|
||||
|
||||
s.L_BV[0][0] = cos(theta)*cos(psi);
|
||||
s.L_BV[0][1] = cos(theta)*sin(psi);
|
||||
s.L_BV[0][2] =-sin(theta);
|
||||
s.L_BV[1][0] = sin(phi)*sin(theta)*cos(psi) - cos(phi)*sin(psi);
|
||||
s.L_BV[1][1] = sin(phi)*sin(theta)*sin(psi) + cos(phi)*cos(psi);
|
||||
s.L_BV[1][2] = sin(phi)*cos(theta);
|
||||
s.L_BV[2][0] = cos(phi)*sin(theta)*cos(psi) + sin(phi)*sin(psi);
|
||||
s.L_BV[2][1] = cos(phi)*sin(theta)*sin(psi) - sin(phi)*cos(psi);
|
||||
s.L_BV[2][2] = cos(phi)*cos(theta);
|
||||
|
||||
init_cond[0] = u; /* velocity component in x */
|
||||
init_cond[1] = v; /* velocity component in y */
|
||||
init_cond[2] = w; /* velocity component in z */
|
||||
init_cond[3] = P+ (s.L_BV[0][0]*WE*cos(lambda)-s.L_BV[0][2]*WE*sin(lambda));
|
||||
init_cond[4] = Q+ (s.L_BV[1][0]*WE*cos(lambda)-s.L_BV[1][2]*WE*sin(lambda));
|
||||
init_cond[5] = R+ (s.L_BV[2][0]*WE*cos(lambda)-s.L_BV[2][2]*WE*sin(lambda));
|
||||
init_cond[6] = lambda; /* latitude */
|
||||
init_cond[7] = mu; /* longitude */
|
||||
init_cond[8] = Re; /* radius */
|
||||
init_cond[9] = phi; /* phi */
|
||||
init_cond[10] = theta; /* theta */
|
||||
init_cond[11] = psi; /* psi */
|
||||
|
||||
time = 0;
|
||||
|
||||
// eom(neq, time, init_cond, res, &s);
|
||||
/*
|
||||
fprintf(stderr, "% e (u dot)\n", res[0]);
|
||||
fprintf(stderr, "% e (v dot)\n", res[1]);
|
||||
fprintf(stderr, "% e (w dot)\n", res[2]);
|
||||
fprintf(stderr, "% e (p dot)\n", res[3]);
|
||||
fprintf(stderr, "% e (q dot)\n", res[4]);
|
||||
fprintf(stderr, "% e (r dot)\n", res[5]);
|
||||
fprintf(stderr, "% e (lambda dot)\n", res[6]);
|
||||
fprintf(stderr, "% e (mu dot)\n", res[7]);
|
||||
fprintf(stderr, "% e (R dot)\n", res[8]);
|
||||
fprintf(stderr, "% e (phi dot)\n", res[9]);
|
||||
fprintf(stderr, "% e (theta dot)\n", res[10]);
|
||||
fprintf(stderr, "% e (psi dot)\n", res[11]);
|
||||
*/
|
||||
|
||||
n = NUM_rk4 (eom, neq, STEP, duration, init_cond, &ans, &s);
|
||||
|
||||
|
||||
|
||||
/* set the initial conditions */
|
||||
//modeleInfo.state[0] = 7.0;
|
||||
//modeleInfo.state[1] = 25.0;//.3944;
|
||||
//modeleInfo.state[2] = 0.0;
|
||||
//modeleInfo.state[3] = 0.0;
|
||||
|
||||
|
||||
// for( i = 0; i < n; i++)
|
||||
// {
|
||||
// printf("% .12e ", ans[0 + neq*i]); /* u */
|
||||
// printf("% .12e ", ans[1 + neq*i]); /* v */
|
||||
// printf("% .12e ", ans[2 + neq*i]); /* w */
|
||||
// printf("% .12e ", ans[3 + neq*i]); /* p */
|
||||
// printf("% .12e ", ans[4 + neq*i]); /* q */
|
||||
// printf("% .12e ", ans[5 + neq*i]); /* r */
|
||||
// printf("% .12e ", ans[6 + neq*i]); /* lambda */
|
||||
// printf("% .12e ", ans[7 + neq*i]); /* mu */
|
||||
// printf("% .12e ", ans[8 + neq*i]); /* R */
|
||||
// printf("% .12e ", ans[9 + neq*i]); /* phi */
|
||||
// printf("% .12e ", ans[10 + neq*i]); /* theta */
|
||||
// printf("% .12e \n", ans[11 + neq*i]); /* psi */
|
||||
// }
|
||||
|
||||
|
||||
// DrawSystem(y);
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
/* This blocks */
|
||||
retval = read(fd, &data, sizeof(unsigned long));
|
||||
if (retval == -1)
|
||||
{
|
||||
perror("read");
|
||||
exit(errno);
|
||||
}
|
||||
|
||||
DrawSystem(ans + neq*i);
|
||||
}
|
||||
|
||||
/* Disable periodic interrupts */
|
||||
retval = ioctl(fd, RTC_PIE_OFF, 0);
|
||||
if (retval == -1)
|
||||
{
|
||||
perror("ioctl");
|
||||
exit(errno);
|
||||
}
|
||||
|
||||
|
||||
free(init_cond);
|
||||
//free(ans);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
TYPE = "debug"
|
||||
ROOT = ../../../..
|
||||
include $(ROOT)/config/makedef
|
||||
include $(ROOT)/config/exesrc.mk
|
||||
@@ -0,0 +1,40 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "librockflight/include/state.h"
|
||||
|
||||
extern int stage(rocket_t *r, double *t);
|
||||
extern int mass(rocket_t *r, double *t);
|
||||
extern int engine(rocket_t *r, double *t);
|
||||
|
||||
/* This function will output rocket state from 0 to t every dt interval.
|
||||
It is useful to check if the thrust, masses, engines and stages follow
|
||||
the configuration we want. */
|
||||
int check(rocket_t *r, double tf, double dt)
|
||||
{
|
||||
double t;
|
||||
|
||||
for (t = 0.0; t < tf; t += dt)
|
||||
{
|
||||
if (stage(r, &t))
|
||||
{
|
||||
printf("Error in function stage.\n");
|
||||
return -1;
|
||||
}
|
||||
if (mass(r, &t))
|
||||
{
|
||||
printf("Error in function mass.\n");
|
||||
return -1;
|
||||
}
|
||||
if (engine(r, &t))
|
||||
{
|
||||
printf("Error in function engine.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Time: %5.2f s -> Stage: %d -> Mass: %7.2f -> Thrust: %7.2f\n",
|
||||
t, r->state.s, r->state.m, r->state.Feng[0]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
LIB = -lrockflight -lgpcp -lnum -lm
|
||||
PROG = rockflight
|
||||
OBJS = parser.o print.o simulate.o check.o rockflight.o
|
||||
@@ -0,0 +1,638 @@
|
||||
/* rocket.c
|
||||
* sample program for parsing a rocket propellant simulator config.
|
||||
*
|
||||
* $Id: parser.c,v 1.6 2002/03/09 18:05:28 antoine Exp $
|
||||
*
|
||||
* Copyright (C) 2000,
|
||||
* Antoine Lefebvre <antoine.lefebvre@polymtl.ca>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "gpcp.h"
|
||||
#include "librockflight/include/state.h"
|
||||
|
||||
int get_point_value(char *name, float *point);
|
||||
int load_data(char *file, float **x, float **y, int *n, parameter_t *p);
|
||||
int load_function_data(function_t *f, char *constant_name, char *table_name);
|
||||
|
||||
Options rockflight_options[] = {
|
||||
{"simulation", PARENT, NULL},
|
||||
|
||||
{"initial_conditions", PARENT, "simulation"},
|
||||
{"u", FLOAT, "initial_conditions"},
|
||||
{"v", FLOAT, "initial_conditions"},
|
||||
{"w", FLOAT, "initial_conditions"},
|
||||
{"P", FLOAT, "initial_conditions"},
|
||||
{"Q", FLOAT, "initial_conditions"},
|
||||
{"R", FLOAT, "initial_conditions"},
|
||||
{"latitude", FLOAT, "initial_conditions"},
|
||||
{"longitude", FLOAT, "initial_conditions"},
|
||||
{"altitude", FLOAT, "initial_conditions"},
|
||||
{"phi", FLOAT, "initial_conditions"},
|
||||
{"theta", FLOAT, "initial_conditions"},
|
||||
{"psi", FLOAT, "initial_conditions"},
|
||||
|
||||
{"rocket", PARENT, "simulation"},
|
||||
{"stage", PARENT, "rocket"},
|
||||
|
||||
{"dry_mass", FLOAT, "stage"},
|
||||
{"Ix", FLOAT, "stage"},
|
||||
{"Ix_data_file", STRING, "stage"},
|
||||
{"Iy", FLOAT, "stage"},
|
||||
{"Iy_data_file", STRING, "stage"},
|
||||
{"Iz", FLOAT, "stage"},
|
||||
{"Iz_data_file", STRING, "stage"},
|
||||
{"Cd", FLOAT, "stage"},
|
||||
{"Cd_data_file", STRING, "stage"},
|
||||
{"CL", FLOAT, "stage"},
|
||||
{"CL_data_file", STRING, "stage"},
|
||||
{"CB", FLOAT, "stage"},
|
||||
{"CB_data_file", STRING, "stage"},
|
||||
{"Cspin", FLOAT, "stage"},
|
||||
{"Cmoment", FLOAT, "stage"},
|
||||
{"Cdamping", FLOAT, "stage"},
|
||||
{"Diameter", FLOAT, "stage"},
|
||||
{"active_time", FLOAT, "stage"},
|
||||
|
||||
{"engine", PARENT, "stage"},
|
||||
{"type", STRING, "engine"},
|
||||
{"propellant_mass", FLOAT, "engine"},
|
||||
{"dry_mass", FLOAT, "engine"},
|
||||
{"thrust", FLOAT, "engine"},
|
||||
{"thrust_data_file", STRING, "engine"},
|
||||
{"mass_flow", FLOAT, "engine"},
|
||||
{"c", FLOAT, "engine"},
|
||||
{"start_time", FLOAT, "engine"},
|
||||
{"burn_time", FLOAT, "engine"},
|
||||
{"drop_time", FLOAT, "engine"},
|
||||
{"position", PARENT, "engine"},
|
||||
{"x", FLOAT, "position"},
|
||||
{"y", FLOAT, "position"},
|
||||
{"z", FLOAT, "position"},
|
||||
{"direction", PARENT, "engine"},
|
||||
{"x", FLOAT, "direction"},
|
||||
{"y", FLOAT, "direction"},
|
||||
{"z", FLOAT, "direction"},
|
||||
|
||||
{"solution", PARENT, "simulation"},
|
||||
{"duration", FLOAT, "solution"},
|
||||
{"dt", FLOAT, "solution"},
|
||||
{"precision", FLOAT, "solution"},
|
||||
{NULL, 0, NULL}
|
||||
};
|
||||
|
||||
int load_config(Data *data, rocket_t *rocket, float *init_cond,
|
||||
solution_t *solution)
|
||||
{
|
||||
int i, j;
|
||||
int n, m;
|
||||
|
||||
/* int status; */
|
||||
|
||||
/*char *type;*/
|
||||
/*char *filename;*/
|
||||
float *val;
|
||||
|
||||
engine_t *engine;
|
||||
|
||||
function_t *f;
|
||||
|
||||
if (GPCP_EnterLevel("simulation", 0) == -1)
|
||||
{
|
||||
printf("Error: no simulation to execute in config file.\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/***************** initial conditions ********************/
|
||||
n = GPCP_NumParent("initial_conditions");
|
||||
if (n > 1)
|
||||
{
|
||||
printf("There should be only one \"initial_conditions\""
|
||||
" keyword in \"simulation\".\n"
|
||||
"The first one will be used.\n");
|
||||
}
|
||||
else if (n == 0)
|
||||
{
|
||||
printf("No \"initial_conditions\" in config file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (GPCP_EnterLevel("initial_conditions", 0) == -1)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (GPCP_GetValue ("u", init_cond) != 0)
|
||||
*(init_cond+0) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("v", init_cond+1) != 0)
|
||||
*(init_cond+1) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("w", init_cond+2) != 0)
|
||||
*(init_cond+2) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("P", init_cond+3) != 0)
|
||||
*(init_cond+3) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("Q", init_cond+4) != 0)
|
||||
*(init_cond+4) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("R", init_cond+5) != 0)
|
||||
*(init_cond+5) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("latitude", init_cond+6) != 0)
|
||||
*(init_cond+6) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("longitude", init_cond+7) != 0)
|
||||
*(init_cond+7) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("altitude", init_cond+8) != 0)
|
||||
*(init_cond+8) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("phi", init_cond+9) != 0)
|
||||
*(init_cond+9) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("theta", init_cond+10) != 0)
|
||||
*(init_cond+10) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("psi", init_cond+11) != 0)
|
||||
*(init_cond+11) = 0.0;
|
||||
|
||||
|
||||
if (GPCP_ExitLevel() != 0)
|
||||
{
|
||||
printf("Unable to leave 'initial_conditions' level.\n");
|
||||
}
|
||||
}
|
||||
/********************* end initial_conditions *****************/
|
||||
|
||||
/********************* rocket *********************************/
|
||||
n = GPCP_NumParent("rocket");
|
||||
if (n > 1)
|
||||
{
|
||||
printf("There should be only one \"rocket\""
|
||||
" keyword in \"simulation\".\n"
|
||||
"The first one will be used.\n");
|
||||
}
|
||||
else if (n == 0)
|
||||
{
|
||||
printf("No \"rocket\" in config file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (GPCP_EnterLevel("rocket", 0) == -1)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
n = GPCP_NumParent("stage");
|
||||
if (n == 0)
|
||||
{
|
||||
printf("No \"stage\" in config file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* allocate memory for stage properties */
|
||||
(*rocket).n_stage = n;
|
||||
(*rocket).stage_properties = (rocket_properties_t *)
|
||||
malloc (sizeof(rocket_properties_t) * n);
|
||||
|
||||
/* for each stage */
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
if (GPCP_EnterLevel("stage", i) == -1)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
val = &(*rocket).stage_properties[i].dry_mass;
|
||||
if (GPCP_GetValue ("dry_mass", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
f = &(*rocket).stage_properties[i].Ix;
|
||||
if (load_function_data(f, "Ix", "Ix_data_file"))
|
||||
return -1;
|
||||
|
||||
f = &(*rocket).stage_properties[i].Iy;
|
||||
if (load_function_data(f, "Iy", "Iy_data_file"))
|
||||
return -1;
|
||||
|
||||
f = &(*rocket).stage_properties[i].Iz;
|
||||
if (load_function_data(f, "Iz", "Iz_data_file"))
|
||||
return -1;
|
||||
|
||||
f = &(*rocket).stage_properties[i].Cd;
|
||||
if (load_function_data(f, "Cd", "Cd_data_file"))
|
||||
return -1;
|
||||
|
||||
f = &(*rocket).stage_properties[i].CL;
|
||||
if (load_function_data(f, "CL", "CL_data_file"))
|
||||
return -1;
|
||||
|
||||
f = &(*rocket).stage_properties[i].CB;
|
||||
if (load_function_data(f, "CB", "CB_data_file"))
|
||||
return -1;
|
||||
|
||||
val = &(*rocket).stage_properties[i].Cspin;
|
||||
if (GPCP_GetValue ("Cspin", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = &(*rocket).stage_properties[i].Cmoment;
|
||||
if (GPCP_GetValue ("Cmoment", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = &(*rocket).stage_properties[i].Cdamping;
|
||||
if (GPCP_GetValue ("Cdamping", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = &(*rocket).stage_properties[i].Diameter;
|
||||
if (GPCP_GetValue ("Diameter", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = &(*rocket).stage_properties[i].active_time;
|
||||
if (GPCP_GetValue ("active_time", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
m = GPCP_NumParent("engine");
|
||||
(*rocket).stage_properties[i].n_engine = m;
|
||||
if (m < 1)
|
||||
{
|
||||
printf("There is no engine for stage %d\n", i);
|
||||
(*rocket).stage_properties[i].engines = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* allocate memory for engines */
|
||||
(*rocket).stage_properties[i].engines =
|
||||
(engine_t *) malloc (sizeof(engine_t)*m);
|
||||
}
|
||||
|
||||
for (j = 0; j < m; j++)
|
||||
{
|
||||
if (GPCP_EnterLevel("engine", j) == -1)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* set a temporary pointer */
|
||||
engine =
|
||||
&((*rocket).stage_properties[i].engines[j]);
|
||||
|
||||
f = &(engine->thrust);
|
||||
if (load_function_data(f, "thrust", "thrust_data_file"))
|
||||
return -1;
|
||||
|
||||
/*
|
||||
if (GPCP_GetValue("type", &type) != 0)
|
||||
{
|
||||
printf("Type of thrust must be specified.\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strcmp("constant_thrust", type) == 0)
|
||||
{
|
||||
engine->thrust.type = _CONSTANT;
|
||||
}
|
||||
else if (strcmp("thrust_table_data", type) == 0)
|
||||
{
|
||||
engine->thrust.type = _TABLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Undefined type of thrust : %s.\n", type);
|
||||
return -1;
|
||||
}
|
||||
free(type);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
switch (engine->thrust.type)
|
||||
{
|
||||
|
||||
case _CONSTANT:
|
||||
engine->thrust.x = NULL;
|
||||
engine->thrust.y = NULL;
|
||||
|
||||
val = &(engine->thrust.constant_value);
|
||||
if (GPCP_GetValue("thrust", val) != 0)
|
||||
*val = 0.0;
|
||||
break;
|
||||
|
||||
case _TABLE:
|
||||
|
||||
if (GPCP_GetValue("thrust_data_file",
|
||||
&filename)
|
||||
== 0)
|
||||
{
|
||||
status = load_data(filename,
|
||||
&(engine->thrust.x),
|
||||
&(engine->thrust.y),
|
||||
&(engine->thrust.n_point),
|
||||
&(engine->thrust.independant_var)
|
||||
);
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
printf("Error reading data file.\n");
|
||||
return -1;
|
||||
}
|
||||
free(filename);
|
||||
}
|
||||
break;
|
||||
|
||||
case _FUNCTION:
|
||||
printf("Functions are not supported yet.\n");
|
||||
break;
|
||||
}
|
||||
*/
|
||||
|
||||
val = &(engine->propellant_mass);
|
||||
if (GPCP_GetValue("propellant_mass", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = &(engine->dry_mass);
|
||||
if (GPCP_GetValue("dry_mass", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = &(engine->mass_flow);
|
||||
if (GPCP_GetValue("mass_flow", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = &(engine->c);
|
||||
if (GPCP_GetValue("c", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = &(engine->start_time);
|
||||
if (GPCP_GetValue("start_time", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = &(engine->burn_time);
|
||||
if (GPCP_GetValue("burn_time", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = &(engine->drop_time);
|
||||
if (GPCP_GetValue("drop_time", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = engine->position;
|
||||
if (get_point_value("position", val) != 0)
|
||||
{
|
||||
printf("Unable to get position.\n");
|
||||
}
|
||||
|
||||
val = engine->direction;
|
||||
if (get_point_value("direction", val) != 0)
|
||||
{
|
||||
printf("Unble to get direction.\n");
|
||||
}
|
||||
|
||||
}
|
||||
if (GPCP_ExitLevel() != 0)
|
||||
{
|
||||
printf("Unable to leave engine level.\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (GPCP_ExitLevel() != 0)
|
||||
{
|
||||
printf("Unable to leave 'initial_conditions'"
|
||||
" level.\n");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (GPCP_ExitLevel() != 0)
|
||||
{
|
||||
printf("Unable to leave 'rocket' level.\n");
|
||||
}
|
||||
}
|
||||
/********************* end rocket *****************************/
|
||||
|
||||
|
||||
/********************* solution *******************************/
|
||||
n = GPCP_NumParent("solution");
|
||||
if (n > 1)
|
||||
{
|
||||
printf("There should be only one \"solution\""
|
||||
" keyword in \"simulation\".\n"
|
||||
"The first one will be used.\n");
|
||||
}
|
||||
else if (n == 0)
|
||||
{
|
||||
printf("No \"solution\" in config file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (GPCP_EnterLevel("solution", 0) == -1)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GPCP_GetValue ("duration", &((*solution).duration)) != 0)
|
||||
{
|
||||
printf("A duration mus be specified.\n");
|
||||
}
|
||||
if (GPCP_GetValue ("dt", &((*solution).dt)) != 0)
|
||||
{
|
||||
(*solution).dt = 0.1;
|
||||
}
|
||||
if (GPCP_GetValue ("precision", &((*solution).precision)) != 0)
|
||||
{
|
||||
(*solution).precision = 0.01;
|
||||
}
|
||||
|
||||
if (GPCP_ExitLevel() != 0)
|
||||
{
|
||||
printf("Unable to leave 'solution' level.\n");
|
||||
}
|
||||
}
|
||||
/***************** end solution *****************************/
|
||||
|
||||
if (GPCP_ExitLevel() != 0)
|
||||
{
|
||||
printf("Unable to leave 'simulation' level.\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int get_point_value(char *name, float *point)
|
||||
{
|
||||
if (GPCP_EnterLevel(name, 0) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GPCP_GetValue("x", point+0) != 0)
|
||||
*(point+0) = 0.0;
|
||||
if (GPCP_GetValue("y", point+1) != 0)
|
||||
*(point+1) = 0.0;
|
||||
if (GPCP_GetValue("z", point+2) != 0)
|
||||
*(point+2) = 0.0;
|
||||
}
|
||||
|
||||
if (GPCP_ExitLevel() != 0)
|
||||
{
|
||||
printf("Unable to leave '%s' level.\n", name);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int read_file(char *config_file, rocket_t *rocket, float *init_cond,
|
||||
solution_t *solution)
|
||||
{
|
||||
Data *data;
|
||||
GPCP_RegisterOptions(rockflight_options);
|
||||
|
||||
if (GPCP_ReadFile(config_file, &data) != 0)
|
||||
{
|
||||
printf("Error reading config file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (load_config(data, rocket, init_cond, solution) != 0)
|
||||
{
|
||||
printf("Error: unable to correctly load data.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* GPCP_PrintData(data); */
|
||||
|
||||
GPCP_FreeData(&data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int load_data(char *file, float **x, float **y, int *n, parameter_t *p)
|
||||
{
|
||||
int i;
|
||||
FILE *fd;
|
||||
char line[128];
|
||||
char *retval;
|
||||
int scan_status;
|
||||
|
||||
fd = fopen(file, "r");
|
||||
|
||||
if (fd == NULL)
|
||||
{
|
||||
printf("Unable to open file: %s.\n", file);
|
||||
return -1;
|
||||
}
|
||||
printf("Reading data file (%s)...\n", file);
|
||||
|
||||
/* read the first line containing the independant variable name */
|
||||
retval = fgets(line, 128, fd);
|
||||
/* find the \n and replace it by \0 */
|
||||
retval = strchr(line, '\n');
|
||||
if (retval != NULL)
|
||||
*retval = '\0';
|
||||
|
||||
if (strcmp("ALT", line) == 0)
|
||||
*p = ALT;
|
||||
else if (strcmp("MACH", line) == 0)
|
||||
*p = MACH;
|
||||
else if (strcmp("AOA", line) == 0)
|
||||
*p = AOA;
|
||||
else if (strcmp("TIME", line) == 0)
|
||||
*p = TIME;
|
||||
else
|
||||
{
|
||||
printf("Unknown independant variable : %s.\n", line);
|
||||
return -1;
|
||||
}
|
||||
|
||||
retval = fgets(line, 128, fd);
|
||||
*x = NULL;
|
||||
*y = NULL;
|
||||
i = 0;
|
||||
while (retval != NULL)
|
||||
{
|
||||
if (line[0] != '#')
|
||||
{
|
||||
i++;
|
||||
|
||||
*x = (float *) realloc(*x, sizeof(float)*i);
|
||||
if (*x == NULL)
|
||||
{
|
||||
printf("memory error.\n");
|
||||
return -1;
|
||||
}
|
||||
*y = (float *) realloc(*y, sizeof(float)*i);
|
||||
if (*y == NULL)
|
||||
{
|
||||
printf("memory error.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
scan_status = sscanf(line, "%f %f", *x+i-1, *y+i-1);
|
||||
|
||||
if (scan_status != 2)
|
||||
{
|
||||
printf("Error reading file.\n");
|
||||
}
|
||||
}
|
||||
retval = fgets(line, 128, fd);
|
||||
}
|
||||
|
||||
*n = i;
|
||||
|
||||
printf("... %d points read.\n", i);
|
||||
|
||||
fclose(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int load_function_data(function_t *f, char *constant_name, char *table_name)
|
||||
{
|
||||
|
||||
int status;
|
||||
char *filename;
|
||||
float *val;
|
||||
|
||||
f->name = (char *) malloc(sizeof(char) * (strlen(constant_name) + 1));
|
||||
strcpy(f->name, constant_name);
|
||||
|
||||
if (GPCP_GetValue(table_name, &filename) == 0)
|
||||
{
|
||||
status = load_data(filename, &(f->x), &(f->y),
|
||||
&(f->n_point), &(f->independant_var));
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
printf("Error reading data file.\n");
|
||||
return -1;
|
||||
}
|
||||
f->type = _TABLE;
|
||||
free(filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
f->type = _CONSTANT;
|
||||
f->x = NULL;
|
||||
f->y = NULL;
|
||||
val = &(f->constant_value);
|
||||
if (GPCP_GetValue (constant_name, val) != 0)
|
||||
*val = 0.0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
#include <stdio.h>
|
||||
#include "librockflight/include/state.h"
|
||||
|
||||
void print_function(function_t *f);
|
||||
|
||||
void print_summary(rocket_t *rocket, float *init_cond, solution_t *solution)
|
||||
{
|
||||
int i, j;
|
||||
double propellant_mass = 0.0;
|
||||
double rocket_mass = 0.0;
|
||||
|
||||
engine_t *e;
|
||||
|
||||
printf("---------------------------------------------\n");
|
||||
printf(" SOLUTION SUMMARY\n");
|
||||
printf("---------------------------------------------\n");
|
||||
printf("Solution duration : %.2f s\n", (*solution).duration);
|
||||
printf("Solution dt : %g \n", (*solution).dt);
|
||||
printf("Solution precision : %.2e \n", (*solution).precision);
|
||||
printf("\n");
|
||||
printf("Initial conditions.\n");
|
||||
printf("-------------------\n");
|
||||
printf(" u = %.2e m/s\n", init_cond[0]);
|
||||
printf(" v = %.2e m/s\n", init_cond[1]);
|
||||
printf(" w = %.2e m/s\n", init_cond[2]);
|
||||
printf(" P = %.2e rad/s\n", init_cond[3]);
|
||||
printf(" Q = %.2e rad/s\n", init_cond[4]);
|
||||
printf(" R = %.2e rad/s\n", init_cond[5]);
|
||||
printf(" longitude = %.2e deg\n", init_cond[6]);
|
||||
printf(" latitude = %.2e deg\n", init_cond[7]);
|
||||
printf(" altitude = %.2e m\n", init_cond[8]);
|
||||
printf(" phi = %.2e deg\n", init_cond[9]);
|
||||
printf(" theta = %.2e deg\n", init_cond[10]);
|
||||
printf(" psi = %.2e deg\n", init_cond[11]);
|
||||
printf("\n");
|
||||
printf("Rocket properties.\n");
|
||||
printf("------------------\n");
|
||||
printf(" Number of stages : %d\n", (*rocket).n_stage);
|
||||
|
||||
for (i = 0; i < (*rocket).n_stage; i++)
|
||||
{
|
||||
/* engines contribution */
|
||||
for (j = 0; j < (*rocket).stage_properties[i].n_engine; j++)
|
||||
{
|
||||
propellant_mass +=
|
||||
(*rocket).stage_properties[i].engines[j].propellant_mass;
|
||||
rocket_mass +=
|
||||
(*rocket).stage_properties[i].engines[j].dry_mass;
|
||||
}
|
||||
/* stage structure and payload */
|
||||
rocket_mass += (*rocket).stage_properties[i].dry_mass;
|
||||
}
|
||||
|
||||
printf(" Propellant mass : %.2e kg\n", propellant_mass);
|
||||
printf(" Rocket dry mass : %.2e kg\n", rocket_mass);
|
||||
printf(" Total mass : %.2e kg\n", propellant_mass + rocket_mass);
|
||||
printf("\n");
|
||||
printf(" Propellant mass fraction : %.2f %%\n",
|
||||
100*propellant_mass/(propellant_mass + rocket_mass));
|
||||
printf("\n");
|
||||
|
||||
printf("Stages properties.\n");
|
||||
printf("------------------\n");
|
||||
|
||||
for (i = 0; i < (*rocket).n_stage; i++)
|
||||
{
|
||||
printf(" Stage %d\n", i+1);
|
||||
printf(" |->Diameter : %.2e m\n",
|
||||
(*rocket).stage_properties[i].Diameter);
|
||||
printf(" |->Dry mass : %.2e kg\n",
|
||||
(*rocket).stage_properties[i].dry_mass);
|
||||
|
||||
print_function(&(*rocket).stage_properties[i].Ix);
|
||||
print_function(&(*rocket).stage_properties[i].Iy);
|
||||
print_function(&(*rocket).stage_properties[i].Iz);
|
||||
|
||||
printf(" |->Active time : %.2e s\n",
|
||||
(*rocket).stage_properties[i].active_time);
|
||||
|
||||
print_function(&(*rocket).stage_properties[i].Cd);
|
||||
print_function(&(*rocket).stage_properties[i].CL);
|
||||
print_function(&(*rocket).stage_properties[i].CB);
|
||||
|
||||
printf(" |->Cross spin coefficient : %.2e\n",
|
||||
(*rocket).stage_properties[i].Cspin);
|
||||
printf(" |->Moment coefficient : %.2e\n",
|
||||
(*rocket).stage_properties[i].Cmoment);
|
||||
printf(" |->Damping coefficient : %.2e\n",
|
||||
(*rocket).stage_properties[i].Cdamping);
|
||||
|
||||
printf(" |->Number of engines : %d\n",
|
||||
(*rocket).stage_properties[i].n_engine);
|
||||
for (j = 0; j < (*rocket).stage_properties[i].n_engine; j++)
|
||||
{
|
||||
e = (*rocket).stage_properties[i].engines + j;
|
||||
|
||||
printf(" |->Engine %d\n", j);
|
||||
printf(" |->Propellant mass : %.2e\n", e->propellant_mass);
|
||||
printf(" |->Dry mass : %.2e\n", e->dry_mass);
|
||||
printf(" |->Start time : %.2e\n", e->start_time);
|
||||
printf(" |->Burn time : %.2e\n", e->burn_time);
|
||||
printf(" |->Drop time : %.2e\n", e->drop_time);
|
||||
printf(" |->Position : (%.2e, %.2e, %.2e)\n",
|
||||
e->position[0], e->position[1], e->position[2]);
|
||||
printf(" |->Direction : (%.2e, %.2e, %.2e)\n",
|
||||
e->direction[0], e->direction[1], e->direction[2]);
|
||||
|
||||
print_function(&(e->thrust));
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
printf("---------------------------------------------\n");
|
||||
printf(" END SUMMARY\n");
|
||||
printf("---------------------------------------------\n");
|
||||
}
|
||||
|
||||
|
||||
void print_function(function_t *f)
|
||||
{
|
||||
int i;
|
||||
|
||||
/*printf(" |->%s type : ", f->name);*/
|
||||
|
||||
switch (f->type)
|
||||
{
|
||||
case _CONSTANT:
|
||||
/*printf("Constant\n");*/
|
||||
printf(" |->%s : %.2e\n",
|
||||
f->name, f->constant_value);
|
||||
break;
|
||||
break;
|
||||
|
||||
case _TABLE:
|
||||
printf(" |->%s : ", f->name);
|
||||
printf("Table (%d points) function of ", f->n_point);
|
||||
|
||||
switch (f->independant_var)
|
||||
{
|
||||
case TIME:
|
||||
printf("time.\n");
|
||||
break;
|
||||
case ALT:
|
||||
printf("altitude.\n");
|
||||
break;
|
||||
case MACH:
|
||||
printf("mach number.\n");
|
||||
break;
|
||||
case AOA:
|
||||
printf("angle of attack.\n");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < f->n_point; i++)
|
||||
{
|
||||
printf(" (%.2e, %.2e)\n",
|
||||
f->x[i], f->y[i]);
|
||||
}
|
||||
break;
|
||||
|
||||
case _FUNCTION:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void print_octave_results(double *ans, const int neq, const int n)
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("# Created by rocflight\n");
|
||||
printf("# name: M\n");
|
||||
printf("# type: matrix\n");
|
||||
printf("# rows: %d\n", n);/*(int)(duration/dt) + 1);*/
|
||||
printf("# columns: %d\n", neq + 1);
|
||||
|
||||
|
||||
for( i = 0; i < n; i++)
|
||||
{
|
||||
printf("% .12e ", ans[12 + (neq+1)*i]); /* t */
|
||||
printf("% .12e ", ans[0 + (neq+1)*i]); /* u */
|
||||
printf("% .12e ", ans[1 + (neq+1)*i]); /* v */
|
||||
printf("% .12e ", ans[2 + (neq+1)*i]); /* w */
|
||||
printf("% .12e ", ans[3 + (neq+1)*i]); /* p */
|
||||
printf("% .12e ", ans[4 + (neq+1)*i]); /* q */
|
||||
printf("% .12e ", ans[5 + (neq+1)*i]); /* r */
|
||||
printf("% .12e ", ans[6 + (neq+1)*i]); /* lambda */
|
||||
printf("% .12e ", ans[7 + (neq+1)*i]); /* mu */
|
||||
printf("% .12e ", ans[8 + (neq+1)*i]); /* R */
|
||||
printf("% .12e ", ans[9 + (neq+1)*i]); /* phi */
|
||||
printf("% .12e ", ans[10 + (neq+1)*i]); /* theta */
|
||||
printf("% .12e ", ans[11 + (neq+1)*i]); /* psi */
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libcompat/include/getopt.h"
|
||||
|
||||
#include "librockflight/include/state.h"
|
||||
#include "librockflight/include/rockflight.h"
|
||||
#include "libnum/include/num.h"
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
void usage(void);
|
||||
extern void print_summary(rocket_t *rocket, float *init_cond,
|
||||
solution_t *solution);
|
||||
extern void print_octave_results(double *ans, int neq, int n);
|
||||
|
||||
int eom(int neq, double time, double *y, double *dy, void *data);
|
||||
int read_file(char *config_file, rocket_t *rocket, float *init_cond,
|
||||
solution_t *solution);
|
||||
extern int simulate(rocket_t *r, solution_t *s, float *ic, double **ans);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
int n = 0, c;
|
||||
int neq = 12;
|
||||
|
||||
/* hold the rocket properties */
|
||||
rocket_t rocket;
|
||||
solution_t solution;
|
||||
double *ans;
|
||||
float *init_cond;
|
||||
|
||||
|
||||
int debug = 0;
|
||||
int check_only = 0;
|
||||
|
||||
int Lfileread = 0;
|
||||
char config_file[FILENAME_MAX];
|
||||
|
||||
/* allocate memory to hold initial conditions */
|
||||
init_cond = (float *) malloc(sizeof(float) * neq);
|
||||
|
||||
/* Read command line options */
|
||||
while (1)
|
||||
{
|
||||
c = getopt(argc, argv, "cdhf:");
|
||||
|
||||
if (c == EOF)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
/* the input file */
|
||||
case 'f':
|
||||
if (strlen(optarg) > FILENAME_MAX)
|
||||
{
|
||||
printf("Filename too long!\n");
|
||||
break;
|
||||
}
|
||||
strncpy (config_file, optarg, FILENAME_MAX - 1);
|
||||
Lfileread = 1;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
check_only = 1;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
debug = 1;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
usage();
|
||||
return 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (! (Lfileread))
|
||||
{
|
||||
printf("Error: A config file must be specified.\n");
|
||||
printf(" try rockflight -h for options.\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
/* parse the configuration file */
|
||||
if ((read_file (config_file, &rocket, init_cond, &solution)) != 0)
|
||||
abort();
|
||||
|
||||
print_summary(&rocket, init_cond, &solution);
|
||||
|
||||
if (check_only)
|
||||
check(&rocket, 300.0, 1.0);
|
||||
else
|
||||
/* solve the model */
|
||||
n = simulate(&rocket, &solution, init_cond, &ans);
|
||||
|
||||
fprintf(stderr, "Memory used: %d kB\n", n*(neq+1)*sizeof(double)/1024);
|
||||
|
||||
print_octave_results(ans, neq, n);
|
||||
|
||||
free(init_cond);
|
||||
free(ans);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
printf("Usage:");
|
||||
printf("\n\trockflight -f infile [-o outfile] [-d]");
|
||||
printf("\n\trockflight -h");
|
||||
|
||||
printf("\n\nArguments:\n");
|
||||
printf("-f file \t Perform a simulation using file.\n");
|
||||
printf("-o file \t Results file, stdout if omitted\n");
|
||||
printf("-d \t Debug mode\n");
|
||||
printf("-h \t Print help\n\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
#include <math.h>
|
||||
|
||||
#include "libnum/include/num.h"
|
||||
|
||||
#include "librockflight/include/state.h"
|
||||
#include "librockflight/include/rockflight.h"
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
int eom(int neq, double time, double *y, double *dy, void *data);
|
||||
|
||||
int simulate(rocket_t *r, solution_t *sol, float *ic, double **ans)
|
||||
{
|
||||
|
||||
int n;
|
||||
|
||||
//double time;
|
||||
float init_cond[12];
|
||||
|
||||
int neq = 12;
|
||||
|
||||
/* s.A = M_PI*s.D*s.D/4;*/ /* reference area (m^2) */
|
||||
/* s.C = 1;*/ /* reference distance */
|
||||
|
||||
double u = ic[0];
|
||||
double v = ic[1];
|
||||
double w = ic[2];
|
||||
double P = ic[3];
|
||||
double Q = ic[4];
|
||||
double R = ic[5];
|
||||
double lambda = ic[6];
|
||||
double mu = ic[7];
|
||||
double Re = ic[8] + EARTH_RAD; /* convert altitude to distance
|
||||
from eartj center */
|
||||
double phi = ic[9];
|
||||
double theta = ic[10]*(M_PI/180); /* convert deg to rad
|
||||
(use convert instead) */
|
||||
double psi = ic[11];
|
||||
|
||||
|
||||
/* in kg */
|
||||
//r->state.m = 16.0;
|
||||
|
||||
//r->state.Ix = 0.0025;
|
||||
//r->state.Iy = 0.84;
|
||||
//r->state.Iz = 0.84;
|
||||
|
||||
/* aerodynamic coefficients */
|
||||
|
||||
//r->state.Cdrag = 0.2;
|
||||
//r->state.Clift = 2.3;
|
||||
//r->state.Cbeta = 2.3;
|
||||
//r->state.Cspin = 20.0;
|
||||
//r->state.Cmoment = 6.32;
|
||||
//r->state.Cdamping = 31.6;
|
||||
|
||||
//r->state.D = 0.1143;
|
||||
|
||||
r->state.Faero[0] = 0;
|
||||
r->state.Faero[1] = 0;
|
||||
r->state.Faero[2] = 0;
|
||||
r->state.Maero[0] = 0;
|
||||
r->state.Maero[1] = 0;
|
||||
r->state.Maero[2] = 0;
|
||||
|
||||
r->state.L_BV[0][0] = cos(theta)*cos(psi);
|
||||
r->state.L_BV[0][1] = cos(theta)*sin(psi);
|
||||
r->state.L_BV[0][2] =-sin(theta);
|
||||
r->state.L_BV[1][0] = sin(phi)*sin(theta)*cos(psi) - cos(phi)*sin(psi);
|
||||
r->state.L_BV[1][1] = sin(phi)*sin(theta)*sin(psi) + cos(phi)*cos(psi);
|
||||
r->state.L_BV[1][2] = sin(phi)*cos(theta);
|
||||
r->state.L_BV[2][0] = cos(phi)*sin(theta)*cos(psi) + sin(phi)*sin(psi);
|
||||
r->state.L_BV[2][1] = cos(phi)*sin(theta)*sin(psi) - sin(phi)*cos(psi);
|
||||
r->state.L_BV[2][2] = cos(phi)*cos(theta);
|
||||
|
||||
init_cond[0] = u; /* velocity component in x */
|
||||
init_cond[1] = v; /* velocity component in y */
|
||||
init_cond[2] = w; /* velocity component in z */
|
||||
init_cond[3] = P+ (r->state.L_BV[0][0]*WE*cos(lambda) -
|
||||
r->state.L_BV[0][2]*WE*sin(lambda));
|
||||
init_cond[4] = Q+ (r->state.L_BV[1][0]*WE*cos(lambda) -
|
||||
r->state.L_BV[1][2]*WE*sin(lambda));
|
||||
init_cond[5] = R+ (r->state.L_BV[2][0]*WE*cos(lambda) -
|
||||
r->state.L_BV[2][2]*WE*sin(lambda));
|
||||
init_cond[6] = lambda; /* latitude */
|
||||
init_cond[7] = mu; /* longitude */
|
||||
init_cond[8] = Re; /* radius */
|
||||
init_cond[9] = phi; /* phi */
|
||||
init_cond[10] = theta; /* theta */
|
||||
init_cond[11] = psi; /* psi */
|
||||
|
||||
//time = 0;
|
||||
|
||||
n = NUM_rkf (eom, neq, sol->dt, sol->duration, init_cond, ans,
|
||||
sol->precision, r);
|
||||
return n;
|
||||
}
|
||||
Reference in New Issue
Block a user