Skip to content
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

Add latch param to throttle #1944

Merged
merged 1 commit into from
Jul 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions tools/topic_tools/src/throttle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ bool g_use_messages;
ros::Time g_last_time;
bool g_use_wallclock;
bool g_lazy;
bool g_force_latch = false;
bool g_force_latch_value = true;
ros::TransportHints g_th;

class Sent
Expand Down Expand Up @@ -87,24 +89,29 @@ void conn_cb(const ros::SingleSubscriberPublisher&)
}
}

bool is_latching(const boost::shared_ptr<const ros::M_string>& connection_header)
{
if (connection_header)
{
ros::M_string::const_iterator it = connection_header->find("latching");
if ((it != connection_header->end()) && (it->second == "1"))
{
ROS_DEBUG("input topic is latched; latching output topic to match");
return true;
}
}

return false;
}

void in_cb(const ros::MessageEvent<ShapeShifter>& msg_event)
{
boost::shared_ptr<ShapeShifter const> const &msg = msg_event.getConstMessage();
boost::shared_ptr<const ros::M_string> const& connection_header = msg_event.getConnectionHeaderPtr();

if (!g_advertised)
{
// If the input topic is latched, make the output topic latched
bool latch = false;
if (connection_header)
{
ros::M_string::const_iterator it = connection_header->find("latching");
if((it != connection_header->end()) && (it->second == "1"))
{
ROS_DEBUG("input topic is latched; latching output topic to match");
latch = true;
}
}
const bool latch = g_force_latch ? g_force_latch_value : is_latching(connection_header);
g_pub = msg->advertise(*g_node, g_output_topic, 10, latch, conn_cb);
g_advertised = true;
printf("advertised as %s\n", g_output_topic.c_str());
Expand Down Expand Up @@ -192,6 +199,7 @@ int main(int argc, char **argv)
pnh.getParam("wall_clock", g_use_wallclock);
pnh.getParam("unreliable", unreliable);
pnh.getParam("lazy", g_lazy);
g_force_latch = pnh.getParam("force_latch", g_force_latch_value);

if (unreliable)
g_th.unreliable().reliable(); // Prefers unreliable, but will accept reliable.
Expand Down