Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update grav string -> Gravity const #14

Merged
merged 1 commit into from
Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ Struct for holding satellite information during and before propagation
#### func ParseTLE

```go
func ParseTLE(line1, line2, gravconst string) (sat Satellite)
func ParseTLE(line1, line2 string, gravConst Gravity) (sat Satellite)
```
Parses a two line element dataset into a Satellite struct

#### func TLEToSat

```go
func TLEToSat(line1, line2 string, gravconst string) Satellite
func TLEToSat(line1, line2 string, gravConst Gravity) Satellite
```
Converts a two line element data set into a Satellite struct and runs sgp4init

Expand Down Expand Up @@ -160,6 +160,6 @@ Initialise a spacetrack API for fetching TLEs

#### func Spacetrack.GetTLE()
```go
func (s *Spacetrack) GetTLE(catid uint64, ts time.Time, gravconst string) (Satellite, error)
func (s *Spacetrack) GetTLE(catid uint64, ts time.Time, gravConst Gravity) (Satellite, error)
```
Get an initialized Satellite based on the latest TLE before the given time.
16 changes: 12 additions & 4 deletions gravity.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@ type GravConst struct {
mu, radiusearthkm, xke, tumin, j2, j3, j4, j3oj2 float64
}

type Gravity string

const (
GravityWGS72Old Gravity = "wgs72old"
GravityWGS72 Gravity = "wgs72"
GravityWGS84 Gravity = "wgs84"
)

// Returns a GravConst with correct information on requested model provided through the name parameter
func getGravConst(name string) (grav GravConst) {
func getGravConst(name Gravity) (grav GravConst) {
switch name {
case "wgs72old":
case GravityWGS72Old:
grav.mu = 398600.79964
grav.radiusearthkm = 6378.135
grav.xke = 0.0743669161
Expand All @@ -22,7 +30,7 @@ func getGravConst(name string) (grav GravConst) {
grav.j3 = -0.00000253881
grav.j4 = -0.00000165597
grav.j3oj2 = grav.j3 / grav.j2
case "wgs72":
case GravityWGS72:
grav.mu = 398600.8
grav.radiusearthkm = 6378.135
grav.xke = 60.0 / math.Sqrt(grav.radiusearthkm*grav.radiusearthkm*grav.radiusearthkm/grav.mu)
Expand All @@ -31,7 +39,7 @@ func getGravConst(name string) (grav GravConst) {
grav.j3 = -0.00000253881
grav.j4 = -0.00000165597
grav.j3oj2 = grav.j3 / grav.j2
case "wgs84":
case GravityWGS84:
grav.mu = 398600.5
grav.radiusearthkm = 6378.137
grav.xke = 60.0 / math.Sqrt(grav.radiusearthkm*grav.radiusearthkm*grav.radiusearthkm/grav.mu)
Expand Down
8 changes: 4 additions & 4 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ type LookAngles struct {
}

// Parses a two line element dataset into a Satellite struct
func ParseTLE(line1, line2, gravconst string) (sat Satellite) {
func ParseTLE(line1, line2 string, gravConst Gravity) (sat Satellite) {
sat.Line1 = line1
sat.Line2 = line2

sat.Error = 0
sat.whichconst = getGravConst(gravconst)
sat.whichconst = getGravConst(gravConst)

// LINE 1 BEGIN
sat.satnum = parseInt(strings.TrimSpace(line1[2:7]))
Expand All @@ -59,9 +59,9 @@ func ParseTLE(line1, line2, gravconst string) (sat Satellite) {
}

// Converts a two line element data set into a Satellite struct and runs sgp4init
func TLEToSat(line1, line2 string, gravconst string) Satellite {
func TLEToSat(line1, line2 string, gravConst Gravity) Satellite {
//sat := Satellite{Line1: line1, Line2: line2}
sat := ParseTLE(line1, line2, gravconst)
sat := ParseTLE(line1, line2, gravConst)

opsmode := "i"

Expand Down
7 changes: 4 additions & 3 deletions satellite_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ var _ = Describe("go-satellite", func() {
PropagationTestCase{
line1: "1 23599U 95029B 06171.76535463 .00085586 12891-6 12956-2 0 2905",
line2: "2 23599 6.9327 0.2849 5782022 274.4436 25.2425 4.47796565123555",
grav: "wgs72",
grav: "wgs72",
testData: `0.00000000 9892.63794341 35.76144969 -1.08228838 3.556643237 6.456009375 0.783610890
20.00000000 11931.95642997 7340.74973750 886.46365987 0.308329116 5.532328972 0.672887281
40.00000000 11321.71039205 13222.84749156 1602.40119049 -1.151973982 4.285810871 0.521919425
Expand Down Expand Up @@ -269,7 +269,8 @@ var _ = Describe("go-satellite", func() {
})

type PropagationTestCase struct {
line1, line2, testData, grav string
line1, line2, testData string
grav Gravity
}

func propagationTest(testCase PropagationTestCase) {
Expand All @@ -296,4 +297,4 @@ func propagationTest(testCase PropagationTestCase) {
})
})
}
}
}
4 changes: 2 additions & 2 deletions spacetrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewSpacetrack(username, password string) *Spacetrack {
}

// GetTLE generates a Satellite from the most recent TLE from space-track.org before the given time
func (s *Spacetrack) GetTLE(catid uint64, ts time.Time, gravconst string) (Satellite, error) {
func (s *Spacetrack) GetTLE(catid uint64, ts time.Time, gravConst Gravity) (Satellite, error) {
zero := Satellite{}
args := spacetrackArgs{
base: baseurl,
Expand Down Expand Up @@ -109,7 +109,7 @@ func (s *Spacetrack) GetTLE(catid uint64, ts time.Time, gravconst string) (Satel
return zero, errors.Wrap(ErrNotSingleSat, fmt.Sprint(sats))

}
sat := TLEToSat(sats[0].Line1, sats[0].Line2, gravconst)
sat := TLEToSat(sats[0].Line1, sats[0].Line2, gravConst)
return sat, nil
}

Expand Down