-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorbit.go
121 lines (104 loc) · 3.61 KB
/
orbit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package sturdyengine
import (
"github.com/golang/protobuf/proto"
util "github.com/jwuensche/sturdyengine/internal"
krpc "github.com/jwuensche/sturdyengine/internal/krpcproto"
)
//Orbit represents a snapshot of a vessel's orbit
type Orbit struct {
sc *SpaceCenter
orbit []byte
}
// ORBIT - SPACECENTER.VESSEL.ORBIT || SPACECENTER.CELESTIALBODY.ORBIT
//GetVesselOrbit returns a snapshot of the current orbit the vessel is on
func (vsl *Vessel) GetVesselOrbit() (orbit Orbit, e error) {
arg := [][]byte{vsl.vessel}
orbit = Orbit{
sc: vsl.sc,
}
pr := createRequest("SpaceCenter", "Vessel_get_Orbit", createArguments(arg))
p, e := orbit.sc.conn.sendMessage(pr)
res := &krpc.Response{}
proto.Unmarshal(p, res)
orbit.orbit = res.GetResults()[0].GetValue()
return
}
//GetApoapsisAltitude returns the apoapsis of the orbit relative to the surface the reference object in meters
func (orb *Orbit) GetApoapsisAltitude() (alt float64, e error) {
alt, e = orb.getOrbitInfo("Orbit_get_ApoapsisAltitude")
return
}
//GetPeriapsisAltitude returns the periapsis of the orbit relative to the surface the reference object in meters
func (orb *Orbit) GetPeriapsisAltitude() (alt float64, e error) {
alt, e = orb.getOrbitInfo("Orbit_get_PeriapsisAltitude")
return
}
//GetSemiMajorAxis returns the semi-major axis in meters
func (orb *Orbit) GetSemiMajorAxis() (alt float64, e error) {
alt, e = orb.getOrbitInfo("Orbit_get_SemiMajorAxis")
return
}
//GetSemiMinorAxis returns the semi-minor axis in meters
func (orb *Orbit) GetSemiMinorAxis() (alt float64, e error) {
alt, e = orb.getOrbitInfo("Orbit_get_SemiMinorAxis")
return
}
//GetRadius returns the current radius to the center of mass of the reference object in meters
func (orb *Orbit) GetRadius() (alt float64, e error) {
alt, e = orb.getOrbitInfo("Orbit_get_Radius")
return
}
//GetSpeed returns the current speed of the object in meters
func (orb *Orbit) GetSpeed() (alt float64, e error) {
alt, e = orb.getOrbitInfo("Orbit_get_Speed")
return
}
//GetPeriod returns the orbital period in seconds
func (orb *Orbit) GetPeriod() (time float64, e error) {
time, e = orb.getOrbitInfo("Orbit_get_Period")
return
}
//GetTimeToApoapsis returns the time to apoapsis in seconds
func (orb *Orbit) GetTimeToApoapsis() (time float64, e error) {
time, e = orb.getOrbitInfo("Orbit_get_TimeToApoapsis")
return
}
//GetTimeToApoapsis returns the time to periapsis in seconds
func (orb *Orbit) GetTimeToPeriapsis() (time float64, e error) {
time, e = orb.getOrbitInfo("Orbit_get_TimeToPeriapsis")
return
}
//GetEpoch returns the time since the epoch at which mean anomaly at epoch was measured in seconds
func (orb *Orbit) GetEpoch() (time float64, e error) {
time, e = orb.getOrbitInfo("Orbit_get_Epoch")
return
}
// GetEccentricity returns the eccentricity of the given orbit
func (orb *Orbit) GetEccentricity() (ecc float32, e error) {
ecc, e = orb.getOrbitInfoFloat32("Orbit_get_Eccentricity")
return
}
func (orb *Orbit) getOrbitInfo(procedure string) (alt float64, e error) {
arg := [][]byte{orb.orbit}
pr := createRequest("SpaceCenter", procedure, createArguments(arg))
p, e := orb.sc.conn.sendMessage(pr)
if e != nil {
return
}
res := &krpc.Response{}
proto.Unmarshal(p, res)
alt = util.ByteToFloat64(res.GetResults()[0].GetValue())
return
}
func (orb *Orbit) getOrbitInfoFloat32(procedure string) (alt float32, e error) {
arg := [][]byte{orb.orbit}
pr := createRequest("SpaceCenter", procedure, createArguments(arg))
p, e := orb.sc.conn.sendMessage(pr)
if e != nil {
return
}
res := &krpc.Response{}
proto.Unmarshal(p, res)
alt = util.ByteToFloat32(res.GetResults()[0].GetValue())
return
}