Skip to content

Commit

Permalink
tello: update FlightData struct
Browse files Browse the repository at this point in the history
- Correct the name of EmSky, EmGround and GroundSpeed to Flying,
  OnGround and VerticalSpeed.
- Remove FlySpeed, WifiDisturb and WifiStrength as these are not part
  of the data.
- Add AirSpeed() and GroundSpeed() for calculating the airspeed and
  ground speed.

Signed-off-by: Silke Hofstra <[email protected]>
  • Loading branch information
silkeh authored and deadprogram committed May 22, 2019
1 parent 6c243af commit 79de57d
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions platforms/dji/tello/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"math"
"net"
"strconv"
"sync"
Expand Down Expand Up @@ -144,19 +145,18 @@ type FlightData struct {
DroneFlyTimeLeft int16
DroneHover bool
EmOpen bool
EmSky bool
EmGround bool
Flying bool
OnGround bool
EastSpeed int16
ElectricalMachineryState int16
FactoryMode bool
FlyMode int8
FlySpeed int16
FlyTime int16
FrontIn bool
FrontLSC bool
FrontOut bool
GravityState bool
GroundSpeed int16
VerticalSpeed int16
Height int16
ImuCalibrationState int8
ImuState bool
Expand All @@ -166,10 +166,8 @@ type FlightData struct {
PowerState bool
PressureState bool
SmartVideoExitMode int16
TemperatureHeight bool
TemperatureHigh bool
ThrowFlyTimer int8
WifiDisturb int8
WifiStrength int8
WindState bool
}

Expand Down Expand Up @@ -584,7 +582,7 @@ func (d *Driver) ParseFlightData(b []byte) (fd *FlightData, err error) {
if err != nil {
return
}
err = binary.Read(buf, binary.LittleEndian, &fd.GroundSpeed)
err = binary.Read(buf, binary.LittleEndian, &fd.VerticalSpeed)
if err != nil {
return
}
Expand Down Expand Up @@ -626,8 +624,8 @@ func (d *Driver) ParseFlightData(b []byte) (fd *FlightData, err error) {
if err != nil {
return
}
fd.EmSky = (data >> 0 & 0x1) == 1
fd.EmGround = (data >> 1 & 0x1) == 1
fd.Flying = (data >> 0 & 0x1) == 1
fd.OnGround = (data >> 1 & 0x1) == 1
fd.EmOpen = (data >> 2 & 0x1) == 1
fd.DroneHover = (data >> 3 & 0x1) == 1
fd.OutageRecording = (data >> 4 & 0x1) == 1
Expand Down Expand Up @@ -666,7 +664,7 @@ func (d *Driver) ParseFlightData(b []byte) (fd *FlightData, err error) {
if err != nil {
return
}
fd.TemperatureHeight = (data >> 0 & 0x1) == 1
fd.TemperatureHigh = (data >> 0 & 0x1) == 1

return
}
Expand Down Expand Up @@ -849,3 +847,16 @@ func (d *Driver) connectionString() string {
res := fmt.Sprintf("conn_req:%s", b)
return res
}

func (f *FlightData) AirSpeed() float64 {
return math.Sqrt(
math.Pow(float64(f.NorthSpeed), 2) +
math.Pow(float64(f.EastSpeed), 2) +
math.Pow(float64(f.VerticalSpeed), 2))
}

func (f *FlightData) GroundSpeed() float64 {
return math.Sqrt(
math.Pow(float64(f.NorthSpeed), 2) +
math.Pow(float64(f.EastSpeed), 2))
}

0 comments on commit 79de57d

Please sign in to comment.