mirror of
https://github.com/nasa/trick.git
synced 2024-12-18 20:57:55 +00:00
Add 2D Satellite Simulation. Ref #387
This commit is contained in:
parent
85f2435af7
commit
1b1490a972
11
trick_sims/SIM_sat2d/Modified_data/realtime.py
Normal file
11
trick_sims/SIM_sat2d/Modified_data/realtime.py
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
trick.frame_log_on()
|
||||
trick.real_time_enable()
|
||||
trick.exec_set_software_frame(0.1)
|
||||
trick.itimer_enable()
|
||||
|
||||
trick.exec_set_enable_freeze(True)
|
||||
trick.exec_set_freeze_command(True)
|
||||
|
||||
simControlPanel = trick.SimControlPanel()
|
||||
trick.add_external_application(simControlPanel)
|
21
trick_sims/SIM_sat2d/Modified_data/satellite.dr
Normal file
21
trick_sims/SIM_sat2d/Modified_data/satellite.dr
Normal file
@ -0,0 +1,21 @@
|
||||
global DR_GROUP_ID
|
||||
global drg
|
||||
try:
|
||||
if DR_GROUP_ID >= 0:
|
||||
DR_GROUP_ID += 1
|
||||
except NameError:
|
||||
DR_GROUP_ID = 0
|
||||
drg = []
|
||||
|
||||
drg.append(trick.DRBinary("satellite"))
|
||||
drg[DR_GROUP_ID].set_freq(trick.DR_Always)
|
||||
drg[DR_GROUP_ID].set_cycle(1.0)
|
||||
drg[DR_GROUP_ID].set_single_prec_only(False)
|
||||
drg[DR_GROUP_ID].add_variable("dyn.satellite.pos[0]")
|
||||
drg[DR_GROUP_ID].add_variable("dyn.satellite.pos[1]")
|
||||
drg[DR_GROUP_ID].add_variable("dyn.satellite.vel[0]")
|
||||
drg[DR_GROUP_ID].add_variable("dyn.satellite.vel[1]")
|
||||
drg[DR_GROUP_ID].add_variable("dyn.satellite.acc[0]")
|
||||
drg[DR_GROUP_ID].add_variable("dyn.satellite.acc[1]")
|
||||
trick.add_data_record_group(drg[DR_GROUP_ID], trick.DR_Buffer)
|
||||
drg[DR_GROUP_ID].enable()
|
26
trick_sims/SIM_sat2d/RUN_test/input.py
Normal file
26
trick_sims/SIM_sat2d/RUN_test/input.py
Normal file
@ -0,0 +1,26 @@
|
||||
execfile("Modified_data/realtime.py")
|
||||
execfile("Modified_data/satellite.dr")
|
||||
|
||||
dyn_integloop.getIntegrator(trick.Runge_Kutta_4, 6)
|
||||
|
||||
#==========================================
|
||||
# Start the Satellite Graphics Client
|
||||
#==========================================
|
||||
varServerPort = trick.var_server_get_port();
|
||||
SatDisplay_path = "models/graphics/dist/SatDisplay.jar"
|
||||
|
||||
if (os.path.isfile(SatDisplay_path)) :
|
||||
SatDisplay_cmd = "java -jar " \
|
||||
+ SatDisplay_path \
|
||||
+ " " + str(varServerPort) + " &" ;
|
||||
print(SatDisplay_cmd)
|
||||
os.system( SatDisplay_cmd);
|
||||
else :
|
||||
print('==================================================================================')
|
||||
print('SatDisplay needs to be built. Please \"cd\" into ../models/graphics and type \"make\".')
|
||||
print('==================================================================================')
|
||||
|
||||
trick.stop(5400);
|
||||
|
||||
|
||||
|
22
trick_sims/SIM_sat2d/S_define
Normal file
22
trick_sims/SIM_sat2d/S_define
Normal file
@ -0,0 +1,22 @@
|
||||
/************************************************************
|
||||
PURPOSE:
|
||||
( Simulate a satellite orbiting the Earth. )
|
||||
LIBRARY DEPENDENCIES:
|
||||
((satellite/src/Satellite.cpp))
|
||||
*************************************************************/
|
||||
#include "sim_objects/default_trick_sys.sm"
|
||||
##include "satellite/include/Satellite.hh"
|
||||
class SatelliteSimObject : public Trick::SimObject {
|
||||
public:
|
||||
Satellite satellite;
|
||||
|
||||
SatelliteSimObject() {
|
||||
("default_data") satellite.default_data() ;
|
||||
("initialization") satellite.state_init() ;
|
||||
("derivative") satellite.state_deriv() ;
|
||||
("integration") trick_ret = satellite.state_integ() ;
|
||||
}
|
||||
};
|
||||
|
||||
SatelliteSimObject dyn;
|
||||
IntegLoop dyn_integloop(0.002) dyn;
|
2
trick_sims/SIM_sat2d/S_overrides.mk
Normal file
2
trick_sims/SIM_sat2d/S_overrides.mk
Normal file
@ -0,0 +1,2 @@
|
||||
TRICK_CFLAGS += -Imodels
|
||||
TRICK_CXXFLAGS += -Imodels
|
3
trick_sims/SIM_sat2d/models/.gitignore
vendored
Normal file
3
trick_sims/SIM_sat2d/models/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
build
|
||||
dist
|
||||
manifest
|
36
trick_sims/SIM_sat2d/models/graphics/Makefile
Normal file
36
trick_sims/SIM_sat2d/models/graphics/Makefile
Normal file
@ -0,0 +1,36 @@
|
||||
SHELL = /bin/sh
|
||||
|
||||
PROJECT_NAME = SatDisplay
|
||||
SRC_DIR = src
|
||||
BUILD_DIR = build
|
||||
CLASSES_DIR = $(BUILD_DIR)/classes
|
||||
JAR_DIR = dist
|
||||
MAIN_CLASS = trick.SatDisplay
|
||||
|
||||
all: jar
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR)
|
||||
rm -f manifest
|
||||
|
||||
spotless: clean
|
||||
rm -rf dist
|
||||
|
||||
$(CLASSES_DIR):
|
||||
@ mkdir -p $(CLASSES_DIR)
|
||||
|
||||
compile: | $(CLASSES_DIR)
|
||||
javac -sourcepath $(SRC_DIR) -d $(CLASSES_DIR) $(SRC_DIR)/trick/SatDisplay.java
|
||||
|
||||
manifest:
|
||||
@ echo "Main-Class: $(MAIN_CLASS)" > $@
|
||||
|
||||
$(JAR_DIR):
|
||||
@ mkdir -p $(JAR_DIR)
|
||||
|
||||
jar: compile manifest | $(JAR_DIR)
|
||||
jar cvfm $(JAR_DIR)/$(PROJECT_NAME).jar manifest -C $(CLASSES_DIR) .
|
||||
@ echo "-------------------------------------------------------------------------------"
|
||||
@ echo " BUILD COMPLETE"
|
||||
@ echo "The Java jar file (the Java Executable) is located at: $(JAR_DIR)/$(PROJECT_NAME).jar"
|
||||
@ echo "-------------------------------------------------------------------------------"
|
28
trick_sims/SIM_sat2d/models/satellite/include/Satellite.hh
Normal file
28
trick_sims/SIM_sat2d/models/satellite/include/Satellite.hh
Normal file
@ -0,0 +1,28 @@
|
||||
/*************************************************************************
|
||||
PURPOSE: (Simulate a satellite orbiting the Earth.)
|
||||
LIBRARY DEPENDENCIES:
|
||||
((satellite/src/Satellite.o))
|
||||
**************************************************************************/
|
||||
#ifndef _satellite_hh_
|
||||
#define _satellite_hh_
|
||||
|
||||
#define GRAVITATIONAL_CONSTANT 6.674e-11
|
||||
#define EARTH_MASS 5.9723e24
|
||||
#define EARTH_RADIUS 6367500.0
|
||||
|
||||
class Satellite {
|
||||
|
||||
public:
|
||||
double pos[2] ; /* m xyz-position */
|
||||
double vel[2] ; /* m/s xyz-velocity */
|
||||
double acc[2] ; /* m/s2 xyz-acceleration */
|
||||
|
||||
int default_data();
|
||||
int state_init();
|
||||
int state_deriv();
|
||||
int state_integ();
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
46
trick_sims/SIM_sat2d/models/satellite/src/Satellite.cpp
Normal file
46
trick_sims/SIM_sat2d/models/satellite/src/Satellite.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/********************************* TRICK HEADER *******************************
|
||||
PURPOSE: ( Simulate a satellite orbiting the Earth. )
|
||||
LIBRARY DEPENDENCY:
|
||||
((Satellite.o))
|
||||
*******************************************************************************/
|
||||
#include "../include/Satellite.hh"
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
|
||||
int Satellite::default_data() {
|
||||
|
||||
pos[0] = 0.0;
|
||||
pos[1] = 6578000.0;
|
||||
vel[0] = 7905.0;
|
||||
vel[1] = 0.0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int Satellite::state_init() {
|
||||
return (0);
|
||||
}
|
||||
|
||||
int Satellite::state_deriv() {
|
||||
|
||||
double d = sqrt( pos[0]*pos[0] + pos[1]*pos[1]);
|
||||
acc[0] = -pos[0] * GRAVITATIONAL_CONSTANT * EARTH_MASS / (d*d*d);
|
||||
acc[1] = -pos[1] * GRAVITATIONAL_CONSTANT * EARTH_MASS / (d*d*d);
|
||||
return(0);
|
||||
}
|
||||
|
||||
#include "sim_services/Integrator/include/integrator_c_intf.h"
|
||||
|
||||
int Satellite::state_integ() {
|
||||
|
||||
int integration_step;
|
||||
|
||||
load_state ( &pos[0], &pos[1], &vel[0], &vel[1], (double*)0);
|
||||
load_deriv ( &vel[0], &vel[1], &acc[0], &acc[1], (double*)0);
|
||||
|
||||
integration_step = integrate();
|
||||
|
||||
unload_state( &pos[0], &pos[1], &vel[0], &vel[1], (double*)0);
|
||||
|
||||
return(integration_step);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user