tutorials are now part of ros_tutorials
This commit is contained in:
parent
dc35d02239
commit
540317da2f
|
@ -1,23 +0,0 @@
|
|||
cmake_minimum_required(VERSION 2.4.6)
|
||||
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
|
||||
rosbuild_init()
|
||||
gensrv()
|
||||
include_directories(${PROJECT_SOURCE_DIR}/srv/cpp)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
|
||||
add_subdirectory(listener)
|
||||
add_subdirectory(notify_connect)
|
||||
add_subdirectory(talker)
|
||||
add_subdirectory(babbler)
|
||||
add_subdirectory(add_two_ints_client)
|
||||
add_subdirectory(add_two_ints_server)
|
||||
add_subdirectory(add_two_ints_server_class)
|
||||
add_subdirectory(anonymous_listener)
|
||||
add_subdirectory(listener_with_userdata)
|
||||
add_subdirectory(time_api)
|
||||
add_subdirectory(listener_multiple)
|
||||
add_subdirectory(listener_threaded_spin)
|
||||
add_subdirectory(listener_with_tracked_object)
|
||||
add_subdirectory(listener_unreliable)
|
||||
add_subdirectory(node_handle_namespaces)
|
||||
add_subdirectory(custom_callback_processing)
|
||||
add_subdirectory(timers)
|
|
@ -1 +0,0 @@
|
|||
include $(shell rospack find mk)/cmake.mk
|
|
@ -1 +0,0 @@
|
|||
rospack_add_executable(add_two_ints_client add_two_ints_client.cpp)
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2008, Morgan Quigley and 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.
|
||||
*/
|
||||
|
||||
#include "ros/ros.h"
|
||||
#include "roscpp_tutorials/TwoInts.h"
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ros::init(argc, argv, "add_two_ints_client");
|
||||
if (argc != 3)
|
||||
{
|
||||
ROS_INFO("usage: add_two_ints_client X Y");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ros::NodeHandle n;
|
||||
ros::ServiceClient client = n.serviceClient<roscpp_tutorials::TwoInts>("add_two_ints");
|
||||
roscpp_tutorials::TwoInts srv;
|
||||
srv.request.a = atoi(argv[1]);
|
||||
srv.request.b = atoi(argv[2]);
|
||||
if (client.call(srv))
|
||||
{
|
||||
ROS_INFO("Sum: %ld", (long int)srv.response.sum);
|
||||
}
|
||||
else
|
||||
{
|
||||
ROS_ERROR("Failed to call service add_two_ints");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
rospack_add_executable(add_two_ints_server add_two_ints_server.cpp)
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2008, Morgan Quigley and 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.
|
||||
*/
|
||||
|
||||
#include "ros/ros.h"
|
||||
#include "roscpp_tutorials/TwoInts.h"
|
||||
|
||||
bool add(roscpp_tutorials::TwoInts::Request &req,
|
||||
roscpp_tutorials::TwoInts::Response &res )
|
||||
{
|
||||
res.sum = req.a + req.b;
|
||||
ROS_INFO("request: x=%ld, y=%ld", (long int)req.a, (long int)req.b);
|
||||
ROS_INFO(" sending back response: [%ld]", (long int)res.sum);
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ros::init(argc, argv, "add_two_ints_server");
|
||||
ros::NodeHandle n;
|
||||
|
||||
ros::ServiceServer service = n.advertiseService("add_two_ints", add);
|
||||
|
||||
ros::spin();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
rospack_add_executable(add_two_ints_server_class add_two_ints_server_class.cpp)
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2008, Morgan Quigley and 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.
|
||||
*/
|
||||
|
||||
#include "ros/ros.h"
|
||||
#include "roscpp_tutorials/TwoInts.h"
|
||||
|
||||
class AddTwo
|
||||
{
|
||||
private:
|
||||
ros::NodeHandle node_handle_;
|
||||
ros::ServiceServer service_;
|
||||
|
||||
public:
|
||||
AddTwo(const ros::NodeHandle& node_handle)
|
||||
: node_handle_(node_handle)
|
||||
{}
|
||||
|
||||
void init()
|
||||
{
|
||||
service_ = node_handle_.advertiseService("add_two_ints", &AddTwo::add, this);
|
||||
}
|
||||
|
||||
bool add(roscpp_tutorials::TwoInts::Request &req,
|
||||
roscpp_tutorials::TwoInts::Response &res )
|
||||
{
|
||||
res.sum = req.a + req.b;
|
||||
ROS_INFO("request: x=%ld, y=%ld", (long int)req.a, (long int)req.b);
|
||||
ROS_INFO(" sending back response: [%ld]", (long int)res.sum);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ros::init(argc, argv, "add_two_ints_server");
|
||||
ros::NodeHandle n;
|
||||
|
||||
AddTwo a(n);
|
||||
a.init();
|
||||
|
||||
ros::spin();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
rospack_add_executable(anonymous_listener anonymous_listener.cpp)
|
|
@ -1,50 +0,0 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// The roscpp_demo package has a few demos of the roscpp c++ client library
|
||||
//
|
||||
// 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 "ros/ros.h"
|
||||
#include "std_msgs/String.h"
|
||||
|
||||
void chatterCallback(const std_msgs::String::ConstPtr& msg)
|
||||
{
|
||||
ROS_INFO("I heard: [%s]", msg->data.c_str());
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// ros::init_options::AnonymousName will add a unique identifier to the end of your node name. This allows
|
||||
// multiple of the same executable to be run without remapping each of their names with
|
||||
// __name:=X
|
||||
ros::init(argc, argv, "listener", ros::init_options::AnonymousName);
|
||||
ros::NodeHandle n;
|
||||
ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback);
|
||||
|
||||
ros::spin();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
rospack_add_executable(babbler babbler.cpp)
|
|
@ -1,111 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2008, Morgan Quigley and 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.
|
||||
*/
|
||||
|
||||
#include "ros/ros.h"
|
||||
#include "std_msgs/String.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
/**
|
||||
* This tutorial demonstrates simple sending of messages over the ROS system.
|
||||
*/
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/**
|
||||
* The ros::init() function needs to see argc and argv so that it can perform
|
||||
* any ROS arguments and name remapping that were provided at the command line. For programmatic
|
||||
* remappings you can use a different version of init() which takes remappings
|
||||
* directly, but for most command-line programs, passing argc and argv is the easiest
|
||||
* way to do it. The third argument to init() is the name of the node.
|
||||
*
|
||||
* You must call one of the versions of ros::init() before using any other
|
||||
* part of the ROS system.
|
||||
*/
|
||||
ros::init(argc, argv, "babbler");
|
||||
|
||||
/**
|
||||
* NodeHandle is the main access point to communications with the ROS system.
|
||||
* The first NodeHandle constructed will fully initialize this node, and the last
|
||||
* NodeHandle destructed will close down the node.
|
||||
*/
|
||||
ros::NodeHandle n;
|
||||
|
||||
/**
|
||||
* The advertise() function is how you tell ROS that you want to
|
||||
* publish on a given topic name. This invokes a call to the ROS
|
||||
* master node, which keeps a registry of who is publishing and who
|
||||
* is subscribing. After this advertise() call is made, the master
|
||||
* node will notify anyone who is trying to subscribe to this topic name,
|
||||
* and they will in turn negotiate a peer-to-peer connection with this
|
||||
* node. advertise() returns a Publisher object which allows you to
|
||||
* publish messages on that topic through a call to publish(). Once
|
||||
* all copies of the returned Publisher object are destroyed, the topic
|
||||
* will be automatically unadvertised.
|
||||
*
|
||||
* The second parameter to advertise() is the size of the message queue
|
||||
* used for publishing messages. If messages are published more quickly
|
||||
* than we can send them, the number here specifies how many messages to
|
||||
* buffer up before throwing some away.
|
||||
*/
|
||||
ros::Publisher pub = n.advertise<std_msgs::String>("babble", 1000);
|
||||
|
||||
/**
|
||||
* A count of how many messages we have sent. This is used to create
|
||||
* a unique string for each message.
|
||||
*/
|
||||
int count = 0;
|
||||
ros::Rate r(10);
|
||||
while (n.ok())
|
||||
{
|
||||
/**
|
||||
* This is a message object. You stuff it with data, and then publish it.
|
||||
*/
|
||||
std_msgs::String msg;
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "hello world " << count;
|
||||
ROS_INFO("%s", ss.str().c_str());
|
||||
msg.data = ss.str();
|
||||
|
||||
/**
|
||||
* The publish() function is how you send messages. The parameter
|
||||
* is the message object. The type of this object must agree with the type
|
||||
* given as a template parameter to the advertise<>() call, as was done
|
||||
* in the constructor above.
|
||||
*/
|
||||
pub.publish(msg);
|
||||
++count;
|
||||
|
||||
ros::spinOnce();
|
||||
r.sleep();
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
rospack_add_executable(custom_callback_processing custom_callback_processing.cpp)
|
|
@ -1,110 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2009, 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.
|
||||
*/
|
||||
|
||||
#include "ros/ros.h"
|
||||
#include "ros/callback_queue.h"
|
||||
#include "std_msgs/String.h"
|
||||
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
/**
|
||||
* This tutorial demonstrates the use of custom separate callback queues that can be processed
|
||||
* independently, whether in different threads or just at different times.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This callback gets called from the main queue processed in spin()
|
||||
*/
|
||||
void chatterCallbackMainQueue(const std_msgs::String::ConstPtr& msg)
|
||||
{
|
||||
ROS_INFO_STREAM("I heard: [ " << msg->data << "] in thread [" << boost::this_thread::get_id() << "] (Main thread)");
|
||||
}
|
||||
|
||||
/**
|
||||
* This callback gets called from the custom queue
|
||||
*/
|
||||
void chatterCallbackCustomQueue(const std_msgs::String::ConstPtr& msg)
|
||||
{
|
||||
ROS_INFO_STREAM("I heard: [ " << msg->data << "] in thread [" << boost::this_thread::get_id() << "]");
|
||||
}
|
||||
|
||||
/**
|
||||
* The custom queue used for one of the subscription callbacks
|
||||
*/
|
||||
ros::CallbackQueue g_queue;
|
||||
void callbackThread()
|
||||
{
|
||||
ROS_INFO_STREAM("Callback thread id=" << boost::this_thread::get_id());
|
||||
|
||||
ros::NodeHandle n;
|
||||
while (n.ok())
|
||||
{
|
||||
g_queue.callAvailable(ros::WallDuration(0.01));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ros::init(argc, argv, "listener_with_custom_callback_processing");
|
||||
ros::NodeHandle n;
|
||||
|
||||
/**
|
||||
* The SubscribeOptions structure lets you specify a custom queue to use for a specific subscription.
|
||||
* You can also set a default queue on a NodeHandle using the NodeHandle::setCallbackQueue() function.
|
||||
*
|
||||
* AdvertiseOptions and AdvertiseServiceOptions offer similar functionality.
|
||||
*/
|
||||
ros::SubscribeOptions ops = ros::SubscribeOptions::create<std_msgs::String>("chatter", 1000,
|
||||
chatterCallbackCustomQueue,
|
||||
ros::VoidPtr(), &g_queue);
|
||||
ros::Subscriber sub = n.subscribe(ops);
|
||||
|
||||
/**
|
||||
* Now we subscribe using the normal method, to demonstrate the difference.
|
||||
*/
|
||||
ros::Subscriber sub2 = n.subscribe("chatter", 1000, chatterCallbackMainQueue);
|
||||
|
||||
/**
|
||||
* Start a thread to service the custom queue
|
||||
*/
|
||||
boost::thread chatter_thread(callbackThread);
|
||||
|
||||
ROS_INFO_STREAM("Main thread id=" << boost::this_thread::get_id());
|
||||
/**
|
||||
* Now do a custom spin, to demonstrate the difference.
|
||||
*/
|
||||
ros::Rate r(1);
|
||||
while (n.ok())
|
||||
{
|
||||
ros::spinOnce();
|
||||
r.sleep();
|
||||
}
|
||||
|
||||
chatter_thread.join();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
rospack_add_executable(listener listener.cpp)
|
|
@ -1,86 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2008, Morgan Quigley and 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.
|
||||
*/
|
||||
|
||||
#include "ros/ros.h"
|
||||
#include "std_msgs/String.h"
|
||||
|
||||
/**
|
||||
* This tutorial demonstrates simple receipt of messages over the ROS system.
|
||||
*/
|
||||
|
||||
void chatterCallback(const std_msgs::String::ConstPtr& msg)
|
||||
{
|
||||
ROS_INFO("I heard: [%s]", msg->data.c_str());
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/**
|
||||
* The ros::init() function needs to see argc and argv so that it can perform
|
||||
* any ROS arguments and name remapping that were provided at the command line. For programmatic
|
||||
* remappings you can use a different version of init() which takes remappings
|
||||
* directly, but for most command-line programs, passing argc and argv is the easiest
|
||||
* way to do it. The third argument to init() is the name of the node.
|
||||
*
|
||||
* You must call one of the versions of ros::init() before using any other
|
||||
* part of the ROS system.
|
||||
*/
|
||||
ros::init(argc, argv, "listener");
|
||||
|
||||
/**
|
||||
* NodeHandle is the main access point to communications with the ROS system.
|
||||
* The first NodeHandle constructed will fully initialize this node, and the last
|
||||
* NodeHandle destructed will close down the node.
|
||||
*/
|
||||
ros::NodeHandle n;
|
||||
|
||||
/**
|
||||
* The subscribe() call is how you tell ROS that you want to receive messages
|
||||
* on a given topic. This invokes a call to the ROS
|
||||
* master node, which keeps a registry of who is publishing and who
|
||||
* is subscribing. Messages are passed to a callback function, here
|
||||
* called chatterCallback. subscribe() returns a Subscriber object that you
|
||||
* must hold on to until you want to unsubscribe. When all copies of the Subscriber
|
||||
* object go out of scope, this callback will automatically be unsubscribed from
|
||||
* this topic.
|
||||
*
|
||||
* The second parameter to the subscribe() function is the size of the message
|
||||
* queue. If messages are arriving faster than they are being processed, this
|
||||
* is the number of messages that will be buffered up before beginning to throw
|
||||
* away the oldest ones.
|
||||
*/
|
||||
ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback);
|
||||
|
||||
/**
|
||||
* ros::spin() will enter a loop, pumping callbacks. With this version, all
|
||||
* callbacks will be called from within this thread (the main one). ros::spin()
|
||||
* will exit when Ctrl-C is pressed, or the node is shutdown by the master.
|
||||
*/
|
||||
ros::spin();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
rospack_add_executable(listener_multiple listener_multiple.cpp)
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2008, Morgan Quigley and 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.
|
||||
*/
|
||||
|
||||
#include "ros/ros.h"
|
||||
#include "std_msgs/String.h"
|
||||
|
||||
/**
|
||||
* This tutorial demonstrates simple receipt of messages over the ROS system, with
|
||||
* multiple callbacks for the same topic. See the "listener" tutorial for more
|
||||
* information.
|
||||
*/
|
||||
|
||||
class Listener
|
||||
{
|
||||
public:
|
||||
void chatter1(const std_msgs::String::ConstPtr& msg) { ROS_INFO("chatter1: [%s]", msg->data.c_str()); }
|
||||
void chatter2(const std_msgs::String::ConstPtr& msg) { ROS_INFO("chatter2: [%s]", msg->data.c_str()); }
|
||||
void chatter3(const std_msgs::String::ConstPtr& msg) { ROS_INFO("chatter3: [%s]", msg->data.c_str()); }
|
||||
};
|
||||
|
||||
void chatter4(const std_msgs::String::ConstPtr& msg)
|
||||
{
|
||||
ROS_INFO("chatter4: [%s]", msg->data.c_str());
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ros::init(argc, argv, "listener");
|
||||
ros::NodeHandle n;
|
||||
|
||||
Listener l;
|
||||
ros::Subscriber sub1 = n.subscribe("chatter", 10, &Listener::chatter1, &l);
|
||||
ros::Subscriber sub2 = n.subscribe("chatter", 10, &Listener::chatter2, &l);
|
||||
ros::Subscriber sub3 = n.subscribe("chatter", 10, &Listener::chatter3, &l);
|
||||
ros::Subscriber sub4 = n.subscribe("chatter", 10, chatter4);
|
||||
|
||||
ros::spin();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
rospack_add_executable(listener_threaded_spin listener_threaded_spin.cpp)
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2008, Morgan Quigley and 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.
|
||||
*/
|
||||
|
||||
#include "ros/ros.h"
|
||||
#include "std_msgs/String.h"
|
||||
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
/**
|
||||
* This tutorial demonstrates simple receipt of messages over the ROS system, using
|
||||
* a threaded Spinner object to receive callbacks in multiple threads at the same time.
|
||||
*/
|
||||
|
||||
ros::Duration d(0.01);
|
||||
|
||||
class Listener
|
||||
{
|
||||
public:
|
||||
void chatter1(const std_msgs::String::ConstPtr& msg)
|
||||
{
|
||||
ROS_INFO_STREAM("chatter1: [" << msg->data << "] [thread=" << boost::this_thread::get_id() << "]");
|
||||
d.sleep();
|
||||
}
|
||||
void chatter2(const std_msgs::String::ConstPtr& msg)
|
||||
{
|
||||
ROS_INFO_STREAM("chatter1: [" << msg->data << "] [thread=" << boost::this_thread::get_id() << "]");
|
||||
d.sleep();
|
||||
}
|
||||
void chatter3(const std_msgs::String::ConstPtr& msg)
|
||||
{
|
||||
ROS_INFO_STREAM("chatter1: [" << msg->data << "] [thread=" << boost::this_thread::get_id() << "]");
|
||||
d.sleep();
|
||||
}
|
||||
};
|
||||
|
||||
void chatter4(const std_msgs::String::ConstPtr& msg)
|
||||
{
|
||||
ROS_INFO_STREAM("chatter1: [" << msg->data << "] [thread=" << boost::this_thread::get_id() << "]");
|
||||
d.sleep();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ros::init(argc, argv, "listener");
|
||||
ros::NodeHandle n;
|
||||
|
||||
Listener l;
|
||||
ros::Subscriber sub1 = n.subscribe("chatter", 10, &Listener::chatter1, &l);
|
||||
ros::Subscriber sub2 = n.subscribe("chatter", 10, &Listener::chatter2, &l);
|
||||
ros::Subscriber sub3 = n.subscribe("chatter", 10, &Listener::chatter3, &l);
|
||||
ros::Subscriber sub4 = n.subscribe("chatter", 10, chatter4);
|
||||
|
||||
/**
|
||||
* The MultiThreadedSpinner object allows you to specify a number of threads to use
|
||||
* to call callbacks. If no explicit # is specified, it will use the # of hardware
|
||||
* threads available on your system. Here we explicitly specify 4 threads.
|
||||
*/
|
||||
ros::MultiThreadedSpinner s(4);
|
||||
ros::spin(s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
rospack_add_executable(listener_unreliable listener_unreliable.cpp)
|
|
@ -1,91 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2008, Morgan Quigley and 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.
|
||||
*/
|
||||
|
||||
#include "ros/ros.h"
|
||||
#include "std_msgs/String.h"
|
||||
|
||||
/*
|
||||
* This tutorial demonstrates simple receipt of messages over the ROS system
|
||||
* using an unreliable transport protocol (UDP).
|
||||
*/
|
||||
|
||||
void chatterCallback(const std_msgs::String::ConstPtr& msg)
|
||||
{
|
||||
ROS_INFO("I heard: [%s]", msg->data.c_str());
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/**
|
||||
* The ros::init() function needs to see argc and argv so that it can perform
|
||||
* any ROS arguments and name remapping that were provided at the command line. For programmatic
|
||||
* remappings you can use a different version of init() which takes remappings
|
||||
* directly, but for most command-line programs, passing argc and argv is the easiest
|
||||
* way to do it. The third argument to init() is the name of the node.
|
||||
*
|
||||
* You must call one of the versions of ros::init() before using any other
|
||||
* part of the ROS system.
|
||||
*/
|
||||
ros::init(argc, argv, "listener_unreliable");
|
||||
|
||||
/**
|
||||
* NodeHandle is the main access point to communications with the ROS system.
|
||||
* The first NodeHandle constructed will fully initialize this node, and the last
|
||||
* NodeHandle destructed will close down the node.
|
||||
*/
|
||||
ros::NodeHandle n;
|
||||
|
||||
/**
|
||||
* The subscribe() call is how you tell ROS that you want to receive messages
|
||||
* on a given topic. This invokes a call to the ROS
|
||||
* master node, which keeps a registry of who is publishing and who
|
||||
* is subscribing. Messages are passed to a callback function, here
|
||||
* called chatterCallback. subscribe() returns a Subscriber object that you
|
||||
* must hold on to until you want to unsubscribe. When all copies of the Subscriber
|
||||
* object go out of scope, this callback will automatically be unsubscribed from
|
||||
* this topic.
|
||||
*
|
||||
* The second parameter to the subscribe() function is the size of the message
|
||||
* queue. If messages are arriving faster than they are being processed, this
|
||||
* is the number of messages that will be buffered up before beginning to throw
|
||||
* away the oldest ones.
|
||||
*
|
||||
* The ros::TransportHints object is use to hint to the advertiser that
|
||||
* an unreliable transport would be preferred.
|
||||
*/
|
||||
|
||||
ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback, ros::TransportHints().unreliable());
|
||||
|
||||
/**
|
||||
* ros::spin() will enter a loop, pumping callbacks. With this version, all
|
||||
* callbacks will be called from within this thread (the main one). ros::spin()
|
||||
* will exit when Ctrl-C is pressed, or the node is shutdown by the master.
|
||||
*/
|
||||
ros::spin();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
rospack_add_executable(listener_with_tracked_object listener_with_tracked_object.cpp)
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2008, Morgan Quigley and 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.
|
||||
*/
|
||||
|
||||
#include "ros/ros.h"
|
||||
#include "std_msgs/String.h"
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
/**
|
||||
* This tutorial demonstrates a tracked object on a subscription.
|
||||
*/
|
||||
|
||||
class Object
|
||||
{
|
||||
public:
|
||||
void chatterCallback(const std_msgs::String::ConstPtr& msg)
|
||||
{
|
||||
ROS_INFO("This should never be printed: [%s]", msg->data.c_str());
|
||||
}
|
||||
};
|
||||
typedef boost::shared_ptr<Object> ObjectPtr;
|
||||
|
||||
void chatterCallback(const std_msgs::String::ConstPtr& msg)
|
||||
{
|
||||
ROS_INFO("Only this version should print: [%s]", msg->data.c_str());
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ros::init(argc, argv, "listener");
|
||||
ros::NodeHandle n;
|
||||
|
||||
ObjectPtr obj(new Object);
|
||||
ros::Subscriber sub = n.subscribe("chatter", 1, &Object::chatterCallback, obj);
|
||||
ros::Subscriber sub2 = n.subscribe("chatter", 1, chatterCallback);
|
||||
|
||||
// Delete the object.
|
||||
// Because we've passed in the object to be tracked as a shared pointer,
|
||||
// this is safe. The callback inside the Object class should never get called,
|
||||
// because its pointer is no longer valid.
|
||||
obj.reset();
|
||||
|
||||
ros::spin();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
rospack_add_executable(listener_with_userdata listener_with_userdata.cpp)
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2008, Morgan Quigley and 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.
|
||||
*/
|
||||
|
||||
#include "ros/ros.h"
|
||||
#include "std_msgs/String.h"
|
||||
|
||||
/**
|
||||
* This tutorial demonstrates a simple use of Boost.Bind to pass arbitrary data into a subscription
|
||||
* callback. For more information on Boost.Bind see the documentation on the boost homepage,
|
||||
* http://www.boost.org/
|
||||
*/
|
||||
|
||||
|
||||
class Listener
|
||||
{
|
||||
public:
|
||||
ros::NodeHandle node_handle_;
|
||||
ros::V_Subscriber subs_;
|
||||
|
||||
Listener(const ros::NodeHandle& node_handle)
|
||||
: node_handle_(node_handle)
|
||||
{
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
subs_.push_back(node_handle_.subscribe<std_msgs::String>("chatter", 1000, boost::bind(&Listener::chatterCallback, this, _1, "User 1")));
|
||||
subs_.push_back(node_handle_.subscribe<std_msgs::String>("chatter", 1000, boost::bind(&Listener::chatterCallback, this, _1, "User 2")));
|
||||
subs_.push_back(node_handle_.subscribe<std_msgs::String>("chatter", 1000, boost::bind(&Listener::chatterCallback, this, _1, "User 3")));
|
||||
}
|
||||
|
||||
void chatterCallback(const std_msgs::String::ConstPtr& msg, std::string user_string)
|
||||
{
|
||||
ROS_INFO("I heard: [%s] with user string [%s]", msg->data.c_str(), user_string.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ros::init(argc, argv, "listener_with_userdata");
|
||||
ros::NodeHandle n;
|
||||
|
||||
Listener l(n);
|
||||
l.init();
|
||||
|
||||
ros::spin();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
<package>
|
||||
<description brief="Shows the features of ROS step-by-step">
|
||||
This package attempts to show the features of ROS step-by-step,
|
||||
including using messages, servers, parameters, etc.
|
||||
</description>
|
||||
<author>Morgan Quigley</author>
|
||||
<license>BSD</license>
|
||||
<review status="unreviewed" notes=""/>
|
||||
<url>http://pr.willowgarage.com</url>
|
||||
<depend package="roscpp"/>
|
||||
<depend package="std_srvs"/>
|
||||
<depend package="std_msgs"/>
|
||||
<export>
|
||||
<cpp cflags="-I${prefix}/srv/cpp"/>
|
||||
</export>
|
||||
</package>
|
||||
|
|
@ -1 +0,0 @@
|
|||
rospack_add_executable(node_handle_namespaces node_handle_namespaces.cpp)
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2008, Morgan Quigley and 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.
|
||||
*/
|
||||
|
||||
#include "ros/ros.h"
|
||||
#include "std_msgs/String.h"
|
||||
|
||||
/**
|
||||
* This tutorial shows the use of NodeHandle namespaces.
|
||||
*/
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ros::init(argc, argv, "node_handle_namespaces");
|
||||
|
||||
/**
|
||||
* Each NodeHandle can be assigned a namespace the same way every node can be assigned
|
||||
* a namespace (this is usually done through the environment variable ROS_NAMESPACE).
|
||||
*
|
||||
* A namespace per NodeHandle allows you to separate different pieces of your application
|
||||
* into different namespaces.
|
||||
*/
|
||||
ros::NodeHandle node1("level1");
|
||||
std::string s = node1.resolveName("a");
|
||||
/// This prints /level1/a
|
||||
ROS_INFO_STREAM(s);
|
||||
|
||||
/**
|
||||
* If another NodeHandle is provided as the first argument to the constructor, it uses
|
||||
* that NodeHandle's namespace as a parent namespace. Therefore, this NodeHandle will be
|
||||
* in the /level1/level2 namespace.
|
||||
*/
|
||||
ros::NodeHandle node2(node1, "level2");
|
||||
s = node2.resolveName("a");
|
||||
/// This prints /level1/level2/a
|
||||
ROS_INFO_STREAM(s);
|
||||
|
||||
/**
|
||||
* Accessing private names (inside the nodes' name) is possible by creating a NodeHandle whose name starts with a
|
||||
* tilde (~).
|
||||
*/
|
||||
ros::NodeHandle node3("~");
|
||||
s = node3.resolveName("a");
|
||||
/// This prints /node_handle_namespaces/a
|
||||
ROS_INFO_STREAM(s);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
rospack_add_executable(notify_connect notify_connect.cpp)
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2008, Morgan Quigley and 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.
|
||||
*/
|
||||
|
||||
#include "ros/ros.h"
|
||||
#include "std_msgs/String.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
/**
|
||||
* This tutorial demonstrates how to get a callback when a new subscriber connects
|
||||
* to an advertised topic, or a subscriber disconnects.
|
||||
*/
|
||||
|
||||
uint32_t g_count = 0;
|
||||
|
||||
void chatterConnect(const ros::SingleSubscriberPublisher& pub)
|
||||
{
|
||||
std_msgs::String msg;
|
||||
std::stringstream ss;
|
||||
ss << "chatter connect #" << g_count++;
|
||||
ROS_INFO("%s", ss.str().c_str());
|
||||
msg.data = ss.str();
|
||||
|
||||
pub.publish(msg); // This message will get published only to the subscriber that just connected
|
||||
}
|
||||
|
||||
void chatterDisconnect(const ros::SingleSubscriberPublisher& pub)
|
||||
{
|
||||
ROS_INFO("chatter disconnect");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ros::init(argc, argv, "notify_connect");
|
||||
ros::NodeHandle n;
|
||||
|
||||
/**
|
||||
* This version of advertise() optionally takes a connect/disconnect callback
|
||||
*/
|
||||
ros::Publisher pub = n.advertise<std_msgs::String>("chatter", 1000, chatterConnect, chatterDisconnect);
|
||||
|
||||
ros::spin();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
int64 a
|
||||
int64 b
|
||||
---
|
||||
int64 sum
|
|
@ -1 +0,0 @@
|
|||
rospack_add_executable(talker talker.cpp)
|
|
@ -1,111 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2008, Morgan Quigley and 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.
|
||||
*/
|
||||
|
||||
#include "ros/ros.h"
|
||||
#include "std_msgs/String.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
/**
|
||||
* This tutorial demonstrates simple sending of messages over the ROS system.
|
||||
*/
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/**
|
||||
* The ros::init() function needs to see argc and argv so that it can perform
|
||||
* any ROS arguments and name remapping that were provided at the command line. For programmatic
|
||||
* remappings you can use a different version of init() which takes remappings
|
||||
* directly, but for most command-line programs, passing argc and argv is the easiest
|
||||
* way to do it. The third argument to init() is the name of the node.
|
||||
*
|
||||
* You must call one of the versions of ros::init() before using any other
|
||||
* part of the ROS system.
|
||||
*/
|
||||
ros::init(argc, argv, "talker");
|
||||
|
||||
/**
|
||||
* NodeHandle is the main access point to communications with the ROS system.
|
||||
* The first NodeHandle constructed will fully initialize this node, and the last
|
||||
* NodeHandle destructed will close down the node.
|
||||
*/
|
||||
ros::NodeHandle n;
|
||||
|
||||
/**
|
||||
* The advertise() function is how you tell ROS that you want to
|
||||
* publish on a given topic name. This invokes a call to the ROS
|
||||
* master node, which keeps a registry of who is publishing and who
|
||||
* is subscribing. After this advertise() call is made, the master
|
||||
* node will notify anyone who is trying to subscribe to this topic name,
|
||||
* and they will in turn negotiate a peer-to-peer connection with this
|
||||
* node. advertise() returns a Publisher object which allows you to
|
||||
* publish messages on that topic through a call to publish(). Once
|
||||
* all copies of the returned Publisher object are destroyed, the topic
|
||||
* will be automatically unadvertised.
|
||||
*
|
||||
* The second parameter to advertise() is the size of the message queue
|
||||
* used for publishing messages. If messages are published more quickly
|
||||
* than we can send them, the number here specifies how many messages to
|
||||
* buffer up before throwing some away.
|
||||
*/
|
||||
ros::Publisher pub = n.advertise<std_msgs::String>("chatter", 1000);
|
||||
|
||||
/**
|
||||
* A count of how many messages we have sent. This is used to create
|
||||
* a unique string for each message.
|
||||
*/
|
||||
int count = 0;
|
||||
ros::Rate r(10);
|
||||
while (n.ok())
|
||||
{
|
||||
/**
|
||||
* This is a message object. You stuff it with data, and then publish it.
|
||||
*/
|
||||
std_msgs::String msg;
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "hello world " << count;
|
||||
ROS_INFO("%s", ss.str().c_str());
|
||||
msg.data = ss.str();
|
||||
|
||||
/**
|
||||
* The publish() function is how you send messages. The parameter
|
||||
* is the message object. The type of this object must agree with the type
|
||||
* given as a template parameter to the advertise<>() call, as was done
|
||||
* in the constructor above.
|
||||
*/
|
||||
pub.publish(msg);
|
||||
++count;
|
||||
|
||||
ros::spinOnce();
|
||||
r.sleep();
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
add_subdirectory(sleep)
|
||||
|
|
@ -1 +0,0 @@
|
|||
rospack_add_executable(sleep sleep.cpp)
|
|
@ -1,60 +0,0 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// The roscpp_tutorials package tries to show off the roscpp c++ client library
|
||||
//
|
||||
// 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/time.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// ros::Duration objects are constructed with two parameters: the first
|
||||
// is the number of seconds in the duration, and the second is the number
|
||||
// of nanoseconds.
|
||||
// Once you have this object constructed, you can call its sleep() method
|
||||
// to sleep for its duration. (The underlying implementation is nanosleep)
|
||||
printf("sleeping for one second\n");
|
||||
ros::Duration(1, 0).sleep();
|
||||
|
||||
// This just shows how you have to have to use a lot of zeros to get a half
|
||||
// second in nanoseconds.
|
||||
printf("sleeping for a half second\n");
|
||||
ros::Duration(0, 500000000).sleep();
|
||||
|
||||
// This usage constructs a ros::Duration object and keeps it around, calling
|
||||
// the sleep() function repeatedly.
|
||||
ros::Duration tenth(0, 100000000); // 0.1 seconds
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
printf("sleeping for a tenth of a second\n");
|
||||
tenth.sleep();
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
rospack_add_executable(timers timers.cpp)
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2008, Morgan Quigley and 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.
|
||||
*/
|
||||
|
||||
#include "ros/ros.h"
|
||||
#include "std_msgs/String.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
/**
|
||||
* This tutorial demonstrates the use of timer callbacks.
|
||||
*/
|
||||
|
||||
void callback1(const ros::TimerEvent& e)
|
||||
{
|
||||
ROS_INFO("Callback 1 triggered");
|
||||
}
|
||||
|
||||
void callback2(const ros::TimerEvent& e)
|
||||
{
|
||||
ROS_INFO("Callback 2 triggered");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ros::init(argc, argv, "talker");
|
||||
ros::NodeHandle n;
|
||||
|
||||
/**
|
||||
* Timers allow you to get a callback at a specified rate. Here we create
|
||||
* two timers at different rates as a demonstration.
|
||||
*/
|
||||
ros::Timer timer1 = n.createTimer(ros::Duration(0.1), callback1);
|
||||
ros::Timer timer2 = n.createTimer(ros::Duration(1.0), callback2);
|
||||
|
||||
ros::spin();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
This is the simplest rospy demo: a talker node that publishes
|
||||
std_msgs/String to the /chatter topic and a listener node that subscribes
|
||||
to these messages.
|
|
@ -1 +0,0 @@
|
|||
listener.py
|
|
@ -1,63 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id$
|
||||
|
||||
## Simple talker demo that listens to std_msgs/Strings published
|
||||
## to the 'chatter' topic
|
||||
|
||||
PKG = 'rospy_tutorials' # this package name
|
||||
import roslib; roslib.load_manifest(PKG)
|
||||
|
||||
import rospy
|
||||
from std_msgs.msg import String
|
||||
|
||||
def callback(data):
|
||||
rospy.loginfo(rospy.get_caller_id()+"I heard %s",data.data)
|
||||
|
||||
def listener():
|
||||
|
||||
# in ROS, nodes are unique named. If two nodes with the same
|
||||
# node are launched, the previous one is kicked off. The
|
||||
# anonymous=True flag means that rospy will choose a unique
|
||||
# name for our 'talker' node so that multiple talkers can
|
||||
# run simultaenously.
|
||||
rospy.init_node('listener', anonymous=True)
|
||||
|
||||
rospy.Subscriber("chatter", String, callback)
|
||||
|
||||
# spin() simply keeps python from exiting until this node is stopped
|
||||
rospy.spin()
|
||||
|
||||
if __name__ == '__main__':
|
||||
listener()
|
|
@ -1 +0,0 @@
|
|||
talker.py
|
|
@ -1,57 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id$
|
||||
|
||||
## Simple talker demo that published std_msgs/Strings messages
|
||||
## to the 'chatter' topic
|
||||
|
||||
import roslib; roslib.load_manifest('rospy_tutorials')
|
||||
|
||||
import rospy
|
||||
from std_msgs.msg import String
|
||||
|
||||
def talker():
|
||||
pub = rospy.Publisher('chatter', String)
|
||||
rospy.init_node('talker', anonymous=True)
|
||||
r = rospy.Rate(10) # 10hz
|
||||
while not rospy.is_shutdown():
|
||||
str = "hello world %s"%rospy.get_time()
|
||||
rospy.loginfo(str)
|
||||
pub.publish(str)
|
||||
r.sleep()
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
talker()
|
||||
except rospy.ROSInterruptException: pass
|
|
@ -1,4 +0,0 @@
|
|||
<launch>
|
||||
<node name="listener" pkg="rospy_tutorials" type="listener.py" output="screen"/>
|
||||
<node name="talker" pkg="rospy_tutorials" type="talker.py" output="screen"/>
|
||||
</launch>
|
|
@ -1,4 +0,0 @@
|
|||
<launch>
|
||||
<node name="listener_header" pkg="rospy_tutorials" type="listener_header.py" output="screen"/>
|
||||
<node name="talker_header" pkg="rospy_tutorials" type="talker_header.py" output="screen"/>
|
||||
</launch>
|
|
@ -1,65 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id: gossipbot 3529 2009-01-23 22:35:53Z sfkwc $
|
||||
|
||||
## listener_header listens to HeaderString messages published
|
||||
## to the 'chatter_header' topic.
|
||||
|
||||
PKG = 'rospy_tutorials'
|
||||
import roslib; roslib.load_manifest(PKG)
|
||||
|
||||
import sys
|
||||
|
||||
import rospy
|
||||
from rospy_tutorials.msg import HeaderString
|
||||
|
||||
NAME = 'listener_header'
|
||||
|
||||
def callback(data):
|
||||
chatter = data.data
|
||||
header = data.header
|
||||
timestamp = header.stamp.to_seconds()
|
||||
print rospy.get_caller_id(), header.seq, "I just heard that %s at %12f"%(chatter, timestamp)
|
||||
|
||||
def listener_header():
|
||||
rospy.Subscriber("chatter_header", HeaderString, callback)
|
||||
rospy.init_node(NAME, anonymous=True)
|
||||
rospy.spin()
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
listener_header()
|
||||
except KeyboardInterrupt, e:
|
||||
pass
|
||||
print "exiting"
|
|
@ -1,65 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id: talker_header 3529 2009-01-23 22:35:53Z sfkwc $
|
||||
|
||||
## talker_header publishes HeaderString messages to the 'chatter_header'
|
||||
## topic.
|
||||
|
||||
PKG = 'rospy_tutorials'
|
||||
import roslib; roslib.load_manifest(PKG)
|
||||
|
||||
import sys
|
||||
|
||||
import rospy
|
||||
from rospy_tutorials.msg import HeaderString
|
||||
|
||||
NAME = 'talker_header'
|
||||
|
||||
def talker_header():
|
||||
pub = rospy.Publisher("chatter_header", HeaderString)
|
||||
|
||||
rospy.init_node(NAME) #blocks until registered with master
|
||||
count = 0
|
||||
while not rospy.is_shutdown():
|
||||
str = 'hello world %s'%count
|
||||
print str
|
||||
# If None is used as the header value, rospy will automatically
|
||||
# fill it in.
|
||||
pub.publish(HeaderString(None, str))
|
||||
count += 1
|
||||
rospy.sleep(0.1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
talker_header()
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
<launch>
|
||||
<node name="listener_with_user_data" pkg="rospy_tutorials" type="listener_with_user_data.py" output="screen" />
|
||||
<node name="talker-1" pkg="rospy_tutorials" type="talker" args="chatter:=chatter1"/>
|
||||
<node name="talker-2" pkg="rospy_tutorials" type="talker" args="chatter:=chatter2"/>
|
||||
<node name="talker-3" pkg="rospy_tutorials" type="talker" args="chatter:=chatter3"/>
|
||||
</launch>
|
|
@ -1,74 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id$
|
||||
|
||||
## Simple listener demo that demonstrates how to register additional
|
||||
## arguments to be passed to a subscription callback
|
||||
|
||||
PKG = 'rospy_tutorials' # this package name
|
||||
NAME = 'listener_with_user_data'
|
||||
|
||||
import roslib; roslib.load_manifest(PKG)
|
||||
|
||||
import sys
|
||||
|
||||
import rospy
|
||||
from std_msgs.msg import *
|
||||
|
||||
def callback(data, args):
|
||||
if args == 1:
|
||||
print "#1: I heard [%s]"%data.data
|
||||
elif args == 2:
|
||||
print "#2: I heard [%s]"%data.data
|
||||
else:
|
||||
print "I heard [%s] with userdata [%s]"%(data.data, str(args))
|
||||
|
||||
def listener_with_user_data():
|
||||
# Callback arguments (aka user data) allow you to reuse the same
|
||||
# callback for different topics, or they can even allow you to use
|
||||
# the same callback for the same topic, but have it do something
|
||||
# different based on the arguments.
|
||||
rospy.Subscriber("chatter", String, callback, 1)
|
||||
rospy.Subscriber("chatter", String, callback, 2)
|
||||
rospy.Subscriber("chatter", String, callback, ("chatter1", 4))
|
||||
rospy.Subscriber("chatter2", String, callback, "This is from chatter2")
|
||||
rospy.init_node(NAME, anonymous=True)
|
||||
rospy.spin()
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
listener_with_user_data()
|
||||
except KeyboardInterrupt, e:
|
||||
pass
|
||||
print "exiting"
|
|
@ -1,7 +0,0 @@
|
|||
<launch>
|
||||
<node name="talker-notify" pkg="rospy_tutorials" type="listener_subscribe_notify.py" output="screen" />
|
||||
<node name="listener-1" pkg="rospy_tutorials" type="listener.py" output="screen" />
|
||||
<node name="listener-2" pkg="rospy_tutorials" type="listener.py" output="screen" />
|
||||
<node name="listener-3" pkg="rospy_tutorials" type="listener.py" output="screen" />
|
||||
<node name="listener-4" pkg="rospy_tutorials" type="listener.py" output="screen" />
|
||||
</launch>
|
|
@ -1,78 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id$
|
||||
|
||||
## talker that receives notification of new subscriptions
|
||||
|
||||
PKG = 'rospy_tutorials' # this package name
|
||||
NAME = 'talker_callback'
|
||||
|
||||
import roslib; roslib.load_manifest(PKG)
|
||||
|
||||
import sys
|
||||
|
||||
import rospy
|
||||
from std_msgs.msg import String
|
||||
|
||||
class ChatterListener(rospy.SubscribeListener):
|
||||
def peer_subscribe(self, topic_name, topic_publish, peer_publish):
|
||||
print "a peer subscribed to topic [%s]"%topic_name
|
||||
|
||||
str = "Hey everyone, we have a new friend!"
|
||||
print str
|
||||
topic_publish(String(str))
|
||||
str = "greetings. welcome to topic "+topic_name
|
||||
print str
|
||||
peer_publish(String(str))
|
||||
|
||||
def peer_unsubscribe(self, topic_name, numPeers):
|
||||
print "a peer unsubscribed from topic [%s]"%topic_name
|
||||
if numPeers == 0:
|
||||
print "I have no friends"
|
||||
|
||||
def talker_callback():
|
||||
pub = rospy.Publisher("chatter", String, ChatterListener())
|
||||
rospy.init_node(NAME, anonymous=True)
|
||||
count = 0
|
||||
while not rospy.is_shutdown():
|
||||
str = "hello world %d"%count
|
||||
print str
|
||||
pub.publish(String(str))
|
||||
count += 1
|
||||
rospy.sleep(0.1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
talker_callback()
|
||||
except rospy.ROSInterruptException: pass
|
|
@ -1 +0,0 @@
|
|||
roslaunch demo.launch
|
|
@ -1,104 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id$
|
||||
|
||||
## Simple demo of a rospy service client that calls a service to add
|
||||
## two integers.
|
||||
|
||||
PKG = 'rospy_tutorials' # this package name
|
||||
|
||||
import roslib; roslib.load_manifest(PKG)
|
||||
|
||||
import sys
|
||||
import os
|
||||
import string
|
||||
|
||||
import rospy
|
||||
|
||||
# imports the AddTwoInts service
|
||||
from rospy_tutorials.srv import *
|
||||
|
||||
## add two numbers using the add_two_ints service
|
||||
## @param x int: first number to add
|
||||
## @param y int: second number to add
|
||||
def add_two_ints_client(x, y):
|
||||
|
||||
# NOTE: you don't have to call rospy.init_node() to make calls against
|
||||
# a service. This is because service clients do not have to be
|
||||
# nodes.
|
||||
|
||||
# block until the add_two_ints service is available
|
||||
# you can optionally specify a timeout
|
||||
rospy.wait_for_service('add_two_ints')
|
||||
|
||||
try:
|
||||
# create a handle to the add_two_ints service
|
||||
add_two_ints = rospy.ServiceProxy('add_two_ints', AddTwoInts)
|
||||
|
||||
print "Requesting %s+%s"%(x, y)
|
||||
|
||||
# simplified style
|
||||
resp1 = add_two_ints(x, y)
|
||||
|
||||
# formal style
|
||||
resp2 = add_two_ints.call(AddTwoIntsRequest(x, y))
|
||||
|
||||
if not resp1.sum == (x + y):
|
||||
raise Exception("test failure, returned sum was %s"%resp1.sum)
|
||||
if not resp2.sum == (x + y):
|
||||
raise Exception("test failure, returned sum was %s"%resp2.sum)
|
||||
return resp1.sum
|
||||
except rospy.ServiceException, e:
|
||||
print "Service call failed: %s"%e
|
||||
|
||||
def usage():
|
||||
return "%s [x y]"%sys.argv[0]
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
import random
|
||||
x = random.randint(-50000, 50000)
|
||||
y = random.randint(-50000, 50000)
|
||||
elif len(sys.argv) == 3:
|
||||
try:
|
||||
x = string.atoi(sys.argv[1])
|
||||
y = string.atoi(sys.argv[2])
|
||||
except:
|
||||
print usage()
|
||||
sys.exit(1)
|
||||
else:
|
||||
print usage()
|
||||
sys.exit(1)
|
||||
print "%s + %s = %s"%(x, y, add_two_ints_client(x, y))
|
|
@ -1,59 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id$
|
||||
|
||||
## Simple demo of a rospy service that add two integers
|
||||
|
||||
PKG = 'rospy_tutorials' # this package name
|
||||
NAME = 'add_two_ints_server'
|
||||
|
||||
import roslib; roslib.load_manifest(PKG)
|
||||
|
||||
# import the AddTwoInts service
|
||||
from rospy_tutorials.srv import *
|
||||
import rospy
|
||||
|
||||
def add_two_ints(req):
|
||||
print "Returning [%s + %s = %s]"%(req.a, req.b, (req.a + req.b))
|
||||
return AddTwoIntsResponse(req.a + req.b)
|
||||
|
||||
def add_two_ints_server():
|
||||
rospy.init_node(NAME)
|
||||
s = rospy.Service('add_two_ints', AddTwoInts, add_two_ints)
|
||||
|
||||
# spin() keeps Python from exiting until node is shutdown
|
||||
rospy.spin()
|
||||
|
||||
if __name__ == "__main__":
|
||||
add_two_ints_server()
|
|
@ -1,29 +0,0 @@
|
|||
<launch>
|
||||
|
||||
<!-- set a /global_example parameter -->
|
||||
<param name="global_example" value="global value" />
|
||||
|
||||
<group ns="foo">
|
||||
|
||||
<!-- set /foo/utterance -->
|
||||
<param name="utterance" value="Hello World" />
|
||||
|
||||
<param name="to_delete" value="Delete Me" />
|
||||
|
||||
<!-- a group of parameters that we will fetch together -->
|
||||
<group ns="gains">
|
||||
<param name="P" value="1.0" />
|
||||
<param name="I" value="2.0" />
|
||||
<param name="D" value="3.0" />
|
||||
</group>
|
||||
|
||||
<node pkg="rospy_tutorials" name="param_talker" type="param_talker.py" output="screen">
|
||||
|
||||
<!-- set /foo/utterance/param_talker/topic_name -->
|
||||
<param name="topic_name" value="chatter" />
|
||||
|
||||
</node>
|
||||
|
||||
</group>
|
||||
|
||||
</launch>
|
|
@ -1,106 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id: listener.py 5263 2009-07-17 23:30:38Z sfkwc $
|
||||
|
||||
## Simple talker demo that listens to std_msgs/Strings published
|
||||
## to the 'chatter' topic
|
||||
|
||||
PKG = 'rospy_tutorials' # this package name
|
||||
import roslib; roslib.load_manifest(PKG)
|
||||
|
||||
import rospy
|
||||
from std_msgs.msg import String
|
||||
|
||||
def param_talker():
|
||||
rospy.init_node('param_talker')
|
||||
|
||||
# Fetch values from the Parameter Server. In this example, we fetch
|
||||
# parameters from three different namespaces:
|
||||
#
|
||||
# 1) global (/global_example)
|
||||
# 2) parent (/foo/utterance)
|
||||
# 3) private (/foo/param_talker/topic_name)
|
||||
|
||||
# fetch a /global parameter
|
||||
global_example = rospy.get_param("/global_example")
|
||||
rospy.loginfo("%s is %s", rospy.resolve_name('/global_example'), global_example)
|
||||
|
||||
# fetch the utterance parameter from our parent namespace
|
||||
utterance = rospy.get_param('utterance')
|
||||
rospy.loginfo("%s is %s", rospy.resolve_name('utterance'), utterance)
|
||||
|
||||
# fetch topic_name from the ~private namespace
|
||||
topic_name = rospy.get_param('~topic_name')
|
||||
rospy.loginfo("%s is %s", rospy.resolve_name('~topic_name'), topic_name)
|
||||
|
||||
# fetch a parameter, using 'default_value' if it doesn't exist
|
||||
default_param = rospy.get_param('default_param', 'default_value')
|
||||
rospy.loginfo('%s is %s', rospy.resolve_name('default_param'), default_param)
|
||||
|
||||
# fetch a group (dictionary) of parameters
|
||||
gains = rospy.get_param('gains')
|
||||
p, i, d = gains['P'], gains['I'], gains['D']
|
||||
rospy.loginfo("gains are %s, %s, %s", p, i, d)
|
||||
|
||||
# set some parameters
|
||||
rospy.loginfo('setting parameters...')
|
||||
rospy.set_param('list_of_floats', [1., 2., 3., 4.])
|
||||
rospy.set_param('bool_True', True)
|
||||
rospy.set_param('~private_bar', 1+2)
|
||||
rospy.set_param('to_delete', 'baz')
|
||||
rospy.loginfo('...parameters have been set')
|
||||
|
||||
# delete a parameter
|
||||
if rospy.has_param('to_delete'):
|
||||
rospy.delete_param('to_delete')
|
||||
rospy.loginfo("deleted %s parameter"%rospy.resolve_name('to_delete'))
|
||||
else:
|
||||
rospy.loginfo('parameter %s was already deleted'%rospy.resolve_name('to_delete'))
|
||||
|
||||
# search for a parameter
|
||||
param_name = rospy.search_param('global_example')
|
||||
rospy.loginfo('found global_example parameter under key: %s'%param_name)
|
||||
|
||||
# publish the value of utterance repeatedly
|
||||
pub = rospy.Publisher(topic_name, String)
|
||||
while not rospy.is_shutdown():
|
||||
pub.publish(utterance)
|
||||
rospy.loginfo(utterance)
|
||||
rospy.sleep(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
param_talker()
|
||||
except rospy.ROSInterruptException: pass
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
This tutorial demonstrates how to access connection header information
|
||||
in rospy.
|
||||
|
||||
For topics, the connection header information allows a Subscriber to
|
||||
determine who the message was published by. There are also additional
|
||||
fields in the connection header that contain runtime type information
|
||||
for the topic. listener_connection_header.py shows how to access
|
||||
this information from a Message. You can run a demo of it in action
|
||||
by running:
|
||||
|
||||
roslaunch connection_header.launch
|
||||
|
||||
Connection headers have additional functionality as a Service client
|
||||
can pass in additional metadata when creating a rospy.ServiceProxy
|
||||
object. This functionality is somewhat similar to HTTP in that you can
|
||||
use it to implement sessions or otherwise provide additional metadata
|
||||
with a service call.
|
||||
|
||||
server_connection_header.py and client_connection_header.py contain
|
||||
variants on the add_two_ints demos that show how this information
|
||||
can be used. In order to run this demo you must run three commands:
|
||||
|
||||
roscore
|
||||
rosrun rospy_tutorials server_connection_header.py
|
||||
rosrun rospy_tutorials client_connection_header.py
|
|
@ -1,89 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id: add_two_ints_client 3804 2009-02-11 02:16:00Z rob_wheeler $
|
||||
|
||||
## Extended version of add_two_int_client that shows how to use
|
||||
## connection header to pass in metadata to service.
|
||||
|
||||
import roslib; roslib.load_manifest('rospy_tutorials')
|
||||
|
||||
import sys
|
||||
|
||||
import rospy
|
||||
|
||||
from rospy_tutorials.srv import AddTwoInts
|
||||
|
||||
## add two numbers using the add_two_ints service
|
||||
## @param x int: first number to add
|
||||
## @param y int: second number to add
|
||||
def add_two_ints_client(x, y):
|
||||
rospy.wait_for_service('add_two_ints')
|
||||
|
||||
try:
|
||||
# initialize ServiceProxy with extra header information.
|
||||
# header is only exchanged on initial connection
|
||||
metadata = { 'cookies' : 'peanut butter' }
|
||||
add_two_ints = rospy.ServiceProxy('add_two_ints', AddTwoInts, headers=metadata)
|
||||
|
||||
print "Requesting %s+%s with cookies=%s"%(x, y, metadata['cookies'])
|
||||
|
||||
# simplified style
|
||||
resp = add_two_ints(x, y)
|
||||
print "Server's connection headers were", resp._connection_header
|
||||
|
||||
return resp.sum
|
||||
except rospy.ServiceException, e:
|
||||
print "Service call failed: %s"%e
|
||||
|
||||
def usage():
|
||||
return "%s [x y]"%sys.argv[0]
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
import random
|
||||
x = random.randint(-50000, 50000)
|
||||
y = random.randint(-50000, 50000)
|
||||
elif len(sys.argv) == 3:
|
||||
try:
|
||||
import string
|
||||
x = string.atoi(sys.argv[1])
|
||||
y = string.atoi(sys.argv[2])
|
||||
except:
|
||||
print usage()
|
||||
sys.exit(1)
|
||||
else:
|
||||
print usage()
|
||||
sys.exit(1)
|
||||
print "%s + %s = %s"%(x, y, add_two_ints_client(x, y))
|
|
@ -1,4 +0,0 @@
|
|||
<launch>
|
||||
<node name="listener-ch" pkg="rospy_tutorials" type="listener_connection_header.py" output="screen"/>
|
||||
<node name="talker-ch" pkg="rospy_tutorials" type="talker_connection_header.py" />
|
||||
</launch>
|
|
@ -1,70 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id: gossipbot 3529 2009-01-23 22:35:53Z sfkwc $
|
||||
|
||||
## listener_connection_header looks at the connection header
|
||||
## from the received message to determine who it is talking to.
|
||||
|
||||
PKG = 'rospy_tutorials'
|
||||
import roslib; roslib.load_manifest(PKG)
|
||||
|
||||
import sys
|
||||
|
||||
import rospy
|
||||
from std_msgs.msg import String
|
||||
|
||||
NAME = 'listener_connection_header'
|
||||
|
||||
def callback(data):
|
||||
chatter = data.data
|
||||
if 'callerid' in data._connection_header:
|
||||
who = data._connection_header['callerid']
|
||||
else:
|
||||
who = 'unknown'
|
||||
if 'cookies' in data._connection_header:
|
||||
print "%s just offered me %s cookies"%(who, data._connection_header['cookies'])
|
||||
else:
|
||||
print "I just heard %s from %s"%(chatter, who)
|
||||
|
||||
def listener_header():
|
||||
rospy.Subscriber("chatter", String, callback)
|
||||
rospy.init_node(NAME, anonymous=True)
|
||||
rospy.spin()
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
listener_header()
|
||||
except KeyboardInterrupt, e:
|
||||
pass
|
||||
print "exiting"
|
|
@ -1,63 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id: add_two_ints_server 3804 2009-02-11 02:16:00Z rob_wheeler $
|
||||
|
||||
## Extended version of add_two_ints_server demo that shows how
|
||||
## to access connection header information
|
||||
|
||||
PKG = 'rospy_tutorials' # this package name
|
||||
NAME = 'add_two_ints_server'
|
||||
|
||||
import roslib; roslib.load_manifest(PKG)
|
||||
|
||||
# import the AddTwoInts service
|
||||
from rospy_tutorials.srv import *
|
||||
import rospy
|
||||
|
||||
def add_two_ints(req):
|
||||
print "Request from %s"%req._connection_header['callerid']
|
||||
if 'cookies' in req._connection_header:
|
||||
print "Request gave me %s cookies"%req._connection_header['cookies']
|
||||
print "Returning [%s + %s = %s]"%(req.a, req.b, (req.a + req.b))
|
||||
return AddTwoIntsResponse(req.a + req.b)
|
||||
|
||||
def add_two_ints_server():
|
||||
rospy.init_node(NAME)
|
||||
s = rospy.Service('add_two_ints', AddTwoInts, add_two_ints)
|
||||
|
||||
# spin() keeps Python from exiting until node is shutdown
|
||||
rospy.spin()
|
||||
|
||||
if __name__ == "__main__":
|
||||
add_two_ints_server()
|
|
@ -1,57 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id: talker.py 5263 2009-07-17 23:30:38Z sfkwc $
|
||||
|
||||
## Simple talker demo that published std_msgs/Strings messages
|
||||
## to the 'chatter' topic
|
||||
|
||||
import roslib; roslib.load_manifest('rospy_tutorials')
|
||||
|
||||
import rospy
|
||||
from std_msgs.msg import String
|
||||
|
||||
def talker():
|
||||
pub = rospy.Publisher('chatter', String, headers={'cookies': 'oreo'})
|
||||
rospy.init_node('talker', anonymous=True)
|
||||
r = rospy.Rate(10) # 10hz
|
||||
while not rospy.is_shutdown():
|
||||
str = "hello world %s"%rospy.get_time()
|
||||
rospy.loginfo(str)
|
||||
pub.publish(str)
|
||||
r.sleep()
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
talker()
|
||||
except rospy.ROSInterruptException: pass
|
|
@ -1,4 +0,0 @@
|
|||
<launch>
|
||||
<node name="listener" pkg="rospy_tutorials" type="listener.py" output="screen"/>
|
||||
<node name="publish_on_shutdown" pkg="rospy_tutorials" type="publish_on_shutdown.py" output="screen"/>
|
||||
</launch>
|
|
@ -1,63 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id: talker.py 4223 2009-04-16 21:47:54Z jfaustwg $
|
||||
|
||||
## Simple talker demo that published std_msgs/Strings messages
|
||||
## to the 'chatter' topic
|
||||
|
||||
import roslib; roslib.load_manifest('rospy_tutorials')
|
||||
|
||||
import rospy
|
||||
from std_msgs.msg import String
|
||||
|
||||
pub = None
|
||||
# publish a message to subscribers when we die
|
||||
def talker_shutdown():
|
||||
print "I'm dead!"
|
||||
pub.publish("I'm dead!")
|
||||
|
||||
def talker():
|
||||
global pub
|
||||
pub = rospy.Publisher('chatter', String)
|
||||
rospy.init_node('talker', anonymous=True)
|
||||
|
||||
# register talker_shutdown() to be called when rospy exits
|
||||
rospy.on_shutdown(talker_shutdown)
|
||||
print "Hit ctrl-C to see on_shutdown example"
|
||||
|
||||
# spin() blocks until the node shuts down
|
||||
rospy.spin()
|
||||
|
||||
if __name__ == '__main__':
|
||||
talker()
|
|
@ -1,3 +0,0 @@
|
|||
<launch>
|
||||
<node name="advanced_talker" pkg="rospy_tutorials" type="advanced_publish.py" output="screen"/>
|
||||
</launch>
|
|
@ -1,67 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id: talker.py 4223 2009-04-16 21:47:54Z jfaustwg $
|
||||
|
||||
## talker demo that published std_msgs/ColorRGBA messages
|
||||
## to the 'color' topic. To see these messages, type:
|
||||
## rostopic echo color
|
||||
## this demo shows some of the more advanced APIs in rospy.
|
||||
|
||||
import roslib; roslib.load_manifest('rospy_tutorials')
|
||||
|
||||
import rospy
|
||||
from std_msgs.msg import ColorRGBA
|
||||
|
||||
def talker():
|
||||
topic = 'color'
|
||||
pub = rospy.Publisher(topic, ColorRGBA)
|
||||
rospy.init_node('color_talker', anonymous=True)
|
||||
print "\n\nNode running. To see messages, please type\n\t'rostopic echo %s'\nIn another window\n\n"%(rospy.resolve_name(topic))
|
||||
while not rospy.is_shutdown():
|
||||
|
||||
# publish with in-order initialization of arguments (r, g, b, a)
|
||||
pub.publish(1, 2, 3, 4)
|
||||
rospy.sleep(.5)
|
||||
|
||||
# publish with a=1, use default values for rest
|
||||
pub.publish(a=1.0)
|
||||
rospy.sleep(.5)
|
||||
|
||||
# print the number of subscribers
|
||||
rospy.loginfo("I have %s subscribers"%pub.get_num_connections())
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
talker()
|
||||
except rospy.ROSInterruptException: pass
|
|
@ -1,13 +0,0 @@
|
|||
cmake_minimum_required(VERSION 2.4.6)
|
||||
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
|
||||
rosbuild_init()
|
||||
genmsg()
|
||||
gensrv()
|
||||
rospack_add_rostest(test/test-add-two-ints.launch)
|
||||
rospack_add_rostest(test/test-peer-subscribe-notify.launch)
|
||||
rospack_add_rostest(test/test-add-two-ints-with-roscpp-server.launch)
|
||||
rospack_add_rostest(test/test-talker-listener.launch)
|
||||
rospack_add_rostest(test/test-talker-listener-with-roscpp.launch)
|
||||
rospack_add_rostest(test/test-on-shutdown.launch)
|
||||
rospack_add_rostest(test/test-connection-header.launch)
|
||||
|
|
@ -1 +0,0 @@
|
|||
include $(shell rospack find mk)/cmake.mk
|
|
@ -1,2 +0,0 @@
|
|||
\mainpage
|
||||
\htmlinclude manifest.html
|
|
@ -1,17 +0,0 @@
|
|||
<package>
|
||||
<description brief="Shows the features of ROS step-by-step">
|
||||
This package attempts to show the features of ROS python API step-by-step,
|
||||
including using messages, servers, parameters, etc. These tutorials are compatible with the nodes in roscpp_tutorial.
|
||||
</description>
|
||||
<author>Ken Conley</author>
|
||||
<license>BSD</license>
|
||||
<review status="unreviewed" notes=""/>
|
||||
<url>http://pr.willowgarage.com</url>
|
||||
<depend package="rospy"/>
|
||||
<depend package="rostest"/>
|
||||
<depend package="std_srvs"/>
|
||||
<depend package="std_msgs"/>
|
||||
<!-- roscpp_tutorials is a dependency for the integration tests -->
|
||||
<depend package="roscpp_tutorials"/>
|
||||
</package>
|
||||
|
|
@ -1 +0,0 @@
|
|||
float32[] data
|
|
@ -1,2 +0,0 @@
|
|||
Header header
|
||||
string data
|
|
@ -1,4 +0,0 @@
|
|||
int64 a
|
||||
int64 b
|
||||
---
|
||||
int64 sum
|
|
@ -1,5 +0,0 @@
|
|||
# Bad version of AddTwoInts for unit testing
|
||||
int64 a
|
||||
int32 b
|
||||
---
|
||||
int32 sum
|
|
@ -1,64 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id: talker.py 4223 2009-04-16 21:47:54Z jfaustwg $
|
||||
|
||||
## Simple talker demo that published std_msgs/Strings messages
|
||||
## to the 'chatter' topic
|
||||
|
||||
import roslib; roslib.load_manifest('rospy_tutorials')
|
||||
|
||||
import rospy
|
||||
from std_msgs.msg import String
|
||||
|
||||
pub = None
|
||||
# publish a message to subscribers when we die
|
||||
def talker_shutdown():
|
||||
print "I'm dead!"
|
||||
pub.publish("I'm dead!")
|
||||
|
||||
def talker():
|
||||
global pub
|
||||
pub = rospy.Publisher('chatter', String)
|
||||
rospy.init_node('talker', anonymous=True)
|
||||
|
||||
# register talker_shutdown() to be called when rospy exits
|
||||
rospy.on_shutdown(talker_shutdown)
|
||||
|
||||
import time
|
||||
time.sleep(2.0)
|
||||
|
||||
rospy.signal_shutdown('test done')
|
||||
|
||||
if __name__ == '__main__':
|
||||
talker()
|
|
@ -1,66 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id: gossipbot.py 1013 2008-05-21 01:08:56Z sfkwc $
|
||||
|
||||
## Talker/listener demo validation
|
||||
|
||||
PKG = 'rospy_tutorials'
|
||||
NAME = 'talker_listener_test'
|
||||
|
||||
import roslib; roslib.update_path(PKG)
|
||||
|
||||
import sys, unittest, time
|
||||
|
||||
import rospy, rostest
|
||||
from std_msgs.msg import *
|
||||
|
||||
class TestTalkerListener(unittest.TestCase):
|
||||
def __init__(self, *args):
|
||||
super(TestTalkerListener, self).__init__(*args)
|
||||
self.success = False
|
||||
|
||||
def callback(self, data):
|
||||
print rospy.get_caller_id(), "I heard %s"%data.data
|
||||
self.success = data.data and data.data.startswith('hello world')
|
||||
|
||||
def test_talker_listener(self):
|
||||
rospy.init_node(NAME, anonymous=True)
|
||||
rospy.Subscriber("chatter", String, self.callback)
|
||||
timeout_t = time.time() + 10.0 #10 seconds
|
||||
while not rospy.is_shutdown() and not self.success and time.time() < timeout_t:
|
||||
time.sleep(0.1)
|
||||
self.assert_(self.success)
|
||||
|
||||
if __name__ == '__main__':
|
||||
rostest.rosrun(PKG, NAME, TestTalkerListener, sys.argv)
|
|
@ -1,4 +0,0 @@
|
|||
<launch>
|
||||
<node name="a2i_server" pkg="roscpp_tutorials" type="add_two_ints_server" />
|
||||
<test time-limit="10" test-name="add_two_ints_with_cpp" pkg="rospy_tutorials" type="test_add_two_ints.py" />
|
||||
</launch>
|
|
@ -1,4 +0,0 @@
|
|||
<launch>
|
||||
<node name="a2i_server" pkg="rospy_tutorials" type="add_two_ints_server" />
|
||||
<test test-name="add_two_ints" pkg="rospy_tutorials" type="test_add_two_ints.py" />
|
||||
</launch>
|
|
@ -1,9 +0,0 @@
|
|||
<launch>
|
||||
<node name="talker" pkg="rospy_tutorials" type="talker.py" />
|
||||
<node name="a2i_server" pkg="rospy_tutorials" type="add_two_ints_server" />
|
||||
<node name="test_client_ch" pkg="rospy_tutorials" type="test_client_connection_header.py" args="--node"/>
|
||||
|
||||
<test test-name="listener_connection_header" pkg="rospy_tutorials" type="test_listener_connection_header.py" />
|
||||
<test test-name="client_connection_header" pkg="rospy_tutorials" type="test_client_connection_header.py" />
|
||||
<test test-name="server_connection_header" pkg="rospy_tutorials" type="test_server_connection_header.py" />
|
||||
</launch>
|
|
@ -1,4 +0,0 @@
|
|||
<launch>
|
||||
<node name="pos_node" pkg="rospy_tutorials" type="publish_on_shutdown_test_node.py" />
|
||||
<test test-name="on_shutdown" pkg="rospy_tutorials" type="test_on_shutdown.py" />
|
||||
</launch>
|
|
@ -1,4 +0,0 @@
|
|||
<launch>
|
||||
<node name="listener" pkg="rospy_tutorials" type="listener_subscribe_notify.py" />
|
||||
<test test-name="listener_subscribe_notify" pkg="rospy_tutorials" type="test_peer_subscribe_notify.py" />
|
||||
</launch>
|
|
@ -1,4 +0,0 @@
|
|||
<launch>
|
||||
<node name="talker" pkg="roscpp_tutorials" type="talker" />
|
||||
<test test-name="talker_listener_test" pkg="rospy_tutorials" type="talker_listener_test.py" />
|
||||
</launch>
|
|
@ -1,4 +0,0 @@
|
|||
<launch>
|
||||
<node name="talker" pkg="rospy_tutorials" type="talker.py" />
|
||||
<test test-name="talker_listener_test" pkg="rospy_tutorials" type="talker_listener_test.py" />
|
||||
</launch>
|
|
@ -1,103 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id$
|
||||
|
||||
## Integration test for add_two_ints
|
||||
|
||||
PKG = 'rospy_tutorials'
|
||||
NAME = 'add_two_ints_test'
|
||||
|
||||
import roslib; roslib.load_manifest(PKG)
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import rospy
|
||||
import rostest
|
||||
from rospy_tutorials.srv import *
|
||||
|
||||
class TestAddTwoInts(unittest.TestCase):
|
||||
|
||||
def test_add_two_ints(self):
|
||||
rospy.wait_for_service('add_two_ints')
|
||||
s = rospy.ServiceProxy('add_two_ints', AddTwoInts)
|
||||
tests = [(1, 2), (0, 0), (-1, -2), (12312, 980123), (sys.maxint, -sys.maxint), (sys.maxint, -1), (sys.maxint, 0)]
|
||||
for x, y in tests:
|
||||
print "Requesting %s+%s"%(x, y)
|
||||
# test both simple and formal call syntax
|
||||
resp = s(x, y)
|
||||
resp2 = s.call(AddTwoIntsRequest(x, y))
|
||||
self.assertEquals(resp.sum,resp2.sum)
|
||||
print "%s+%s = %s"%(x, y, resp.sum)
|
||||
self.assertEquals(resp.sum,(x + y), "integration failure, returned sum was %s vs. %s"%(resp.sum, (x+y)))
|
||||
|
||||
def test_add_two_ints_bad_then_good(self):
|
||||
rospy.wait_for_service('add_two_ints')
|
||||
try:
|
||||
s = rospy.ServiceProxy('add_two_ints', BadTwoInts)
|
||||
resp = s(1, 2)
|
||||
self.fail("service call should have failed with exception but instead returned 1+2=%s"%resp.sum)
|
||||
except rospy.ServiceException, e:
|
||||
print "success -- ros exception was thrown: %s"%e
|
||||
s = rospy.ServiceProxy('add_two_ints', AddTwoInts)
|
||||
resp = s.call(AddTwoIntsRequest(1, 2))
|
||||
self.assertEquals(3,resp.sum)
|
||||
|
||||
|
||||
def test_add_two_ints_bad_type(self):
|
||||
rospy.wait_for_service('add_two_ints')
|
||||
s = rospy.ServiceProxy('add_two_ints', BadTwoInts)
|
||||
tests = [(1, 2), (0, 0), (-1, -2), (12312, 980123), (sys.maxint, -sys.maxint), (sys.maxint, -1), (sys.maxint, 0)]
|
||||
for x, y in tests:
|
||||
print "Requesting %s+%s"%(x, y)
|
||||
# test both simple and formal call syntax
|
||||
try:
|
||||
resp = s(x, y)
|
||||
if resp.sum == x+y:
|
||||
self.fail("call 1 with bad type failed: the server appears to be incorrectly deserialing the packet as it returned: %s"%resp.sum)
|
||||
else:
|
||||
self.fail("call 1 with bad type failed to throw exception: %s"%resp.sum)
|
||||
except rospy.ServiceException, e:
|
||||
print "success -- ros exception was thrown: %s"%e
|
||||
try:
|
||||
resp = s.call(BadTwoIntsRequest(x, y))
|
||||
if resp.sum == x+y:
|
||||
self.fail("call 2 with bad type failed: the server appears to be incorrectly deserialing the packet as it returned: %s"%resp.sum)
|
||||
else:
|
||||
self.fail("call 2 with bad type failed to throw exception: %s"%resp.sum)
|
||||
except rospy.ServiceException, e:
|
||||
print "success -- ros exception was thrown: %s"%e
|
||||
|
||||
if __name__ == '__main__':
|
||||
rostest.rosrun(PKG, NAME, TestAddTwoInts, sys.argv)
|
|
@ -1,100 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id: add_two_ints_client 3804 2009-02-11 02:16:00Z rob_wheeler $
|
||||
|
||||
## Extended version of add_two_int_client that shows how to use
|
||||
## connection header to pass in metadata to service.
|
||||
|
||||
PKG = 'rospy_tutorials'
|
||||
NAME = 'test_client_connection_header'
|
||||
import roslib; roslib.load_manifest(PKG)
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from rospy_tutorials.srv import AddTwoInts
|
||||
import rospy
|
||||
import rostest
|
||||
|
||||
|
||||
class TestClientConnectionHeader(unittest.TestCase):
|
||||
def __init__(self, *args):
|
||||
super(TestClientConnectionHeader, self).__init__(*args)
|
||||
self.success = False
|
||||
|
||||
def test_header(self):
|
||||
import random
|
||||
x = random.randint(0, 1000)
|
||||
y = random.randint(0, 1000)
|
||||
|
||||
rospy.wait_for_service('add_two_ints')
|
||||
|
||||
try:
|
||||
# initialize ServiceProxy with extra header information.
|
||||
# header is only exchanged on initial connection
|
||||
metadata = { 'cookies' : 'peanut butter' }
|
||||
add_two_ints = rospy.ServiceProxy('add_two_ints', AddTwoInts, headers=metadata)
|
||||
|
||||
print "Requesting %s+%s with cookies=%s"%(x, y, metadata['cookies'])
|
||||
|
||||
# simplified style
|
||||
resp = add_two_ints(x, y)
|
||||
print "Server's connection headers were", resp._connection_header
|
||||
self.assert_('callerid' in resp._connection_header)
|
||||
|
||||
return resp.sum
|
||||
except rospy.ServiceException, e:
|
||||
print "Service call failed: %s"%e
|
||||
raise #fail
|
||||
|
||||
if __name__ == '__main__':
|
||||
if '--node' in sys.argv:
|
||||
# run as a normal node instead (test of server_connection_header)
|
||||
# the test here is to send the cookies header, which the server test node looks for
|
||||
rospy.init_node('sch_test_client', anonymous=True)
|
||||
# NOTE different service name
|
||||
service_name = 'add_two_ints_header_test'
|
||||
rospy.wait_for_service(service_name)
|
||||
metadata = { 'cookies' : 'peanut butter' }
|
||||
add_two_ints = rospy.ServiceProxy(service_name, AddTwoInts, headers=metadata)
|
||||
try:
|
||||
while not rospy.is_shutdown():
|
||||
resp = add_two_ints(1, 2)
|
||||
# call at 10hz until test is over
|
||||
rospy.sleep(0.1)
|
||||
except rospy.ServiceException, e:
|
||||
pass # happens when test is over
|
||||
else:
|
||||
rostest.rosrun(PKG, NAME, TestClientConnectionHeader, sys.argv)
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id: test_peer_subscribe_notify.py 3803 2009-02-11 02:04:39Z rob_wheeler $
|
||||
|
||||
## Integration test for peer_subscribe_notify
|
||||
|
||||
PKG = 'rospy_tutorials'
|
||||
NAME = 'peer_subscribe_notify_test'
|
||||
import roslib; roslib.load_manifest(PKG)
|
||||
|
||||
import sys
|
||||
import time
|
||||
import unittest
|
||||
|
||||
import rospy
|
||||
import rostest
|
||||
import roslib.scriptutil as scriptutil
|
||||
from std_msgs.msg import String
|
||||
|
||||
|
||||
class TestListenerConnectionHeader(unittest.TestCase):
|
||||
def __init__(self, *args):
|
||||
super(TestListenerConnectionHeader, self).__init__(*args)
|
||||
self.success = False
|
||||
|
||||
def callback(self, data):
|
||||
chatter = data.data
|
||||
if 'callerid' in data._connection_header:
|
||||
who = data._connection_header['callerid']
|
||||
self.success = True
|
||||
else:
|
||||
who = 'unknown'
|
||||
print "I just heard %s from %s"%(chatter, who)
|
||||
|
||||
def test_notify(self):
|
||||
rospy.Subscriber("chatter", String, self.callback)
|
||||
rospy.init_node(NAME, anonymous=True)
|
||||
timeout_t = time.time() + 10.0*1000 #10 seconds
|
||||
while not rospy.is_shutdown() and not self.success and time.time() < timeout_t:
|
||||
time.sleep(0.1)
|
||||
self.assert_(self.success, str(self.success))
|
||||
|
||||
if __name__ == '__main__':
|
||||
rostest.rosrun(PKG, NAME, TestListenerConnectionHeader, sys.argv)
|
|
@ -1,72 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id: test_peer_subscribe_notify.py 3803 2009-02-11 02:04:39Z rob_wheeler $
|
||||
|
||||
## Integration test for peer_subscribe_notify
|
||||
|
||||
PKG = 'rospy_tutorials'
|
||||
NAME = 'peer_subscribe_notify_test'
|
||||
import roslib; roslib.load_manifest(PKG)
|
||||
|
||||
import sys
|
||||
import time
|
||||
import unittest
|
||||
|
||||
import rospy
|
||||
import rostest
|
||||
import roslib.scriptutil as scriptutil
|
||||
from std_msgs.msg import String
|
||||
|
||||
|
||||
class TestOnShutdown(unittest.TestCase):
|
||||
def __init__(self, *args):
|
||||
super(TestOnShutdown, self).__init__(*args)
|
||||
self.success = False
|
||||
|
||||
def callback(self, data):
|
||||
print rospy.get_caller_id(), "I heard %s"%data.data
|
||||
#greetings is only sent over peer_publish callback, so hearing it is a success condition
|
||||
if "I'm dead" in data.data:
|
||||
self.success = True
|
||||
|
||||
def test_notify(self):
|
||||
rospy.Subscriber("chatter", String, self.callback)
|
||||
rospy.init_node(NAME, anonymous=True)
|
||||
timeout_t = time.time() + 10.0*1000 #10 seconds
|
||||
while not rospy.is_shutdown() and not self.success and time.time() < timeout_t:
|
||||
time.sleep(0.1)
|
||||
self.assert_(self.success, str(self.success))
|
||||
|
||||
if __name__ == '__main__':
|
||||
rostest.rosrun(PKG, NAME, TestOnShutdown, sys.argv)
|
|
@ -1,72 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id$
|
||||
|
||||
## Integration test for peer_subscribe_notify
|
||||
|
||||
PKG = 'rospy_tutorials'
|
||||
NAME = 'peer_subscribe_notify_test'
|
||||
import roslib; roslib.load_manifest(PKG)
|
||||
|
||||
import sys
|
||||
import time
|
||||
import unittest
|
||||
|
||||
import rospy
|
||||
import rostest
|
||||
import roslib.scriptutil as scriptutil
|
||||
from std_msgs.msg import String
|
||||
|
||||
|
||||
class TestPeerSubscribeListener(unittest.TestCase):
|
||||
def __init__(self, *args):
|
||||
super(TestPeerSubscribeListener, self).__init__(*args)
|
||||
self.success = False
|
||||
|
||||
def callback(self, data):
|
||||
print rospy.get_caller_id(), "I heard %s"%data.data
|
||||
#greetings is only sent over peer_publish callback, so hearing it is a success condition
|
||||
if data.data.startswith('greetings'):
|
||||
self.success = True
|
||||
|
||||
def test_notify(self):
|
||||
rospy.Subscriber("chatter", String, self.callback)
|
||||
rospy.init_node(NAME, anonymous=True)
|
||||
timeout_t = time.time() + 10.0*1000 #10 seconds
|
||||
while not rospy.is_shutdown() and not self.success and time.time() < timeout_t:
|
||||
time.sleep(0.1)
|
||||
self.assert_(self.success, str(self.success))
|
||||
|
||||
if __name__ == '__main__':
|
||||
rostest.rosrun(PKG, NAME, TestPeerSubscribeListener, sys.argv)
|
|
@ -1,72 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
# Revision $Id: add_two_ints_client 3804 2009-02-11 02:16:00Z rob_wheeler $
|
||||
|
||||
## Extended version of add_two_int_client that shows how to use
|
||||
## connection header to pass in metadata to service.
|
||||
|
||||
PKG = 'rospy_tutorials'
|
||||
NAME = 'test_server_connection_header'
|
||||
import roslib; roslib.load_manifest(PKG)
|
||||
|
||||
import sys
|
||||
import time
|
||||
import unittest
|
||||
|
||||
from rospy_tutorials.srv import AddTwoInts, AddTwoIntsResponse
|
||||
import rospy
|
||||
import rostest
|
||||
|
||||
class TestServerConnectionHeader(unittest.TestCase):
|
||||
def __init__(self, *args):
|
||||
super(TestServerConnectionHeader, self).__init__(*args)
|
||||
self.success = False
|
||||
rospy.init_node(NAME, anonymous=True)
|
||||
s = rospy.Service('add_two_ints_header_test', AddTwoInts, self.handle_request)
|
||||
|
||||
def handle_request(self, req):
|
||||
if 'cookies' in req._connection_header:
|
||||
print "GOT", req._connection_header['cookies']
|
||||
self.success = req._connection_header['cookies'] == 'peanut butter'
|
||||
return AddTwoIntsResponse(3)
|
||||
|
||||
def test_header(self):
|
||||
timeout_t = time.time() + 10.0*1000 #10 seconds
|
||||
while not rospy.is_shutdown() and not self.success and time.time() < timeout_t:
|
||||
time.sleep(0.1)
|
||||
self.assert_(self.success, str(self.success))
|
||||
|
||||
if __name__ == '__main__':
|
||||
rostest.rosrun(PKG, NAME, TestServerConnectionHeader, sys.argv)
|
||||
|
Loading…
Reference in New Issue