Skip to main content

Advanced 6-DOF trajectory simulation for High-Power Rocketry.

Project description

RocketPy

RocketPy is a trajectory simulation for High-Power Rocketry built by Projeto Jupiter. The code is written as a Python library and allows for a complete 6 degrees of freedom simulation of a rocket's flight trajectory, including high fidelity variable mass effects as well as descent under parachutes. Weather conditions, such as wind profile, can be imported from sophisticated datasets, allowing for realistic scenarios. Furthermore, the implementation facilitates complex simulations, such as multi-stage rockets, design and trajectory optimization and dispersion analysis.

Previewing

You can preview RocketPy's main functionalities by browsing through a sample notebook!

Then, you can read the Getting Started section to get your own copy!

Getting Started

These instructions will get you a copy of RocketPy up and running on your local machine for development and testing purposes.

Prerequisites

The following is needed in order to run RocketPy:

  • Python >= 3.0
  • Numpy >= 1.0
  • Scipy >= 1.0
  • Matplotlib >= 3.0
  • netCDF4 >= 1.4 (optional, requires Cython)

The first 4 prerequisites come with Anaconda, but Scipy might need updating. The nedCDF4 package can be installed if there is interest in importing weather data from netCDF files. To update Scipy and install netCDF4 using Conda, the following code is used:

$ conda install "scipy>=1.0"
$ conda install -c anaconda "netcdf4>=1.4"

Alternatively, if you only have Python 3.X installed, the packages needed can be installed using pip:

$ pip install "numpy>=1.0"
$ pip install "scipy>=1.0"
$ pip install "matplotlib>=3.0"
$ pip install "netCDF4>=1.4"

Although Jupyter Notebooks are by no means required to run RocketPy, they are strongly recommend. They already come with Anaconda builds, but can also be installed separately using pip:

$ pip install jupyter

Downloading

To get a copy of RocketPy, you currently have two options:

  • Download it from RocketPy's GitHub page
    • Unzip the folder and you are ready to go
  • Or clone it to a desired directory using git:
    • $ git clone https://github.com/giovaniceotto/RocketPy.git

The repository comes with the following content:

  • Files
    • README.md
    • LICENSE.md
  • Folders
    • data - Input data for the simulation, such as motor thrust curves and wind profiles.
    • disp - Example of dispersion analysis, but needs to be refined.
    • docs - Documentation available about the physics models used.
    • nbks - Main python library, some example notebooks and other random files which will soon be cleaned up.

The main Python library is kept under the nkbs folder and is currently named rocketpy.py. Keep in mind that the files are still being organized for a proper release.

Running Your First Simulation

In order to run your first rocket trajectory simulation using RocketPy, you can start a Jupyter Notebook and navigate to the nbks folder. Open Calisto.ipynb and you are ready to go.

Otherwise, you may want to create your own script or your own notebook using RocketPy. To do this, let's see how to use RocketPy's four main classes:

  • Environment - Keeps data related to weather.
  • Motor - Keeps data related to solid motors.
  • Rocket - Keeps data related to a rocket.
  • Flight - Runs the simulation and process the results.

A typical workflow starts with importing these classes from RocketPy:

from rocketpy import *

Then create an Environment object. To learn more about it, you can use:

help(Environment)

A sample code is:

Env = Environment(railLength=5.2
                  latitude=32.990254
                  longitude=-106.974998,
                  elevation=1400,
                  date=(2018, 6, 20, 18))

Env.setAtmosphericModel(type='Reanalysis', file='../data/weather/SpaceportAmerica2018.nc')

This can be followed up by starting a Motor object. To get help on it, just use:

help(Motor)

A sample Motor object can be created by the following code:

Cesaroni_M1670 = Motor(thrustSource="../data/motors/Cesaroni_M1670.eng",
                       burnOut=3.9,
                       grainNumber=5,
                       grainSeparation=5/1000,
                       grainDensity=1815,
                       grainOuterRadius=33/1000,
                       grainInitialInnerRadius=15/1000,
                       grainInitialHeight=120/1000,
                       nozzleRadius=33/1000,
                       throatRadius=11/1000)

With a Motor defined, you are ready to create your Rocket object. As you may have guessed, to get help on it, use:

help(Rocket)

A sample code to create a Rocket is:

Calisto = Rocket(motor=Cesaroni_M1670,
                 radius=127/2000,
                 mass=19.197-2.956,
                 inertiaI=6.60,
                 inertiaZ=0.0351,
                 distanceRocketNozzle=1.255,
                 distanceRocketPropellant=0.85704,
                 powerOffDrag='../data/calisto/powerOffDragCurve.csv',
                 powerOnDrag='../data/calisto/powerOnDragCurve.csv')

Calisto.addNose(length=0.55829, kind="vonKarman", distanceToCM=0.71971)

Calisto.addFins(4, span=0.100, rootChord=0.120, tipChord=0.040, distanceToCM=-1.049)

Calisto.addTail(topRadius=0.0635, bottomRadius=0.0435, length=0.060, distanceToCM=-1.194)

Calisto.addParachute('Drogue',
                     CdS=1.0,
                     trigger=lambda p, y: return y[5] < 0,
                     samplingRate=1,
                     lag=1.5)

Calisto.addParachute('Main',
                     CdS=10.0,
                     trigger=lambda p, y: return (y[2] < 500 and y[5] < 0), 
                     samplingRate=1,
                     lag=1.5)

Finally, you can create a Flight object to simulate your trajectory. To get help on the Flight class, use:

help(Flight)

To actually create a Flight object, use:

TestFlight = Flight(rocket=Calisto, environment=Env, inclination=85, heading=0)

Once the TestFlight object is created, your simulation is done! Use the following code to get a summary of the results:

TestFlight.info()

To seel all available results, use:

TestFlight.allInfo()

To summarize, the complete code would be:

from rocketpy import *

Env = Environment(railLength=5.2
                  latitude=32.990254
                  longitude=-106.974998,
                  elevation=1400,
                  date=(2018, 6, 20, 18))

Env.setAtmosphericModel(type='Reanalysis', file='../data/weather/SpaceportAmerica2018.nc')

Cesaroni_M1670 = Motor(thrustSource="../data/motors/Cesaroni_M1670.eng",
                       burnOut=3.9,
                       grainNumber=5,
                       grainSeparation=5/1000,
                       grainDensity=1815,
                       grainOuterRadius=33/1000,
                       grainInitialInnerRadius=15/1000,
                       grainInitialHeight=120/1000,
                       nozzleRadius=33/1000,
                       throatRadius=11/1000)

Calisto = Rocket(motor=Cesaroni_M1670,
                 radius=127/2000,
                 mass=19.197-2.956,
                 inertiaI=6.60,
                 inertiaZ=0.0351,
                 distanceRocketNozzle=1.255,
                 distanceRocketPropellant=0.85704,
                 powerOffDrag='../data/calisto/powerOffDragCurve.csv',
                 powerOnDrag='../data/calisto/powerOnDragCurve.csv')

Calisto.addNose(length=0.55829, kind="vonKarman", distanceToCM=0.71971)

Calisto.addFins(4, span=0.100, rootChord=0.120, tipChord=0.040, distanceToCM=-1.049)

Calisto.addTail(topRadius=0.0635, bottomRadius=0.0435, length=0.060, distanceToCM=-1.194)

Calisto.addParachute('Drogue',
                     CdS=1.0,
                     trigger=lambda p, y: return y[5] < 0,
                     samplingRate=1,
                     lag=1.5)

Calisto.addParachute('Main',
                     CdS=10.0,
                     trigger=lambda p, y: return (y[2] < 500 and y[5] < 0), 
                     samplingRate=1,
                     lag=1.5)

TestFlight = Flight(rocket=Calisto, environment=Env, inclination=85, heading=0)

TestFlight.info()

TestFlight.allInfo()

Built With

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us. - Still working on this!

Versioning

Still working on this!

Authors

  • Giovani Hidalgo Ceotto

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

Still working on this!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rocketpy-0.9.0.tar.gz (72.0 kB view hashes)

Uploaded Source

Built Distribution

rocketpy-0.9.0-py3-none-any.whl (71.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page