Package: pysamss
pySAMSSPython Space Asset Management and Simulation SystemA Python package for managing and simulating assets in Space.IntroductionpySAMSS provides a full 6 degree of freedom state space model representation of CelestialBody and Vessel objects. Using a numerical integration scheme (i.e. Euler or RK4) the future state of CelestialBody and Vessel objects can be found explicitly where:state0=np.array([u,v,w,x,y,z,phi_d,theta_d,psi_d,qw,qx,qy,qz])# State vectorU=np.array([Fx,Fy,Fz,Mx,My,Mz])# Input vectorA=np.array([[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[1,0,0,0,0,0,0,0,0,0,0,0,0],[0,1,0,0,0,0,0,0,0,0,0,0,0],[0,0,1,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,-0.5*state0[6],-0.5*state0[7],-0.5*state0[8]],[0,0,0,0,0,0,0,0,0,0.5*state0[6],0,0.5*state0[8],-0.5*state0[7]],[0,0,0,0,0,0,0,0,0,0.5*state0[7],-0.5*state0[8],0,0.5*state0[6]],[0,0,0,0,0,0,0,0,0,0.5*state0[8],0.5*state0[7],-0.5*state0[6],0]])# System matrixB=np.array([[1/m,0,0,0,0,0],[0,1/m,0,0,0,0],[0,0,1/m,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,Ii[0,0],Ii[0,1],Ii[0,2]],[0,0,0,Ii[1,0],Ii[1,1],Ii[1,2]],[0,0,0,Ii[2,0],Ii[2,1],Ii[2,2]],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]])# Control matrix. Note: m = mass, Ii = inverse inertia matrixstate_d=np.dot(A,state0)+np.dot(B,U)# State derivative vector [u_d, v_d, w_d, x_d, y_d, z_d, phi_dd, theta_dd, psi_dd, qw_d, qx_d, qy_d, qz_d]InstallationInstall latest version on pip using:pip install pysamssAlternatively, to install the latest development version of pySAMSS first make sure you have git installed, seehere, then clone the repository:git clone https://github.com/c-bruce/pysamss.gitNext, build the .tar.gz distributable:python setup.py sdistFinally, cd into the ./dist/ directory and install using pip:pip install pysamss-0.0.1.tar.gzUsing pySAMSSBegin by creating a System instance and add CelestialBody and Vessel objects to the current Timestep:# Create System instancesystem=pysamss.System('EarthMoonISS')# Add CelestialBody objects to systemsystem.current.addCelestialBody(pysamss.CelestialBody('Earth',5.972e24,6.371e6))system.current.addCelestialBody(pysamss.CelestialBody('Moon',7.348e22,1.737e6,parent_name='Earth'))# Add Vessel objects to systemsystem.current.addVessel(pysamss.Vessel('ISS',[pysamss.Stage(419725,1,10,np.array([0,0,0]))],parent_name='Earth'))Define and set initial conditions for CelestialBody objects. This can be done convieniently using thejplephempackage which can load and use ephemeris from NASA's Jet Propulsion Laboratory:time=system.current.getJulianDate()kernel=SPK.open('de430.bsp')# Earthearth_pos,earth_vel=kernel[3,399].compute_and_differentiate(time)earth_pos*=1000# Convert from km -> mearth_vel/=86.4# Convert from km/day -> m/ssystem.current.celestial_bodies['Earth'].setPosition(earth_pos)system.current.celestial_bodies['Earth'].setVelocity(earth_vel)# Moonmoon_pos,moon_vel=kernel[3,301].compute_and_differentiate(time)moon_pos*=1000# Convert from km -> mmoon_vel/=86.4# Convert from km/day -> m/ssystem.current.celestial_bodies['Moon'].setPosition(moon_pos)system.current.celestial_bodies['Moon'].setVelocity(moon_vel)Define and set initial conditions for Vessel objects. This can be done convieniently using thespk4package which takes Two Line Element (TLE) data fromCelesTrakand returns position and velocity vectors relative to the Earth-centered inertial coordinate system:# Get TLE data from CelesTrakhttp=urllib3.PoolManager()tle=http.request('GET','https://www.celestrak.com/NORAD/elements/stations.txt')tle=tle.data.decode('utf-8').strip().split('\r\n')# Gets full TLE's for constelation into a list# ISStime=np.modf(time)# Split Julian date into integer and decimal for spg4 libraryiss_tle=tle[0:3]iss=Satrec.twoline2rv(iss_tle[1],iss_tle[2])e,iss_pos,iss_vel=iss.sgp4(time[1],time[0])iss_pos=np.array(iss_pos)*1000iss_vel=np.array(iss_vel)*1000system.current.vessels['ISS'].setPosition(iss_pos,local=True)system.current.vessels['ISS'].setVelocity(iss_vel,local=True)Set system timestep, end time, save interval and run the simulation:# Simulate systemsystem.setDt(0.1)system.setEndTime(5561.0)system.setSaveInterval(10)system.simulateSystem()All simulation data is written out to *.h5 files saved in the *_data directory. Once a simulation is complete this data can be read and post processed. pySAMSS comes with an interactive widget, based onmayavi, for visually post processing simulation data:# Load system datasystem.load('EarthMoonISS.psm')# Get dataiss_pos=system.timestep[100].vessels['ISS'].getPosition()# Visual post processingfig=pysamss.MainWidget()fig.loadSystem(system)fig.showMaximized()mlab.show()See theexamplesdirectory for more pySAMSS examples.Notes:The System class currently only supports a gravity as a force/torque source. See "Future Developments" for information on how this will change in the future.CelestialBody and Vessel objects can be used and simulated independently. Falcon9_example.py shows an example of how this can be achieved - in this example, a Vessel "falcon9", has two force/torque sources - gravity and thrust. The Vessels orientation over time is controlled using a pitch PID controller. A disadvantage of this approach is that the user is required to manually set up all reference frames and relationships between objects - this is usually automatically handled by the System and Timestep classes.LimitationspySAMSS is currently in an early stage of development and as such there are a number of limitations, such as:Performance (pySAMSS is currently not optimized for speed)System class only includes gravity force/torque sourceNo aerodynamic force/torque sourceNot able to use controllers inside System classFuture DevelopmentsIn no particular order here is a list of some planned future developments:GroundStation class (to be able to do coverage analysis etc.)Maneuver class (for maneuver/mission planning)FlightProgram class (to support a series of Maneuvers for a given Vessel similar to Falcon9_example.py)Aerodynamics force/torque sourcePerformance optimizationSupport for advanced gravity modelsAutomatically define CelestialBody orientations at a given datetime (i.e. due to rotation speed)Update parent CelestialBody depending on current sphere of influence