Created
September 19, 2019 12:09
-
-
Save surinoel/576c3a4babcc2b67e383dcf36747a3b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 2.8.3) | |
project(beginner_tutorials) | |
## Compile as C++11, supported in ROS Kinetic and newer | |
# add_compile_options(-std=c++11) | |
## Find catkin macros and libraries | |
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) | |
## is used, also find other catkin packages | |
find_package(catkin REQUIRED COMPONENTS | |
roscpp | |
rospy | |
std_msgs | |
message_generation | |
) | |
## Uncomment this if the package has a setup.py. This macro ensures | |
## modules and global scripts declared therein get installed | |
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html | |
# catkin_python_setup() | |
## Generate added messages and services with any dependencies listed here | |
generate_messages( | |
DEPENDENCIES | |
std_msgs | |
) | |
catkin_package( | |
# INCLUDE_DIRS include | |
# LIBRARIES beginner_tutorials | |
CATKIN_DEPENDS #roscpp rospy std_msgs | |
# DEPENDS system_lib | |
) | |
include_directories( | |
${catkin_INCLUDE_DIRS} | |
) | |
add_executable(sub_hello src/sub_hello.cpp) | |
add_dependencies(sub_hello ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) | |
target_link_libraries(sub_hello | |
${catkin_LIBRARIES} | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<package format="2"> | |
<name>beginner_tutorials</name> | |
<version>0.0.0</version> | |
<description>The beginner_tutorials package</description> | |
<!-- One maintainer tag required, multiple allowed, one person per tag --> | |
<!-- Example: --> | |
<!-- <maintainer email="[email protected]">Jane Doe</maintainer> --> | |
<maintainer email="[email protected]">nim</maintainer> | |
<!-- One license tag required, multiple allowed, one license per tag --> | |
<!-- Commonly used license strings: --> | |
<!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 --> | |
<license>TODO</license> | |
<!-- Url tags are optional, but multiple are allowed, one per tag --> | |
<!-- Optional attribute type can be: website, bugtracker, or repository --> | |
<!-- Example: --> | |
<!-- <url type="website">http://wiki.ros.org/beginner_tutorials</url> --> | |
<!-- Author tags are optional, multiple are allowed, one per tag --> | |
<!-- Authors do not have to be maintainers, but could be --> | |
<!-- Example: --> | |
<!-- <author email="[email protected]">Jane Doe</author> --> | |
<!-- The *depend tags are used to specify dependencies --> | |
<!-- Dependencies can be catkin packages or system dependencies --> | |
<!-- Examples: --> | |
<!-- Use depend as a shortcut for packages that are both build and exec dependencies --> | |
<!-- <depend>roscpp</depend> --> | |
<!-- Note that this is equivalent to the following: --> | |
<!-- <build_depend>roscpp</build_depend> --> | |
<!-- <exec_depend>roscpp</exec_depend> --> | |
<!-- Use build_depend for packages you need at compile time: --> | |
<!-- <build_depend>message_generation</build_depend> --> | |
<!-- Use build_export_depend for packages you need in order to build against this package: --> | |
<!-- <build_export_depend>message_generation</build_export_depend> --> | |
<!-- Use buildtool_depend for build tool packages: --> | |
<!-- <buildtool_depend>catkin</buildtool_depend> --> | |
<!-- Use exec_depend for packages you need at runtime: --> | |
<!-- <exec_depend>message_runtime</exec_depend> --> | |
<!-- Use test_depend for packages you need only for testing: --> | |
<!-- <test_depend>gtest</test_depend> --> | |
<!-- Use doc_depend for packages you need only for building documentation: --> | |
<!-- <doc_depend>doxygen</doc_depend> --> | |
<buildtool_depend>catkin</buildtool_depend> | |
<build_depend>roscpp</build_depend> | |
<build_depend>rospy</build_depend> | |
<build_depend>std_msgs</build_depend> | |
<build_depend>message_generation</build_depend> | |
<build_export_depend>roscpp</build_export_depend> | |
<build_export_depend>rospy</build_export_depend> | |
<build_export_depend>std_msgs</build_export_depend> | |
<exec_depend>roscpp</exec_depend> | |
<exec_depend>rospy</exec_depend> | |
<exec_depend>std_msgs</exec_depend> | |
<exec_depend>message_runtime</exec_depend> | |
<!-- The export tag contains other, unspecified, tags --> | |
<export> | |
<!-- Other tools can request additional information be placed here --> | |
</export> | |
</package> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import rospy | |
from std_msgs.msg import String | |
def talker(): | |
pub = rospy.Publisher('hello', String, queue_size=10) | |
rospy.init_node('pub_hello', anonymous=True) | |
r=rospy.Rate(10) | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include"ros/ros.h" | |
#include"std_msgs/String.h" | |
void cb_hello(const std_msgs::String::ConstPtr& msg){ | |
ROS_INFO("I heard: [%s]", msg->data.c_str()); | |
} | |
int main(int argc, char **argv){ | |
ros::init(argc, argv, "sub_hello"); | |
ros::NodeHandle nh; | |
ros::Subscriber sub = nh.subscribe("hello", 1000, cb_hello); | |
ros::spin(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment