mirror of
https://github.com/swri-robotics/mapviz.git
synced 2025-09-15 17:48:34 +08:00
Make string plugin also support string stamped (#666)
* Make string plugin also support string stamped Co-authored-by: Matthew Bries <matthew.bries@swri.org>
This commit is contained in:
parent
f4d09d8dc3
commit
2dac5a7360
@ -46,7 +46,9 @@
|
||||
|
||||
|
||||
#include <ros/ros.h>
|
||||
#include <topic_tools/shape_shifter.h>
|
||||
#include <std_msgs/String.h>
|
||||
#include <marti_common_msgs/StringStamped.h>
|
||||
|
||||
// QT autogenerated files
|
||||
#include "ui_string_config.h"
|
||||
@ -130,7 +132,7 @@ namespace mapviz_plugins
|
||||
QFont font_;
|
||||
QStaticText message_;
|
||||
|
||||
void stringCallback(const std_msgs::StringConstPtr& str);
|
||||
void stringCallback(const topic_tools::ShapeShifter::ConstPtr& msg);
|
||||
|
||||
std::string AnchorToString(Anchor anchor);
|
||||
std::string UnitsToString(Units units);
|
||||
|
||||
@ -295,7 +295,7 @@ namespace mapviz_plugins
|
||||
void StringPlugin::SelectTopic()
|
||||
{
|
||||
ros::master::TopicInfo topic = mapviz::SelectTopicDialog::selectTopic(
|
||||
"std_msgs/String");
|
||||
"std_msgs/String", "marti_common_msgs/StringStamped");
|
||||
|
||||
if (!topic.name.empty())
|
||||
{
|
||||
@ -318,7 +318,7 @@ namespace mapviz_plugins
|
||||
topic_ = topic;
|
||||
if (!topic.empty())
|
||||
{
|
||||
string_sub_ = node_.subscribe(topic_, 1, &StringPlugin::stringCallback, this);
|
||||
string_sub_ = node_.subscribe<topic_tools::ShapeShifter>(topic_, 1, &StringPlugin::stringCallback, this);
|
||||
|
||||
ROS_INFO("Subscribing to %s", topic_.c_str());
|
||||
}
|
||||
@ -387,9 +387,23 @@ namespace mapviz_plugins
|
||||
offset_y_ = offset;
|
||||
}
|
||||
|
||||
void StringPlugin::stringCallback(const std_msgs::StringConstPtr& str)
|
||||
template <class T, class M>
|
||||
bool is_instance(const M& msg)
|
||||
{
|
||||
message_.setText(QString(str->data.c_str()));
|
||||
return msg->getDataType() == ros::message_traits::datatype<T>();
|
||||
}
|
||||
|
||||
void StringPlugin::stringCallback(const topic_tools::ShapeShifter::ConstPtr& msg)
|
||||
{
|
||||
if (is_instance<std_msgs::String>(msg))
|
||||
{
|
||||
message_.setText(QString(msg->instantiate<std_msgs::String>()->data.c_str()));
|
||||
}
|
||||
else if (is_instance<marti_common_msgs::StringStamped>(msg))
|
||||
{
|
||||
message_.setText(QString(msg->instantiate<marti_common_msgs::StringStamped>()->value.c_str()));
|
||||
}
|
||||
|
||||
message_.prepare(QTransform(), font_);
|
||||
|
||||
has_message_ = true;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user