Skip to content

Commit

Permalink
Add new RPM vehicle FactGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
DonLakeFlyer committed Dec 3, 2024
1 parent cbc944f commit e208322
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 0 deletions.
1 change: 1 addition & 0 deletions qgroundcontrol.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@
<file alias="Vehicle/SetpointFact.json">src/Vehicle/FactGroups/SetpointFact.json</file>
<file alias="Vehicle/LocalPositionFact.json">src/Vehicle/FactGroups/LocalPositionFact.json</file>
<file alias="Vehicle/LocalPositionSetpointFact.json">src/Vehicle/FactGroups/LocalPositionFact.json</file>
<file alias="Vehicle/RPMFact.json">src/Vehicle/FactGroups/RPMFact.json</file>
<file alias="Vehicle/SubmarineFact.json">src/Vehicle/FactGroups/SubmarineFact.json</file>
<file alias="Vehicle/TemperatureFact.json">src/Vehicle/FactGroups/TemperatureFact.json</file>
<file alias="Vehicle/TerrainFactGroup.json">src/Vehicle/FactGroups/TerrainFactGroup.json</file>
Expand Down
2 changes: 2 additions & 0 deletions src/Vehicle/FactGroups/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ qt_add_library(VehicleFactGroups STATIC
VehicleLocalPositionFactGroup.h
VehicleLocalPositionSetpointFactGroup.cc
VehicleLocalPositionSetpointFactGroup.h
VehicleRPMFactGroup.cc
VehicleRPMFactGroup.h
VehicleSetpointFactGroup.cc
VehicleSetpointFactGroup.h
VehicleTemperatureFactGroup.cc
Expand Down
35 changes: 35 additions & 0 deletions src/Vehicle/FactGroups/RPMFact.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"version": 1,
"fileType": "FactMetaData",
"QGC.MetaData.Facts":
[
{
"name": "rpm1",
"shortDesc": "RPM 1",
"type": "double",
"decimalPlaces": 2,
"units": "rpm"
},
{
"name": "rpm2",
"shortDesc": "RPM 2",
"type": "double",
"decimalPlaces": 2,
"units": "rpm"
},
{
"name": "rpm3",
"shortDesc": "RPM 3",
"type": "double",
"decimalPlaces": 2,
"units": "rpm"
},
{
"name": "rpm4",
"shortDesc": "RPM 4",
"type": "double",
"decimalPlaces": 2,
"units": "rpm"
}
]
}
61 changes: 61 additions & 0 deletions src/Vehicle/FactGroups/VehicleRPMFactGroup.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/****************************************************************************
*
* (c) 2009-2023 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/

#include "VehicleSetpointFactGroup.h"
#include "Vehicle.h"

const char* VehicleRPMFactGroup::_rpm1FactName = "rpm1";
const char* VehicleRPMFactGroup::_rpm2FactName = "rpm2";
const char* VehicleRPMFactGroup::_rpm3FactName = "rpm3";
const char* VehicleRPMFactGroup::_rpm4FactName = "rpm4";

VehicleRPMFactGroup::VehicleRPMFactGroup(QObject* parent)
: FactGroup(1000, ":/json/Vehicle/RPMFact.json", parent)
, _rpm1Fact(0, _rpm1FactName, FactMetaData::valueTypeDouble)
, _rpm2Fact(0, _rpm2FactName, FactMetaData::valueTypeDouble)
, _rpm3Fact(0, _rpm3FactName, FactMetaData::valueTypeDouble)
, _rpm4Fact(0, _rpm4FactName, FactMetaData::valueTypeDouble)
{
_addFact(&_rpm1Fact, _rpm1FactName);
_addFact(&_rpm2Fact, _rpm2FactName);
_addFact(&_rpm3Fact, _rpm3FactName);
_addFact(&_rpm4Fact, _rpm4FactName);

// Start out as not available "--.--"
_rpm1Fact.setRawValue(qQNaN());
_rpm2Fact.setRawValue(qQNaN());
_rpm3Fact.setRawValue(qQNaN());
_rpm4Fact.setRawValue(qQNaN());
}

void VehicleRPMFactGroup::handleMessage(Vehicle* /* vehicle */, mavlink_message_t& message)
{
if (message.msgid == MAVLINK_MSG_ID_RAW_RPM) {
mavlink_raw_rpm_t raw_rpm;
mavlink_msg_raw_rpm_decode(&message, &raw_rpm);
switch (raw_rpm.index) {
case 0:
rpm1()->setRawValue(raw_rpm.frequency);
break;
case 1:
rpm2()->setRawValue(raw_rpm.frequency);
break;
case 2:
rpm3()->setRawValue(raw_rpm.frequency);
break;
case 3:
rpm4()->setRawValue(raw_rpm.frequency);
break;
default:
break;

}
_setTelemetryAvailable(true);
}
}
45 changes: 45 additions & 0 deletions src/Vehicle/FactGroups/VehicleRPMFactGroup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/****************************************************************************
*
* (c) 2009-2023 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/

#pragma once

#include "FactGroup.h"
#include "QGCMAVLink.h"

class VehicleRPMFactGroup : public FactGroup
{
Q_OBJECT

public:
VehicleRPMFactGroup(QObject* parent = nullptr);

Q_PROPERTY(Fact* rpm1 READ rpm1 CONSTANT)
Q_PROPERTY(Fact* rpm2 READ rpm2 CONSTANT)
Q_PROPERTY(Fact* rpm3 READ rpm3 CONSTANT)
Q_PROPERTY(Fact* rpm4 READ rpm4 CONSTANT)

Fact* rpm1 () { return &_rpm1Fact; }
Fact* rpm2 () { return &_rpm2Fact; }
Fact* rpm3 () { return &_rpm3Fact; }
Fact* rpm4 () { return &_rpm4Fact; }

// Overrides from FactGroup
void handleMessage(Vehicle* vehicle, mavlink_message_t& message) override;

static const char* _rpm1FactName;
static const char* _rpm2FactName;
static const char* _rpm3FactName;
static const char* _rpm4FactName;

private:
Fact _rpm1Fact;
Fact _rpm2Fact;
Fact _rpm3Fact;
Fact _rpm4Fact;
};
2 changes: 2 additions & 0 deletions src/Vehicle/Vehicle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Vehicle::Vehicle(LinkInterface* link,
, _hygrometerFactGroup (this)
, _generatorFactGroup (this)
, _efiFactGroup (this)
, _rpmFactGroup (this)
, _terrainFactGroup (this)
, _terrainProtocolHandler (new TerrainProtocolHandler(this, &_terrainFactGroup, this))
{
Expand Down Expand Up @@ -330,6 +331,7 @@ void Vehicle::_commonInit()
_addFactGroup(&_hygrometerFactGroup, _hygrometerFactGroupName);
_addFactGroup(&_generatorFactGroup, _generatorFactGroupName);
_addFactGroup(&_efiFactGroup, _efiFactGroupName);
_addFactGroup(&_rpmFactGroup, _rpmFactGroupName);
_addFactGroup(&_terrainFactGroup, _terrainFactGroupName);

// Add firmware-specific fact groups, if provided
Expand Down
4 changes: 4 additions & 0 deletions src/Vehicle/Vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "VehicleHygrometerFactGroup.h"
#include "VehicleLocalPositionFactGroup.h"
#include "VehicleLocalPositionSetpointFactGroup.h"
#include "VehicleRPMFactGroup.h"
#include "VehicleSetpointFactGroup.h"
#include "VehicleTemperatureFactGroup.h"
#include "VehicleVibrationFactGroup.h"
Expand Down Expand Up @@ -601,6 +602,7 @@ class Vehicle : public VehicleFactGroup
FactGroup* hygrometerFactGroup () { return &_hygrometerFactGroup; }
FactGroup* generatorFactGroup () { return &_generatorFactGroup; }
FactGroup* efiFactGroup () { return &_efiFactGroup; }
FactGroup* rpmFactGroup () { return &_rpmFactGroup; }
QmlObjectListModel* batteries () { return &_batteryFactGroupListModel; }

MissionManager* missionManager () { return _missionManager; }
Expand Down Expand Up @@ -1229,6 +1231,7 @@ private slots:
const QString _hygrometerFactGroupName = QStringLiteral("hygrometer");
const QString _generatorFactGroupName = QStringLiteral("generator");
const QString _efiFactGroupName = QStringLiteral("efi");
const QString _rpmFactGroupName = QStringLiteral("rpm");

VehicleFactGroup* _vehicleFactGroup;
VehicleGPSFactGroup _gpsFactGroup;
Expand All @@ -1246,6 +1249,7 @@ private slots:
VehicleHygrometerFactGroup _hygrometerFactGroup;
VehicleGeneratorFactGroup _generatorFactGroup;
VehicleEFIFactGroup _efiFactGroup;
VehicleRPMFactGroup _rpmFactGroup;
TerrainFactGroup _terrainFactGroup;
QmlObjectListModel _batteryFactGroupListModel;

Expand Down

0 comments on commit e208322

Please sign in to comment.