From 1b1490a972b33b1373dee175557c02489f10eed4 Mon Sep 17 00:00:00 2001 From: "John M. Penn" Date: Tue, 28 Feb 2017 15:49:35 -0600 Subject: [PATCH] Add 2D Satellite Simulation. Ref #387 --- .../SIM_sat2d/Modified_data/realtime.py | 11 +++++ .../SIM_sat2d/Modified_data/satellite.dr | 21 +++++++++ trick_sims/SIM_sat2d/RUN_test/input.py | 26 +++++++++++ trick_sims/SIM_sat2d/S_define | 22 +++++++++ trick_sims/SIM_sat2d/S_overrides.mk | 2 + trick_sims/SIM_sat2d/models/.gitignore | 3 ++ trick_sims/SIM_sat2d/models/graphics/Makefile | 36 +++++++++++++++ .../models/satellite/include/Satellite.hh | 28 +++++++++++ .../models/satellite/src/Satellite.cpp | 46 +++++++++++++++++++ 9 files changed, 195 insertions(+) create mode 100644 trick_sims/SIM_sat2d/Modified_data/realtime.py create mode 100644 trick_sims/SIM_sat2d/Modified_data/satellite.dr create mode 100644 trick_sims/SIM_sat2d/RUN_test/input.py create mode 100644 trick_sims/SIM_sat2d/S_define create mode 100644 trick_sims/SIM_sat2d/S_overrides.mk create mode 100644 trick_sims/SIM_sat2d/models/.gitignore create mode 100644 trick_sims/SIM_sat2d/models/graphics/Makefile create mode 100644 trick_sims/SIM_sat2d/models/satellite/include/Satellite.hh create mode 100644 trick_sims/SIM_sat2d/models/satellite/src/Satellite.cpp diff --git a/trick_sims/SIM_sat2d/Modified_data/realtime.py b/trick_sims/SIM_sat2d/Modified_data/realtime.py new file mode 100644 index 00000000..e8ce8380 --- /dev/null +++ b/trick_sims/SIM_sat2d/Modified_data/realtime.py @@ -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) diff --git a/trick_sims/SIM_sat2d/Modified_data/satellite.dr b/trick_sims/SIM_sat2d/Modified_data/satellite.dr new file mode 100644 index 00000000..dc11621b --- /dev/null +++ b/trick_sims/SIM_sat2d/Modified_data/satellite.dr @@ -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() diff --git a/trick_sims/SIM_sat2d/RUN_test/input.py b/trick_sims/SIM_sat2d/RUN_test/input.py new file mode 100644 index 00000000..2efa69b2 --- /dev/null +++ b/trick_sims/SIM_sat2d/RUN_test/input.py @@ -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); + + + diff --git a/trick_sims/SIM_sat2d/S_define b/trick_sims/SIM_sat2d/S_define new file mode 100644 index 00000000..ca58495b --- /dev/null +++ b/trick_sims/SIM_sat2d/S_define @@ -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; diff --git a/trick_sims/SIM_sat2d/S_overrides.mk b/trick_sims/SIM_sat2d/S_overrides.mk new file mode 100644 index 00000000..e1f6cccd --- /dev/null +++ b/trick_sims/SIM_sat2d/S_overrides.mk @@ -0,0 +1,2 @@ +TRICK_CFLAGS += -Imodels +TRICK_CXXFLAGS += -Imodels diff --git a/trick_sims/SIM_sat2d/models/.gitignore b/trick_sims/SIM_sat2d/models/.gitignore new file mode 100644 index 00000000..474b09b3 --- /dev/null +++ b/trick_sims/SIM_sat2d/models/.gitignore @@ -0,0 +1,3 @@ +build +dist +manifest diff --git a/trick_sims/SIM_sat2d/models/graphics/Makefile b/trick_sims/SIM_sat2d/models/graphics/Makefile new file mode 100644 index 00000000..31d9d77f --- /dev/null +++ b/trick_sims/SIM_sat2d/models/graphics/Makefile @@ -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 "-------------------------------------------------------------------------------" diff --git a/trick_sims/SIM_sat2d/models/satellite/include/Satellite.hh b/trick_sims/SIM_sat2d/models/satellite/include/Satellite.hh new file mode 100644 index 00000000..f2999f99 --- /dev/null +++ b/trick_sims/SIM_sat2d/models/satellite/include/Satellite.hh @@ -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 + + + diff --git a/trick_sims/SIM_sat2d/models/satellite/src/Satellite.cpp b/trick_sims/SIM_sat2d/models/satellite/src/Satellite.cpp new file mode 100644 index 00000000..7144f469 --- /dev/null +++ b/trick_sims/SIM_sat2d/models/satellite/src/Satellite.cpp @@ -0,0 +1,46 @@ +/********************************* TRICK HEADER ******************************* +PURPOSE: ( Simulate a satellite orbiting the Earth. ) +LIBRARY DEPENDENCY: + ((Satellite.o)) +*******************************************************************************/ +#include "../include/Satellite.hh" +#include +#include + +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); +} +