repo_id
stringlengths
19
138
file_path
stringlengths
32
200
content
stringlengths
1
12.9M
__index_level_0__
int64
0
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/test/mux.test
<launch> <node pkg="rostopic" type="rostopic" name="rostopic_pub1" args="pub -r 10 input1 std_msgs/String input1"/> <node pkg="rostopic" type="rostopic" name="rostopic_pub2" args="pub -r 5 input2 std_msgs/String input2"/> <!-- Explicit output name --> <node pkg="topic_tools" type="mux" name="mux_explicit" output="screen" args="output input1 input2"/> <test test-name="mux_hztest_explicit" pkg="rostest" type="hztest"> <param name="topic" value="output"/> <param name="hz" value="10.0"/> <param name="hzerror" value="0.5"/> <param name="test_duration" value="2.0" /> </test> </launch>
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/test/drop.test
<launch> <node pkg="rostopic" type="rostopic" name="rostopic_pub" args="pub -r 10 input std_msgs/String chatter"/> <!-- Automatic output name --> <node pkg="topic_tools" type="drop" name="drop" args="input 1 2"/> <test test-name="drop_hztest" pkg="rostest" type="hztest"> <param name="topic" value="input_drop"/> <param name="hz" value="5.0"/> <param name="hzerror" value="0.5"/> <param name="test_duration" value="2.0" /> </test> <!-- Explicit output name --> <node pkg="topic_tools" type="drop" name="drop_explicit" args="input 1 2 output"/> <test test-name="drop_hztest_explicit" pkg="rostest" type="hztest"> <param name="topic" value="output"/> <param name="hz" value="5.0"/> <param name="hzerror" value="0.5"/> <param name="test_duration" value="2.0" /> </test> </launch>
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/test/test_shapeshifter.cpp
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ********************************************************************/ // Bring in my package's API, which is what I'm testing #include "ros/ros.h" #include "topic_tools/shape_shifter.h" #include "std_msgs/String.h" #include "std_msgs/Int32.h" // Bring in gtest #include <gtest/gtest.h> class ShapeShifterSubscriber : public testing::Test { public: bool success; void messageCallbackInt(const topic_tools::ShapeShifter::ConstPtr& msg) { try { std_msgs::Int32::Ptr s = msg->instantiate<std_msgs::Int32>(); } catch (topic_tools::ShapeShifterException& e) { success = true; } } void messageCallbackString(const topic_tools::ShapeShifter::ConstPtr& msg) { try { std_msgs::String::Ptr s = msg->instantiate<std_msgs::String>(); if (s->data == "chatter") success = true; } catch (topic_tools::ShapeShifterException& e) { } } void messageCallbackLoopback(const topic_tools::ShapeShifter::ConstPtr& msg) { try { std_msgs::String::Ptr s = msg->instantiate<std_msgs::String>(); printf("Got data: %s", s->data.c_str()); if (s->data == "abc123") success = true; } catch (topic_tools::ShapeShifterException& e) { printf("Instantiate failed!\n"); } } protected: ShapeShifterSubscriber() {} void SetUp() { success = false; } void TearDown() {} }; TEST_F(ShapeShifterSubscriber, testInstantiateString) { ros::NodeHandle nh; ros::Subscriber sub = nh.subscribe<topic_tools::ShapeShifter>("input",1,&ShapeShifterSubscriber::messageCallbackString, (ShapeShifterSubscriber*)this); ros::Time t1(ros::Time::now()+ros::Duration(10.0)); while(ros::Time::now() < t1 && !success) { ros::WallDuration(0.01).sleep(); ros::spinOnce(); } EXPECT_FALSE(topic_tools::ShapeShifter::uses_old_API_); if(success) SUCCEED(); else FAIL(); } TEST_F(ShapeShifterSubscriber, testInstantiateInt) { ros::NodeHandle nh; ros::Subscriber sub = nh.subscribe<topic_tools::ShapeShifter>("input",1,&ShapeShifterSubscriber::messageCallbackInt, (ShapeShifterSubscriber*)this); ros::Time t1(ros::Time::now()+ros::Duration(10.0)); while(ros::Time::now() < t1 && !success) { ros::WallDuration(0.01).sleep(); ros::spinOnce(); } EXPECT_FALSE(topic_tools::ShapeShifter::uses_old_API_); if(success) SUCCEED(); else FAIL(); } TEST_F(ShapeShifterSubscriber, testLoopback) { ros::NodeHandle nh; ros::Subscriber sub = nh.subscribe<topic_tools::ShapeShifter>("loopback",1,&ShapeShifterSubscriber::messageCallbackLoopback, (ShapeShifterSubscriber*)this); ros::Time t1(ros::Time::now()+ros::Duration(10.0)); ros::Publisher pub = nh.advertise<std_msgs::String>("loopback", 1); std_msgs::String s; s.data = "abc123"; pub.publish(s); while(ros::Time::now() < t1 && !success) { ros::WallDuration(0.01).sleep(); ros::spinOnce(); } EXPECT_FALSE(topic_tools::ShapeShifter::uses_old_API_); if(success) SUCCEED(); else FAIL(); } int main(int argc, char **argv){ ros::init(argc, argv, "test_shapeshifter"); testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/test/utest.cpp
// Copyright (c) 2009, Willow Garage, Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of Willow Garage, Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. #include "topic_tools/parse.h" #include <gtest/gtest.h> TEST(GetBaseName, simpleName) { std::string in("foo"); std::string expected("foo"); std::string out; ASSERT_TRUE(topic_tools::getBaseName(in, out)); ASSERT_EQ(expected, out); } TEST(GetBaseName, leadingSlash) { std::string in("/foo"); std::string expected("foo"); std::string out; ASSERT_TRUE(topic_tools::getBaseName(in, out)); ASSERT_EQ(expected, out); } TEST(GetBaseName, trailingSlash) { std::string in("foo/"); std::string expected("foo"); std::string out; ASSERT_TRUE(topic_tools::getBaseName(in, out)); ASSERT_EQ(expected, out); } TEST(GetBaseName, multipleLevels) { std::string in("bar/bat/baz/foo"); std::string expected("foo"); std::string out; ASSERT_TRUE(topic_tools::getBaseName(in, out)); ASSERT_EQ(expected, out); } TEST(GetBaseName, multipleSlashes) { std::string in("//bar///bat/baz/foo///"); std::string expected("foo"); std::string out; ASSERT_TRUE(topic_tools::getBaseName(in, out)); ASSERT_EQ(expected, out); } TEST(GetBaseName, emptyName) { std::string in("///"); std::string out; ASSERT_FALSE(topic_tools::getBaseName(in, out)); } int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/test/test_mux_services.py
#!/usr/bin/env python # Software License Agreement (BSD License) # # Copyright (c) 2008, Willow Garage, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # * Neither the name of Willow Garage, Inc. nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # # Author: Brian Gerkey PKG = 'topic_tools' import unittest import rospy from topic_tools.srv import MuxAdd from topic_tools.srv import MuxDelete from topic_tools.srv import MuxList from topic_tools.srv import MuxSelect class MuxServiceTestCase(unittest.TestCase): def make_srv_proxies(self): try: rospy.wait_for_service('mux/add', 5) rospy.wait_for_service('mux/delete', 5) rospy.wait_for_service('mux/list', 5) rospy.wait_for_service('mux/select', 5) except rospy.ROSException as e: self.fail('failed to find a required service: ' + `e`) add_srv = rospy.ServiceProxy('mux/add', MuxAdd) delete_srv = rospy.ServiceProxy('mux/delete', MuxDelete) list_srv = rospy.ServiceProxy('mux/list', MuxList) select_srv = rospy.ServiceProxy('mux/select', MuxSelect) return (add_srv, delete_srv, list_srv, select_srv) def test_add_delete_list(self): add_srv, delete_srv, list_srv, select_srv = self.make_srv_proxies() # Check initial condition topics = list_srv().topics self.assertEquals(set(topics), set(['/input'])) # Add a topic and make sure it's there add_srv('/new_input') topics = list_srv().topics self.assertEquals(set(topics), set(['/input', '/new_input'])) # Try to add the same topic again, make sure it fails, and that # nothing changes. try: add_srv('/new_input') except rospy.ServiceException: pass else: self.fail('service call should have thrown an exception') topics = list_srv().topics self.assertEquals(set(topics), set(['/input', '/new_input'])) # Select a topic, then try to delete it, make sure it fails, and # that nothing changes. select_srv('/input') try: delete_srv('/input') except rospy.ServiceException: pass else: self.fail('service call should have thrown an exception') topics = list_srv().topics self.assertEquals(set(topics), set(['/input', '/new_input'])) # Select nothing, to allow deletion select_srv('__none') # Delete topics delete_srv('/input') topics = list_srv().topics self.assertEquals(set(topics), set(['/new_input'])) delete_srv('/new_input') topics = list_srv().topics self.assertEquals(set(topics), set([])) if __name__ == "__main__": import rostest rostest.unitrun(PKG, 'mux_services', MuxServiceTestCase)
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/test/relay.test
<launch> <node pkg="rostopic" type="rostopic" name="rostopic_pub" args="pub -r 10 input std_msgs/String chatter"/> <!-- Automatic output name --> <node pkg="topic_tools" type="relay" name="relay" args="input"/> <test test-name="relay_hztest" pkg="rostest" type="hztest"> <param name="topic" value="input_relay"/> <param name="hz" value="10.0"/> <param name="hzerror" value="0.5"/> <param name="test_duration" value="2.0" /> </test> <!-- Explicit output name --> <node pkg="topic_tools" type="relay" name="relay_explicit" args="input output"/> <test test-name="relay_hztest_explicit" pkg="rostest" type="hztest"> <param name="topic" value="output"/> <param name="hz" value="10.0"/> <param name="hzerror" value="0.5"/> <param name="test_duration" value="2.0" /> </test> </launch>
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/test/switch_mux_none.test
<launch> <node pkg="rostopic" type="rostopic" name="rostopic_pub1" args="pub -r 10 input1 std_msgs/String chatter"/> <node pkg="rostopic" type="rostopic" name="rostopic_pub2" args="pub -r 5 input2 std_msgs/String chatter"/> <!-- Explicit output name --> <node pkg="topic_tools" type="mux" name="mux_explicit" args="output input1 input2"/> <node pkg="topic_tools" type="mux_select" name="mux_select" args="mux __none"/> <test test-name="switch_mux_none_hztest_explicit" pkg="rostest" type="hztest"> <param name="topic" value="output"/> <param name="hz" value="0.0"/> <param name="hzerror" value="0.5"/> <param name="test_duration" value="2.0" /> </test> </launch>
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/test/test_one_message.py
#!/usr/bin/env python # Software License Agreement (BSD License) # # Copyright (c) 2008, Willow Garage, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # * Neither the name of Willow Garage, Inc. nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. import unittest import rospy import rostest import sys from std_msgs.msg import * class LatchedSub(unittest.TestCase): def msg_cb(self, msg): self.success = True def test_latched_sub(self): rospy.init_node('random_sub') self.success = False sub = rospy.Subscriber("output", String, self.msg_cb) while not self.success: rospy.sleep(rospy.Duration.from_sec(0.5)) self.assertEqual(self.success, True) if __name__ == '__main__': rostest.rosrun('rosbag', 'latched_sub', LatchedSub, sys.argv)
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/test/args.py
# Software License Agreement (BSD License) # # Copyright (c) 2008, Willow Garage, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # * Neither the name of Willow Garage, Inc. nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # # Author: Brian Gerkey # Test that arg-parsing works PKG = 'topic_tools' import unittest import os from subprocess import call class TopicToolsTestCase(unittest.TestCase): def test_drop_invalid(self): cmd = ['rosrun', 'topic_tools', 'drop'] self.assertNotEquals(0, call(cmd)) self.assertNotEquals(0, call(cmd + ['//', '1', '2', 'output'])) self.assertNotEquals(0, call(cmd + ['input', '1', '2', 'output', 'extra'])) self.assertNotEquals(0, call(cmd + ['input', '-1', '2', 'output'])) self.assertNotEquals(0, call(cmd + ['input', '1', '0', 'output'])) def test_mux_invalid(self): cmd = ['rosrun', 'topic_tools', 'mux'] self.assertNotEquals(0, call(cmd)) self.assertNotEquals(0, call(cmd + ['//', 'input'])) def test_switch_mux_invalid(self): cmd = ['rosrun', 'topic_tools', 'switch_mux'] self.assertNotEquals(0, call(cmd)) self.assertNotEquals(0, call(cmd + ['//', 'input'])) def test_relay_invalid(self): cmd = ['rosrun', 'topic_tools', 'relay'] self.assertNotEquals(0, call(cmd)) self.assertNotEquals(0, call(cmd + ['//', 'input'])) if __name__ == "__main__": import rostest rostest.unitrun(PKG, 'topic_tools_arg_parsing', TopicToolsTestCase)
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/test/mux_add.test
<launch> <node pkg="rostopic" type="rostopic" name="rostopic_pub1" args="pub -r 10 input1 std_msgs/String input"/> <node pkg="topic_tools" type="mux" name="mux_explicit" output="screen" args="output input"/> <test test-name="mux_services" pkg="test_topic_tools" type="test_mux_services.py"/> </launch>
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/test/throttle.test
<launch> <node pkg="rostopic" type="rostopic" name="rostopic_pub" args="pub -r 20 input std_msgs/String chatter"/> <!-- Automatic output name --> <node pkg="topic_tools" type="throttle" name="throttle" args="messages input 5"/> <test test-name="throttle_hztest" pkg="rostest" type="hztest"> <param name="topic" value="input_throttle"/> <param name="hz" value="5.0"/> <param name="hzerror" value="1.0"/> <param name="test_duration" value="2.0" /> </test> <!-- Explicit output name --> <node pkg="topic_tools" type="throttle" name="throttle_explicit" args="messages input 5 output"/> <test test-name="throttle_hztest_explicit" pkg="rostest" type="hztest"> <param name="topic" value="output"/> <param name="hz" value="5.0"/> <param name="hzerror" value="1.0"/> <param name="test_duration" value="2.0" /> </test> <!-- Test byte-based throttling. Note that the desired rate for the hztest is a function of both the requested bytes/second and the length of the string being published: 10 msg/sec = 110 B/sec / 11 B/msg (11 = 4-byte length + 7 characters in "chatter") It would be more direct to test the bandwidth directly, but hztest doesn't do that. --> <node pkg="topic_tools" type="throttle" name="throttle_bytes" args="bytes input 110 1 output_bytes"/> <test test-name="throttle_hztest_bytes" pkg="rostest" type="hztest"> <param name="topic" value="output_bytes"/> <param name="hz" value="10.0"/> <!-- Wider tolerance because we're seeing occasional under-minimum failures --> <param name="hzerror" value="1.5"/> <param name="test_duration" value="4.0" /> </test> </launch>
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/test/test_mux_delete_add.py
#!/usr/bin/env python # Software License Agreement (BSD License) # # Copyright (c) 2008, Willow Garage, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # * Neither the name of Willow Garage, Inc. nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # # Author: Brian Gerkey PKG = 'topic_tools' import rospy from topic_tools.srv import MuxAdd from topic_tools.srv import MuxDelete from topic_tools.srv import MuxList from topic_tools.srv import MuxSelect from std_msgs.msg import String def go(): rospy.init_node('chatter') rospy.wait_for_service('mux/add', 5) rospy.wait_for_service('mux/delete', 5) rospy.wait_for_service('mux/list', 5) rospy.wait_for_service('mux/select', 5) add_srv = rospy.ServiceProxy('mux/add', MuxAdd) delete_srv = rospy.ServiceProxy('mux/delete', MuxDelete) list_srv = rospy.ServiceProxy('mux/list', MuxList) select_srv = rospy.ServiceProxy('mux/select', MuxSelect) b_pub = rospy.Publisher('b', String) # Execute the sequence given in #2863 select_srv('c') delete_srv('b') add_srv('b') select_srv('b') # Now start publishing on b while not rospy.is_shutdown(): b_pub.publish('foo') rospy.sleep(0.2) if __name__ == "__main__": go()
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/include
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/include/topic_tools/shape_shifter.h
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ********************************************************************/ #ifndef TOPIC_TOOLS_SHAPE_SHIFTER_H #define TOPIC_TOOLS_SHAPE_SHIFTER_H #include "ros/ros.h" #include "ros/console.h" #include "ros/assert.h" #include <vector> #include <string> #include <string.h> #include <ros/message_traits.h> #include "macros.h" namespace topic_tools { class ShapeShifterException : public ros::Exception { public: ShapeShifterException(const std::string& msg) : ros::Exception(msg) {} }; class TOPIC_TOOLS_DECL ShapeShifter { public: typedef boost::shared_ptr<ShapeShifter> Ptr; typedef boost::shared_ptr<ShapeShifter const> ConstPtr; static bool uses_old_API_; // Constructor and destructor ShapeShifter(); virtual ~ShapeShifter(); // Helpers for inspecting shapeshifter std::string const& getDataType() const; std::string const& getMD5Sum() const; std::string const& getMessageDefinition() const; void morph(const std::string& md5sum, const std::string& datatype, const std::string& msg_def, const std::string& latching); // Helper for advertising ros::Publisher advertise(ros::NodeHandle& nh, const std::string& topic, uint32_t queue_size_, bool latch=false, const ros::SubscriberStatusCallback &connect_cb=ros::SubscriberStatusCallback()) const; //! Call to try instantiating as a particular type template<class M> boost::shared_ptr<M> instantiate() const; //! Write serialized message contents out to a stream template<typename Stream> void write(Stream& stream) const; template<typename Stream> void read(Stream& stream); //! Return the size of the serialized message uint32_t size() const; private: std::string md5, datatype, msg_def, latching; bool typed; uint8_t *msgBuf; uint32_t msgBufUsed; uint32_t msgBufAlloc; }; } // Message traits allow shape shifter to work with the new serialization API namespace ros { namespace message_traits { template <> struct IsMessage<topic_tools::ShapeShifter> : TrueType { }; template <> struct IsMessage<const topic_tools::ShapeShifter> : TrueType { }; template<> struct MD5Sum<topic_tools::ShapeShifter> { static const char* value(const topic_tools::ShapeShifter& m) { return m.getMD5Sum().c_str(); } // Used statically, a shapeshifter appears to be of any type static const char* value() { return "*"; } }; template<> struct DataType<topic_tools::ShapeShifter> { static const char* value(const topic_tools::ShapeShifter& m) { return m.getDataType().c_str(); } // Used statically, a shapeshifter appears to be of any type static const char* value() { return "*"; } }; template<> struct Definition<topic_tools::ShapeShifter> { static const char* value(const topic_tools::ShapeShifter& m) { return m.getMessageDefinition().c_str(); } }; } // namespace message_traits namespace serialization { template<> struct Serializer<topic_tools::ShapeShifter> { template<typename Stream> inline static void write(Stream& stream, const topic_tools::ShapeShifter& m) { m.write(stream); } template<typename Stream> inline static void read(Stream& stream, topic_tools::ShapeShifter& m) { m.read(stream); } inline static uint32_t serializedLength(const topic_tools::ShapeShifter& m) { return m.size(); } }; template<> struct PreDeserialize<topic_tools::ShapeShifter> { static void notify(const PreDeserializeParams<topic_tools::ShapeShifter>& params) { std::string md5 = (*params.connection_header)["md5sum"]; std::string datatype = (*params.connection_header)["type"]; std::string msg_def = (*params.connection_header)["message_definition"]; std::string latching = (*params.connection_header)["latching"]; params.message->morph(md5, datatype, msg_def, latching); } }; } // namespace serialization } //namespace ros // Template implementations: namespace topic_tools { // // only used in testing, seemingly // template<class M> boost::shared_ptr<M> ShapeShifter::instantiate() const { if (!typed) throw ShapeShifterException("Tried to instantiate message from an untyped shapeshifter."); if (ros::message_traits::datatype<M>() != getDataType()) throw ShapeShifterException("Tried to instantiate message without matching datatype."); if (ros::message_traits::md5sum<M>() != getMD5Sum()) throw ShapeShifterException("Tried to instantiate message without matching md5sum."); boost::shared_ptr<M> p(boost::make_shared<M>()); ros::serialization::IStream s(msgBuf, msgBufUsed); ros::serialization::deserialize(s, *p); return p; } template<typename Stream> void ShapeShifter::write(Stream& stream) const { if (msgBufUsed > 0) memcpy(stream.advance(msgBufUsed), msgBuf, msgBufUsed); } template<typename Stream> void ShapeShifter::read(Stream& stream) { stream.getLength(); stream.getData(); // stash this message in our buffer if (stream.getLength() > msgBufAlloc) { delete[] msgBuf; msgBuf = new uint8_t[stream.getLength()]; msgBufAlloc = stream.getLength(); } msgBufUsed = stream.getLength(); memcpy(msgBuf, stream.getData(), stream.getLength()); } } // namespace topic_tools #endif
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/include
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/include/topic_tools/parse.h
// Copyright (c) 2009, Willow Garage, Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of Willow Garage, Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. // Reusable parser routines #include <string> #include "macros.h" namespace topic_tools { // Strip any leading namespace qualification from a topic (or other kind // of) ROS name TOPIC_TOOLS_DECL bool getBaseName(const std::string& full_name, std::string& base_name); }
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/include
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/include/topic_tools/macros.h
/* * Copyright (C) 2008, Willow Garage, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef TOPIC_TOOLS_MACROS_H_ #define TOPIC_TOOLS_MACROS_H_ #include <ros/macros.h> // for the DECL's // Import/export for windows dll's and visibility for gcc shared libraries. #ifdef ROS_BUILD_SHARED_LIBS // ros is being built around shared libraries #ifdef topic_tools_EXPORTS // we are building a shared lib/dll #define TOPIC_TOOLS_DECL ROS_HELPER_EXPORT #else // we are using shared lib/dll #define TOPIC_TOOLS_DECL ROS_HELPER_IMPORT #endif #else // ros is being built around static libraries #define TOPIC_TOOLS_DECL #endif #endif /* TOPIC_TOOLS_MACROS_H_ */
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/env-hooks/20.transform.bash
function _roscomplete_node_transform { local arg opts COMPREPLY=() arg="${COMP_WORDS[COMP_CWORD]}" local cword=$COMP_CWORD for a in $(seq $((COMP_CWORD-1))); do if [ -z "${COMP_WORDS[a]//-*}" ]; then ((cword--)) fi done local words=(${COMP_WORDS[@]//-*}) if [[ $cword == 3 ]]; then opts=`rostopic list 2> /dev/null` COMPREPLY=($(compgen -W "$opts" -- ${arg})) elif [[ $cword == 5 ]]; then opts=`rosmsg list 2> /dev/null` COMPREPLY=($(compgen -W "$opts" -- ${arg})) fi } _sav_transform_roscomplete_rosrun=$(complete | grep -w rosrun | awk '{print $3}') function is_transform_node { local words=(${COMP_WORDS[@]//-*}) [ ${#words[@]} -gt 2 ] && \ [ "${words[1]}" = "topic_tools" ] && \ [ "${words[2]}" = "transform" ] } function _roscomplete_rosrun_transform { if is_transform_node; then _roscomplete_node_transform else eval "$_sav_transform_roscomplete_rosrun" fi } complete -F "_roscomplete_rosrun_transform" "rosrun"
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/scripts/demux_add
#!/usr/bin/env python # Software License Agreement (BSD License) # # Copyright (c) 2008, Willow Garage, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # * Neither the name of Willow Garage, Inc. nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. import sys import os import string import rospy # imports the DemuxAdd service from topic_tools.srv import DemuxAdd USAGE = 'USAGE: demux_add DEMUX_NAME TOPIC' def call_srv(m, t): # There's probably a nicer rospy way of doing this s = m + '/add' print "Waiting for service \"%s\""%(s) rospy.wait_for_service(s) print "Adding \"%s\" to demux \"%s\""%(t, m) try: srv = rospy.ServiceProxy(s, DemuxAdd) return srv(t) except rospy.ServiceException, e: print "Service call failed: %s"%e def usage(): return "%s "%sys.argv[0] if __name__ == "__main__": args = rospy.myargv() if len(args) != 3: print USAGE sys.exit(1) m = args[1] t = args[2] call_srv(m, t)
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/scripts/demux_select
#!/usr/bin/env python # Software License Agreement (BSD License) # # Copyright (c) 2008, Willow Garage, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # * Neither the name of Willow Garage, Inc. nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. import sys import os import string import rospy # imports the DemuxSelect service from topic_tools.srv import DemuxSelect USAGE = 'USAGE: demux_select DEMUX_NAME TOPIC' def call_srv(m, t): # There's probably a nicer rospy way of doing this s = m + '/select' print "Waiting for service \"%s\""%(s) rospy.wait_for_service(s) print "Selecting \"%s\" at demux \"%s\""%(t, m) try: srv = rospy.ServiceProxy(s, DemuxSelect) return srv(t) except rospy.ServiceException, e: print "Service call failed: %s"%e def usage(): return "%s "%sys.argv[0] if __name__ == "__main__": args = rospy.myargv() if len(args) != 3: print USAGE sys.exit(1) m = args[1] t = args[2] call_srv(m, t)
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/scripts/mux_select
#!/usr/bin/env python # Software License Agreement (BSD License) # # Copyright (c) 2008, Willow Garage, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # * Neither the name of Willow Garage, Inc. nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. import sys import os import string import rospy # imports the MuxSelect service from topic_tools.srv import MuxSelect USAGE = 'USAGE: mux_select MUX_NAME TOPIC' def call_srv(m, t): # There's probably a nicer rospy way of doing this s = m + '/select' print "Waiting for service \"%s\""%(s) rospy.wait_for_service(s) print "Selecting \"%s\" at mux \"%s\""%(t, m) try: srv = rospy.ServiceProxy(s, MuxSelect) return srv(t) except rospy.ServiceException as e: print "Service call failed: %s"%e def usage(): return "%s "%sys.argv[0] if __name__ == "__main__": args = rospy.myargv() if len(args) != 3: print USAGE sys.exit(1) m = args[1] t = args[2] call_srv(m, t)
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/scripts/demux_delete
#!/usr/bin/env python # Software License Agreement (BSD License) # # Copyright (c) 2008, Willow Garage, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # * Neither the name of Willow Garage, Inc. nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. import sys import os import rospy # imports the DemuxDelete service from topic_tools.srv import DemuxDelete USAGE = 'USAGE: demux_delete DEMUX_NAME TOPIC' def call_srv(m, t): # There's probably a nicer rospy way of doing this s = m + '/delete' print "Waiting for service \"%s\""%(s) rospy.wait_for_service(s) print "Deleting \"%s\" from demux \"%s\""%(t, m) try: srv = rospy.ServiceProxy(s, DemuxDelete) return srv(t) except rospy.ServiceException, e: print "Service call failed: %s"%e def usage(): return "%s "%sys.argv[0] if __name__ == "__main__": args = rospy.myargv() if len(args) != 3: print USAGE sys.exit(1) m = args[1] t = args[2] call_srv(m, t)
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/scripts/mux_delete
#!/usr/bin/env python # Software License Agreement (BSD License) # # Copyright (c) 2008, Willow Garage, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # * Neither the name of Willow Garage, Inc. nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. import sys import os import rospy # imports the MuxDelete service from topic_tools.srv import MuxDelete USAGE = 'USAGE: mux_delete MUX_NAME TOPIC' def call_srv(m, t): # There's probably a nicer rospy way of doing this s = m + '/delete' print "Waiting for service \"%s\""%(s) rospy.wait_for_service(s) print "Deleting \"%s\" from mux \"%s\""%(t, m) try: srv = rospy.ServiceProxy(s, MuxDelete) return srv(t) except rospy.ServiceException as e: print "Service call failed: %s"%e def usage(): return "%s "%sys.argv[0] if __name__ == "__main__": args = rospy.myargv() if len(args) != 3: print USAGE sys.exit(1) m = args[1] t = args[2] call_srv(m, t)
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/scripts/relay_field
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Allows to take a topic or one of its fields and output it on another topic or fields. The operations are done on the message, which is taken in the variable 'm'. Example: $ rosrun topic_tools relay_field /chatter /header std_msgs/Header "seq: 0 stamp: secs: 0 nsecs: 0 frame_id: m.data" """ from __future__ import print_function import argparse import sys import copy import yaml import roslib import rospy import rostopic import genpy import std_msgs __author__ = '[email protected] (Kentaro Wada)' def _eval_in_dict_impl(dict_, globals_, locals_): res = copy.deepcopy(dict_) for k, v in res.items(): type_ = type(v) if type_ is dict: res[k] = _eval_in_dict_impl(v, globals_, locals_) elif (type_ is str) or (type_ is unicode): try: res[k] = eval(v, globals_, locals_) except NameError: pass except SyntaxError: pass return res class RelayField(object): def __init__(self): parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter, description=( 'Allows to relay field data from one topic to another.\n\n' 'Usage:\n\trosrun topic_tools relay_field ' '<input> <output topic> <output type> ' '<expression on m>\n\n' 'Example:\n\trosrun topic_tools relay_field ' '/chatter /header std_msgs/Header\n\t' '"seq: 0\n\t stamp:\n\t secs: 0\n\t nsecs: 0\n\t ' 'frame_id: m.data"\n\n' ) ) parser.add_argument('input', help='Input topic or topic field.') parser.add_argument('output_topic', help='Output topic.') parser.add_argument('output_type', help='Output topic type.') parser.add_argument( 'expression', help='Python expression to apply on the input message \'m\'.' ) parser.add_argument( '--wait-for-start', action='store_true', help='Wait for input messages.' ) # get and strip out ros args first argv = rospy.myargv() args = parser.parse_args(argv[1:]) self.expression = args.expression input_class, input_topic, self.input_fn = rostopic.get_topic_class( args.input, blocking=args.wait_for_start) if input_topic is None: print('ERROR: Wrong input topic (or topic field): %s' % args.input, file=sys.stderr) sys.exit(1) self.output_class = roslib.message.get_message_class(args.output_type) self.sub = rospy.Subscriber(input_topic, input_class, self.callback) self.pub = rospy.Publisher(args.output_topic, self.output_class, queue_size=1) def callback(self, m): if self.input_fn is not None: m = self.input_fn(m) msg_generation = yaml.load(self.expression) pub_args = _eval_in_dict_impl(msg_generation, None, {'m': m}) now = rospy.get_rostime() keys = {'now': now, 'auto': std_msgs.msg.Header(stamp=now)} msg = self.output_class() genpy.message.fill_message_args(msg, [pub_args], keys=keys) self.pub.publish(msg) if __name__ == '__main__': rospy.init_node('relay_field', anonymous=True) app = RelayField() rospy.spin()
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/scripts/mux_list
#!/usr/bin/env python # Software License Agreement (BSD License) # # Copyright (c) 2008, Willow Garage, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # * Neither the name of Willow Garage, Inc. nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. import sys import os import string import rospy # imports the MuxList service from topic_tools.srv import MuxList USAGE = 'USAGE: mux_list MUX_NAME' def call_srv(m): # There's probably a nicer rospy way of doing this s = m + '/list' print "Waiting for service \"%s\""%(s) rospy.wait_for_service(s) print "Listing topics from mux \"%s\""%(m) try: srv = rospy.ServiceProxy(s, MuxList) resp = srv() if resp: print resp.topics return resp except rospy.ServiceException as e: print "Service call failed: %s"%e def usage(): return "%s "%sys.argv[0] if __name__ == "__main__": args = rospy.myargv() if len(args) != 2: print USAGE sys.exit(1) m = args[1] call_srv(m)
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/scripts/mux_add
#!/usr/bin/env python # Software License Agreement (BSD License) # # Copyright (c) 2008, Willow Garage, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # * Neither the name of Willow Garage, Inc. nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. import sys import os import string import rospy # imports the MuxAdd service from topic_tools.srv import MuxAdd USAGE = 'USAGE: mux_add MUX_NAME TOPIC' def call_srv(m, t): # There's probably a nicer rospy way of doing this s = m + '/add' print "Waiting for service \"%s\""%(s) rospy.wait_for_service(s) print "Adding \"%s\" to mux \"%s\""%(t, m) try: srv = rospy.ServiceProxy(s, MuxAdd) return srv(t) except rospy.ServiceException as e: print "Service call failed: %s"%e def usage(): return "%s "%sys.argv[0] if __name__ == "__main__": args = rospy.myargv() if len(args) != 3: print USAGE sys.exit(1) m = args[1] t = args[2] call_srv(m, t)
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/scripts/transform
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @author: enriquefernandez Allows to take a topic or one of it fields and output it on another topic after performing a valid python operation. The operations are done on the message, which is taken in the variable 'm'. * Examples (note that numpy is imported by default): $ rosrun topic_tools transform /imu/orientation/x /x_str std_msgs/String 'str(m)' $ rosrun topic_tools transform /imu/orientation/x /x_in_degrees std_msgs/Float64 -- '-numpy.rad2deg(m)' $ rosrun topic_tools transform /imu/orientation /norm std_msgs/Float64 'numpy.sqrt(numpy.sum(numpy.array([m.x, m.y, m.z, m.w])))' $ rosrun topic_tools transform /imu/orientation /norm std_msgs/Float64 'numpy.linalg.norm([m.x, m.y, m.z, m.w])' $ rosrun topic_tools transform /imu/orientation /euler geometry_msgs/Vector3 'tf.transformations.euler_from_quaternion([m.x, m.y, m.z, m.w])' --import tf """ from __future__ import print_function import roslib import rospy import rostopic import argparse import importlib import sys class TopicOp: def __init__(self): parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter, description='Apply a Python operation to a topic.\n\n' 'A node is created that subscribes to a topic,\n' 'applies a Python expression to the topic (or topic\n' 'field) message \'m\', and publishes the result\n' 'through another topic.\n\n' 'Usage:\n\trosrun topic_tools transform ' '<input> <output topic> <output type> ' '[<expression on m>] [--import numpy tf]\n\n' 'Example:\n\trosrun topic_tools transform /imu/orientation ' '/norm std_msgs/Float64 ' '\'sqrt(sum(array([m.x, m.y, m.z, m.w])))\'') parser.add_argument('input', help='Input topic or topic field.') parser.add_argument('output_topic', help='Output topic.') parser.add_argument('output_type', help='Output topic type.') parser.add_argument( 'expression', default='m', help='Python expression to apply on the input message \'m\'.' ) parser.add_argument( '-i', '--import', dest='modules', nargs='+', default=['numpy'], help='List of Python modules to import.' ) parser.add_argument( '--wait-for-start', action='store_true', help='Wait for input messages.' ) # get and strip out ros args first argv = rospy.myargv() args = parser.parse_args(argv[1:]) self.modules = {} for module in args.modules: try: mod = importlib.import_module(module) except ImportError: print('Failed to import module: %s' % module, file=sys.stderr) else: self.modules[module] = mod self.expression = args.expression input_class, input_topic, self.input_fn = rostopic.get_topic_class( args.input, blocking=args.wait_for_start) if input_topic is None: print('ERROR: Wrong input topic (or topic field): %s' % args.input, file=sys.stderr) sys.exit(1) self.output_class = roslib.message.get_message_class(args.output_type) self.sub = rospy.Subscriber(input_topic, input_class, self.callback) self.pub = rospy.Publisher(args.output_topic, self.output_class, queue_size=1) def callback(self, m): if self.input_fn is not None: m = self.input_fn(m) try: res = eval("{}".format(self.expression), self.modules, {'m': m}) except NameError as e: print("Expression using variables other than 'm': %s" % e.message, file=sys.stderr) except UnboundLocalError as e: print('Wrong expression:%s' % e.message, file=sys.stderr) except Exception: raise else: if not isinstance(res, (list, tuple)): res = [res] self.pub.publish(*res) if __name__ == '__main__': rospy.init_node('transform', anonymous=True) app = TopicOp() rospy.spin()
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/scripts/demux_list
#!/usr/bin/env python # Software License Agreement (BSD License) # # Copyright (c) 2008, Willow Garage, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # * Neither the name of Willow Garage, Inc. nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. import sys import os import string import rospy # imports the DemuxList service from topic_tools.srv import DemuxList USAGE = 'USAGE: demux_list DEMUX_NAME' def call_srv(m): # There's probably a nicer rospy way of doing this s = m + '/list' print "Waiting for service \"%s\""%(s) rospy.wait_for_service(s) print "Listing topics from demux \"%s\""%(m) try: srv = rospy.ServiceProxy(s, DemuxList) resp = srv() if resp: print resp.topics return resp except rospy.ServiceException, e: print "Service call failed: %s"%e def usage(): return "%s "%sys.argv[0] if __name__ == "__main__": args = rospy.myargv() if len(args) != 2: print USAGE sys.exit(1) m = args[1] call_srv(m)
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/demos/test_drop
#!/bin/bash xterm -e "source ~/.bashrc && rosrun roscpp_tutorials talker" & xterm -e "source ~/.bashrc && rosrun roscpp_tutorials listener chatter:=chatter_drop" & # this will make it drop 2 out of 3 messages rosrun topic_tools drop chatter 2 3
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/demos/test_mux
#!/bin/bash #xterm -e "roscore" & #sleep 2 xterm -e "source ~/.bashrc && roscd roscpp_tutorials/bin; ./talker" & sleep 2 xterm -e "source ~/.bashrc && roscd roscpp_tutorials/bin; ./talker __name:=talker2 chatter:=chatter2" & xterm -e "source ~/.bashrc && roscd roscpp_tutorials/bin; ./listener chatter:=chat" & ./mux chat chatter chatter2 #valgrind -v ./mux chat chatter chatter2
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/demos/test_throttle
#!/bin/bash xterm -e "source ~/.bashrc && rosrun roscpp_tutorials talker" & xterm -e "source ~/.bashrc && rosrun roscpp_tutorials listener chatter:=chatter_throttle" & # this will make it drop 2 out of 3 messages #valgrind rosrun topic_tools throttle chatter 50 1 valgrind ./throttle chatter 50 1
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/demos/test_relay
#!/bin/bash #xterm -e "roscore" & #sleep 2 xterm -e "source ~/.bashrc && roscd roscpp_tutorials/bin; ./talker" & xterm -e "source ~/.bashrc && roscd roscpp_tutorials/bin; ./listener chatter:=chatter_relay" & ./relay chatter
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/srv/DemuxSelect.srv
string topic --- string prev_topic
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/srv/DemuxDelete.srv
string topic ---
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/srv/DemuxList.srv
--- string[] topics
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/srv/MuxSelect.srv
string topic --- string prev_topic
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/srv/MuxList.srv
--- string[] topics
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/srv/MuxAdd.srv
string topic ---
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/srv/DemuxAdd.srv
string topic ---
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/srv/MuxDelete.srv
string topic ---
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/src/parse.cpp
// Copyright (c) 2009, Willow Garage, Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of Willow Garage, Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. // Reusable parser routines #include "topic_tools/parse.h" #include <ros/console.h> namespace topic_tools { // Strip any leading namespace qualification from a topic (or other kind // of) ROS name bool getBaseName(const std::string& full_name, std::string& base_name) { std::string tmp = full_name; int i = tmp.rfind('/'); // Strip off trailing slahes (are those legal anyway?) while((tmp.size() > 0) && (i >= (int)(tmp.size() - 1))) { tmp = tmp.substr(0,tmp.size()-1); i = tmp.rfind('/'); } if(tmp.size() == 0) { ROS_ERROR("Base name extracted from \"%s\" is an empty string", full_name.c_str()); return false; } if(i < 0) base_name = tmp; else base_name = tmp.substr(i+1, tmp.size()-i-1); return true; } }
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/src/switch_mux.cpp
/////////////////////////////////////////////////////////////////////////////// // The mux package provides a generic multiplexer // // Copyright (C) 2008, Morgan Quigley // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of Stanford University nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. ///////////////////////////////////////////////////////////////////////////// #include <cstdio> #include "ros/console.h" #include "ros/ros.h" #include "topic_tools/MuxSelect.h" #include "topic_tools/parse.h" using namespace std; using namespace ros; using namespace topic_tools; int main(int argc, char **argv) { ROS_WARN("topic_tools/switch_mux is deprecated; please use topic_tools/mux_select instead"); if (argc < 3) { printf("usage: switch MUXED_TOPIC SELECT_TOPIC\n"); return 1; } std::string topic_name; if(!getBaseName(string(argv[1]), topic_name)) return 1; ros::init(argc, argv, topic_name + string("_switcher")); ros::NodeHandle nh; string srv_name = string(argv[1]) + "_select"; ROS_INFO("Waiting for service %s...\n", srv_name.c_str()); ros::service::waitForService(srv_name, -1); ros::ServiceClient client = nh.serviceClient<MuxSelect>(srv_name); MuxSelect cmd; cmd.request.topic = argv[2]; if (client.call(cmd)) { ROS_INFO("muxed topic %s successfully switched from %s to %s", argv[1], cmd.response.prev_topic.c_str(), cmd.request.topic.c_str()); return 0; } else { ROS_ERROR("failed to switch muxed topic %s to %s", argv[1], cmd.request.topic.c_str()); return 1; } }
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/src/drop.cpp
/////////////////////////////////////////////////////////////////////////////// // drop will (intentionally) drop X out of every Y messages that hits it // // Copyright (C) 2009, Morgan Quigley // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of Stanford University nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. ///////////////////////////////////////////////////////////////////////////// #include <cstdlib> #include <cstdio> #include "topic_tools/shape_shifter.h" #include "topic_tools/parse.h" using std::string; using std::vector; using namespace topic_tools; static ros::NodeHandle *g_node = NULL; static int g_x = 0, g_y = 1; static bool g_advertised = false; static string g_output_topic; static ros::Publisher g_pub; void in_cb(const boost::shared_ptr<ShapeShifter const>& msg) { static int s_count = 0; if (!g_advertised) { g_pub = msg->advertise(*g_node, g_output_topic, 10); g_advertised = true; printf("advertised as %s\n", g_output_topic.c_str()); } if (s_count >= g_x) g_pub.publish(msg); ++s_count; if (s_count >= g_y) s_count = 0; } #define USAGE "\nusage: drop IN_TOPIC X Y [OUT_TOPIC]\n\n" \ " This program will drop X out of every Y messages from IN_TOPIC,\n" \ " forwarding the rest to OUT_TOPIC if given, else to a topic \n" \ " named IN_TOPIC_drop\n\n" int main(int argc, char **argv) { if(argc < 2) { puts(USAGE); return 1; } std::string topic_name; if(!getBaseName(string(argv[1]), topic_name)) return 1; ros::init(argc, argv, topic_name + string("_drop"), ros::init_options::AnonymousName); if ((argc != 4 && argc != 5) || atoi(argv[2]) < 0 || atoi(argv[3]) < 1) { puts(USAGE); return 1; } if (argc == 4) g_output_topic = string(argv[1]) + string("_drop"); else // argc == 5 g_output_topic = string(argv[4]); ros::NodeHandle n; g_node = &n; g_x = atoi(argv[2]); g_y = atoi(argv[3]); ros::Subscriber sub = n.subscribe<ShapeShifter>(string(argv[1]), 10, in_cb); ros::spin(); return 0; }
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/src/mux.cpp
/////////////////////////////////////////////////////////////////////////////// // demux is a generic ROS topic demultiplexer: one input topic is fanned out // to 1 of N output topics. A service is provided to select between the outputs // // Copyright (C) 2009, Morgan Quigley // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of Stanford University nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. ///////////////////////////////////////////////////////////////////////////// #include <cstdio> #include <vector> #include <list> #include "ros/console.h" #include "std_msgs/String.h" #include "topic_tools/MuxSelect.h" #include "topic_tools/MuxAdd.h" #include "topic_tools/MuxList.h" #include "topic_tools/MuxDelete.h" #include "topic_tools/shape_shifter.h" #include "topic_tools/parse.h" using std::string; using std::vector; using std::list; using namespace topic_tools; const static string g_none_topic = "__none"; static ros::NodeHandle *g_node = NULL; static bool g_lazy = false; static bool g_advertised = false; static string g_output_topic; static ros::Publisher g_pub; static ros::Publisher g_pub_selected; struct sub_info_t { std::string topic_name; ros::Subscriber *sub; ShapeShifter* msg; }; void in_cb(const boost::shared_ptr<ShapeShifter const>& msg, ShapeShifter* s); static list<struct sub_info_t> g_subs; static list<struct sub_info_t>::iterator g_selected = g_subs.end(); void conn_cb(const ros::SingleSubscriberPublisher&) { // If we're in lazy subscribe mode, and the first subscriber just // connected, then subscribe if(g_lazy && g_selected != g_subs.end() && !g_selected->sub) { ROS_DEBUG("lazy mode; resubscribing to %s", g_selected->topic_name.c_str()); g_selected->sub = new ros::Subscriber(g_node->subscribe<ShapeShifter>(g_selected->topic_name, 10, boost::bind(in_cb, _1, g_selected->msg))); } } bool sel_srv_cb( topic_tools::MuxSelect::Request &req, topic_tools::MuxSelect::Response &res ) { bool ret = false; if (g_selected != g_subs.end()) { res.prev_topic = g_selected->topic_name; // Unsubscribe to old topic if lazy if (g_lazy) { ROS_DEBUG("Unsubscribing to %s, lazy", res.prev_topic.c_str()); if (g_selected->sub) g_selected->sub->shutdown(); delete g_selected->sub; g_selected->sub = NULL; } } else res.prev_topic = string(""); // see if it's the magical '__none' topic, in which case we open the circuit if (req.topic == g_none_topic) { ROS_INFO("mux selected to no input."); g_selected = g_subs.end(); ret = true; } else { ROS_INFO("trying to switch mux to %s", req.topic.c_str()); // spin through our vector of inputs and find this guy for (list<struct sub_info_t>::iterator it = g_subs.begin(); it != g_subs.end(); ++it) { if (ros::names::resolve(it->topic_name) == ros::names::resolve(req.topic)) { g_selected = it; ROS_INFO("mux selected input: [%s]", it->topic_name.c_str()); ret = true; if (!g_selected->sub && (!g_advertised || g_pub.getNumSubscribers())) { g_selected->sub = new ros::Subscriber(g_node->subscribe<ShapeShifter>(g_selected->topic_name, 10, boost::bind(in_cb, _1, g_selected->msg))); } } } } if(ret) { std_msgs::String t; t.data = req.topic; g_pub_selected.publish(t); } return ret; } bool sel_srv_cb_dep( topic_tools::MuxSelect::Request &req, topic_tools::MuxSelect::Response &res ) { ROS_WARN("the <topic>_select service is deprecated; use mux/select instead"); return sel_srv_cb(req,res); } void in_cb(const boost::shared_ptr<ShapeShifter const>& msg, ShapeShifter* s) { if (!g_advertised) { ROS_INFO("advertising"); g_pub = msg->advertise(*g_node, g_output_topic, 10, false, conn_cb); g_advertised = true; // If lazy, unregister from all but the selected topic if (g_lazy) { for (static list<struct sub_info_t>::iterator it = g_subs.begin(); it != g_subs.end(); ++it) { if (it != g_selected) { ROS_INFO("Unregistering from %s", it->topic_name.c_str()); if (it->sub) it->sub->shutdown(); delete it->sub; it->sub = NULL; } } } } if (s != g_selected->msg) return; // If we're in lazy subscribe mode, and nobody's listening, then unsubscribe if (g_lazy && !g_pub.getNumSubscribers() && g_selected != g_subs.end()) { ROS_INFO("lazy mode; unsubscribing"); g_selected->sub->shutdown(); delete g_selected->sub; g_selected->sub = NULL; } else g_pub.publish(msg); } bool list_topic_cb(topic_tools::MuxList::Request& req, topic_tools::MuxList::Response& res) { (void)req; for (list<struct sub_info_t>::iterator it = g_subs.begin(); it != g_subs.end(); ++it) { res.topics.push_back(it->topic_name); } return true; } bool add_topic_cb(topic_tools::MuxAdd::Request& req, topic_tools::MuxAdd::Response& res) { (void)res; // Check that it's not already in our list ROS_INFO("trying to add %s to mux", req.topic.c_str()); // Can't add the __none topic if(req.topic == g_none_topic) { ROS_WARN("failed to add topic %s to mux, because it's reserved for special use", req.topic.c_str()); return false; } // spin through our vector of inputs and find this guy for (list<struct sub_info_t>::iterator it = g_subs.begin(); it != g_subs.end(); ++it) { if (ros::names::resolve(it->topic_name) == ros::names::resolve(req.topic)) { ROS_WARN("tried to add a topic that mux was already listening to: [%s]", it->topic_name.c_str()); return false; } } struct sub_info_t sub_info; sub_info.msg = new ShapeShifter; sub_info.topic_name = ros::names::resolve(req.topic); try { if (g_lazy) sub_info.sub = NULL; else sub_info.sub = new ros::Subscriber(g_node->subscribe<ShapeShifter>(sub_info.topic_name, 10, boost::bind(in_cb, _1, sub_info.msg))); } catch(ros::InvalidNameException& e) { ROS_WARN("failed to add topic %s to mux, because it's an invalid name: %s", req.topic.c_str(), e.what()); delete sub_info.msg; return false; } g_subs.push_back(sub_info); ROS_INFO("added %s to mux", req.topic.c_str()); return true; } bool del_topic_cb(topic_tools::MuxDelete::Request& req, topic_tools::MuxDelete::Response& res) { (void)res; // Check that it's in our list ROS_INFO("trying to delete %s from mux", req.topic.c_str()); // spin through our vector of inputs and find this guy for (list<struct sub_info_t>::iterator it = g_subs.begin(); it != g_subs.end(); ++it) { if (ros::names::resolve(it->topic_name) == ros::names::resolve(req.topic)) { // Can't delete the currently selected input, #2863 if(it == g_selected) { ROS_WARN("tried to delete currently selected topic %s from mux", req.topic.c_str()); return false; } if (it->sub) it->sub->shutdown(); delete it->sub; delete it->msg; g_subs.erase(it); ROS_INFO("deleted topic %s from mux", req.topic.c_str()); return true; } } ROS_WARN("tried to delete non-subscribed topic %s from mux", req.topic.c_str()); return false; } int main(int argc, char **argv) { vector<string> args; ros::removeROSArgs(argc, (const char**)argv, args); if (args.size() < 3) { printf("\nusage: mux OUT_TOPIC IN_TOPIC1 [IN_TOPIC2 [...]]\n\n"); return 1; } std::string topic_name; if(!getBaseName(args[1], topic_name)) return 1; ros::init(argc, argv, topic_name + string("_mux"), ros::init_options::AnonymousName); vector<string> topics; for (unsigned int i = 2; i < args.size(); i++) topics.push_back(args[i]); ros::NodeHandle n; g_node = &n; g_output_topic = args[1]; // Put our API into the "mux" namespace, which the user should usually remap ros::NodeHandle mux_nh("mux"), pnh("~"); pnh.getParam("lazy", g_lazy); // Latched publisher for selected input topic name g_pub_selected = mux_nh.advertise<std_msgs::String>(string("selected"), 1, true); for (size_t i = 0; i < topics.size(); i++) { struct sub_info_t sub_info; sub_info.msg = new ShapeShifter; sub_info.topic_name = ros::names::resolve(topics[i]); sub_info.sub = new ros::Subscriber(n.subscribe<ShapeShifter>(sub_info.topic_name, 10, boost::bind(in_cb, _1, sub_info.msg))); g_subs.push_back(sub_info); } g_selected = g_subs.begin(); // select first topic to start std_msgs::String t; t.data = g_selected->topic_name; g_pub_selected.publish(t); // Backward compatibility ros::ServiceServer ss = n.advertiseService(g_output_topic + string("_select"), sel_srv_cb_dep); // New service ros::ServiceServer ss_select = mux_nh.advertiseService(string("select"), sel_srv_cb); ros::ServiceServer ss_add = mux_nh.advertiseService(string("add"), add_topic_cb); ros::ServiceServer ss_list = mux_nh.advertiseService(string("list"), list_topic_cb); ros::ServiceServer ss_del = mux_nh.advertiseService(string("delete"), del_topic_cb); ros::spin(); for (list<struct sub_info_t>::iterator it = g_subs.begin(); it != g_subs.end(); ++it) { if (it->sub) it->sub->shutdown(); delete it->sub; delete it->msg; } g_subs.clear(); return 0; }
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/src/throttle.cpp
/////////////////////////////////////////////////////////////////////////////// // throttle will transform a topic to have a limited number of bytes per second // // Copyright (C) 2009, Morgan Quigley // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of Stanford University nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. ///////////////////////////////////////////////////////////////////////////// // this could be made a lot smarter by trying to analyze and predict the // message stream density, etc., rather than just being greedy and stuffing // the output as fast as it can. #include <cstdio> #include <cstdlib> #include <deque> #include "topic_tools/shape_shifter.h" #include "topic_tools/parse.h" using std::string; using std::vector; using std::deque; using namespace topic_tools; // TODO: move all these globals into a reasonable local scope ros::NodeHandle *g_node = NULL; uint32_t g_bps = 0; // bytes per second, not bits! ros::Duration g_period; // minimum inter-message period double g_window = 1.0; // 1 second window for starters bool g_advertised = false; string g_output_topic; string g_input_topic; ros::Publisher g_pub; ros::Subscriber* g_sub; bool g_use_messages; ros::Time g_last_time; bool g_use_wallclock; bool g_lazy; ros::TransportHints g_th; class Sent { public: double t; uint32_t len; Sent(double _t, uint32_t _len) : t(_t), len(_len) { } }; deque<Sent> g_sent; void conn_cb(const ros::SingleSubscriberPublisher&); void in_cb(const ros::MessageEvent<ShapeShifter>& msg_event); void subscribe() { g_sub = new ros::Subscriber(g_node->subscribe(g_input_topic, 10, &in_cb, g_th)); } void conn_cb(const ros::SingleSubscriberPublisher&) { // If we're in lazy subscribe mode, and the first subscriber just // connected, then subscribe, #3546 if(g_lazy && !g_sub) { ROS_DEBUG("lazy mode; resubscribing"); subscribe(); } } 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; } } 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()); } // If we're in lazy subscribe mode, and nobody's listening, // then unsubscribe, #3546. if(g_lazy && !g_pub.getNumSubscribers()) { ROS_DEBUG("lazy mode; unsubscribing"); delete g_sub; g_sub = NULL; } else { if(g_use_messages) { ros::Time now; if(g_use_wallclock) now.fromSec(ros::WallTime::now().toSec()); else now = ros::Time::now(); if((now - g_last_time) > g_period) { g_pub.publish(msg); g_last_time = now; } } else { // pop the front of the queue until it's within the window ros::Time now; if(g_use_wallclock) now.fromSec(ros::WallTime::now().toSec()); else now = ros::Time::now(); const double t = now.toSec(); while (!g_sent.empty() && g_sent.front().t < t - g_window) g_sent.pop_front(); // sum up how many bytes are in the window uint32_t bytes = 0; for (deque<Sent>::iterator i = g_sent.begin(); i != g_sent.end(); ++i) bytes += i->len; if (bytes < g_bps) { g_pub.publish(msg); g_sent.push_back(Sent(t, msg->size())); } } } } #define USAGE "\nusage: \n"\ " throttle messages IN_TOPIC MSGS_PER_SEC [OUT_TOPIC]]\n"\ "OR\n"\ " throttle bytes IN_TOPIC BYTES_PER_SEC WINDOW [OUT_TOPIC]]\n\n"\ " This program will drop messages from IN_TOPIC so that either: the \n"\ " average bytes per second on OUT_TOPIC, averaged over WINDOW \n"\ " seconds, remains below BYTES_PER_SEC, or: the minimum inter-message\n"\ " period is 1/MSGS_PER_SEC. The messages are output \n"\ " to OUT_TOPIC, or (if not supplied), to IN_TOPIC_throttle.\n\n" int main(int argc, char **argv) { if(argc < 3) { puts(USAGE); return 1; } g_input_topic = string(argv[2]); std::string topic_name; if(!getBaseName(string(argv[2]), topic_name)) return 1; ros::init(argc, argv, topic_name + string("_throttle"), ros::init_options::AnonymousName); bool unreliable = false; ros::NodeHandle pnh("~"); pnh.getParam("wall_clock", g_use_wallclock); pnh.getParam("unreliable", unreliable); pnh.getParam("lazy", g_lazy); if (unreliable) g_th.unreliable().reliable(); // Prefers unreliable, but will accept reliable. if(!strcmp(argv[1], "messages")) g_use_messages = true; else if(!strcmp(argv[1], "bytes")) g_use_messages = false; else { puts(USAGE); return 1; } if(g_use_messages && argc == 5) g_output_topic = string(argv[4]); else if(!g_use_messages && argc == 6) g_output_topic = string(argv[5]); else g_output_topic = g_input_topic + "_throttle"; if(g_use_messages) { if(argc < 4) { puts(USAGE); return 1; } g_period = ros::Duration(1.0/atof(argv[3])); } else { if(argc < 5) { puts(USAGE); return 1; } g_bps = atoi(argv[3]); g_window = atof(argv[4]); } ros::NodeHandle n; g_node = &n; subscribe(); ros::spin(); return 0; }
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/src/demux.cpp
/////////////////////////////////////////////////////////////////////////////// // demux is a generic ROS topic demultiplexer: one input topic is fanned out // to 1 of N output topics. A service is provided to select between the outputs // // Copyright (C) 2009, Morgan Quigley // Copyright (C) 2014, Andreas Hermann // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of Stanford University nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. ///////////////////////////////////////////////////////////////////////////// #include <cstdio> #include <vector> #include <list> #include "ros/console.h" #include "std_msgs/String.h" #include "topic_tools/DemuxSelect.h" #include "topic_tools/DemuxAdd.h" #include "topic_tools/DemuxList.h" #include "topic_tools/DemuxDelete.h" #include "topic_tools/shape_shifter.h" #include "topic_tools/parse.h" using std::string; using std::vector; using std::list; using namespace topic_tools; const static string g_none_topic = "__none"; static ros::NodeHandle *g_node = NULL; static string g_input_topic; static ros::Subscriber g_sub; // the input toppic static ros::Publisher g_pub_selected; // publishes name of selected publisher toppic struct pub_info_t { std::string topic_name; ros::Publisher *pub; }; void in_cb(const boost::shared_ptr<ShapeShifter const>& msg); static list<struct pub_info_t> g_pubs; // the list of publishers static list<struct pub_info_t>::iterator g_selected = g_pubs.end(); bool sel_srv_cb( topic_tools::DemuxSelect::Request &req, topic_tools::DemuxSelect::Response &res ) { bool ret = false; if (g_selected != g_pubs.end()) { res.prev_topic = g_selected->topic_name; // Unregister old topic ROS_INFO("Unregistering %s", res.prev_topic.c_str()); if (g_selected->pub) g_selected->pub->shutdown(); delete g_selected->pub; g_selected->pub = NULL; } else res.prev_topic = string(""); // see if it's the magical '__none' topic, in which case we open the circuit if (req.topic == g_none_topic) { ROS_INFO("demux selected to no output."); g_selected = g_pubs.end(); ret = true; } else { ROS_INFO("trying to switch demux to %s", req.topic.c_str()); // spin through our vector of inputs and find this guy for (list<struct pub_info_t>::iterator it = g_pubs.begin(); it != g_pubs.end(); ++it) { if (ros::names::resolve(it->topic_name) == ros::names::resolve(req.topic)) { g_selected = it; ROS_INFO("demux selected output: [%s]", it->topic_name.c_str()); ret = true; } } if(!ret) { ROS_WARN("Failed to switch to non-existing topic %s in demux.", req.topic.c_str()); } } if(ret) { std_msgs::String t; t.data = req.topic; g_pub_selected.publish(t); } return ret; } void in_cb(const boost::shared_ptr<ShapeShifter const>& msg) { ROS_DEBUG("Received an incoming msg ..."); // when a message is incoming, check, if the requested publisher is already existing. // if not, create it with the information available from the incoming message. if(!g_selected->pub) { try { g_selected->pub = new ros::Publisher(msg->advertise(*g_node, g_selected->topic_name, 10, false)); } catch(ros::InvalidNameException& e) { ROS_WARN("failed to add topic %s to demux, because it's an invalid name: %s", g_selected->topic_name.c_str(), e.what()); return; } ROS_INFO("Added publisher %s to demux! Sleeping for 0.5 secs.", g_selected->topic_name.c_str()); // This is needed, because it takes some time before publisher is registered and can send out messages. ros::Duration(0.5).sleep(); } // finally: send out the message over the active publisher g_selected->pub->publish(msg); ROS_DEBUG("... and sent it out again!"); } bool list_topic_cb(topic_tools::DemuxList::Request& req, topic_tools::DemuxList::Response& res) { (void)req; for (list<struct pub_info_t>::iterator it = g_pubs.begin(); it != g_pubs.end(); ++it) { res.topics.push_back(it->topic_name); } return true; } bool add_topic_cb(topic_tools::DemuxAdd::Request& req, topic_tools::DemuxAdd::Response& res) { (void)res; // Check that it's not already in our list ROS_INFO("trying to add %s to demux", req.topic.c_str()); // Can't add the __none topic if(req.topic == g_none_topic) { ROS_WARN("failed to add topic %s to demux, because it's reserved for special use", req.topic.c_str()); return false; } // spin through our vector of inputs and find this guy for (list<struct pub_info_t>::iterator it = g_pubs.begin(); it != g_pubs.end(); ++it) { if (ros::names::resolve(it->topic_name) == ros::names::resolve(req.topic)) { ROS_WARN("tried to add a topic that demux was already publishing: [%s]", it->topic_name.c_str()); return false; } } struct pub_info_t pub_info; pub_info.topic_name = ros::names::resolve(req.topic); pub_info.pub = NULL; g_pubs.push_back(pub_info); ROS_INFO("PRE added %s to demux", req.topic.c_str()); return true; } bool del_topic_cb(topic_tools::DemuxDelete::Request& req, topic_tools::DemuxDelete::Response& res) { (void)res; // Check that it's in our list ROS_INFO("trying to delete %s from demux", req.topic.c_str()); // spin through our vector of inputs and find this guy for (list<struct pub_info_t>::iterator it = g_pubs.begin(); it != g_pubs.end(); ++it) { if (ros::names::resolve(it->topic_name) == ros::names::resolve(req.topic)) { // Can't delete the currently selected input, #2863 if(it == g_selected) { ROS_WARN("tried to delete currently selected topic %s from demux", req.topic.c_str()); return false; } if (it->pub) it->pub->shutdown(); delete it->pub; g_pubs.erase(it); ROS_INFO("deleted topic %s from demux", req.topic.c_str()); return true; } } ROS_WARN("tried to delete non-published topic %s from demux", req.topic.c_str()); return false; } int main(int argc, char **argv) { vector<string> args; ros::removeROSArgs(argc, (const char**)argv, args); if (args.size() < 3) { printf("\nusage: demux IN_TOPIC OUT_TOPIC1 [OUT_TOPIC2 [...]]\n\n"); return 1; } std::string topic_name; if(!getBaseName(args[1], topic_name)) return 1; ros::init(argc, argv, topic_name + string("_demux"), ros::init_options::AnonymousName); vector<string> topics; for (unsigned int i = 2; i < args.size(); i++) topics.push_back(args[i]); ros::NodeHandle n; g_node = &n; g_input_topic = args[1]; // Put our API into the "demux" namespace, which the user should usually remap ros::NodeHandle demux_nh("demux"), pnh("~"); // Latched publisher for selected output topic name g_pub_selected = demux_nh.advertise<std_msgs::String>(string("selected"), 1, true); for (size_t i = 0; i < topics.size(); i++) { struct pub_info_t pub_info; pub_info.topic_name = ros::names::resolve(topics[i]); pub_info.pub = NULL; g_pubs.push_back(pub_info); ROS_INFO("PRE added %s to demux", topics[i].c_str()); } g_selected = g_pubs.begin(); // select first topic to start std_msgs::String t; t.data = g_selected->topic_name; g_pub_selected.publish(t); // Create the one subscriber g_sub = ros::Subscriber(n.subscribe<ShapeShifter>(g_input_topic, 10, boost::bind(in_cb, _1))); // New service ros::ServiceServer ss_select = demux_nh.advertiseService(string("select"), sel_srv_cb); ros::ServiceServer ss_add = demux_nh.advertiseService(string("add"), add_topic_cb); ros::ServiceServer ss_list = demux_nh.advertiseService(string("list"), list_topic_cb); ros::ServiceServer ss_del = demux_nh.advertiseService(string("delete"), del_topic_cb); // Run ros::spin(); // Destruction for (list<struct pub_info_t>::iterator it = g_pubs.begin(); it != g_pubs.end(); ++it) { if (it->pub) it->pub->shutdown(); delete it->pub; } g_pubs.clear(); return 0; }
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/src/shape_shifter.cpp
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ********************************************************************/ #include <topic_tools/shape_shifter.h> using namespace topic_tools; bool ShapeShifter::uses_old_API_ = false; ShapeShifter::ShapeShifter() : typed(false), msgBuf(NULL), msgBufUsed(0), msgBufAlloc(0) { } ShapeShifter::~ShapeShifter() { if (msgBuf) delete[] msgBuf; msgBuf = NULL; msgBufAlloc = 0; } std::string const& ShapeShifter::getDataType() const { return datatype; } std::string const& ShapeShifter::getMD5Sum() const { return md5; } std::string const& ShapeShifter::getMessageDefinition() const { return msg_def; } void ShapeShifter::morph(const std::string& _md5sum, const std::string& _datatype, const std::string& _msg_def, const std::string& _latching) { md5 = _md5sum; datatype = _datatype; msg_def = _msg_def; latching = _latching; typed = md5 != "*"; } ros::Publisher ShapeShifter::advertise(ros::NodeHandle& nh, const std::string& topic, uint32_t queue_size_, bool latch, const ros::SubscriberStatusCallback &connect_cb) const { ros::AdvertiseOptions opts(topic, queue_size_, getMD5Sum(), getDataType(), getMessageDefinition(), connect_cb); opts.latch = latch; return nh.advertise(opts); } uint32_t ShapeShifter::size() const { return msgBufUsed; }
0
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools
apollo_public_repos/apollo-platform/ros/ros_comm/topic_tools/src/relay.cpp
/////////////////////////////////////////////////////////////////////////////// // relay just passes messages on. it can be useful if you're trying to ensure // that a message doesn't get sent twice over a wireless link, by having the // relay catch the message and then do the fanout on the far side of the // wireless link. // // Copyright (C) 2009, Morgan Quigley // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of Stanford University nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. ///////////////////////////////////////////////////////////////////////////// #include <cstdio> #include "topic_tools/shape_shifter.h" #include "topic_tools/parse.h" using std::string; using std::vector; using namespace topic_tools; ros::NodeHandle *g_node = NULL; bool g_advertised = false; string g_input_topic; string g_output_topic; ros::Publisher g_pub; ros::Subscriber* g_sub; bool g_lazy; ros::TransportHints g_th; void conn_cb(const ros::SingleSubscriberPublisher&); void in_cb(const ros::MessageEvent<ShapeShifter>& msg_event); void subscribe() { g_sub = new ros::Subscriber(g_node->subscribe(g_input_topic, 10, &in_cb, g_th)); } void conn_cb(const ros::SingleSubscriberPublisher&) { // If we're in lazy subscribe mode, and the first subscriber just // connected, then subscribe, #3389. if(g_lazy && !g_sub) { ROS_DEBUG("lazy mode; resubscribing"); subscribe(); } } 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, #3385. 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; } } g_pub = msg->advertise(*g_node, g_output_topic, 10, latch, conn_cb); g_advertised = true; ROS_INFO("advertised as %s\n", g_output_topic.c_str()); } // If we're in lazy subscribe mode, and nobody's listening, // then unsubscribe, #3389. if(g_lazy && !g_pub.getNumSubscribers()) { ROS_DEBUG("lazy mode; unsubscribing"); delete g_sub; g_sub = NULL; } else g_pub.publish(msg); } int main(int argc, char **argv) { if (argc < 2) { printf("\nusage: relay IN_TOPIC [OUT_TOPIC]\n\n"); return 1; } std::string topic_name; if(!getBaseName(string(argv[1]), topic_name)) return 1; ros::init(argc, argv, topic_name + string("_relay"), ros::init_options::AnonymousName); if (argc == 2) g_output_topic = string(argv[1]) + string("_relay"); else // argc == 3 g_output_topic = string(argv[2]); g_input_topic = string(argv[1]); ros::NodeHandle n; g_node = &n; ros::NodeHandle pnh("~"); bool unreliable = false; pnh.getParam("unreliable", unreliable); pnh.getParam("lazy", g_lazy); if (unreliable) g_th.unreliable().reliable(); // Prefers unreliable, but will accept reliable. subscribe(); ros::spin(); return 0; }
0
apollo_public_repos/apollo-platform/ros
apollo_public_repos/apollo-platform/ros/pcl_msgs/CMakeLists.txt
cmake_minimum_required(VERSION 2.8.3) project(pcl_msgs) # Deal with catkin find_package(catkin REQUIRED COMPONENTS message_generation sensor_msgs std_msgs) # create messages add_message_files(DIRECTORY msg FILES ModelCoefficients.msg PointIndices.msg PolygonMesh.msg Vertices.msg ) add_service_files(DIRECTORY srv FILES UpdateFilename.srv) generate_messages(DEPENDENCIES sensor_msgs std_msgs) catkin_package(CATKIN_DEPENDS message_runtime sensor_msgs std_msgs)
0
apollo_public_repos/apollo-platform/ros
apollo_public_repos/apollo-platform/ros/pcl_msgs/package.xml
<?xml version="1.0"?> <package> <name>pcl_msgs</name> <version>0.2.0</version> <description>Package containing PCL (Point Cloud Library)-related ROS messages.</description> <author>Open Perception</author> <author email="[email protected]">Julius Kammerl</author> <author email="[email protected]">William Woodall</author> <maintainer email="[email protected]">Paul Bovbel</maintainer> <maintainer email="[email protected]">Bill Morris</maintainer> <license>BSD</license> <url>http://wiki.ros.org/pcl_msgs</url> <url type="repository">https://github.com/ros-perception/pcl_msgs</url> <url type="bugtracker">https://github.com/ros-perception/pcl_msgs/issues</url> <buildtool_depend>catkin</buildtool_depend> <build_depend>message_generation</build_depend> <build_depend>sensor_msgs</build_depend> <build_depend>std_msgs</build_depend> <run_depend>message_runtime</run_depend> <run_depend>sensor_msgs</run_depend> <run_depend>std_msgs</run_depend> </package>
0
apollo_public_repos/apollo-platform/ros
apollo_public_repos/apollo-platform/ros/pcl_msgs/README.md
pcl_msgs ======== ROS package containing PCL-related messages
0
apollo_public_repos/apollo-platform/ros
apollo_public_repos/apollo-platform/ros/pcl_msgs/CHANGELOG.rst
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Changelog for package pcl_msgs ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 0.2.0 (2014-04-09) ------------------ * clean up package.xml * update maintainer info * remove eigen dependency * Merge pull request `#1 <https://github.com/ros-perception/pcl_msgs/issues/1>`_ from bulwahn/patch-1 * Contributors: Lukas Bulwahn, Paul Bovbel 0.1.0 (2013-07-09) ------------------ * Generate messages into the pcl_msgs namespace rather than the pcl namespace 0.0.3 (2012-12-15) ------------------ * fix deps for messages * Updated for new <buildtool_depend>catkin<...> rule 0.0.2 (2012-11-26 18:50) ------------------------ * increasing version * ros message generation prefix hack 0.0.1 (2012-11-26 17:48) ------------------------ * initial commit - pcl ROS messages
0
apollo_public_repos/apollo-platform/ros/pcl_msgs
apollo_public_repos/apollo-platform/ros/pcl_msgs/msg/PolygonMesh.msg
# Separate header for the polygonal surface Header header # Vertices of the mesh as a point cloud sensor_msgs/PointCloud2 cloud # List of polygons Vertices[] polygons
0
apollo_public_repos/apollo-platform/ros/pcl_msgs
apollo_public_repos/apollo-platform/ros/pcl_msgs/msg/Vertices.msg
# List of point indices uint32[] vertices
0
apollo_public_repos/apollo-platform/ros/pcl_msgs
apollo_public_repos/apollo-platform/ros/pcl_msgs/msg/PointIndices.msg
Header header int32[] indices
0
apollo_public_repos/apollo-platform/ros/pcl_msgs
apollo_public_repos/apollo-platform/ros/pcl_msgs/msg/ModelCoefficients.msg
Header header float32[] values
0
apollo_public_repos/apollo-platform/ros/pcl_msgs
apollo_public_repos/apollo-platform/ros/pcl_msgs/srv/UpdateFilename.srv
string filename --- bool success
0
apollo_public_repos/apollo-platform/ros/image_common
apollo_public_repos/apollo-platform/ros/image_common/image_transport/CMakeLists.txt
cmake_minimum_required(VERSION 2.8.3) project(image_transport) find_package(catkin REQUIRED COMPONENTS message_filters pluginlib rosconsole roscpp roslib sensor_msgs ) find_package(Boost REQUIRED) catkin_package( INCLUDE_DIRS include LIBRARIES ${PROJECT_NAME} DEPENDS message_filters pluginlib rosconsole roscpp roslib sensor_msgs ) include_directories(include ${catkin_INCLUDE_DIRS}) # Build libimage_transport add_library(${PROJECT_NAME} src/camera_common.cpp src/camera_publisher.cpp src/camera_subscriber.cpp src/image_transport.cpp src/publisher.cpp src/single_subscriber_publisher.cpp src/subscriber.cpp ) add_dependencies(${PROJECT_NAME} ${catkin_EXPORTED_TARGETS}) target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES} ${catkin_LIBRARIES} ) # Build libimage_transport_plugins add_library(${PROJECT_NAME}_plugins src/manifest.cpp src/raw_publisher.cpp) target_link_libraries(${PROJECT_NAME}_plugins ${PROJECT_NAME}) install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_plugins DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} COMPONENT main ) install(DIRECTORY include/${PROJECT_NAME}/ DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} ) # add two execs add_executable(republish src/republish.cpp) target_link_libraries(republish ${PROJECT_NAME}) add_executable(list_transports src/list_transports.cpp) target_link_libraries(list_transports ${PROJECT_NAME} ${catkin_LIBRARIES} ) install(TARGETS list_transports republish DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} ) # add xml file install(FILES default_plugins.xml DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} )
0
apollo_public_repos/apollo-platform/ros/image_common
apollo_public_repos/apollo-platform/ros/image_common/image_transport/package.xml
<package> <name>image_transport</name> <version>1.11.12</version> <description> image_transport should always be used to subscribe to and publish images. It provides transparent support for transporting images in low-bandwidth compressed formats. Examples (provided by separate plugin packages) include JPEG/PNG compression and Theora streaming video. </description> <author>Patrick Mihelich</author> <maintainer email="[email protected]">Jack O'Quin</maintainer> <maintainer email="[email protected]">Vincent Rabaud</maintainer> <license>BSD</license> <url type="website">http://ros.org/wiki/image_transport</url> <url type="bugtracker">https://github.com/ros-perception/image_common/issues</url> <url type="repository">https://github.com/ros-perception/image_common</url> <export> <image_transport plugin="${prefix}/default_plugins.xml" /> </export> <buildtool_depend>catkin</buildtool_depend> <build_depend>message_filters</build_depend> <build_depend>pluginlib</build_depend> <build_depend>rosconsole</build_depend> <build_depend>roscpp</build_depend> <build_depend>roslib</build_depend> <build_depend>sensor_msgs</build_depend> <run_depend>message_filters</run_depend> <run_depend>pluginlib</run_depend> <run_depend>rosconsole</run_depend> <run_depend>roscpp</run_depend> <run_depend>roslib</run_depend> <run_depend>sensor_msgs</run_depend> </package>
0
apollo_public_repos/apollo-platform/ros/image_common
apollo_public_repos/apollo-platform/ros/image_common/image_transport/mainpage.dox
/** \mainpage \htmlinclude manifest.html \section codeapi Code API When transporting images, you should use image_transport's classes as drop-in replacements for ros::Publisher and ros::Subscriber. - image_transport::ImageTransport - use this to create a Publisher or Subscriber - image_transport::Publisher - manage advertisements for an image topic, using all available transport options - image_transport::Subscriber - manage an Image subscription callback using a particular transport Camera drivers publish a "camera_info" sibling topic containing important metadata on how to interpret an image for vision applications. image_transport included helper classes to publish (image, info) message pairs and re-synchronize them on the client side: - image_transport::CameraPublisher - manage advertisements for camera images - image_transport::CameraSubscriber - manage a single subscription callback to synchronized image (using any transport) and CameraInfo topics For other synchronization or filtering needs, see the low-level filter class: - image_transport::SubscriberFilter - a wrapper for image_transport::Subscriber compatible with message_filters \subsection writing_plugin Writing a plugin If you are an advanced user implementing your own image transport option, you will need to implement these base-level interfaces: - image_transport::PublisherPlugin - image_transport::SubscriberPlugin In the common case that all communication between PublisherPlugin and SubscriberPlugin happens over a single ROS topic using a transport-specific message type, writing the plugins is vastly simplified by using these base classes instead: - image_transport::SimplePublisherPlugin - see image_transport::RawPublisher for a trivial example - image_transport::SimpleSubscriberPlugin - see image_transport::RawSubscriber for a trivial example \section rosapi ROS API \subsection pub_sub_rosapi Publishers and Subscribers Because they encapsulate complicated communication behavior, image_transport publisher and subscriber classes have a public ROS API as well as a code API. See the wiki documentation for details. Although image_transport::Publisher may publish many topics, in all code interfaces you should use only the name of the "base topic." The image transport classes will figure out the name of the dedicated ROS topic to use for the desired transport. */
0
apollo_public_repos/apollo-platform/ros/image_common
apollo_public_repos/apollo-platform/ros/image_common/image_transport/default_plugins.xml
<library path="lib/libimage_transport_plugins"> <class name="image_transport/raw_pub" type="image_transport::RawPublisher" base_class_type="image_transport::PublisherPlugin"> <description> This is the default publisher. It publishes the Image as-is on the base topic. </description> </class> <class name="image_transport/raw_sub" type="image_transport::RawSubscriber" base_class_type="image_transport::SubscriberPlugin"> <description> This is the default pass-through subscriber for topics of type sensor_msgs/Image. </description> </class> </library>
0
apollo_public_repos/apollo-platform/ros/image_common
apollo_public_repos/apollo-platform/ros/image_common/image_transport/CHANGELOG.rst
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Changelog for package image_transport ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1.11.12 (2017-01-29) -------------------- * Fix CMake of image_transport/tutorial and polled_camera Fix loads of problems with the CMakeLists. * image_transport/tutorial: Add dependency on generated msg Without this, build fails on Kinetic because ResizedImage.h has not been generated yet. * image_transport/tutorial: Add missing catkin_INCLUDE_DIRS Without this, compilation files on Kinetic because ros.h cannot be found. * 1.11.11 * update changelogs * Contributors: Martin Guenther, Vincent Rabaud 1.11.11 (2016-09-24) -------------------- 1.11.10 (2016-01-19) -------------------- 1.11.9 (2016-01-17) ------------------- * fix linkage in tutorials * Use $catkin_EXPORTED_TARGETS * Contributors: Jochen Sprickerhof, Vincent Rabaud 1.11.8 (2015-11-29) ------------------- 1.11.7 (2015-07-28) ------------------- 1.11.6 (2015-07-16) ------------------- 1.11.5 (2015-05-14) ------------------- * image_transport: fix CameraSubscriber shutdown (circular shared_ptr ref) CameraSubscriber uses a private boost::shared_ptr to share an impl object between copied instances. In CameraSubscriber::CameraSubscriber(), it handed this shared_ptr to boost::bind() and saved the created wall timer in the impl object, thus creating a circular reference. The impl object was therefore never freed. Fix that by passing a plain pointer to boost::bind(). * avoid a memory copy for the raw publisher * add a way to publish an image with only the data pointer * Make function inline to avoid duplicated names when linking statically * add plugin examples for the tutorial * update instructions for catkin * remove uselessly linked library fixes `#28 <https://github.com/ros-perception/image_common/issues/28>`_ * add a tutorial for image_transport * Contributors: Gary Servin, Max Schwarz, Vincent Rabaud 1.11.4 (2014-09-21) ------------------- 1.11.3 (2014-05-19) ------------------- 1.11.2 (2014-02-13) ------------------- 1.11.1 (2014-01-26 02:33) ------------------------- 1.11.0 (2013-07-20 12:23) ------------------------- 1.10.5 (2014-01-26 02:34) ------------------------- 1.10.4 (2013-07-20 11:42) ------------------------- * add Jack as maintainer * update my email address * Contributors: Vincent Rabaud 1.10.3 (2013-02-21 05:33) ------------------------- 1.10.2 (2013-02-21 04:48) ------------------------- 1.10.1 (2013-02-21 04:16) ------------------------- 1.10.0 (2013-01-13) ------------------- * fix the urls * use the pluginlib script to remove some warnings * added license headers to various cpp and h files * Contributors: Aaron Blasdel, Vincent Rabaud 1.9.22 (2012-12-16) ------------------- * get rid of the deprecated class_loader interface * Contributors: Vincent Rabaud 1.9.21 (2012-12-14) ------------------- * CMakeLists.txt clean up * Updated package.xml file(s) to handle new catkin buildtool_depend requirement * Contributors: William Woodall, mirzashah 1.9.20 (2012-12-04) ------------------- 1.9.19 (2012-11-08) ------------------- * add the right link libraries * Contributors: Vincent Rabaud 1.9.18 (2012-11-06) ------------------- * Isolated plugins into their own library to follow new class_loader/pluginlib guidelines. * remove the brief attribute * Contributors: Mirza Shah, Vincent Rabaud 1.9.17 (2012-10-30 19:32) ------------------------- 1.9.16 (2012-10-30 09:10) ------------------------- * add xml file * Contributors: Vincent Rabaud 1.9.15 (2012-10-13 08:43) ------------------------- * fix bad folder/libraries * Contributors: Vincent Rabaud 1.9.14 (2012-10-13 01:07) ------------------------- 1.9.13 (2012-10-06) ------------------- 1.9.12 (2012-10-04) ------------------- 1.9.11 (2012-10-02 02:56) ------------------------- 1.9.10 (2012-10-02 02:42) ------------------------- 1.9.9 (2012-10-01) ------------------ * fix dependencies * Contributors: Vincent Rabaud 1.9.8 (2012-09-30) ------------------ * add catkin as a dependency * comply to the catkin API * Contributors: Vincent Rabaud 1.9.7 (2012-09-18 11:39) ------------------------ 1.9.6 (2012-09-18 11:07) ------------------------ 1.9.5 (2012-09-13) ------------------ * install the include directories * Contributors: Vincent Rabaud 1.9.4 (2012-09-12 23:37) ------------------------ 1.9.3 (2012-09-12 20:44) ------------------------ 1.9.2 (2012-09-10) ------------------ 1.9.1 (2012-09-07 15:33) ------------------------ * make the libraries public * Contributors: Vincent Rabaud 1.9.0 (2012-09-07 13:03) ------------------------ * catkinize for Groovy * Initial image_common stack check-in, containing image_transport. * Contributors: Vincent Rabaud, gerkey, kwc, mihelich, pmihelich, straszheim, vrabaud
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport
apollo_public_repos/apollo-platform/ros/image_common/image_transport/tutorial/CMakeLists.txt
cmake_minimum_required(VERSION 2.8) project(image_transport_tutorial) find_package(catkin REQUIRED COMPONENTS cv_bridge image_transport message_generation sensor_msgs) # add the resized image message add_message_files(DIRECTORY msg FILES ResizedImage.msg ) generate_messages(DEPENDENCIES sensor_msgs) catkin_package(CATKIN_DEPENDS cv_bridge image_transport message_runtime sensor_msgs) find_package(OpenCV) include_directories(include ${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS}) # add the publisher example add_executable(my_publisher src/my_publisher.cpp) add_dependencies(my_publisher ${catkin_EXPORTED_TARGETS} ${${PROJECT_NAME}_EXPORTED_TARGETS}) target_link_libraries(my_publisher ${catkin_LIBRARIES} ${OpenCV_LIBRARIES}) # add the subscriber example add_executable(my_subscriber src/my_subscriber.cpp) add_dependencies(my_subscriber ${catkin_EXPORTED_TARGETS} ${${PROJECT_NAME}_EXPORTED_TARGETS}) target_link_libraries(my_subscriber ${catkin_LIBRARIES} ${OpenCV_LIBRARIES}) # add the plugin example add_library(resized_publisher src/manifest.cpp src/resized_publisher.cpp src/resized_subscriber.cpp) add_dependencies(resized_publisher ${catkin_EXPORTED_TARGETS} ${${PROJECT_NAME}_EXPORTED_TARGETS}) target_link_libraries(resized_publisher ${catkin_LIBRARIES} ${OpenCV_LIBRARIES}) # Mark executables and/or libraries for installation install(TARGETS my_publisher my_subscriber resized_publisher ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} ) install(FILES resized_plugins.xml DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} )
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport
apollo_public_repos/apollo-platform/ros/image_common/image_transport/tutorial/package.xml
<package> <name>image_transport_tutorial</name> <version>0.0.0</version> <description>Tutorial for image_transport. This is useful for the tutorials at http://wiki.ros.org/image_transport/Tutorials/</description> <author>Vincent Rabaud</author> <maintainer email="[email protected]">Vincent Rabaud</maintainer> <license>Apache 2.0</license> <build_depend>cv_bridge</build_depend> <build_depend>image_transport</build_depend> <build_depend>message_generation</build_depend> <build_depend>opencv2</build_depend> <build_depend>sensor_msgs</build_depend> <run_depend>cv_bridge</run_depend> <run_depend>image_transport</run_depend> <run_depend>message_runtime</run_depend> <run_depend>opencv2</run_depend> <run_depend>sensor_msgs</run_depend> <buildtool_depend>catkin</buildtool_depend> <export> <image_transport plugin="${prefix}/resized_plugins.xml"/> </export> </package>
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport
apollo_public_repos/apollo-platform/ros/image_common/image_transport/tutorial/resized_plugins.xml
<library path="lib/libresized_image_transport"> <class name="resized_pub" type="ResizedPublisher" base_class_type="image_transport::PublisherPlugin"> <description> This plugin publishes a decimated version of the image. </description> </class> <class name="resized_sub" type="ResizedSubscriber" base_class_type="image_transport::SubscriberPlugin"> <description> This plugin rescales a decimated image to its original size. </description> </class> </library>
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/tutorial
apollo_public_repos/apollo-platform/ros/image_common/image_transport/tutorial/msg/ResizedImage.msg
uint32 original_height uint32 original_width sensor_msgs/Image image
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/tutorial/include
apollo_public_repos/apollo-platform/ros/image_common/image_transport/tutorial/include/image_transport_tutorial/resized_subscriber.h
#include <image_transport/simple_subscriber_plugin.h> #include <image_transport_tutorial/ResizedImage.h> class ResizedSubscriber : public image_transport::SimpleSubscriberPlugin<image_transport_tutorial::ResizedImage> { public: virtual ~ResizedSubscriber() {} virtual std::string getTransportName() const { return "resized"; } protected: virtual void internalCallback(const typename image_transport_tutorial::ResizedImage::ConstPtr& message, const Callback& user_cb); };
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/tutorial/include
apollo_public_repos/apollo-platform/ros/image_common/image_transport/tutorial/include/image_transport_tutorial/resized_publisher.h
#include <image_transport/simple_publisher_plugin.h> #include <image_transport_tutorial/ResizedImage.h> class ResizedPublisher : public image_transport::SimplePublisherPlugin<image_transport_tutorial::ResizedImage> { public: virtual std::string getTransportName() const { return "resized"; } protected: virtual void publish(const sensor_msgs::Image& message, const PublishFn& publish_fn) const; };
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/tutorial
apollo_public_repos/apollo-platform/ros/image_common/image_transport/tutorial/src/my_subscriber.cpp
#include <ros/ros.h> #include <image_transport/image_transport.h> #include <opencv2/highgui/highgui.hpp> #include <cv_bridge/cv_bridge.h> void imageCallback(const sensor_msgs::ImageConstPtr& msg) { try { cv::imshow("view", cv_bridge::toCvShare(msg, "bgr8")->image); } catch (cv_bridge::Exception& e) { ROS_ERROR("Could not convert from '%s' to 'bgr8'.", msg->encoding.c_str()); } } int main(int argc, char **argv) { ros::init(argc, argv, "image_listener"); ros::NodeHandle nh; cv::namedWindow("view"); cv::startWindowThread(); image_transport::ImageTransport it(nh); image_transport::Subscriber sub = it.subscribe("camera/image", 1, imageCallback); ros::spin(); cv::destroyWindow("view"); }
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/tutorial
apollo_public_repos/apollo-platform/ros/image_common/image_transport/tutorial/src/resized_subscriber.cpp
#include <image_transport_tutorial/resized_subscriber.h> #include <cv_bridge/cv_bridge.h> #include <opencv2/imgproc/imgproc.hpp> void ResizedSubscriber::internalCallback(const image_transport_tutorial::ResizedImage::ConstPtr& msg, const Callback& user_cb) { // This is only for optimization, not to copy the image boost::shared_ptr<void const> tracked_object_tmp; cv::Mat img_rsz = cv_bridge::toCvShare(msg->image, tracked_object_tmp)->image; // Resize the image to its original size cv::Mat img_restored; cv::resize(img_rsz, img_restored, cv::Size(msg->original_width, msg->original_height)); // Call the user callback with the restored image cv_bridge::CvImage cv_img(msg->image.header, msg->image.encoding, img_restored); user_cb(cv_img.toImageMsg()); };
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/tutorial
apollo_public_repos/apollo-platform/ros/image_common/image_transport/tutorial/src/my_publisher.cpp
#include <ros/ros.h> #include <image_transport/image_transport.h> #include <opencv2/highgui/highgui.hpp> #include <cv_bridge/cv_bridge.h> int main(int argc, char** argv) { ros::init(argc, argv, "image_publisher"); ros::NodeHandle nh; image_transport::ImageTransport it(nh); image_transport::Publisher pub = it.advertise("camera/image", 1); cv::Mat image = cv::imread(argv[1], CV_LOAD_IMAGE_COLOR); sensor_msgs::ImagePtr msg = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image).toImageMsg(); ros::Rate loop_rate(5); while (nh.ok()) { pub.publish(msg); ros::spinOnce(); loop_rate.sleep(); } }
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/tutorial
apollo_public_repos/apollo-platform/ros/image_common/image_transport/tutorial/src/resized_publisher.cpp
#include <image_transport_tutorial/resized_publisher.h> #include <opencv2/imgproc/imgproc.hpp> #include <cv_bridge/cv_bridge.h> void ResizedPublisher::publish(const sensor_msgs::Image& message, const PublishFn& publish_fn) const { cv::Mat cv_image; boost::shared_ptr<void const> tracked_object; try { cv_image = cv_bridge::toCvShare(message, tracked_object, message.encoding)->image; } catch (cv::Exception &e) { ROS_ERROR("Could not convert from '%s' to '%s'.", message.encoding.c_str(), message.encoding.c_str()); return; } // Retrieve subsampling factor from the parameter server double subsampling_factor; std::string param_name; nh().param<double>("resized_image_transport_subsampling_factor", subsampling_factor, 2.0); // Rescale image int new_width = cv_image.cols / subsampling_factor + 0.5; int new_height = cv_image.rows / subsampling_factor + 0.5; cv::Mat buffer; cv::resize(cv_image, buffer, cv::Size(new_width, new_height)); // Set up ResizedImage and publish image_transport_tutorial::ResizedImage resized_image; resized_image.original_height = cv_image.rows; resized_image.original_width = cv_image.cols; resized_image.image = *(cv_bridge::CvImage(message.header, "bgr8", cv_image).toImageMsg()); publish_fn(resized_image); }
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/tutorial
apollo_public_repos/apollo-platform/ros/image_common/image_transport/tutorial/src/manifest.cpp
#include <pluginlib/class_list_macros.h> #include <image_transport_tutorial/resized_publisher.h> #include <image_transport_tutorial/resized_subscriber.h> PLUGINLIB_REGISTER_CLASS(resized_pub, ResizedPublisher, image_transport::PublisherPlugin) PLUGINLIB_REGISTER_CLASS(resized_sub, ResizedSubscriber, image_transport::SubscriberPlugin)
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include/image_transport/simple_subscriber_plugin.h
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef IMAGE_TRANSPORT_SIMPLE_SUBSCRIBER_PLUGIN_H #define IMAGE_TRANSPORT_SIMPLE_SUBSCRIBER_PLUGIN_H #include "image_transport/subscriber_plugin.h" #include <boost/scoped_ptr.hpp> namespace image_transport { /** * \brief Base class to simplify implementing most plugins to Subscriber. * * The base class simplifies implementing a SubscriberPlugin in the common case that * all communication with the matching PublisherPlugin happens over a single ROS * topic using a transport-specific message type. SimpleSubscriberPlugin is templated * on the transport-specific message type. * * A subclass need implement only two methods: * - getTransportName() from SubscriberPlugin * - internalCallback() - processes a message and invoked the user Image callback if * appropriate. * * For access to the parameter server and name remappings, use nh(). * * getTopicToSubscribe() controls the name of the internal communication topic. It * defaults to \<base topic\>/\<transport name\>. */ template <class M> class SimpleSubscriberPlugin : public SubscriberPlugin { public: virtual ~SimpleSubscriberPlugin() {} virtual std::string getTopic() const { if (simple_impl_) return simple_impl_->sub_.getTopic(); return std::string(); } virtual uint32_t getNumPublishers() const { if (simple_impl_) return simple_impl_->sub_.getNumPublishers(); return 0; } virtual void shutdown() { if (simple_impl_) simple_impl_->sub_.shutdown(); } protected: /** * \brief Process a message. Must be implemented by the subclass. * * @param message A message from the PublisherPlugin. * @param user_cb The user Image callback to invoke, if appropriate. */ virtual void internalCallback(const typename M::ConstPtr& message, const Callback& user_cb) = 0; /** * \brief Return the communication topic name for a given base topic. * * Defaults to \<base topic\>/\<transport name\>. */ virtual std::string getTopicToSubscribe(const std::string& base_topic) const { return base_topic + "/" + getTransportName(); } virtual void subscribeImpl(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size, const Callback& callback, const ros::VoidPtr& tracked_object, const TransportHints& transport_hints) { // Push each group of transport-specific parameters into a separate sub-namespace ros::NodeHandle param_nh(transport_hints.getParameterNH(), getTransportName()); simple_impl_.reset(new SimpleSubscriberPluginImpl(param_nh)); simple_impl_->sub_ = nh.subscribe<M>(getTopicToSubscribe(base_topic), queue_size, boost::bind(&SimpleSubscriberPlugin::internalCallback, this, _1, callback), tracked_object, transport_hints.getRosHints()); } /** * \brief Returns the ros::NodeHandle to be used for parameter lookup. */ const ros::NodeHandle& nh() const { return simple_impl_->param_nh_; } private: struct SimpleSubscriberPluginImpl { SimpleSubscriberPluginImpl(const ros::NodeHandle& nh) : param_nh_(nh) { } const ros::NodeHandle param_nh_; ros::Subscriber sub_; }; boost::scoped_ptr<SimpleSubscriberPluginImpl> simple_impl_; }; } //namespace image_transport #endif
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include/image_transport/transport_hints.h
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef IMAGE_TRANSPORT_TRANSPORT_HINTS_H #define IMAGE_TRANSPORT_TRANSPORT_HINTS_H #include <ros/ros.h> namespace image_transport { /** * \brief Stores transport settings for an image topic subscription. */ class TransportHints { public: /** * \brief Constructor. * * The default transport can be overridden by setting a certain parameter to the * name of the desired transport. By default this parameter is named "image_transport" * in the node's local namespace. For consistency across ROS applications, the * name of this parameter should not be changed without good reason. * * @param default_transport Preferred transport to use * @param ros_hints Hints to pass through to ROS subscriptions * @param parameter_nh Node handle to use when looking up the transport parameter. * Defaults to the local namespace. * @param parameter_name The name of the transport parameter */ TransportHints(const std::string& default_transport = "raw", const ros::TransportHints& ros_hints = ros::TransportHints(), const ros::NodeHandle& parameter_nh = ros::NodeHandle("~"), const std::string& parameter_name = "image_transport") : ros_hints_(ros_hints), parameter_nh_(parameter_nh) { parameter_nh_.param(parameter_name, transport_, default_transport); } const std::string& getTransport() const { return transport_; } const ros::TransportHints& getRosHints() const { return ros_hints_; } const ros::NodeHandle& getParameterNH() const { return parameter_nh_; } private: std::string transport_; ros::TransportHints ros_hints_; ros::NodeHandle parameter_nh_; }; } //namespace image_transport #endif
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include/image_transport/subscriber_plugin.h
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef IMAGE_TRANSPORT_SUBSCRIBER_PLUGIN_H #define IMAGE_TRANSPORT_SUBSCRIBER_PLUGIN_H #include <ros/ros.h> #include <sensor_msgs/Image.h> #include <boost/noncopyable.hpp> #include "image_transport/transport_hints.h" namespace image_transport { /** * \brief Base class for plugins to Subscriber. */ class SubscriberPlugin : boost::noncopyable { public: typedef boost::function<void(const sensor_msgs::ImageConstPtr&)> Callback; virtual ~SubscriberPlugin() {} /** * \brief Get a string identifier for the transport provided by * this plugin. */ virtual std::string getTransportName() const = 0; /** * \brief Subscribe to an image topic, version for arbitrary boost::function object. */ void subscribe(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size, const Callback& callback, const ros::VoidPtr& tracked_object = ros::VoidPtr(), const TransportHints& transport_hints = TransportHints()) { return subscribeImpl(nh, base_topic, queue_size, callback, tracked_object, transport_hints); } /** * \brief Subscribe to an image topic, version for bare function. */ void subscribe(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size, void(*fp)(const sensor_msgs::ImageConstPtr&), const TransportHints& transport_hints = TransportHints()) { return subscribe(nh, base_topic, queue_size, boost::function<void(const sensor_msgs::ImageConstPtr&)>(fp), ros::VoidPtr(), transport_hints); } /** * \brief Subscribe to an image topic, version for class member function with bare pointer. */ template<class T> void subscribe(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size, void(T::*fp)(const sensor_msgs::ImageConstPtr&), T* obj, const TransportHints& transport_hints = TransportHints()) { return subscribe(nh, base_topic, queue_size, boost::bind(fp, obj, _1), ros::VoidPtr(), transport_hints); } /** * \brief Subscribe to an image topic, version for class member function with shared_ptr. */ template<class T> void subscribe(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size, void(T::*fp)(const sensor_msgs::ImageConstPtr&), const boost::shared_ptr<T>& obj, const TransportHints& transport_hints = TransportHints()) { return subscribe(nh, base_topic, queue_size, boost::bind(fp, obj.get(), _1), obj, transport_hints); } /** * \brief Get the transport-specific communication topic. */ virtual std::string getTopic() const = 0; /** * \brief Returns the number of publishers this subscriber is connected to. */ virtual uint32_t getNumPublishers() const = 0; /** * \brief Unsubscribe the callback associated with this SubscriberPlugin. */ virtual void shutdown() = 0; /** * \brief Return the lookup name of the SubscriberPlugin associated with a specific * transport identifier. */ static std::string getLookupName(const std::string& transport_type) { return "image_transport/" + transport_type + "_sub"; } protected: /** * \brief Subscribe to an image transport topic. Must be implemented by the subclass. */ virtual void subscribeImpl(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size, const Callback& callback, const ros::VoidPtr& tracked_object, const TransportHints& transport_hints) = 0; }; } //namespace image_transport #endif
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include/image_transport/camera_subscriber.h
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef IMAGE_TRANSPORT_CAMERA_SUBSCRIBER_H #define IMAGE_TRANSPORT_CAMERA_SUBSCRIBER_H #include <ros/ros.h> #include <sensor_msgs/CameraInfo.h> #include <sensor_msgs/Image.h> #include "image_transport/transport_hints.h" namespace image_transport { class ImageTransport; /** * \brief Manages a subscription callback on synchronized Image and CameraInfo topics. * * CameraSubscriber is the client-side counterpart to CameraPublisher, and assumes the * same topic naming convention. The callback is of type: \verbatim void callback(const sensor_msgs::ImageConstPtr&, const sensor_msgs::CameraInfoConstPtr&); \endverbatim * * A CameraSubscriber should always be created through a call to * ImageTransport::subscribeCamera(), or copied from one that was. * Once all copies of a specific CameraSubscriber go out of scope, the subscription callback * associated with that handle will stop being called. Once all CameraSubscriber for a given * topic go out of scope the topic will be unsubscribed. */ class CameraSubscriber { public: typedef boost::function<void(const sensor_msgs::ImageConstPtr&, const sensor_msgs::CameraInfoConstPtr&)> Callback; CameraSubscriber() {} /** * \brief Get the base topic (on which the raw image is published). */ std::string getTopic() const; /** * \brief Get the camera info topic. */ std::string getInfoTopic() const; /** * \brief Returns the number of publishers this subscriber is connected to. */ uint32_t getNumPublishers() const; /** * \brief Returns the name of the transport being used. */ std::string getTransport() const; /** * \brief Unsubscribe the callback associated with this CameraSubscriber. */ void shutdown(); operator void*() const; bool operator< (const CameraSubscriber& rhs) const { return impl_ < rhs.impl_; } bool operator!=(const CameraSubscriber& rhs) const { return impl_ != rhs.impl_; } bool operator==(const CameraSubscriber& rhs) const { return impl_ == rhs.impl_; } private: CameraSubscriber(ImageTransport& image_it, ros::NodeHandle& info_nh, const std::string& base_topic, uint32_t queue_size, const Callback& callback, const ros::VoidPtr& tracked_object = ros::VoidPtr(), const TransportHints& transport_hints = TransportHints()); struct Impl; typedef boost::shared_ptr<Impl> ImplPtr; typedef boost::weak_ptr<Impl> ImplWPtr; ImplPtr impl_; friend class ImageTransport; }; } //namespace image_transport #endif
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include/image_transport/publisher_plugin.h
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef IMAGE_TRANSPORT_PUBLISHER_PLUGIN_H #define IMAGE_TRANSPORT_PUBLISHER_PLUGIN_H #include <ros/ros.h> #include <sensor_msgs/Image.h> #include "image_transport/single_subscriber_publisher.h" namespace image_transport { /** * \brief Base class for plugins to Publisher. */ class PublisherPlugin : boost::noncopyable { public: virtual ~PublisherPlugin() {} /** * \brief Get a string identifier for the transport provided by * this plugin. */ virtual std::string getTransportName() const = 0; /** * \brief Advertise a topic, simple version. */ void advertise(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size, bool latch = true) { advertiseImpl(nh, base_topic, queue_size, SubscriberStatusCallback(), SubscriberStatusCallback(), ros::VoidPtr(), latch); } /** * \brief Advertise a topic with subscriber status callbacks. */ void advertise(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size, const SubscriberStatusCallback& connect_cb, const SubscriberStatusCallback& disconnect_cb = SubscriberStatusCallback(), const ros::VoidPtr& tracked_object = ros::VoidPtr(), bool latch = true) { advertiseImpl(nh, base_topic, queue_size, connect_cb, disconnect_cb, tracked_object, latch); } /** * \brief Returns the number of subscribers that are currently connected to * this PublisherPlugin. */ virtual uint32_t getNumSubscribers() const = 0; /** * \brief Returns the communication topic that this PublisherPlugin will publish on. */ virtual std::string getTopic() const = 0; /** * \brief Publish an image using the transport associated with this PublisherPlugin. */ virtual void publish(const sensor_msgs::Image& message) const = 0; /** * \brief Publish an image using the transport associated with this PublisherPlugin. */ virtual void publish(const sensor_msgs::ImageConstPtr& message) const { publish(*message); } /** * \brief Publish an image using the transport associated with this PublisherPlugin. * This version of the function can be used to optimize cases where you don't want to * fill a ROS message first to avoid useless copies. * @param message an image message to use information from (but not data) * @param data a pointer to the image data to use to fill the Image message */ virtual void publish(const sensor_msgs::Image& message, const uint8_t* data) const { sensor_msgs::Image msg; msg.header = message.header; msg.height = message.height; msg.width = message.width; msg.encoding = message.encoding; msg.is_bigendian = message.is_bigendian; msg.step = message.step; msg.data = std::vector<uint8_t>(data, data + msg.step*msg.height); publish(msg); } /** * \brief Shutdown any advertisements associated with this PublisherPlugin. */ virtual void shutdown() = 0; /** * \brief Return the lookup name of the PublisherPlugin associated with a specific * transport identifier. */ static std::string getLookupName(const std::string& transport_name) { return "image_transport/" + transport_name + "_pub"; } protected: /** * \brief Advertise a topic. Must be implemented by the subclass. */ virtual void advertiseImpl(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size, const SubscriberStatusCallback& connect_cb, const SubscriberStatusCallback& disconnect_cb, const ros::VoidPtr& tracked_object, bool latch) = 0; }; } //namespace image_transport #endif
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include/image_transport/loader_fwds.h
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef IMAGE_TRANSPORT_LOADER_FWDS_H #define IMAGE_TRANSPORT_LOADER_FWDS_H // Forward-declare some classes most users shouldn't care about so that // image_transport.h doesn't bring them in. namespace pluginlib { template<class T> class ClassLoader; } namespace image_transport { class PublisherPlugin; class SubscriberPlugin; typedef pluginlib::ClassLoader<PublisherPlugin> PubLoader; typedef boost::shared_ptr<PubLoader> PubLoaderPtr; typedef pluginlib::ClassLoader<SubscriberPlugin> SubLoader; typedef boost::shared_ptr<SubLoader> SubLoaderPtr; } #endif
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include/image_transport/simple_publisher_plugin.h
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef IMAGE_TRANSPORT_SIMPLE_PUBLISHER_PLUGIN_H #define IMAGE_TRANSPORT_SIMPLE_PUBLISHER_PLUGIN_H #include "image_transport/publisher_plugin.h" #include <boost/scoped_ptr.hpp> namespace image_transport { /** * \brief Base class to simplify implementing most plugins to Publisher. * * This base class vastly simplifies implementing a PublisherPlugin in the common * case that all communication with the matching SubscriberPlugin happens over a * single ROS topic using a transport-specific message type. SimplePublisherPlugin * is templated on the transport-specific message type. * * A subclass need implement only two methods: * - getTransportName() from PublisherPlugin * - publish() with an extra PublishFn argument * * For access to the parameter server and name remappings, use nh(). * * getTopicToAdvertise() controls the name of the internal communication topic. * It defaults to \<base topic\>/\<transport name\>. */ template <class M> class SimplePublisherPlugin : public PublisherPlugin { public: virtual ~SimplePublisherPlugin() {} virtual uint32_t getNumSubscribers() const { if (simple_impl_) return simple_impl_->pub_.getNumSubscribers(); return 0; } virtual std::string getTopic() const { if (simple_impl_) return simple_impl_->pub_.getTopic(); return std::string(); } virtual void publish(const sensor_msgs::Image& message) const { if (!simple_impl_ || !simple_impl_->pub_) { ROS_ASSERT_MSG(false, "Call to publish() on an invalid image_transport::SimplePublisherPlugin"); return; } publish(message, bindInternalPublisher(simple_impl_->pub_)); } virtual void shutdown() { if (simple_impl_) simple_impl_->pub_.shutdown(); } protected: virtual void advertiseImpl(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size, const SubscriberStatusCallback& user_connect_cb, const SubscriberStatusCallback& user_disconnect_cb, const ros::VoidPtr& tracked_object, bool latch) { std::string transport_topic = getTopicToAdvertise(base_topic); ros::NodeHandle param_nh(transport_topic); simple_impl_.reset(new SimplePublisherPluginImpl(param_nh)); simple_impl_->pub_ = nh.advertise<M>(transport_topic, queue_size, bindCB(user_connect_cb, &SimplePublisherPlugin::connectCallback), bindCB(user_disconnect_cb, &SimplePublisherPlugin::disconnectCallback), tracked_object, latch); } //! Generic function for publishing the internal message type. typedef boost::function<void(const M&)> PublishFn; /** * \brief Publish an image using the specified publish function. Must be implemented by * the subclass. * * The PublishFn publishes the transport-specific message type. This indirection allows * SimpleSubscriberPlugin to use this function for both normal broadcast publishing and * single subscriber publishing (in subscription callbacks). */ virtual void publish(const sensor_msgs::Image& message, const PublishFn& publish_fn) const = 0; /** * \brief Return the communication topic name for a given base topic. * * Defaults to \<base topic\>/\<transport name\>. */ virtual std::string getTopicToAdvertise(const std::string& base_topic) const { return base_topic + "/" + getTransportName(); } /** * \brief Function called when a subscriber connects to the internal publisher. * * Defaults to noop. */ virtual void connectCallback(const ros::SingleSubscriberPublisher& pub) {} /** * \brief Function called when a subscriber disconnects from the internal publisher. * * Defaults to noop. */ virtual void disconnectCallback(const ros::SingleSubscriberPublisher& pub) {} /** * \brief Returns the ros::NodeHandle to be used for parameter lookup. */ const ros::NodeHandle& nh() const { return simple_impl_->param_nh_; } /** * \brief Returns the internal ros::Publisher. * * This really only exists so RawPublisher can implement no-copy intraprocess message * passing easily. */ const ros::Publisher& getPublisher() const { ROS_ASSERT(simple_impl_); return simple_impl_->pub_; } private: struct SimplePublisherPluginImpl { SimplePublisherPluginImpl(const ros::NodeHandle& nh) : param_nh_(nh) { } const ros::NodeHandle param_nh_; ros::Publisher pub_; }; boost::scoped_ptr<SimplePublisherPluginImpl> simple_impl_; typedef void (SimplePublisherPlugin::*SubscriberStatusMemFn)(const ros::SingleSubscriberPublisher& pub); /** * Binds the user callback to subscriberCB(), which acts as an intermediary to expose * a publish(Image) interface to the user while publishing to an internal topic. */ ros::SubscriberStatusCallback bindCB(const SubscriberStatusCallback& user_cb, SubscriberStatusMemFn internal_cb_fn) { ros::SubscriberStatusCallback internal_cb = boost::bind(internal_cb_fn, this, _1); if (user_cb) return boost::bind(&SimplePublisherPlugin::subscriberCB, this, _1, user_cb, internal_cb); else return internal_cb; } /** * Forms the ros::SingleSubscriberPublisher for the internal communication topic into * an image_transport::SingleSubscriberPublisher for Image messages and passes it * to the user subscriber status callback. */ void subscriberCB(const ros::SingleSubscriberPublisher& ros_ssp, const SubscriberStatusCallback& user_cb, const ros::SubscriberStatusCallback& internal_cb) { // First call the internal callback (for sending setup headers, etc.) internal_cb(ros_ssp); // Construct a function object for publishing sensor_msgs::Image through the // subclass-implemented publish() using the ros::SingleSubscriberPublisher to send // messages of the transport-specific type. typedef void (SimplePublisherPlugin::*PublishMemFn)(const sensor_msgs::Image&, const PublishFn&) const; PublishMemFn pub_mem_fn = &SimplePublisherPlugin::publish; ImagePublishFn image_publish_fn = boost::bind(pub_mem_fn, this, _1, bindInternalPublisher(ros_ssp)); SingleSubscriberPublisher ssp(ros_ssp.getSubscriberName(), getTopic(), boost::bind(&SimplePublisherPlugin::getNumSubscribers, this), image_publish_fn); user_cb(ssp); } typedef boost::function<void(const sensor_msgs::Image&)> ImagePublishFn; /** * Returns a function object for publishing the transport-specific message type * through some ROS publisher type. * * @param pub An object with method void publish(const M&) */ template <class PubT> PublishFn bindInternalPublisher(const PubT& pub) const { // Bind PubT::publish(const Message&) as PublishFn typedef void (PubT::*InternalPublishMemFn)(const M&) const; InternalPublishMemFn internal_pub_mem_fn = &PubT::publish; return boost::bind(internal_pub_mem_fn, &pub, _1); } }; } //namespace image_transport #endif
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include/image_transport/raw_publisher.h
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef IMAGE_TRANSPORT_RAW_PUBLISHER_H #define IMAGE_TRANSPORT_RAW_PUBLISHER_H #include "image_transport/simple_publisher_plugin.h" namespace image_transport { /** * \brief The default PublisherPlugin. * * RawPublisher is a simple wrapper for ros::Publisher, publishing unaltered Image * messages on the base topic. */ class RawPublisher : public SimplePublisherPlugin<sensor_msgs::Image> { public: virtual ~RawPublisher() {} virtual std::string getTransportName() const { return "raw"; } // Override the default implementation because publishing the message pointer allows // the no-copy intraprocess optimization. virtual void publish(const sensor_msgs::ImageConstPtr& message) const { getPublisher().publish(message); } // Override the default implementation to not copy data to a sensor_msgs::Image first virtual void publish(const sensor_msgs::Image& message, const uint8_t* data) const; protected: virtual void publish(const sensor_msgs::Image& message, const PublishFn& publish_fn) const { publish_fn(message); } virtual std::string getTopicToAdvertise(const std::string& base_topic) const { return base_topic; } }; } //namespace image_transport #endif
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include/image_transport/publisher.h
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef IMAGE_TRANSPORT_PUBLISHER_H #define IMAGE_TRANSPORT_PUBLISHER_H #include <ros/ros.h> #include <sensor_msgs/Image.h> #include "image_transport/single_subscriber_publisher.h" #include "image_transport/exception.h" #include "image_transport/loader_fwds.h" namespace image_transport { /** * \brief Manages advertisements of multiple transport options on an Image topic. * * Publisher is a drop-in replacement for ros::Publisher when publishing * Image topics. In a minimally built environment, they behave the same; however, * Publisher is extensible via plugins to publish alternative representations of * the image on related subtopics. This is especially useful for limiting bandwidth and * latency over a network connection, when you might (for example) use the theora plugin * to transport the images as streamed video. All topics are published only on demand * (i.e. if there are subscribers). * * A Publisher should always be created through a call to ImageTransport::advertise(), * or copied from one that was. * Once all copies of a specific Publisher go out of scope, any subscriber callbacks * associated with that handle will stop being called. Once all Publisher for a * given base topic go out of scope the topic (and all subtopics) will be unadvertised. */ class Publisher { public: Publisher() {} /*! * \brief Returns the number of subscribers that are currently connected to * this Publisher. * * Returns the total number of subscribers to all advertised topics. */ uint32_t getNumSubscribers() const; /*! * \brief Returns the base topic of this Publisher. */ std::string getTopic() const; /*! * \brief Publish an image on the topics associated with this Publisher. */ void publish(const sensor_msgs::Image& message) const; /*! * \brief Publish an image on the topics associated with this Publisher. */ void publish(const sensor_msgs::ImageConstPtr& message) const; /*! * \brief Shutdown the advertisements associated with this Publisher. */ void shutdown(); operator void*() const; bool operator< (const Publisher& rhs) const { return impl_ < rhs.impl_; } bool operator!=(const Publisher& rhs) const { return impl_ != rhs.impl_; } bool operator==(const Publisher& rhs) const { return impl_ == rhs.impl_; } private: Publisher(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size, const SubscriberStatusCallback& connect_cb, const SubscriberStatusCallback& disconnect_cb, const ros::VoidPtr& tracked_object, bool latch, const PubLoaderPtr& loader); struct Impl; typedef boost::shared_ptr<Impl> ImplPtr; typedef boost::weak_ptr<Impl> ImplWPtr; ImplPtr impl_; static void weakSubscriberCb(const ImplWPtr& impl_wptr, const SingleSubscriberPublisher& plugin_pub, const SubscriberStatusCallback& user_cb); SubscriberStatusCallback rebindCB(const SubscriberStatusCallback& user_cb); friend class ImageTransport; }; } //namespace image_transport #endif
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include/image_transport/camera_common.h
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef IMAGE_TRANSPORT_CAMERA_COMMON_H #define IMAGE_TRANSPORT_CAMERA_COMMON_H #include <string> namespace image_transport { /// \brief Form the camera info topic name, sibling to the base topic std::string getCameraInfoTopic(const std::string& base_topic); } //namespace image_transport #endif
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include/image_transport/raw_subscriber.h
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef IMAGE_TRANSPORT_RAW_SUBSCRIBER_H #define IMAGE_TRANSPORT_RAW_SUBSCRIBER_H #include "image_transport/simple_subscriber_plugin.h" namespace image_transport { /** * \brief The default SubscriberPlugin. * * RawSubscriber is a simple wrapper for ros::Subscriber which listens for Image messages * and passes them through to the callback. */ class RawSubscriber : public SimpleSubscriberPlugin<sensor_msgs::Image> { public: virtual ~RawSubscriber() {} virtual std::string getTransportName() const { return "raw"; } protected: virtual void internalCallback(const sensor_msgs::ImageConstPtr& message, const Callback& user_cb) { user_cb(message); } virtual std::string getTopicToSubscribe(const std::string& base_topic) const { return base_topic; } }; } //namespace image_transport #endif
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include/image_transport/subscriber.h
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef IMAGE_TRANSPORT_SUBSCRIBER_H #define IMAGE_TRANSPORT_SUBSCRIBER_H #include <ros/ros.h> #include <sensor_msgs/Image.h> #include "image_transport/transport_hints.h" #include "image_transport/exception.h" #include "image_transport/loader_fwds.h" namespace image_transport { /** * \brief Manages a subscription callback on a specific topic that can be interpreted * as an Image topic. * * Subscriber is the client-side counterpart to Publisher. By loading the * appropriate plugin, it can subscribe to a base image topic using any available * transport. The complexity of what transport is actually used is hidden from the user, * who sees only a normal Image callback. * * A Subscriber should always be created through a call to ImageTransport::subscribe(), * or copied from one that was. * Once all copies of a specific Subscriber go out of scope, the subscription callback * associated with that handle will stop being called. Once all Subscriber for a given * topic go out of scope the topic will be unsubscribed. */ class Subscriber { public: Subscriber() {} /** * \brief Returns the base image topic. * * The Subscriber may actually be subscribed to some transport-specific topic that * differs from the base topic. */ std::string getTopic() const; /** * \brief Returns the number of publishers this subscriber is connected to. */ uint32_t getNumPublishers() const; /** * \brief Returns the name of the transport being used. */ std::string getTransport() const; /** * \brief Unsubscribe the callback associated with this Subscriber. */ void shutdown(); operator void*() const; bool operator< (const Subscriber& rhs) const { return impl_ < rhs.impl_; } bool operator!=(const Subscriber& rhs) const { return impl_ != rhs.impl_; } bool operator==(const Subscriber& rhs) const { return impl_ == rhs.impl_; } private: Subscriber(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size, const boost::function<void(const sensor_msgs::ImageConstPtr&)>& callback, const ros::VoidPtr& tracked_object, const TransportHints& transport_hints, const SubLoaderPtr& loader); struct Impl; typedef boost::shared_ptr<Impl> ImplPtr; typedef boost::weak_ptr<Impl> ImplWPtr; ImplPtr impl_; friend class ImageTransport; }; } //namespace image_transport #endif
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include/image_transport/camera_publisher.h
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef IMAGE_TRANSPORT_CAMERA_PUBLISHER_H #define IMAGE_TRANSPORT_CAMERA_PUBLISHER_H #include <ros/ros.h> #include <sensor_msgs/Image.h> #include <sensor_msgs/CameraInfo.h> #include "image_transport/single_subscriber_publisher.h" namespace image_transport { class ImageTransport; /** * \brief Manages advertisements for publishing camera images. * * CameraPublisher is a convenience class for publishing synchronized image and * camera info topics using the standard topic naming convention, where the info * topic name is "camera_info" in the same namespace as the base image topic. * * On the client side, CameraSubscriber simplifies subscribing to camera images. * * A CameraPublisher should always be created through a call to * ImageTransport::advertiseCamera(), or copied from one that was. * Once all copies of a specific CameraPublisher go out of scope, any subscriber callbacks * associated with that handle will stop being called. Once all CameraPublisher for a * given base topic go out of scope the topic (and all subtopics) will be unadvertised. */ class CameraPublisher { public: CameraPublisher() {} /*! * \brief Returns the number of subscribers that are currently connected to * this CameraPublisher. * * Returns max(image topic subscribers, info topic subscribers). */ uint32_t getNumSubscribers() const; /*! * \brief Returns the base (image) topic of this CameraPublisher. */ std::string getTopic() const; /** * \brief Returns the camera info topic of this CameraPublisher. */ std::string getInfoTopic() const; /*! * \brief Publish an (image, info) pair on the topics associated with this CameraPublisher. */ void publish(const sensor_msgs::Image& image, const sensor_msgs::CameraInfo& info) const; /*! * \brief Publish an (image, info) pair on the topics associated with this CameraPublisher. */ void publish(const sensor_msgs::ImageConstPtr& image, const sensor_msgs::CameraInfoConstPtr& info) const; /*! * \brief Publish an (image, info) pair with given timestamp on the topics associated with * this CameraPublisher. * * Convenience version, which sets the timestamps of both image and info to stamp before * publishing. */ void publish(sensor_msgs::Image& image, sensor_msgs::CameraInfo& info, ros::Time stamp) const; /*! * \brief Shutdown the advertisements associated with this Publisher. */ void shutdown(); operator void*() const; bool operator< (const CameraPublisher& rhs) const { return impl_ < rhs.impl_; } bool operator!=(const CameraPublisher& rhs) const { return impl_ != rhs.impl_; } bool operator==(const CameraPublisher& rhs) const { return impl_ == rhs.impl_; } private: CameraPublisher(ImageTransport& image_it, ros::NodeHandle& info_nh, const std::string& base_topic, uint32_t queue_size, const SubscriberStatusCallback& image_connect_cb, const SubscriberStatusCallback& image_disconnect_cb, const ros::SubscriberStatusCallback& info_connect_cb, const ros::SubscriberStatusCallback& info_disconnect_cb, const ros::VoidPtr& tracked_object, bool latch); struct Impl; typedef boost::shared_ptr<Impl> ImplPtr; typedef boost::weak_ptr<Impl> ImplWPtr; ImplPtr impl_; friend class ImageTransport; }; } //namespace image_transport #endif
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include/image_transport/subscriber_filter.h
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef IMAGE_TRANSPORT_SUBSCRIBER_FILTER_H #define IMAGE_TRANSPORT_SUBSCRIBER_FILTER_H #include <ros/ros.h> #include <message_filters/simple_filter.h> #include "image_transport/image_transport.h" namespace image_transport { /** * \brief Image subscription filter. * * This class wraps Subscriber as a "filter" compatible with the message_filters * package. It acts as a highest-level filter, simply passing messages from an image * transport subscription through to the filters which have connected to it. * * When this object is destroyed it will unsubscribe from the ROS subscription. * * \section connections CONNECTIONS * * SubscriberFilter has no input connection. * * The output connection for the SubscriberFilter object is the same signature as for roscpp * subscription callbacks, ie. \verbatim void callback(const boost::shared_ptr<const sensor_msgs::Image>&); \endverbatim */ class SubscriberFilter : public message_filters::SimpleFilter<sensor_msgs::Image> { public: /** * \brief Constructor * * See the ros::NodeHandle::subscribe() variants for more information on the parameters * * \param nh The ros::NodeHandle to use to subscribe. * \param base_topic The topic to subscribe to. * \param queue_size The subscription queue size * \param transport_hints The transport hints to pass along */ SubscriberFilter(ImageTransport& it, const std::string& base_topic, uint32_t queue_size, const TransportHints& transport_hints = TransportHints()) { subscribe(it, base_topic, queue_size, transport_hints); } /** * \brief Empty constructor, use subscribe() to subscribe to a topic */ SubscriberFilter() { } ~SubscriberFilter() { unsubscribe(); } /** * \brief Subscribe to a topic. * * If this Subscriber is already subscribed to a topic, this function will first unsubscribe. * * \param nh The ros::NodeHandle to use to subscribe. * \param base_topic The topic to subscribe to. * \param queue_size The subscription queue size * \param transport_hints The transport hints to pass along */ void subscribe(ImageTransport& it, const std::string& base_topic, uint32_t queue_size, const TransportHints& transport_hints = TransportHints()) { unsubscribe(); sub_ = it.subscribe(base_topic, queue_size, boost::bind(&SubscriberFilter::cb, this, _1), ros::VoidPtr(), transport_hints); } /** * \brief Force immediate unsubscription of this subscriber from its topic */ void unsubscribe() { sub_.shutdown(); } std::string getTopic() const { return sub_.getTopic(); } /** * \brief Returns the number of publishers this subscriber is connected to. */ uint32_t getNumPublishers() const { return sub_.getNumPublishers(); } /** * \brief Returns the name of the transport being used. */ std::string getTransport() const { return sub_.getTransport(); } /** * \brief Returns the internal image_transport::Subscriber object. */ const Subscriber& getSubscriber() const { return sub_; } private: void cb(const sensor_msgs::ImageConstPtr& m) { signalMessage(m); } Subscriber sub_; }; } #endif
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include/image_transport/exception.h
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef IMAGE_TRANSPORT_EXCEPTION_H #define IMAGE_TRANSPORT_EXCEPTION_H #include <stdexcept> namespace image_transport { /** * \brief A base class for all image_transport exceptions inheriting from std::runtime_error. */ class Exception : public std::runtime_error { public: Exception(const std::string& message) : std::runtime_error(message) {} }; /** * \brief An exception class thrown when image_transport is unable to load a requested transport. */ class TransportLoadException : public Exception { public: TransportLoadException(const std::string& transport, const std::string& message) : Exception("Unable to load plugin for transport '" + transport + "', error string:\n" + message), transport_(transport.c_str()) { } std::string getTransport() const { return transport_; } protected: const char* transport_; }; } //namespace image_transport #endif
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include/image_transport/single_subscriber_publisher.h
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef IMAGE_TRANSPORT_SINGLE_SUBSCRIBER_PUBLISHER #define IMAGE_TRANSPORT_SINGLE_SUBSCRIBER_PUBLISHER #include <boost/noncopyable.hpp> #include <boost/function.hpp> #include <sensor_msgs/Image.h> namespace image_transport { /** * \brief Allows publication of an image to a single subscriber. Only available inside * subscriber connection callbacks. */ class SingleSubscriberPublisher : boost::noncopyable { public: typedef boost::function<uint32_t()> GetNumSubscribersFn; typedef boost::function<void(const sensor_msgs::Image&)> PublishFn; SingleSubscriberPublisher(const std::string& caller_id, const std::string& topic, const GetNumSubscribersFn& num_subscribers_fn, const PublishFn& publish_fn); std::string getSubscriberName() const; std::string getTopic() const; uint32_t getNumSubscribers() const; void publish(const sensor_msgs::Image& message) const; void publish(const sensor_msgs::ImageConstPtr& message) const; private: std::string caller_id_; std::string topic_; GetNumSubscribersFn num_subscribers_fn_; PublishFn publish_fn_; friend class Publisher; // to get publish_fn_ directly }; typedef boost::function<void(const SingleSubscriberPublisher&)> SubscriberStatusCallback; } //namespace image_transport #endif
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include
apollo_public_repos/apollo-platform/ros/image_common/image_transport/include/image_transport/image_transport.h
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #ifndef IMAGE_TRANSPORT_IMAGE_TRANSPORT_H #define IMAGE_TRANSPORT_IMAGE_TRANSPORT_H #include "image_transport/publisher.h" #include "image_transport/subscriber.h" #include "image_transport/camera_publisher.h" #include "image_transport/camera_subscriber.h" namespace image_transport { /** * \brief Advertise and subscribe to image topics. * * ImageTransport is analogous to ros::NodeHandle in that it contains advertise() and * subscribe() functions for creating advertisements and subscriptions of image topics. */ class ImageTransport { public: explicit ImageTransport(const ros::NodeHandle& nh); ~ImageTransport(); /*! * \brief Advertise an image topic, simple version. */ Publisher advertise(const std::string& base_topic, uint32_t queue_size, bool latch = false); /*! * \brief Advertise an image topic with subcriber status callbacks. */ Publisher advertise(const std::string& base_topic, uint32_t queue_size, const SubscriberStatusCallback& connect_cb, const SubscriberStatusCallback& disconnect_cb = SubscriberStatusCallback(), const ros::VoidPtr& tracked_object = ros::VoidPtr(), bool latch = false); /** * \brief Subscribe to an image topic, version for arbitrary boost::function object. */ Subscriber subscribe(const std::string& base_topic, uint32_t queue_size, const boost::function<void(const sensor_msgs::ImageConstPtr&)>& callback, const ros::VoidPtr& tracked_object = ros::VoidPtr(), const TransportHints& transport_hints = TransportHints()); /** * \brief Subscribe to an image topic, version for bare function. */ Subscriber subscribe(const std::string& base_topic, uint32_t queue_size, void(*fp)(const sensor_msgs::ImageConstPtr&), const TransportHints& transport_hints = TransportHints()) { return subscribe(base_topic, queue_size, boost::function<void(const sensor_msgs::ImageConstPtr&)>(fp), ros::VoidPtr(), transport_hints); } /** * \brief Subscribe to an image topic, version for class member function with bare pointer. */ template<class T> Subscriber subscribe(const std::string& base_topic, uint32_t queue_size, void(T::*fp)(const sensor_msgs::ImageConstPtr&), T* obj, const TransportHints& transport_hints = TransportHints()) { return subscribe(base_topic, queue_size, boost::bind(fp, obj, _1), ros::VoidPtr(), transport_hints); } /** * \brief Subscribe to an image topic, version for class member function with shared_ptr. */ template<class T> Subscriber subscribe(const std::string& base_topic, uint32_t queue_size, void(T::*fp)(const sensor_msgs::ImageConstPtr&), const boost::shared_ptr<T>& obj, const TransportHints& transport_hints = TransportHints()) { return subscribe(base_topic, queue_size, boost::bind(fp, obj.get(), _1), obj, transport_hints); } /*! * \brief Advertise a synchronized camera raw image + info topic pair, simple version. */ CameraPublisher advertiseCamera(const std::string& base_topic, uint32_t queue_size, bool latch = false); /*! * \brief Advertise a synchronized camera raw image + info topic pair with subscriber status * callbacks. */ CameraPublisher advertiseCamera(const std::string& base_topic, uint32_t queue_size, const SubscriberStatusCallback& image_connect_cb, const SubscriberStatusCallback& image_disconnect_cb = SubscriberStatusCallback(), const ros::SubscriberStatusCallback& info_connect_cb = ros::SubscriberStatusCallback(), const ros::SubscriberStatusCallback& info_disconnect_cb = ros::SubscriberStatusCallback(), const ros::VoidPtr& tracked_object = ros::VoidPtr(), bool latch = false); /** * \brief Subscribe to a synchronized image & camera info topic pair, version for arbitrary * boost::function object. * * This version assumes the standard topic naming scheme, where the info topic is * named "camera_info" in the same namespace as the base image topic. */ CameraSubscriber subscribeCamera(const std::string& base_topic, uint32_t queue_size, const CameraSubscriber::Callback& callback, const ros::VoidPtr& tracked_object = ros::VoidPtr(), const TransportHints& transport_hints = TransportHints()); /** * \brief Subscribe to a synchronized image & camera info topic pair, version for bare function. */ CameraSubscriber subscribeCamera(const std::string& base_topic, uint32_t queue_size, void(*fp)(const sensor_msgs::ImageConstPtr&, const sensor_msgs::CameraInfoConstPtr&), const TransportHints& transport_hints = TransportHints()) { return subscribeCamera(base_topic, queue_size, CameraSubscriber::Callback(fp), ros::VoidPtr(), transport_hints); } /** * \brief Subscribe to a synchronized image & camera info topic pair, version for class member * function with bare pointer. */ template<class T> CameraSubscriber subscribeCamera(const std::string& base_topic, uint32_t queue_size, void(T::*fp)(const sensor_msgs::ImageConstPtr&, const sensor_msgs::CameraInfoConstPtr&), T* obj, const TransportHints& transport_hints = TransportHints()) { return subscribeCamera(base_topic, queue_size, boost::bind(fp, obj, _1, _2), ros::VoidPtr(), transport_hints); } /** * \brief Subscribe to a synchronized image & camera info topic pair, version for class member * function with shared_ptr. */ template<class T> CameraSubscriber subscribeCamera(const std::string& base_topic, uint32_t queue_size, void(T::*fp)(const sensor_msgs::ImageConstPtr&, const sensor_msgs::CameraInfoConstPtr&), const boost::shared_ptr<T>& obj, const TransportHints& transport_hints = TransportHints()) { return subscribeCamera(base_topic, queue_size, boost::bind(fp, obj.get(), _1, _2), obj, transport_hints); } /** * \brief Returns the names of all transports declared in the system. Declared * transports are not necessarily built or loadable. */ std::vector<std::string> getDeclaredTransports() const; /** * \brief Returns the names of all transports that are loadable in the system. */ std::vector<std::string> getLoadableTransports() const; private: struct Impl; typedef boost::shared_ptr<Impl> ImplPtr; typedef boost::weak_ptr<Impl> ImplWPtr; ImplPtr impl_; }; } //namespace image_transport #endif
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport
apollo_public_repos/apollo-platform/ros/image_common/image_transport/src/publisher.cpp
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #include "image_transport/publisher.h" #include "image_transport/publisher_plugin.h" #include <pluginlib/class_loader.h> #include <boost/foreach.hpp> #include <boost/algorithm/string/erase.hpp> namespace image_transport { struct Publisher::Impl { Impl() : unadvertised_(false) { } ~Impl() { shutdown(); } uint32_t getNumSubscribers() const { uint32_t count = 0; BOOST_FOREACH(const boost::shared_ptr<PublisherPlugin>& pub, publishers_) count += pub->getNumSubscribers(); return count; } std::string getTopic() const { return base_topic_; } bool isValid() const { return !unadvertised_; } void shutdown() { if (!unadvertised_) { unadvertised_ = true; BOOST_FOREACH(boost::shared_ptr<PublisherPlugin>& pub, publishers_) pub->shutdown(); publishers_.clear(); } } void subscriberCB(const SingleSubscriberPublisher& plugin_pub, const SubscriberStatusCallback& user_cb) { SingleSubscriberPublisher ssp(plugin_pub.getSubscriberName(), getTopic(), boost::bind(&Publisher::Impl::getNumSubscribers, this), plugin_pub.publish_fn_); user_cb(ssp); } std::string base_topic_; PubLoaderPtr loader_; std::vector<boost::shared_ptr<PublisherPlugin> > publishers_; bool unadvertised_; //double constructed_; }; Publisher::Publisher(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size, const SubscriberStatusCallback& connect_cb, const SubscriberStatusCallback& disconnect_cb, const ros::VoidPtr& tracked_object, bool latch, const PubLoaderPtr& loader) : impl_(new Impl) { // Resolve the name explicitly because otherwise the compressed topics don't remap // properly (#3652). impl_->base_topic_ = nh.resolveName(base_topic); impl_->loader_ = loader; BOOST_FOREACH(const std::string& lookup_name, loader->getDeclaredClasses()) { try { boost::shared_ptr<PublisherPlugin> pub = loader->createInstance(lookup_name); impl_->publishers_.push_back(pub); pub->advertise(nh, impl_->base_topic_, queue_size, rebindCB(connect_cb), rebindCB(disconnect_cb), tracked_object, latch); } catch (const std::runtime_error& e) { ROS_DEBUG("Failed to load plugin %s, error string: %s", lookup_name.c_str(), e.what()); } } if (impl_->publishers_.empty()) throw Exception("No plugins found! Does `rospack plugins --attrib=plugin " "image_transport` find any packages?"); } uint32_t Publisher::getNumSubscribers() const { if (impl_ && impl_->isValid()) return impl_->getNumSubscribers(); return 0; } std::string Publisher::getTopic() const { if (impl_) return impl_->getTopic(); return std::string(); } void Publisher::publish(const sensor_msgs::Image& message) const { if (!impl_ || !impl_->isValid()) { ROS_ASSERT_MSG(false, "Call to publish() on an invalid image_transport::Publisher"); return; } BOOST_FOREACH(const boost::shared_ptr<PublisherPlugin>& pub, impl_->publishers_) { if (pub->getNumSubscribers() > 0) pub->publish(message); } } void Publisher::publish(const sensor_msgs::ImageConstPtr& message) const { if (!impl_ || !impl_->isValid()) { ROS_ASSERT_MSG(false, "Call to publish() on an invalid image_transport::Publisher"); return; } BOOST_FOREACH(const boost::shared_ptr<PublisherPlugin>& pub, impl_->publishers_) { if (pub->getNumSubscribers() > 0) pub->publish(message); } } void Publisher::shutdown() { if (impl_) { impl_->shutdown(); impl_.reset(); } } Publisher::operator void*() const { return (impl_ && impl_->isValid()) ? (void*)1 : (void*)0; } void Publisher::weakSubscriberCb(const ImplWPtr& impl_wptr, const SingleSubscriberPublisher& plugin_pub, const SubscriberStatusCallback& user_cb) { if (ImplPtr impl = impl_wptr.lock()) impl->subscriberCB(plugin_pub, user_cb); } SubscriberStatusCallback Publisher::rebindCB(const SubscriberStatusCallback& user_cb) { // Note: the subscriber callback must be bound to the internal Impl object, not // 'this'. Due to copying behavior the Impl object may outlive the original Publisher // instance. But it should not outlive the last Publisher, so we use a weak_ptr. if (user_cb) { ImplWPtr impl_wptr(impl_); return boost::bind(&Publisher::weakSubscriberCb, impl_wptr, _1, user_cb); } else return SubscriberStatusCallback(); } } //namespace image_transport
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport
apollo_public_repos/apollo-platform/ros/image_common/image_transport/src/camera_publisher.cpp
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #include "image_transport/image_transport.h" #include "image_transport/camera_common.h" namespace image_transport { struct CameraPublisher::Impl { Impl() : unadvertised_(false) { } ~Impl() { shutdown(); } bool isValid() const { return !unadvertised_; } void shutdown() { if (!unadvertised_) { unadvertised_ = true; image_pub_.shutdown(); info_pub_.shutdown(); } } Publisher image_pub_; ros::Publisher info_pub_; bool unadvertised_; //double constructed_; }; CameraPublisher::CameraPublisher(ImageTransport& image_it, ros::NodeHandle& info_nh, const std::string& base_topic, uint32_t queue_size, const SubscriberStatusCallback& image_connect_cb, const SubscriberStatusCallback& image_disconnect_cb, const ros::SubscriberStatusCallback& info_connect_cb, const ros::SubscriberStatusCallback& info_disconnect_cb, const ros::VoidPtr& tracked_object, bool latch) : impl_(new Impl) { // Explicitly resolve name here so we compute the correct CameraInfo topic when the // image topic is remapped (#4539). std::string image_topic = info_nh.resolveName(base_topic); std::string info_topic = getCameraInfoTopic(image_topic); impl_->image_pub_ = image_it.advertise(image_topic, queue_size, image_connect_cb, image_disconnect_cb, tracked_object, latch); impl_->info_pub_ = info_nh.advertise<sensor_msgs::CameraInfo>(info_topic, queue_size, info_connect_cb, info_disconnect_cb, tracked_object, latch); } uint32_t CameraPublisher::getNumSubscribers() const { if (impl_ && impl_->isValid()) return std::max(impl_->image_pub_.getNumSubscribers(), impl_->info_pub_.getNumSubscribers()); return 0; } std::string CameraPublisher::getTopic() const { if (impl_) return impl_->image_pub_.getTopic(); return std::string(); } std::string CameraPublisher::getInfoTopic() const { if (impl_) return impl_->info_pub_.getTopic(); return std::string(); } void CameraPublisher::publish(const sensor_msgs::Image& image, const sensor_msgs::CameraInfo& info) const { if (!impl_ || !impl_->isValid()) { ROS_ASSERT_MSG(false, "Call to publish() on an invalid image_transport::CameraPublisher"); return; } impl_->image_pub_.publish(image); impl_->info_pub_.publish(info); } void CameraPublisher::publish(const sensor_msgs::ImageConstPtr& image, const sensor_msgs::CameraInfoConstPtr& info) const { if (!impl_ || !impl_->isValid()) { ROS_ASSERT_MSG(false, "Call to publish() on an invalid image_transport::CameraPublisher"); return; } impl_->image_pub_.publish(image); impl_->info_pub_.publish(info); } void CameraPublisher::publish(sensor_msgs::Image& image, sensor_msgs::CameraInfo& info, ros::Time stamp) const { if (!impl_ || !impl_->isValid()) { ROS_ASSERT_MSG(false, "Call to publish() on an invalid image_transport::CameraPublisher"); return; } image.header.stamp = stamp; info.header.stamp = stamp; publish(image, info); } void CameraPublisher::shutdown() { if (impl_) { impl_->shutdown(); impl_.reset(); } } CameraPublisher::operator void*() const { return (impl_ && impl_->isValid()) ? (void*)1 : (void*)0; } } //namespace image_transport
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport
apollo_public_repos/apollo-platform/ros/image_common/image_transport/src/camera_common.cpp
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #include "image_transport/camera_common.h" #include <boost/algorithm/string/classification.hpp> #include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/join.hpp> #include <vector> namespace image_transport { std::string getCameraInfoTopic(const std::string& base_topic) { // Split into separate names std::vector<std::string> names; boost::algorithm::split(names, base_topic, boost::algorithm::is_any_of("/"), boost::algorithm::token_compress_on); // Get rid of empty tokens from trailing slashes while (names.back().empty()) names.pop_back(); // Replace image name with "camera_info" names.back() = "camera_info"; // Join back together into topic name return boost::algorithm::join(names, "/"); } } //namespace image_transport
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport
apollo_public_repos/apollo-platform/ros/image_common/image_transport/src/raw_publisher.cpp
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #include <image_transport/raw_publisher.h> #include <ros/static_assert.h> #include <sensor_msgs/Image.h> /** The code in the following namespace copies a lof of code from cv_bridge * It does not depend on cv_bridge to not depend on OpenCV * It re-defines a CvImage so that we can publish that object and not a * sensor_msgs::Image, which requires a memory copy */ class ImageTransportImage { public: sensor_msgs::Image image_; //!< ROS header const uint8_t* data_; //!< Image data for use with OpenCV /** * \brief Empty constructor. */ ImageTransportImage() {} /** * \brief Constructor. */ ImageTransportImage(const sensor_msgs::Image& image, const uint8_t* data) : image_(image), data_(data) { } }; /// @cond DOXYGEN_IGNORE namespace ros { namespace message_traits { template<> struct MD5Sum<ImageTransportImage> { static const char* value() { return MD5Sum<sensor_msgs::Image>::value(); } static const char* value(const ImageTransportImage&) { return value(); } static const uint64_t static_value1 = MD5Sum<sensor_msgs::Image>::static_value1; static const uint64_t static_value2 = MD5Sum<sensor_msgs::Image>::static_value2; // If the definition of sensor_msgs/Image changes, we'll get a compile error here. ROS_STATIC_ASSERT(MD5Sum<sensor_msgs::Image>::static_value1 == 0x060021388200f6f0ULL); ROS_STATIC_ASSERT(MD5Sum<sensor_msgs::Image>::static_value2 == 0xf447d0fcd9c64743ULL); }; template<> struct DataType<ImageTransportImage> { static const char* value() { return DataType<sensor_msgs::Image>::value(); } static const char* value(const ImageTransportImage&) { return value(); } }; template<> struct Definition<ImageTransportImage> { static const char* value() { return Definition<sensor_msgs::Image>::value(); } static const char* value(const ImageTransportImage&) { return value(); } }; template<> struct HasHeader<ImageTransportImage> : TrueType {}; } // namespace ros::message_traits namespace serialization { template<> struct Serializer<ImageTransportImage> { /// @todo Still ignoring endianness... template<typename Stream> inline static void write(Stream& stream, const ImageTransportImage& m) { stream.next(m.image_.header); stream.next((uint32_t)m.image_.height); // height stream.next((uint32_t)m.image_.width); // width stream.next(m.image_.encoding); uint8_t is_bigendian = 0; stream.next(is_bigendian); stream.next((uint32_t)m.image_.step); size_t data_size = m.image_.step*m.image_.height; stream.next((uint32_t)data_size); if (data_size > 0) memcpy(stream.advance(data_size), m.data_, data_size); } inline static uint32_t serializedLength(const ImageTransportImage& m) { size_t data_size = m.image_.step*m.image_.height; return serializationLength(m.image_.header) + serializationLength(m.image_.encoding) + 17 + data_size; } }; } // namespace ros::serialization } // namespace ros namespace image_transport { void RawPublisher::publish(const sensor_msgs::Image& message, const uint8_t* data) const { getPublisher().publish(ImageTransportImage(message, data)); } } //namespace image_transport
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport
apollo_public_repos/apollo-platform/ros/image_common/image_transport/src/camera_subscriber.cpp
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #include "image_transport/camera_subscriber.h" #include "image_transport/subscriber_filter.h" #include "image_transport/camera_common.h" #include <message_filters/subscriber.h> #include <message_filters/time_synchronizer.h> inline void increment(int* value) { ++(*value); } namespace image_transport { struct CameraSubscriber::Impl { Impl(uint32_t queue_size) : sync_(queue_size), unsubscribed_(false), image_received_(0), info_received_(0), both_received_(0) {} ~Impl() { shutdown(); } bool isValid() const { return !unsubscribed_; } void shutdown() { if (!unsubscribed_) { unsubscribed_ = true; image_sub_.unsubscribe(); info_sub_.unsubscribe(); } } void checkImagesSynchronized() { int threshold = 3 * both_received_; if (image_received_ > threshold || info_received_ > threshold) { ROS_WARN_NAMED("sync", // Can suppress ros.image_transport.sync independent of anything else "[image_transport] Topics '%s' and '%s' do not appear to be synchronized. " "In the last 10s:\n" "\tImage messages received: %d\n" "\tCameraInfo messages received: %d\n" "\tSynchronized pairs: %d", image_sub_.getTopic().c_str(), info_sub_.getTopic().c_str(), image_received_, info_received_, both_received_); } image_received_ = info_received_ = both_received_ = 0; } SubscriberFilter image_sub_; message_filters::Subscriber<sensor_msgs::CameraInfo> info_sub_; message_filters::TimeSynchronizer<sensor_msgs::Image, sensor_msgs::CameraInfo> sync_; bool unsubscribed_; // For detecting when the topics aren't synchronized ros::WallTimer check_synced_timer_; int image_received_, info_received_, both_received_; }; CameraSubscriber::CameraSubscriber(ImageTransport& image_it, ros::NodeHandle& info_nh, const std::string& base_topic, uint32_t queue_size, const Callback& callback, const ros::VoidPtr& tracked_object, const TransportHints& transport_hints) : impl_(new Impl(queue_size)) { // Must explicitly remap the image topic since we then do some string manipulation on it // to figure out the sibling camera_info topic. std::string image_topic = info_nh.resolveName(base_topic); std::string info_topic = getCameraInfoTopic(image_topic); impl_->image_sub_.subscribe(image_it, image_topic, queue_size, transport_hints); impl_->info_sub_ .subscribe(info_nh, info_topic, queue_size, transport_hints.getRosHints()); impl_->sync_.connectInput(impl_->image_sub_, impl_->info_sub_); // need for Boost.Bind here is kind of broken impl_->sync_.registerCallback(boost::bind(callback, _1, _2)); // Complain every 10s if it appears that the image and info topics are not synchronized impl_->image_sub_.registerCallback(boost::bind(increment, &impl_->image_received_)); impl_->info_sub_.registerCallback(boost::bind(increment, &impl_->info_received_)); impl_->sync_.registerCallback(boost::bind(increment, &impl_->both_received_)); impl_->check_synced_timer_ = info_nh.createWallTimer(ros::WallDuration(10.0), boost::bind(&Impl::checkImagesSynchronized, impl_.get())); } std::string CameraSubscriber::getTopic() const { if (impl_) return impl_->image_sub_.getTopic(); return std::string(); } std::string CameraSubscriber::getInfoTopic() const { if (impl_) return impl_->info_sub_.getTopic(); return std::string(); } uint32_t CameraSubscriber::getNumPublishers() const { /// @todo Fix this when message_filters::Subscriber has getNumPublishers() //if (impl_) return std::max(impl_->image_sub_.getNumPublishers(), impl_->info_sub_.getNumPublishers()); if (impl_) return impl_->image_sub_.getNumPublishers(); return 0; } std::string CameraSubscriber::getTransport() const { if (impl_) return impl_->image_sub_.getTransport(); return std::string(); } void CameraSubscriber::shutdown() { if (impl_) impl_->shutdown(); } CameraSubscriber::operator void*() const { return (impl_ && impl_->isValid()) ? (void*)1 : (void*)0; } } //namespace image_transport
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport
apollo_public_repos/apollo-platform/ros/image_common/image_transport/src/subscriber.cpp
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #include "image_transport/subscriber.h" #include "image_transport/subscriber_plugin.h" #include <ros/names.h> #include <pluginlib/class_loader.h> #include <boost/scoped_ptr.hpp> namespace image_transport { struct Subscriber::Impl { Impl() : unsubscribed_(false) { } ~Impl() { shutdown(); } bool isValid() const { return !unsubscribed_; } void shutdown() { if (!unsubscribed_) { unsubscribed_ = true; if (subscriber_) subscriber_->shutdown(); } } SubLoaderPtr loader_; boost::shared_ptr<SubscriberPlugin> subscriber_; bool unsubscribed_; //double constructed_; }; Subscriber::Subscriber(ros::NodeHandle& nh, const std::string& base_topic, uint32_t queue_size, const boost::function<void(const sensor_msgs::ImageConstPtr&)>& callback, const ros::VoidPtr& tracked_object, const TransportHints& transport_hints, const SubLoaderPtr& loader) : impl_(new Impl) { // Load the plugin for the chosen transport. std::string lookup_name = SubscriberPlugin::getLookupName(transport_hints.getTransport()); try { impl_->subscriber_ = loader->createInstance(lookup_name); } catch (pluginlib::PluginlibException& e) { throw TransportLoadException(transport_hints.getTransport(), e.what()); } // Hang on to the class loader so our shared library doesn't disappear from under us. impl_->loader_ = loader; // Try to catch if user passed in a transport-specific topic as base_topic. std::string clean_topic = ros::names::clean(base_topic); size_t found = clean_topic.rfind('/'); if (found != std::string::npos) { std::string transport = clean_topic.substr(found+1); std::string plugin_name = SubscriberPlugin::getLookupName(transport); std::vector<std::string> plugins = loader->getDeclaredClasses(); if (std::find(plugins.begin(), plugins.end(), plugin_name) != plugins.end()) { std::string real_base_topic = clean_topic.substr(0, found); ROS_WARN("[image_transport] It looks like you are trying to subscribe directly to a " "transport-specific image topic '%s', in which case you will likely get a connection " "error. Try subscribing to the base topic '%s' instead with parameter ~image_transport " "set to '%s' (on the command line, _image_transport:=%s). " "See http://ros.org/wiki/image_transport for details.", clean_topic.c_str(), real_base_topic.c_str(), transport.c_str(), transport.c_str()); } } // Tell plugin to subscribe. impl_->subscriber_->subscribe(nh, base_topic, queue_size, callback, tracked_object, transport_hints); } std::string Subscriber::getTopic() const { if (impl_) return impl_->subscriber_->getTopic(); return std::string(); } uint32_t Subscriber::getNumPublishers() const { if (impl_) return impl_->subscriber_->getNumPublishers(); return 0; } std::string Subscriber::getTransport() const { if (impl_) return impl_->subscriber_->getTransportName(); return std::string(); } void Subscriber::shutdown() { if (impl_) impl_->shutdown(); } Subscriber::operator void*() const { return (impl_ && impl_->isValid()) ? (void*)1 : (void*)0; } } //namespace image_transport
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport
apollo_public_repos/apollo-platform/ros/image_common/image_transport/src/image_transport.cpp
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #include "image_transport/image_transport.h" #include "image_transport/publisher_plugin.h" #include "image_transport/subscriber_plugin.h" #include <pluginlib/class_loader.h> #include <boost/make_shared.hpp> #include <boost/foreach.hpp> #include <boost/algorithm/string/erase.hpp> namespace image_transport { struct ImageTransport::Impl { ros::NodeHandle nh_; PubLoaderPtr pub_loader_; SubLoaderPtr sub_loader_; Impl(const ros::NodeHandle& nh) : nh_(nh), pub_loader_( boost::make_shared<PubLoader>("image_transport", "image_transport::PublisherPlugin") ), sub_loader_( boost::make_shared<SubLoader>("image_transport", "image_transport::SubscriberPlugin") ) { } }; ImageTransport::ImageTransport(const ros::NodeHandle& nh) : impl_(new Impl(nh)) { } ImageTransport::~ImageTransport() { } Publisher ImageTransport::advertise(const std::string& base_topic, uint32_t queue_size, bool latch) { return advertise(base_topic, queue_size, SubscriberStatusCallback(), SubscriberStatusCallback(), ros::VoidPtr(), latch); } Publisher ImageTransport::advertise(const std::string& base_topic, uint32_t queue_size, const SubscriberStatusCallback& connect_cb, const SubscriberStatusCallback& disconnect_cb, const ros::VoidPtr& tracked_object, bool latch) { return Publisher(impl_->nh_, base_topic, queue_size, connect_cb, disconnect_cb, tracked_object, latch, impl_->pub_loader_); } Subscriber ImageTransport::subscribe(const std::string& base_topic, uint32_t queue_size, const boost::function<void(const sensor_msgs::ImageConstPtr&)>& callback, const ros::VoidPtr& tracked_object, const TransportHints& transport_hints) { return Subscriber(impl_->nh_, base_topic, queue_size, callback, tracked_object, transport_hints, impl_->sub_loader_); } CameraPublisher ImageTransport::advertiseCamera(const std::string& base_topic, uint32_t queue_size, bool latch) { return advertiseCamera(base_topic, queue_size, SubscriberStatusCallback(), SubscriberStatusCallback(), ros::SubscriberStatusCallback(), ros::SubscriberStatusCallback(), ros::VoidPtr(), latch); } CameraPublisher ImageTransport::advertiseCamera(const std::string& base_topic, uint32_t queue_size, const SubscriberStatusCallback& image_connect_cb, const SubscriberStatusCallback& image_disconnect_cb, const ros::SubscriberStatusCallback& info_connect_cb, const ros::SubscriberStatusCallback& info_disconnect_cb, const ros::VoidPtr& tracked_object, bool latch) { return CameraPublisher(*this, impl_->nh_, base_topic, queue_size, image_connect_cb, image_disconnect_cb, info_connect_cb, info_disconnect_cb, tracked_object, latch); } CameraSubscriber ImageTransport::subscribeCamera(const std::string& base_topic, uint32_t queue_size, const CameraSubscriber::Callback& callback, const ros::VoidPtr& tracked_object, const TransportHints& transport_hints) { return CameraSubscriber(*this, impl_->nh_, base_topic, queue_size, callback, tracked_object, transport_hints); } std::vector<std::string> ImageTransport::getDeclaredTransports() const { std::vector<std::string> transports = impl_->sub_loader_->getDeclaredClasses(); // Remove the "_sub" at the end of each class name. BOOST_FOREACH(std::string& transport, transports) { transport = boost::erase_last_copy(transport, "_sub"); } return transports; } std::vector<std::string> ImageTransport::getLoadableTransports() const { std::vector<std::string> loadableTransports; BOOST_FOREACH( const std::string& transportPlugin, impl_->sub_loader_->getDeclaredClasses() ) { // If the plugin loads without throwing an exception, add its // transport name to the list of valid plugins, otherwise ignore // it. try { boost::shared_ptr<image_transport::SubscriberPlugin> sub = impl_->sub_loader_->createInstance(transportPlugin); loadableTransports.push_back(boost::erase_last_copy(transportPlugin, "_sub")); // Remove the "_sub" at the end of each class name. } catch (const pluginlib::LibraryLoadException& e) {} catch (const pluginlib::CreateClassException& e) {} } return loadableTransports; } } //namespace image_transport
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport
apollo_public_repos/apollo-platform/ros/image_common/image_transport/src/list_transports.cpp
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #include "image_transport/publisher_plugin.h" #include "image_transport/subscriber_plugin.h" #include <pluginlib/class_loader.h> #include <boost/foreach.hpp> #include <boost/algorithm/string/erase.hpp> #include <map> using namespace image_transport; using namespace pluginlib; enum PluginStatus {SUCCESS, CREATE_FAILURE, LIB_LOAD_FAILURE, DOES_NOT_EXIST}; /// \cond struct TransportDesc { TransportDesc() : pub_status(DOES_NOT_EXIST), sub_status(DOES_NOT_EXIST) {} std::string package_name; std::string pub_name; PluginStatus pub_status; std::string sub_name; PluginStatus sub_status; }; /// \endcond int main(int argc, char** argv) { ClassLoader<PublisherPlugin> pub_loader("image_transport", "image_transport::PublisherPlugin"); ClassLoader<SubscriberPlugin> sub_loader("image_transport", "image_transport::SubscriberPlugin"); typedef std::map<std::string, TransportDesc> StatusMap; StatusMap transports; BOOST_FOREACH(const std::string& lookup_name, pub_loader.getDeclaredClasses()) { std::string transport_name = boost::erase_last_copy(lookup_name, "_pub"); transports[transport_name].pub_name = lookup_name; transports[transport_name].package_name = pub_loader.getClassPackage(lookup_name); try { boost::shared_ptr<PublisherPlugin> pub = pub_loader.createInstance(lookup_name); transports[transport_name].pub_status = SUCCESS; } catch (const LibraryLoadException& e) { transports[transport_name].pub_status = LIB_LOAD_FAILURE; } catch (const CreateClassException& e) { transports[transport_name].pub_status = CREATE_FAILURE; } } BOOST_FOREACH(const std::string& lookup_name, sub_loader.getDeclaredClasses()) { std::string transport_name = boost::erase_last_copy(lookup_name, "_sub"); transports[transport_name].sub_name = lookup_name; transports[transport_name].package_name = sub_loader.getClassPackage(lookup_name); try { boost::shared_ptr<SubscriberPlugin> sub = sub_loader.createInstance(lookup_name); transports[transport_name].sub_status = SUCCESS; } catch (const LibraryLoadException& e) { transports[transport_name].sub_status = LIB_LOAD_FAILURE; } catch (const CreateClassException& e) { transports[transport_name].sub_status = CREATE_FAILURE; } } bool problem_package = false; printf("Declared transports:\n"); BOOST_FOREACH(const StatusMap::value_type& value, transports) { const TransportDesc& td = value.second; printf("%s", value.first.c_str()); if ((td.pub_status == CREATE_FAILURE || td.pub_status == LIB_LOAD_FAILURE) || (td.sub_status == CREATE_FAILURE || td.sub_status == LIB_LOAD_FAILURE)) { printf(" (*): Not available. Try 'catkin_make --pkg %s'.", td.package_name.c_str()); problem_package = true; } printf("\n"); } #if 0 if (problem_package) printf("(*) \n"); #endif printf("\nDetails:\n"); BOOST_FOREACH(const StatusMap::value_type& value, transports) { const TransportDesc& td = value.second; printf("----------\n"); printf("\"%s\"\n", value.first.c_str()); if (td.pub_status == CREATE_FAILURE || td.sub_status == CREATE_FAILURE) { printf("*** Plugins are built, but could not be loaded. The package may need to be rebuilt or may not be compatible with this release of image_common. ***\n"); } else if (td.pub_status == LIB_LOAD_FAILURE || td.sub_status == LIB_LOAD_FAILURE) { printf("*** Plugins are not built. ***\n"); } printf(" - Provided by package: %s\n", td.package_name.c_str()); if (td.pub_status == DOES_NOT_EXIST) printf(" - No publisher provided\n"); else printf(" - Publisher: %s\n", pub_loader.getClassDescription(td.pub_name).c_str()); if (td.sub_status == DOES_NOT_EXIST) printf(" - No subscriber provided\n"); else printf(" - Subscriber: %s\n", sub_loader.getClassDescription(td.sub_name).c_str()); } return 0; }
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport
apollo_public_repos/apollo-platform/ros/image_common/image_transport/src/single_subscriber_publisher.cpp
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #include "image_transport/single_subscriber_publisher.h" #include "image_transport/publisher.h" namespace image_transport { SingleSubscriberPublisher::SingleSubscriberPublisher(const std::string& caller_id, const std::string& topic, const GetNumSubscribersFn& num_subscribers_fn, const PublishFn& publish_fn) : caller_id_(caller_id), topic_(topic), num_subscribers_fn_(num_subscribers_fn), publish_fn_(publish_fn) { } std::string SingleSubscriberPublisher::getSubscriberName() const { return caller_id_; } std::string SingleSubscriberPublisher::getTopic() const { return topic_; } uint32_t SingleSubscriberPublisher::getNumSubscribers() const { return num_subscribers_fn_(); } void SingleSubscriberPublisher::publish(const sensor_msgs::Image& message) const { publish_fn_(message); } void SingleSubscriberPublisher::publish(const sensor_msgs::ImageConstPtr& message) const { publish_fn_(*message); } } //namespace image_transport
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport
apollo_public_repos/apollo-platform/ros/image_common/image_transport/src/manifest.cpp
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #include <pluginlib/class_list_macros.h> #include "image_transport/raw_publisher.h" #include "image_transport/raw_subscriber.h" PLUGINLIB_EXPORT_CLASS( image_transport::RawPublisher, image_transport::PublisherPlugin) PLUGINLIB_EXPORT_CLASS( image_transport::RawSubscriber, image_transport::SubscriberPlugin)
0
apollo_public_repos/apollo-platform/ros/image_common/image_transport
apollo_public_repos/apollo-platform/ros/image_common/image_transport/src/republish.cpp
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ #include "image_transport/image_transport.h" #include "image_transport/publisher_plugin.h" #include <pluginlib/class_loader.h> int main(int argc, char** argv) { ros::init(argc, argv, "image_republisher", ros::init_options::AnonymousName); if (argc < 2) { printf("Usage: %s in_transport in:=<in_base_topic> [out_transport] out:=<out_base_topic>\n", argv[0]); return 0; } ros::NodeHandle nh; std::string in_topic = nh.resolveName("in"); std::string in_transport = argv[1]; std::string out_topic = nh.resolveName("out"); image_transport::ImageTransport it(nh); image_transport::Subscriber sub; if (argc < 3) { // Use all available transports for output image_transport::Publisher pub = it.advertise(out_topic, 1); // Use Publisher::publish as the subscriber callback typedef void (image_transport::Publisher::*PublishMemFn)(const sensor_msgs::ImageConstPtr&) const; PublishMemFn pub_mem_fn = &image_transport::Publisher::publish; sub = it.subscribe(in_topic, 1, boost::bind(pub_mem_fn, &pub, _1), ros::VoidPtr(), in_transport); ros::spin(); } else { // Use one specific transport for output std::string out_transport = argv[2]; // Load transport plugin typedef image_transport::PublisherPlugin Plugin; pluginlib::ClassLoader<Plugin> loader("image_transport", "image_transport::PublisherPlugin"); std::string lookup_name = Plugin::getLookupName(out_transport); boost::shared_ptr<Plugin> pub( loader.createInstance(lookup_name) ); pub->advertise(nh, out_topic, 1, image_transport::SubscriberStatusCallback(), image_transport::SubscriberStatusCallback(), ros::VoidPtr(), false); // Use PublisherPlugin::publish as the subscriber callback typedef void (Plugin::*PublishMemFn)(const sensor_msgs::ImageConstPtr&) const; PublishMemFn pub_mem_fn = &Plugin::publish; sub = it.subscribe(in_topic, 1, boost::bind(pub_mem_fn, pub.get(), _1), pub, in_transport); ros::spin(); } return 0; }
0
apollo_public_repos/apollo-platform/ros/image_common
apollo_public_repos/apollo-platform/ros/image_common/camera_info_manager/CMakeLists.txt
cmake_minimum_required(VERSION 2.8) project(camera_info_manager) find_package(catkin REQUIRED COMPONENTS camera_calibration_parsers image_transport roscpp roslib sensor_msgs) find_package(Boost) catkin_package(INCLUDE_DIRS include LIBRARIES ${PROJECT_NAME} CATKIN_DEPENDS camera_calibration_parsers DEPENDS Boost roscpp sensor_msgs ) include_directories(${catkin_INCLUDE_DIRS}) include_directories(include) # add a library add_library(${PROJECT_NAME} src/camera_info_manager.cpp) target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES}) install(TARGETS ${PROJECT_NAME} DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} COMPONENT main ) install(DIRECTORY include/${PROJECT_NAME}/ DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} ) if(CATKIN_ENABLE_TESTING) find_package(rostest) # Unit test uses gtest, but needs rostest to create a ROS environment. # Hence, it must be created as a normal executable, not using # catkin_add_gtest() which runs an additional test without rostest. add_executable(unit_test tests/unit_test.cpp) target_link_libraries(unit_test ${PROJECT_NAME} ${GTEST_LIBRARIES} ${catkin_LIBRARIES}) add_rostest(tests/unit_test.test DEPENDENCIES unit_test) endif()
0