-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NavSat (GPS) map plugin #342
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ign_gui_add_plugin(NavSatMap | ||
SOURCES | ||
NavSatMap.cc | ||
QT_HEADERS | ||
NavSatMap.hh | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
/* | ||
* Copyright (C) 2021 Open Source Robotics Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
#include "NavSatMap.hh" | ||
|
||
#include <algorithm> | ||
#include <iostream> | ||
#include <limits> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include <ignition/common/Console.hh> | ||
#include <ignition/plugin/Register.hh> | ||
#include <ignition/transport/Node.hh> | ||
|
||
#include "ignition/gui/Application.hh" | ||
|
||
namespace ignition | ||
{ | ||
namespace gui | ||
{ | ||
namespace plugins | ||
{ | ||
class NavSatMapPrivate | ||
{ | ||
/// \brief List of topics publishing navSat messages. | ||
public: QStringList topicList; | ||
|
||
/// \brief Holds data to set as the next navSat | ||
public: msgs::NavSat navSatMsg; | ||
|
||
/// \brief Node for communication. | ||
public: transport::Node node; | ||
|
||
/// \brief Mutex for accessing navSat data | ||
public: std::recursive_mutex navSatMutex; | ||
}; | ||
} | ||
} | ||
} | ||
|
||
using namespace ignition; | ||
using namespace gui; | ||
using namespace plugins; | ||
|
||
///////////////////////////////////////////////// | ||
NavSatMap::NavSatMap() | ||
: Plugin(), dataPtr(new NavSatMapPrivate) | ||
{ | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
NavSatMap::~NavSatMap() | ||
{ | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
void NavSatMap::LoadConfig(const tinyxml2::XMLElement *_pluginElem) | ||
{ | ||
// Default name in case user didn't define one | ||
if (this->title.empty()) | ||
this->title = "Navigation satellite map"; | ||
|
||
std::string topic; | ||
bool topicPicker = true; | ||
|
||
// Read configuration | ||
if (_pluginElem) | ||
{ | ||
if (auto topicElem = _pluginElem->FirstChildElement("topic")) | ||
topic = topicElem->GetText(); | ||
|
||
if (auto pickerElem = _pluginElem->FirstChildElement("topic_picker")) | ||
pickerElem->QueryBoolText(&topicPicker); | ||
} | ||
|
||
if (topic.empty() && !topicPicker) | ||
{ | ||
ignwarn << "Can't hide topic picker without a default topic." << std::endl; | ||
topicPicker = true; | ||
} | ||
|
||
this->PluginItem()->setProperty("showPicker", topicPicker); | ||
|
||
if (!topic.empty()) | ||
{ | ||
this->SetTopicList({QString::fromStdString(topic)}); | ||
this->OnTopic(QString::fromStdString(topic)); | ||
} | ||
else | ||
this->OnRefresh(); | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
void NavSatMap::ProcessMessage() | ||
{ | ||
std::lock_guard<std::recursive_mutex> lock(this->dataPtr->navSatMutex); | ||
|
||
this->newMessage(this->dataPtr->navSatMsg.latitude_deg(), | ||
this->dataPtr->navSatMsg.longitude_deg()); | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
void NavSatMap::OnMessage(const msgs::NavSat &_msg) | ||
{ | ||
std::lock_guard<std::recursive_mutex> lock(this->dataPtr->navSatMutex); | ||
this->dataPtr->navSatMsg = _msg; | ||
|
||
// Signal to main thread that the navSat changed | ||
QMetaObject::invokeMethod(this, "ProcessMessage"); | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
void NavSatMap::OnTopic(const QString _topic) | ||
{ | ||
auto topic = _topic.toStdString(); | ||
if (topic.empty()) | ||
return; | ||
|
||
// Unsubscribe | ||
auto subs = this->dataPtr->node.SubscribedTopics(); | ||
for (auto sub : subs) | ||
this->dataPtr->node.Unsubscribe(sub); | ||
|
||
// Subscribe to new topic | ||
if (!this->dataPtr->node.Subscribe(topic, &NavSatMap::OnMessage, | ||
this)) | ||
{ | ||
ignerr << "Unable to subscribe to topic [" << topic << "]" << std::endl; | ||
} | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
void NavSatMap::OnRefresh() | ||
{ | ||
// Clear | ||
this->dataPtr->topicList.clear(); | ||
|
||
// Get updated list | ||
std::vector<std::string> allTopics; | ||
this->dataPtr->node.TopicList(allTopics); | ||
for (auto topic : allTopics) | ||
{ | ||
std::vector<transport::MessagePublisher> publishers; | ||
this->dataPtr->node.TopicInfo(topic, publishers); | ||
for (auto pub : publishers) | ||
{ | ||
if (pub.MsgTypeName() == "ignition.msgs.NavSat") | ||
{ | ||
this->dataPtr->topicList.push_back(QString::fromStdString(topic)); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
// Select first one | ||
if (this->dataPtr->topicList.count() > 0) | ||
this->OnTopic(this->dataPtr->topicList.at(0)); | ||
this->TopicListChanged(); | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
QStringList NavSatMap::TopicList() const | ||
{ | ||
return this->dataPtr->topicList; | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
void NavSatMap::SetTopicList(const QStringList &_topicList) | ||
{ | ||
this->dataPtr->topicList = _topicList; | ||
this->TopicListChanged(); | ||
} | ||
|
||
// Register this plugin | ||
IGNITION_ADD_PLUGIN(ignition::gui::plugins::NavSatMap, | ||
ignition::gui::Plugin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright (C) 2021 Open Source Robotics Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
#ifndef IGNITION_GUI_PLUGINS_IMAGEDISPLAY_HH_ | ||
#define IGNITION_GUI_PLUGINS_IMAGEDISPLAY_HH_ | ||
|
||
#include <memory> | ||
#ifdef _MSC_VER | ||
#pragma warning(push, 0) | ||
#endif | ||
#include <ignition/msgs/navsat.pb.h> | ||
#ifdef _MSC_VER | ||
#pragma warning(pop) | ||
#endif | ||
|
||
#include "ignition/gui/Plugin.hh" | ||
|
||
namespace ignition | ||
{ | ||
namespace gui | ||
{ | ||
namespace plugins | ||
{ | ||
class NavSatMapPrivate; | ||
|
||
/// \brief Display NavSat messages coming through an Ignition transport topic | ||
/// on top of a map. | ||
/// | ||
/// ## Configuration | ||
/// | ||
/// \<topic\> : Set the topic to receive NavSat messages. | ||
/// \<topic_picker\> : Whether to show the topic picker, true by default. If | ||
/// this is false, a \<topic\> must be specified. | ||
class NavSatMap : public Plugin | ||
{ | ||
Q_OBJECT | ||
|
||
/// \brief Topic list | ||
Q_PROPERTY( | ||
QStringList topicList | ||
READ TopicList | ||
WRITE SetTopicList | ||
NOTIFY TopicListChanged | ||
) | ||
|
||
/// \brief Constructor | ||
public: NavSatMap(); | ||
|
||
/// \brief Destructor | ||
public: virtual ~NavSatMap(); | ||
|
||
// Documentation inherited | ||
public: virtual void LoadConfig(const tinyxml2::XMLElement *_pluginElem); | ||
|
||
/// \brief Callback when refresh button is pressed. | ||
public slots: void OnRefresh(); | ||
|
||
/// \brief Callback when a new topic is chosen on the combo box. | ||
public slots: void OnTopic(const QString _topic); | ||
|
||
/// \brief Get the list of topics publishing NavSat messages | ||
/// \return List of topics | ||
public: Q_INVOKABLE QStringList TopicList() const; | ||
|
||
/// \brief Set the topic list | ||
/// \param[in] _topicList List of topics | ||
public: Q_INVOKABLE void SetTopicList(const QStringList &_topicList); | ||
|
||
/// \brief Notify that topic list has changed | ||
signals: void TopicListChanged(); | ||
|
||
/// \brief Notify that a new message has been received. | ||
/// \param[in] _latitudeDeg Latitude in degrees | ||
/// \param[in] _longitudeDeg Longitude in degrees | ||
signals: void newMessage(double _latitudeDeg, double _longitudeDeg); | ||
|
||
/// \brief Callback in main thread when message changes | ||
private slots: void ProcessMessage(); | ||
|
||
/// \brief Subscriber callback when new message is received | ||
/// \param[in] _msg New message | ||
private: void OnMessage(const ignition::msgs::NavSat &_msg); | ||
|
||
/// \internal | ||
/// \brief Pointer to private data. | ||
private: std::unique_ptr<NavSatMapPrivate> dataPtr; | ||
}; | ||
} | ||
} | ||
} | ||
|
||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if
latitude/longitude_deg
is not set in the new message?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that's a tough one, protobuf doesn't make a distinction between
double
s that are not set or set to zero. I think it's not unreasonable to assume that these values must be set here.We could determine a convention like passing NaN when the fields are unknown. I see that the ROS message specifies NaNs for a missing altitude, but not for missing lat/lon ๐ค https://github.com/ros2/common_interfaces/blob/master/sensor_msgs/msg/NavSatFix.msg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๐ Sounds good to me