File Exchange

image thumbnail

Gravity-assist Trajectory Design and Analysis

version 2.0.0.0 (670 KB) by David Eagle
A MATLAB Script for Interplanetary Gravity-Assist Trajectory Design and Optimization

23 Downloads

Updated 20 Sep 2019

View License

PDF document and a MATLAB script called flyby_matlab that can be used to design and optimize interplanetary trajectories that include a single gravity assist maneuver. The user specifies the launch, flyby and destination planets, and the desired flyby altitude. The algorithm also requires initial guesses for the launch, flyby and arrival calendar dates. This script searches for a patched-conic gravity-assist trajectory that satisfies the flyby mission constraints (V-infinity matching and user-defined flyby altitude) and minimizes the launch, arrival or total impulsive delta-v for the mission. The type of delta-v optimization is specified by the user.

Cite As

David Eagle (2019). Gravity-assist Trajectory Design and Analysis (https://www.mathworks.com/matlabcentral/fileexchange/39462-gravity-assist-trajectory-design-and-analysis), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (10)

David Eagle

Recommended setup (1) create a sub-directory named flyby_matlab (for example) (2) copy all files from flyby_matlab.zip to this directory (3) copy all SNOPT files and the DE421 ephemeris file to this sub-directory (4) log in to this sub-directory from within MATLAB (5) run the script in the flyby_matlab sub-directory

Hello, I followed the SNOPT steps by Mick Smith, and the following error occurred:
"Error using snoptmex
Error reading license file
Error in snopt (line 294)
xstate,Fstate,itn,mjritn] = snoptmex(solveopt, ...
Error in t1diet (line 12)
[x,F,INFO,xmul,Fmul,xstate,Fstate,output]= snopt( x, xlow,
xupp, xmul, xstate, ...
Error in runNPexamples (line 10)
[x,xmul,F,Fmul,info] = t1diet;"
Any idea on how to fix this issue?

Mick Smith

For everyone below that was having trouble getting this to work:

For SNOPT:
1. Go here to request a license for SNOPT (snopt7.lic) and to get the snoptmex file: https://ccom.ucsd.edu/~optimizers/downloads/
2. Download the *.m files for snopt: https://github.com/snopt/snopt-matlab/releases
Make sure you get the latest version.
3. Move the snopt7.lic and snoptmex file into the snopt-matlab-2.5.0 file you downloaded in part 2
4. On Matlab, go to Home - > Environment - > Set Path
5. Click 'Add with subfolders' and then click the snopt-matlab-2.5.0
6. In the matlab terminal type setenv('SNOPT_LICENSE','C:\Users\User\Documents\MATLAB\snopt-matlab-2.5.0\snopt7.lic')
hit enter and then type runNPexamples to test the NLP solver. If no errors occur then it's working.

For JPL ephemeris:
1. Go to this website: https://cdeaglejr.wordpress.com
2. Find 'Ephemeris Binary Files' and click on the dropbox link
3. Download de421.bin
4. Move de421.bin to the flyby_matlab file you downloaded

Getting the de421.bin file will solve the "userfun should return 1 or 2 arguments" error.

ahmed morsi

can you give me instructions for using SNOP with Gravity-assist Trajectory Design and Analysis. thank you.

Okay it's great to be honest. I have a small problem though and it's kind of a pain. I am unable to run the snopt function. When I try to run it I get the following error:
Error using snopt (line 189)
userfun should return 1 or 2 arguments

Please help me out. This is really a pain and is not letting me go forward.

I think there is miss-typing in " fbyfunc"
In this code, the equation to obtain the turn angle is typed as below
phi1 = 0.5 * pi + 0.5 * asin(v1crossv2m / (vinfm_in * vinfm_out));

but I think it should be fixed like this
phi1 = 0.5 * pi - 0.5 * asin(v1crossv2m / (vinfm_in * vinfm_out));

can you check for me ?

When compiling the program I get the following error, can you help me please?

error: userfun should return 1 or 2 arguments
error: called from
snopt at line 188 column 5
flyby_matlab at line 356 column 23
>>

Undefined function or variable 'snopt'.

Error in flyby_matlab (line 356)
[x, f, inform, xmul, fmul] = snopt(xg, xlwr, xupr,
xmul, xstate, ...

Where is the snopt function defined?

Updates

2.0.0.0

Script is now "data file driven". Added asteroid or comet as arrival body. Updated PDF document and added several new example missions.

1.6.0.0

MATLAB source code updates (new keywords, etc.)

1.5.0.0

Fixed bug in code that calculated the heliocentric orbital elements and state vector of the departure planet. (emu replaced with smu in the calling argument).

1.4.0.0

UPDATED LINKS

SNOPT ccom.ucsd.edu/~optimizers/

Binary Ephemeris Files

https://www.dropbox.com/sh/hul0g7ia6nhspwo/AAATqfVXb5ClZODfGGvEbRZEa?dl=0

1.3.0.0

Bug fixes. Added three-dimensional graphics for the flyby trajectory. Updated PDF document.

1.2.0.0

Added main script (flyby_matlab_64bit.m) that uses the March 17, 2014 version of SNOPT.

1.1.0.0

MICE version included in flyby_mice.zip archive.

MATLAB Release Compatibility
Created with R2019a
Compatible with any release
Platform Compatibility
Windows macOS Linux