Sorry guys I am quite new to python. I am writing a 'main.py' as follows:
from time import time
import numpy as np
from astropy.constants import G, M_earth, R_earth
from astropy import units as u
import modules.OrbitDescription as orbit
# ------------------------------------------------------------------------------
# SIMULATION PARAMETERS
nOrbits = 1; # number of orbits to be simulated
dt = 1.0; # time step of simulation
# ------------------------------------------------------------------------------
# INITIAL ORBIT
a = 7078.145; # semi-major axis
e = 0.07; # eccentricity
inc = 70.0; # inclination
Omega = 57.0; # longitude of ascending node
omega = 0.0; # argument of periapsis
Theta = 0.0; # true anomaly
# GLOBAL CONSTANTS
inRadians = np.pi/180.0; # conversion to radians
inDegrees = 180.0/np.pi; # conversion to Degrees
global mu
mu = 398600.0; # km^3/s^2
And I am using variable mu here in 'OrbitDescription.py' that is located inside the modules folder. The modules folder is located in the same directory with main.py. the code inside 'OrbitDescription.py' is:
import numpy as np
def coe_2_rv(a,e,i,RA,w,theta):
h = np.sqrt(a*mu*(1-e**2))
rp = ((h**2)/(mu*(1+e*np.cos(theta)))) * np.array([np.cos(theta),np.sin(theta),0.0])
vp = (mu/h)*np.array([-np.sin(theta),e+np.cos(theta),0.0])
QxX = np.array([ (-np.sin(RA)*np.cos(i)*np.sin(w)+np.cos(RA)*np.cos(w), -
np.sin(RA)*np.cos(i)*np.cos(w)-np.cos(RA)*np.sin(w), np.sin(RA)*np.sin(i))
(np.cos(RA)*np.cos(i)*np.sin(w)+np.sin(RA)*np.cos(w),
np.cos(RA)*np.cos(i)*np.cos(w)-np.sin(RA)*np.sin(w), -np.cos(RA)*np.sin(i))
(np.sin(i)*np.sin(w),
np.sin(i)*np.cos(w), np.cos(i))])
r = QxX*rp
v = QxX*vp
return r,v
I continue to get the error in the third line of the code 'OrbitDescription.py': "NameError: name 'mu' is not defined" How should I define a global mu in 'Main.py' that can be used all over the project code? Thanks in advance