From 475d622d5d25b549ff0e7a57dfd4cffae0086846 Mon Sep 17 00:00:00 2001 From: Arne-W Date: Tue, 14 Feb 2023 21:34:37 +0100 Subject: [PATCH 1/2] Comms: Fix wrong system ID and component ID for timesync message. Fixes #1270 --- src/uas/UAS.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index 2069d26f1..a8b24ed38 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -1436,7 +1436,7 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message) // QLOG_DEBUG() << "timesync tc1:" << timeSync.tc1 << " ts1:" << timeSync.ts1; mavlink_message_t answer; - mavlink_msg_timesync_encode(message.sysid, message.compid, &answer, &timeSync); + mavlink_msg_timesync_encode(systemId, componentId, &answer, &timeSync); sendMessage(answer); break; } From 18dc5b2e9f2aae421df8cf008cdd6c108507f998 Mon Sep 17 00:00:00 2001 From: Arne-W Date: Tue, 21 Feb 2023 20:44:38 +0100 Subject: [PATCH 2/2] mavlink ComponentID used when handling waypoints can be changed now. --- src/configuration.h | 8 +++++ src/globalobject.cc | 22 ++++++++++++++ src/globalobject.h | 5 ++++ src/uas/UASWaypointManager.cc | 26 ++++++++-------- src/uas/UASWaypointManager.h | 2 ++ src/ui/QGCSettingsWidget.cc | 10 +++++++ src/ui/QGCSettingsWidget.h | 2 ++ src/ui/QGCSettingsWidget.ui | 56 ++++++++++++++++++++++++++++++++--- 8 files changed, 115 insertions(+), 16 deletions(-) diff --git a/src/configuration.h b/src/configuration.h index 3ac72785d..7fc667a29 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -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 diff --git a/src/globalobject.cc b/src/globalobject.cc index a1800797a..f22f1fc16 100644 --- a/src/globalobject.cc +++ b/src/globalobject.cc @@ -1,6 +1,7 @@ #include "logging.h" #include "configuration.h" #include "globalobject.h" +#include "mavlink.h" #include #include #include @@ -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(settings.value("MAVLINK_ID", defaultMavlinkID()).toUInt()); + m_componentID = static_cast(settings.value("COMPONENT_ID", defaultComponentID()).toUInt()); settings.endGroup(); } @@ -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(); } @@ -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 diff --git a/src/globalobject.h b/src/globalobject.h index 700b9c967..7a30f3af4 100644 --- a/src/globalobject.h +++ b/src/globalobject.h @@ -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: @@ -83,6 +87,7 @@ class GlobalObject QString m_parameterDirectory; QString m_missionDirectory; quint8 m_mavlinkID; + quint8 m_componentID; }; diff --git a/src/uas/UASWaypointManager.cc b/src/uas/UASWaypointManager.cc index 61ef1d086..17a77fac0 100644 --- a/src/uas/UASWaypointManager.cc +++ b/src/uas/UASWaypointManager.cc @@ -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 @@ -71,6 +71,8 @@ UASWaypointManager::UASWaypointManager(UAS* _uas) } m_defaultRelativeAlt = readSetting(DEFAULT_REL_ALT, 20.0f).toDouble(); + + m_waypointComponentID = QGC::ComponentID(); } UASWaypointManager::~UASWaypointManager() @@ -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(); } @@ -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(); @@ -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); @@ -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() ? @@ -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...")); @@ -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...")); @@ -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; @@ -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...")); @@ -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)); @@ -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); @@ -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); diff --git a/src/uas/UASWaypointManager.h b/src/uas/UASWaypointManager.h index 6c5ff5664..3182083ed 100644 --- a/src/uas/UASWaypointManager.h +++ b/src/uas/UASWaypointManager.h @@ -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 diff --git a/src/ui/QGCSettingsWidget.cc b/src/ui/QGCSettingsWidget.cc index 6d97b21d0..76953a7cc 100644 --- a/src/ui/QGCSettingsWidget.cc +++ b/src/ui/QGCSettingsWidget.cc @@ -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::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()); @@ -286,6 +290,12 @@ void QGCSettingsWidget::mavIdChanged(int id) QGC::setMavlinkID(localID); } +void QGCSettingsWidget::componentIdChanged(int id) +{ + quint8 localID = static_cast(id); + QGC::setComponentID(localID); +} + void QGCSettingsWidget::setBetaRelease(bool state) { QString type; diff --git a/src/ui/QGCSettingsWidget.h b/src/ui/QGCSettingsWidget.h index c437c9664..f7e0933dd 100644 --- a/src/ui/QGCSettingsWidget.h +++ b/src/ui/QGCSettingsWidget.h @@ -34,6 +34,8 @@ private slots: void mavIdChanged(int id); + void componentIdChanged(int id); + private: void setDataRateLineEdits(); diff --git a/src/ui/QGCSettingsWidget.ui b/src/ui/QGCSettingsWidget.ui index 00523d315..dfa4184f3 100644 --- a/src/ui/QGCSettingsWidget.ui +++ b/src/ui/QGCSettingsWidget.ui @@ -7,7 +7,7 @@ 0 0 1014 - 701 + 839 @@ -17,7 +17,7 @@ - 0 + 1 @@ -439,10 +439,15 @@ 10 70 - 171 + 170 25 + + + 8 + + Mavlink ID of Apm Planner @@ -450,12 +455,15 @@ - 180 + 160 70 100 25 + + <html><head/><body><p>Mavlink ID used by APM-Planner when communicating with the UAS. Normally there is no need to change the default.</p></body></html> + 1 @@ -479,6 +487,46 @@ <html><head/><body><p><span style=" font-weight:600;">After changing the settings on this page you have to restart APM Planner</span></p></body></html> + + + + 340 + 60 + 180 + 50 + + + + + 8 + + + + <html><head/><body>Mavlink component ID<br/>when uploading waypoints</body></html> + + + + + + 500 + 70 + 100 + 25 + + + + <html><head/><body><p>Component ID used by APM-Planner when uploading waypoints to a UAS. Normally there is no need to change the default.</p></body></html> + + + 1 + + + 255 + + + 190 + +