Browse Source

Add Vehicle fact timeToHome

TimeToHome fact calculates the time in seconds till the UAV reaches the
home position. We take the distance to home and divide it by the
current ground speed to get the seconds till we arrive at the home
point. I did not add any fancy logic to find out if we actually fly
towards the home point or are in RTL so the value shows increasing
seconds even if we fly away from the home point
QGC4.4
Philipp Borgers 2 years ago committed by Patrick José Pereira
parent
commit
3f32dd414d
  1. 6
      src/Vehicle/Vehicle.cc
  2. 4
      src/Vehicle/Vehicle.h
  3. 7
      src/Vehicle/VehicleFact.json

6
src/Vehicle/Vehicle.cc

@ -91,6 +91,7 @@ const char* Vehicle::_altitudeTuningSetpointFactName = "altitudeTuningSetpoint"; @@ -91,6 +91,7 @@ const char* Vehicle::_altitudeTuningSetpointFactName = "altitudeTuningSetpoint";
const char* Vehicle::_flightDistanceFactName = "flightDistance";
const char* Vehicle::_flightTimeFactName = "flightTime";
const char* Vehicle::_distanceToHomeFactName = "distanceToHome";
const char* Vehicle::_timeToHomeFactName = "timeToHome";
const char* Vehicle::_missionItemIndexFactName = "missionItemIndex";
const char* Vehicle::_headingToNextWPFactName = "headingToNextWP";
const char* Vehicle::_headingToHomeFactName = "headingToHome";
@ -154,6 +155,7 @@ Vehicle::Vehicle(LinkInterface* link, @@ -154,6 +155,7 @@ Vehicle::Vehicle(LinkInterface* link,
, _flightDistanceFact (0, _flightDistanceFactName, FactMetaData::valueTypeDouble)
, _flightTimeFact (0, _flightTimeFactName, FactMetaData::valueTypeElapsedTimeInSeconds)
, _distanceToHomeFact (0, _distanceToHomeFactName, FactMetaData::valueTypeDouble)
, _timeToHomeFact (0, _timeToHomeFactName, FactMetaData::valueTypeDouble)
, _missionItemIndexFact (0, _missionItemIndexFactName, FactMetaData::valueTypeUint16)
, _headingToNextWPFact (0, _headingToNextWPFactName, FactMetaData::valueTypeDouble)
, _headingToHomeFact (0, _headingToHomeFactName, FactMetaData::valueTypeDouble)
@ -439,6 +441,7 @@ void Vehicle::_commonInit() @@ -439,6 +441,7 @@ void Vehicle::_commonInit()
_addFact(&_flightDistanceFact, _flightDistanceFactName);
_addFact(&_flightTimeFact, _flightTimeFactName);
_addFact(&_distanceToHomeFact, _distanceToHomeFactName);
_addFact(&_timeToHomeFact, _timeToHomeFactName);
_addFact(&_missionItemIndexFact, _missionItemIndexFactName);
_addFact(&_headingToNextWPFact, _headingToNextWPFactName);
_addFact(&_headingToHomeFact, _headingToHomeFactName);
@ -1023,6 +1026,9 @@ void Vehicle::_handleVfrHud(mavlink_message_t& message) @@ -1023,6 +1026,9 @@ void Vehicle::_handleVfrHud(mavlink_message_t& message)
_altitudeTuningOffset = vfrHud.alt;
}
_altitudeTuningFact.setRawValue(vfrHud.alt - _altitudeTuningOffset);
if (!qIsNaN(vfrHud.groundspeed) && !qIsNaN(_distanceToHomeFact.cookedValue().toDouble())) {
_timeToHomeFact.setRawValue(_distanceToHomeFact.cookedValue().toDouble() / vfrHud.groundspeed);
}
}
void Vehicle::_handleNavControllerOutput(mavlink_message_t& message)

4
src/Vehicle/Vehicle.h

@ -302,6 +302,7 @@ public: @@ -302,6 +302,7 @@ public:
Q_PROPERTY(Fact* rangeFinderDist READ rangeFinderDist CONSTANT)
Q_PROPERTY(Fact* flightDistance READ flightDistance CONSTANT)
Q_PROPERTY(Fact* distanceToHome READ distanceToHome CONSTANT)
Q_PROPERTY(Fact* timeToHome READ timeToHome CONSTANT)
Q_PROPERTY(Fact* missionItemIndex READ missionItemIndex CONSTANT)
Q_PROPERTY(Fact* headingToNextWP READ headingToNextWP CONSTANT)
Q_PROPERTY(Fact* headingToHome READ headingToHome CONSTANT)
@ -679,6 +680,7 @@ public: @@ -679,6 +680,7 @@ public:
Fact* rangeFinderDist () { return &_rangeFinderDistFact; }
Fact* flightDistance () { return &_flightDistanceFact; }
Fact* distanceToHome () { return &_distanceToHomeFact; }
Fact* timeToHome () { return &_timeToHomeFact; }
Fact* missionItemIndex () { return &_missionItemIndexFact; }
Fact* headingToNextWP () { return &_headingToNextWPFact; }
Fact* headingToHome () { return &_headingToHomeFact; }
@ -1358,6 +1360,7 @@ private: @@ -1358,6 +1360,7 @@ private:
Fact _flightDistanceFact;
Fact _flightTimeFact;
Fact _distanceToHomeFact;
Fact _timeToHomeFact;
Fact _missionItemIndexFact;
Fact _headingToNextWPFact;
Fact _headingToHomeFact;
@ -1413,6 +1416,7 @@ private: @@ -1413,6 +1416,7 @@ private:
static const char* _flightDistanceFactName;
static const char* _flightTimeFactName;
static const char* _distanceToHomeFactName;
static const char* _timeToHomeFactName;
static const char* _missionItemIndexFactName;
static const char* _headingToNextWPFactName;
static const char* _headingToHomeFactName;

7
src/Vehicle/VehicleFact.json

@ -95,6 +95,13 @@ @@ -95,6 +95,13 @@
"units": "m"
},
{
"name": "timeToHome",
"shortDesc": "Time to Home",
"type": "double",
"decimalPlaces": 1,
"units": "s"
},
{
"name": "headingToHome",
"shortDesc": "Heading to Home",
"type": "double",

Loading…
Cancel
Save