Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "jsk_topic_tools/snapshot_nodelet.h"
00037 #include <std_msgs/Time.h>
00038
00039 namespace jsk_topic_tools
00040 {
00041 void Snapshot::onInit()
00042 {
00043 advertised_ = false;
00044 subscribing_ = false;
00045 pnh_ = getPrivateNodeHandle();
00046 pnh_.param("latch", latch_, false);
00047 pub_timestamp_ = pnh_.advertise<std_msgs::Time>("output/stamp", 1);
00048 sub_ = pnh_.subscribe<topic_tools::ShapeShifter>(
00049 "input", 1,
00050 &Snapshot::inputCallback, this);
00051 request_service_ = pnh_.advertiseService(
00052 "request",
00053 &Snapshot::requestCallback, this);
00054 }
00055
00056 void Snapshot::inputCallback(
00057 const boost::shared_ptr<topic_tools::ShapeShifter const>& msg)
00058 {
00059 boost::mutex::scoped_lock lock(mutex_);
00060 if (!advertised_) {
00061 ros::AdvertiseOptions opts("output", 1,
00062 msg->getMD5Sum(),
00063 msg->getDataType(),
00064 msg->getMessageDefinition());
00065 opts.latch = latch_;
00066 pub_ = pnh_.advertise(opts);
00067 advertised_ = true;
00068 if (requested_) {
00069 pub_.publish(msg);
00070 std_msgs::Time timestamp;
00071 timestamp.data = ros::Time::now();
00072 pub_timestamp_.publish(timestamp);
00073 requested_ = false;
00074 }
00075 sub_.shutdown();
00076 }
00077 else {
00078 if (requested_) {
00079 pub_.publish(msg);
00080 std_msgs::Time timestamp;
00081 timestamp.data = ros::Time::now();
00082 pub_timestamp_.publish(timestamp);
00083 requested_ = false;
00084 sub_.shutdown();
00085 }
00086 }
00087 }
00088
00089
00090 bool Snapshot::requestCallback(
00091 std_srvs::Empty::Request& req,
00092 std_srvs::Empty::Response& res)
00093 {
00094 boost::mutex::scoped_lock lock(mutex_);
00095 requested_ = true;
00096 sub_ = pnh_.subscribe<topic_tools::ShapeShifter>(
00097 "input", 1,
00098 &Snapshot::inputCallback, this);
00099 return true;
00100 }
00101
00102 }
00103
00104 #include <pluginlib/class_list_macros.h>
00105 PLUGINLIB_EXPORT_CLASS (jsk_topic_tools::Snapshot, nodelet::Nodelet);