Skip to content

Commit

Permalink
mavlink ComponentID used when handling waypoints can be changed now.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arne-W committed Mar 11, 2023
1 parent d53fe3e commit f843627
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 16 deletions.
8 changes: 8 additions & 0 deletions src/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ const static quint8 defaultMavlinkSystemId = 252; // Using 252 to 'crudely' iden
GlobalObject::sharedInstance()->setMavlinkID(ID);
}

inline quint8 ComponentID(){
return GlobalObject::sharedInstance()->ComponentID();
}

inline void setComponentID(const quint8 ID){
GlobalObject::sharedInstance()->setComponentID(ID);
}


//Returns the absolute parth to the files, data, qml support directories
//It could be in 1 of 2 places under Linux
Expand Down
22 changes: 22 additions & 0 deletions src/globalobject.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "logging.h"
#include "configuration.h"
#include "globalobject.h"
#include "mavlink.h"
#include <QSettings>
#include <QDateTime>
#include <QDir>
Expand Down Expand Up @@ -36,6 +37,7 @@ void GlobalObject::loadSettings()
m_parameterDirectory = settings.value("PARAMETER_DIRECTORY", defaultParameterDirectory()).toString();
m_missionDirectory = settings.value("MISSION_DIRECTORY", defaultMissionDirectory()).toString();
m_mavlinkID = static_cast<quint8>(settings.value("MAVLINK_ID", defaultMavlinkID()).toUInt());
m_componentID = static_cast<quint8>(settings.value("COMPONENT_ID", defaultComponentID()).toUInt());

settings.endGroup();
}
Expand All @@ -51,6 +53,7 @@ void GlobalObject::saveSettings()
settings.setValue("PARAMETER_DIRECTORY", m_parameterDirectory);
settings.setValue("MISSION_DIRECTORY", m_missionDirectory);
settings.setValue("MAVLINK_ID", m_mavlinkID);
settings.setValue("COMPONENT_ID", m_componentID);

settings.sync();
}
Expand Down Expand Up @@ -205,6 +208,25 @@ void GlobalObject::setMavlinkID(const quint8 mavlinkID)
m_mavlinkID = mavlinkID;
}

//
// Component ID of APM Planner when uploading Waypoints via mavlink
//

quint8 GlobalObject::defaultComponentID()
{
return MAV_COMP_ID_MISSIONPLANNER;
}

quint8 GlobalObject::ComponentID()
{
return m_componentID;
}

void GlobalObject::setComponentID(const quint8 componentID)
{
m_componentID = componentID;
}


//
// Share Directory
Expand Down
5 changes: 5 additions & 0 deletions src/globalobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ class GlobalObject
quint8 MavlinkID();
void setMavlinkID(const quint8 mavlinkID);

quint8 defaultComponentID();
quint8 ComponentID();
void setComponentID(const quint8 mavlinkID);

QString shareDirectory();

private:
Expand All @@ -83,6 +87,7 @@ class GlobalObject
QString m_parameterDirectory;
QString m_missionDirectory;
quint8 m_mavlinkID;
quint8 m_componentID;

};

Expand Down
26 changes: 14 additions & 12 deletions src/uas/UASWaypointManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ This file is part of the QGROUNDCONTROL project
#include "logging.h"
#include "UASWaypointManager.h"
#include "UAS.h"
#include "UASManager.h"
#include "configuration.h"
#include "MainWindow.h"

#define PROTOCOL_TIMEOUT_MS 2000 ///< maximum time to wait for pending messages until timeout
Expand Down Expand Up @@ -71,6 +71,8 @@ UASWaypointManager::UASWaypointManager(UAS* _uas)
}

m_defaultRelativeAlt = readSetting(DEFAULT_REL_ALT, 20.0f).toDouble();

m_waypointComponentID = QGC::ComponentID();
}

UASWaypointManager::~UASWaypointManager()
Expand Down Expand Up @@ -622,7 +624,7 @@ void UASWaypointManager::clearWaypointList()
current_state = WP_CLEARLIST;
current_wp_id = 0;
current_partner_systemid = uasid;
current_partner_compid = MAV_COMP_ID_MISSIONPLANNER;
current_partner_compid = m_waypointComponentID;

sendWaypointClearAll();
}
Expand Down Expand Up @@ -874,7 +876,7 @@ void UASWaypointManager::readWaypoints(bool readToEdit)
current_state = WP_GETLIST;
current_wp_id = 0;
current_partner_systemid = uasid;
current_partner_compid = MAV_COMP_ID_MISSIONPLANNER;
current_partner_compid = m_waypointComponentID;

sendWaypointRequestList();

Expand Down Expand Up @@ -913,7 +915,7 @@ void UASWaypointManager::goToWaypoint(Waypoint *wp)
mission.z = wp->getZ();
mavlink_message_t message;
mission.target_system = uasid;
mission.target_component = MAV_COMP_ID_MISSIONPLANNER;
mission.target_component = m_waypointComponentID;
//using mavlink_msg_mission_item_int_encode to encode mavlink_mission_item_int_t type message
mavlink_msg_mission_item_int_encode(uas->getSystemId(), uas->getComponentId(), &message, &mission);
uas->sendMessage(message);
Expand All @@ -934,7 +936,7 @@ void UASWaypointManager::writeWaypoints()
current_state = WP_SENDLIST;
current_wp_id = 0;
current_partner_systemid = uasid;
current_partner_compid = MAV_COMP_ID_MISSIONPLANNER;
current_partner_compid = m_waypointComponentID;

//clear local buffer
// Why not replace with waypoint_buffer.clear() ?
Expand Down Expand Up @@ -998,7 +1000,7 @@ void UASWaypointManager::sendWaypointClearAll()
mavlink_mission_clear_all_t wpca;

wpca.target_system = uasid;
wpca.target_component = MAV_COMP_ID_MISSIONPLANNER;
wpca.target_component = m_waypointComponentID;

emit updateStatusString(QString("Clearing waypoint list..."));

Expand All @@ -1015,7 +1017,7 @@ void UASWaypointManager::sendWaypointSetCurrent(quint16 seq)
mavlink_mission_set_current_t wpsc;

wpsc.target_system = uasid;
wpsc.target_component = MAV_COMP_ID_MISSIONPLANNER;
wpsc.target_component = m_waypointComponentID;
wpsc.seq = seq;

emit updateStatusString(QString("Updating target waypoint..."));
Expand All @@ -1032,7 +1034,7 @@ void UASWaypointManager::sendWaypointCount()
mavlink_mission_count_t wpc;

wpc.target_system = uasid;
wpc.target_component = MAV_COMP_ID_MISSIONPLANNER;
wpc.target_component = m_waypointComponentID;
wpc.count = current_count;
wpc.mission_type = MAV_MISSION_TYPE_MISSION;

Expand All @@ -1050,7 +1052,7 @@ void UASWaypointManager::sendWaypointRequestList()
mavlink_mission_request_list_t wprl;

wprl.target_system = uasid;
wprl.target_component = MAV_COMP_ID_MISSIONPLANNER;
wprl.target_component = m_waypointComponentID;

emit updateStatusString(QString("Requesting waypoint list..."));

Expand All @@ -1068,7 +1070,7 @@ void UASWaypointManager::sendWaypointRequest(quint16 seq)
mavlink_mission_request_int_t wpr;

wpr.target_system = uasid;
wpr.target_component = MAV_COMP_ID_MISSIONPLANNER;
wpr.target_component = m_waypointComponentID;
wpr.seq = seq;

emit updateStatusString(QString("Retrieving waypoint ID %1 of %2 total").arg(wpr.seq).arg(current_count));
Expand All @@ -1091,7 +1093,7 @@ void UASWaypointManager::sendWaypoint(quint16 seq)

wp = waypoint_buffer.at(seq);
wp->target_system = uasid;
wp->target_component = MAV_COMP_ID_MISSIONPLANNER;
wp->target_component = m_waypointComponentID;

if (current_state == WP_SENDLIST_SENDWPSINT) {
mavlink_msg_mission_item_int_encode(uas->getSystemId(), uas->getComponentId(), &message, wp);
Expand Down Expand Up @@ -1119,7 +1121,7 @@ void UASWaypointManager::sendWaypointAck(quint8 type)
mavlink_mission_ack_t wpa;

wpa.target_system = uasid;
wpa.target_component = MAV_COMP_ID_MISSIONPLANNER;
wpa.target_component = m_waypointComponentID;
wpa.type = type;

mavlink_msg_mission_ack_encode(uas->getSystemId(), uas->getComponentId(), &message, &wpa);
Expand Down
2 changes: 2 additions & 0 deletions src/uas/UASWaypointManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ public slots:
bool standalone; ///< If standalone is set, do not write to UAS
quint16 uasid;

quint8 m_waypointComponentID{0}; ///< Component ID used for waypoint transmission

double m_defaultAcceptanceRadius; ///< Default Acceptance Radius in meters
double m_defaultRelativeAlt; ///< Default relative alt in meters

Expand Down
10 changes: 10 additions & 0 deletions src/ui/QGCSettingsWidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ void QGCSettingsWidget::showEvent(QShowEvent *evt)
ui->MavlinkspinBox->setValue(QGC::MavlinkID());
connect(ui->MavlinkspinBox, SIGNAL(valueChanged(int)), this, SLOT(mavIdChanged(int)));

ui->ComponentspinBox->setValue(QGC::ComponentID());
connect(ui->ComponentspinBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &QGCSettingsWidget::componentIdChanged);
// Ahgrl sowas muss auch für componentID

connect(UASManager::instance(),SIGNAL(activeUASSet(UASInterface*)),this,SLOT(setActiveUAS(UASInterface*)));
setActiveUAS(UASManager::instance()->getActiveUAS());

Expand Down Expand Up @@ -286,6 +290,12 @@ void QGCSettingsWidget::mavIdChanged(int id)
QGC::setMavlinkID(localID);
}

void QGCSettingsWidget::componentIdChanged(int id)
{
quint8 localID = static_cast<quint8>(id);
QGC::setComponentID(localID);
}

void QGCSettingsWidget::setBetaRelease(bool state)
{
QString type;
Expand Down
2 changes: 2 additions & 0 deletions src/ui/QGCSettingsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ private slots:

void mavIdChanged(int id);

void componentIdChanged(int id);

private:
void setDataRateLineEdits();

Expand Down
56 changes: 52 additions & 4 deletions src/ui/QGCSettingsWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>1014</width>
<height>701</height>
<height>839</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -17,7 +17,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="general">
<attribute name="title">
Expand Down Expand Up @@ -439,23 +439,31 @@
<rect>
<x>10</x>
<y>70</y>
<width>171</width>
<width>170</width>
<height>25</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="text">
<string>Mavlink ID of Apm Planner</string>
</property>
</widget>
<widget class="QSpinBox" name="MavlinkspinBox">
<property name="geometry">
<rect>
<x>180</x>
<x>160</x>
<y>70</y>
<width>100</width>
<height>25</height>
</rect>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Mavlink ID used by APM-Planner when communicating with the UAS. Normally there is no need to change the default.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="minimum">
<number>1</number>
</property>
Expand All @@ -479,6 +487,46 @@
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;After changing the settings on this page you have to restart APM Planner&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QLabel" name="label_15">
<property name="geometry">
<rect>
<x>340</x>
<y>60</y>
<width>180</width>
<height>50</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;Mavlink component ID&lt;br/&gt;when uploading waypoints&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QSpinBox" name="ComponentspinBox">
<property name="geometry">
<rect>
<x>500</x>
<y>70</y>
<width>100</width>
<height>25</height>
</rect>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Component ID used by APM-Planner when uploading waypoints to a UAS. Normally there is no need to change the default.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>255</number>
</property>
<property name="value">
<number>190</number>
</property>
</widget>
</widget>
</widget>
</item>
Expand Down

0 comments on commit f843627

Please sign in to comment.