From f5cb1c287b2c6b3c296cb4a319bcf6c4e661da94 Mon Sep 17 00:00:00 2001 From: mech-user Date: Wed, 14 Oct 2015 12:11:33 +0900 Subject: [PATCH 1/6] add 2015-09-29 shukudai --- .../src/beginner_tutorials/CMakeLists.txt | 198 ++++++++++++++++++ 20150930/src/beginner_tutorials/msg/Hello.msg | 3 + 20150930/src/beginner_tutorials/package.xml | 60 ++++++ .../src/beginner_tutorials/scripts/talker.py | 16 ++ .../src/beginner_tutorials/scripts/talker.py~ | 16 ++ .../src/beginner_tutorials/scripts/talker2.py | 23 ++ .../beginner_tutorials/scripts/talker2.py~ | 16 ++ .../src/beginner_tutorials/src/listener.cpp | 16 ++ .../src/beginner_tutorials/src/listener2.cpp | 18 ++ .../src/beginner_tutorials/src/listener2.cpp~ | 18 ++ 10 files changed, 384 insertions(+) create mode 100644 20150930/src/beginner_tutorials/CMakeLists.txt create mode 100644 20150930/src/beginner_tutorials/msg/Hello.msg create mode 100644 20150930/src/beginner_tutorials/package.xml create mode 100644 20150930/src/beginner_tutorials/scripts/talker.py create mode 100644 20150930/src/beginner_tutorials/scripts/talker.py~ create mode 100644 20150930/src/beginner_tutorials/scripts/talker2.py create mode 100644 20150930/src/beginner_tutorials/scripts/talker2.py~ create mode 100644 20150930/src/beginner_tutorials/src/listener.cpp create mode 100644 20150930/src/beginner_tutorials/src/listener2.cpp create mode 100644 20150930/src/beginner_tutorials/src/listener2.cpp~ diff --git a/20150930/src/beginner_tutorials/CMakeLists.txt b/20150930/src/beginner_tutorials/CMakeLists.txt new file mode 100644 index 00000000..2b9a8502 --- /dev/null +++ b/20150930/src/beginner_tutorials/CMakeLists.txt @@ -0,0 +1,198 @@ +cmake_minimum_required(VERSION 2.8.3) +project(beginner_tutorials) + +## 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 + geometry_msgs + message_generation + message_runtime + roscpp + rospy + std_msgs +) + +## System dependencies are found with CMake's conventions +# find_package(Boost REQUIRED COMPONENTS system) + + +## 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() + +################################################ +## Declare ROS messages, services and actions ## +################################################ + +## To declare and build messages, services or actions from within this +## package, follow these steps: +## * Let MSG_DEP_SET be the set of packages whose message types you use in +## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...). +## * In the file package.xml: +## * add a build_depend tag for "message_generation" +## * add a build_depend and a run_depend tag for each package in MSG_DEP_SET +## * If MSG_DEP_SET isn't empty the following dependency has been pulled in +## but can be declared for certainty nonetheless: +## * add a run_depend tag for "message_runtime" +## * In this file (CMakeLists.txt): +## * add "message_generation" and every package in MSG_DEP_SET to +## find_package(catkin REQUIRED COMPONENTS ...) +## * add "message_runtime" and every package in MSG_DEP_SET to +## catkin_package(CATKIN_DEPENDS ...) +## * uncomment the add_*_files sections below as needed +## and list every .msg/.srv/.action file to be processed +## * uncomment the generate_messages entry below +## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...) + +## Generate messages in the 'msg' folder +# add_message_files( +# FILES +# Message1.msg +# Message2.msg +# ) + +## Generate services in the 'srv' folder +# add_service_files( +# FILES +# Service1.srv +# Service2.srv +# ) + +## Generate actions in the 'action' folder +# add_action_files( +# FILES +# Action1.action +# Action2.action +# ) + +## Generate added messages and services with any dependencies listed here +# generate_messages( +# DEPENDENCIES +# geometry_msgs# std_msgs +# ) + +################################################ +## Declare ROS dynamic reconfigure parameters ## +################################################ + +## To declare and build dynamic reconfigure parameters within this +## package, follow these steps: +## * In the file package.xml: +## * add a build_depend and a run_depend tag for "dynamic_reconfigure" +## * In this file (CMakeLists.txt): +## * add "dynamic_reconfigure" to +## find_package(catkin REQUIRED COMPONENTS ...) +## * uncomment the "generate_dynamic_reconfigure_options" section below +## and list every .cfg file to be processed + +## Generate dynamic reconfigure parameters in the 'cfg' folder +# generate_dynamic_reconfigure_options( +# cfg/DynReconf1.cfg +# cfg/DynReconf2.cfg +# ) + +################################### +## catkin specific configuration ## +################################### +## The catkin_package macro generates cmake config files for your package +## Declare things to be passed to dependent projects +## INCLUDE_DIRS: uncomment this if you package contains header files +## LIBRARIES: libraries you create in this project that dependent projects also need +## CATKIN_DEPENDS: catkin_packages dependent projects also need +## DEPENDS: system dependencies of this project that dependent projects also need +add_message_files(FILES Hello.msg) +generate_messages(DEPENDENCIES geometry_msgs) +catkin_package( +# INCLUDE_DIRS include +# LIBRARIES beginner_tutorials +# CATKIN_DEPENDS geometry_msgs message_generation message_runtime roscpp rospy std_msgs +# DEPENDS system_lib +) + +########### +## Build ## +########### + +## Specify additional locations of header files +## Your package locations should be listed before other locations +# include_directories(include) +include_directories( + ${catkin_INCLUDE_DIRS} +) + +## Declare a C++ library +# add_library(beginner_tutorials +# src/${PROJECT_NAME}/beginner_tutorials.cpp +# ) + +## Add cmake target dependencies of the library +## as an example, code may need to be generated before libraries +## either from message generation or dynamic reconfigure +# add_dependencies(beginner_tutorials ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) + +## Declare a C++ executable +# add_executable(beginner_tutorials_node src/beginner_tutorials_node.cpp) + +## Add cmake target dependencies of the executable +## same as for the library above +# add_dependencies(beginner_tutorials_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) + +## Specify libraries to link a library or executable target against +# target_link_libraries(beginner_tutorials_node +# ${catkin_LIBRARIES} +# ) + +############# +## Install ## +############# + +# all install targets should use catkin DESTINATION variables +# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html + +## Mark executable scripts (Python etc.) for installation +## in contrast to setup.py, you can choose the destination +# install(PROGRAMS +# scripts/my_python_script +# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) + +## Mark executables and/or libraries for installation +# install(TARGETS beginner_tutorials beginner_tutorials_node +# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) + +## Mark cpp header files for installation +# install(DIRECTORY include/${PROJECT_NAME}/ +# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} +# FILES_MATCHING PATTERN "*.h" +# PATTERN ".svn" EXCLUDE +# ) + +## Mark other files for installation (e.g. launch and bag files, etc.) +# install(FILES +# # myfile1 +# # myfile2 +# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} +# ) + +############# +## Testing ## +############# + +## Add gtest based cpp test target and link libraries +# catkin_add_gtest(${PROJECT_NAME}-test test/test_beginner_tutorials.cpp) +# if(TARGET ${PROJECT_NAME}-test) +# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) +# endif() + +## Add folders to be run by python nosetests +# catkin_add_nosetests(test) + +#add_executable(listener src/listener.cpp) +#target_link_libraries(listener ${catkin_LIBRARIES}) +add_executable(listener2 src/listener2.cpp) +target_link_libraries(listener2 ${catkin_LIBRARIES}) \ No newline at end of file diff --git a/20150930/src/beginner_tutorials/msg/Hello.msg b/20150930/src/beginner_tutorials/msg/Hello.msg new file mode 100644 index 00000000..f04a1a0b --- /dev/null +++ b/20150930/src/beginner_tutorials/msg/Hello.msg @@ -0,0 +1,3 @@ +Header header +string hello +geometry_msgs/Vector3 pos diff --git a/20150930/src/beginner_tutorials/package.xml b/20150930/src/beginner_tutorials/package.xml new file mode 100644 index 00000000..a90f79bb --- /dev/null +++ b/20150930/src/beginner_tutorials/package.xml @@ -0,0 +1,60 @@ + + + beginner_tutorials + 0.0.0 + The beginner_tutorials package + + + + + mech-user + + + + + + TODO + + + + + + + + + + + + + + + + + + + + + + + + + + catkin + geometry_msgs + message_generation + roscpp + rosp + std_msgs + geometry_msgs + message_runtime + roscpp + rosp + std_msgs + + + + + + + + \ No newline at end of file diff --git a/20150930/src/beginner_tutorials/scripts/talker.py b/20150930/src/beginner_tutorials/scripts/talker.py new file mode 100644 index 00000000..a2103d0b --- /dev/null +++ b/20150930/src/beginner_tutorials/scripts/talker.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python +import roslib +import rospy +from std_msgs.msg import String +def talker(): + pub = rospy.Publisher('chatter',String) + rospy.init_node('talker') + while not rospy.is_shutdown(): + str = "hello world %s"%rospy.get_time() + rospy.loginfo(str) + pub.publish(String(str)) + rospy.sleep(1.0) +if __name__ == '__main__': + try: + talker() + except rospy.ROSInterruptException: pass diff --git a/20150930/src/beginner_tutorials/scripts/talker.py~ b/20150930/src/beginner_tutorials/scripts/talker.py~ new file mode 100644 index 00000000..95c2e9de --- /dev/null +++ b/20150930/src/beginner_tutorials/scripts/talker.py~ @@ -0,0 +1,16 @@ +#!/usr/bin/env python +import roslib +import rospy +from std_msgs.msg import String +def talker(): + pub = rospy.Pulisher('chatter',String) + rospy.init_node('talker') + while not rospy.is_shutdown(): + str = "hello world %s"%rospy.get_time() + rospy.loginfo(str) + pub.publish(String(str)) + rospy.sleep(1.0) +if __name__ == '__main__': + try: + talker() + except rospy.ROSInterruptException: pass diff --git a/20150930/src/beginner_tutorials/scripts/talker2.py b/20150930/src/beginner_tutorials/scripts/talker2.py new file mode 100644 index 00000000..8c30d1e5 --- /dev/null +++ b/20150930/src/beginner_tutorials/scripts/talker2.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +import roslib +import rospy +from std_msgs.msg import String +from beginner_tutorials.msgs import Hello + +def talker(): + pub = rospy.Publisher('chatter2',String) + rospy.init_node('talker') + while not rospy.is_shutdown(): + str = "hello world %s"%rospy.get_time() + rospy.loginfo(str) + hello = Hello(); + hello.hello = "world" + hello.pos.x = 0; + hello.pos.y = 1; + hello.pos.z = 2; + pub.publish(hello) + rospy.sleep(1.0) +if __name__ == '__main__': + try: + talker2() + except rospy.ROSInterruptException: pass diff --git a/20150930/src/beginner_tutorials/scripts/talker2.py~ b/20150930/src/beginner_tutorials/scripts/talker2.py~ new file mode 100644 index 00000000..a2103d0b --- /dev/null +++ b/20150930/src/beginner_tutorials/scripts/talker2.py~ @@ -0,0 +1,16 @@ +#!/usr/bin/env python +import roslib +import rospy +from std_msgs.msg import String +def talker(): + pub = rospy.Publisher('chatter',String) + rospy.init_node('talker') + while not rospy.is_shutdown(): + str = "hello world %s"%rospy.get_time() + rospy.loginfo(str) + pub.publish(String(str)) + rospy.sleep(1.0) +if __name__ == '__main__': + try: + talker() + except rospy.ROSInterruptException: pass diff --git a/20150930/src/beginner_tutorials/src/listener.cpp b/20150930/src/beginner_tutorials/src/listener.cpp new file mode 100644 index 00000000..3055741d --- /dev/null +++ b/20150930/src/beginner_tutorials/src/listener.cpp @@ -0,0 +1,16 @@ +#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(argc, argv, "listener"); + ros::NodeHandle n; + ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback); + ros::spin(); + return 0; +} diff --git a/20150930/src/beginner_tutorials/src/listener2.cpp b/20150930/src/beginner_tutorials/src/listener2.cpp new file mode 100644 index 00000000..40516b8d --- /dev/null +++ b/20150930/src/beginner_tutorials/src/listener2.cpp @@ -0,0 +1,18 @@ +#include "ros/ros.h" +#include "std_msgs/String.h" +#include "beginner_tutorials/Hello.h" + +void chatterCallback(const beginner_tutorials::Hello::ConstPtr& msg) +{ + ROS_INFO("I heard: [%s %f %f %f]", msg->hello.c_str(), + msg->pos.x, msg->pos.y, msg->pos.z); +} + +int main(int argc, char **argv) +{ + ros::init(argc, argv, "listener2"); + ros::NodeHandle n; + ros::Subscriber sub = n.subscribe("chatter2", 1000, chatterCallback); + ros::spin(); + return 0; +} diff --git a/20150930/src/beginner_tutorials/src/listener2.cpp~ b/20150930/src/beginner_tutorials/src/listener2.cpp~ new file mode 100644 index 00000000..d6ce5b75 --- /dev/null +++ b/20150930/src/beginner_tutorials/src/listener2.cpp~ @@ -0,0 +1,18 @@ +#include "ros/ros.h" +#include "std_msgs/String.h" +#include "beginner_tutorials/Hello.h" + +void chatterCallback(const std_msgs::String::ConstPtr& msg) +{ + ROS_INFO("I heard: [%s %f %f %f]", msg->hello.c_str(), + msg->pos.x, msg->pos.y, msg->pos.z); +} + +int main(int argc, char **argv) +{ + ros::init(argc, argv, "listener2"); + ros::NodeHandle n; + ros::Subscriber sub = n.subscribe("chatter2", 1000, chatterCallback); + ros::spin(); + return 0; +} From ebd4730fe3d4dcadf5535097008c281c380536b0 Mon Sep 17 00:00:00 2001 From: mech-user Date: Tue, 3 Nov 2015 11:59:04 +0900 Subject: [PATCH 2/6] 2016-10-07 syukudai --- 20151007/beginner_tutorials/CMakeLists.txt | 204 ++++++++++++++++++ .../scripts/add_two_ints_client.py | 29 +++ .../scripts/add_two_ints_server.py | 18 ++ .../beginner_tutorials/scripts/listener.py | 14 ++ .../scripts/simple_action_client.py | 22 ++ 20151007/beginner_tutorials/scripts/talker.py | 17 ++ .../src/add_two_ints_client.cpp | 26 +++ .../src/add_two_ints_server.cpp | 24 +++ 20151007/beginner_tutorials/src/listener.cpp | 16 ++ .../src/simple_action_client.cpp | 20 ++ 20151007/beginner_tutorials/src/talker.cpp | 137 ++++++++++++ 11 files changed, 527 insertions(+) create mode 100644 20151007/beginner_tutorials/CMakeLists.txt create mode 100755 20151007/beginner_tutorials/scripts/add_two_ints_client.py create mode 100755 20151007/beginner_tutorials/scripts/add_two_ints_server.py create mode 100755 20151007/beginner_tutorials/scripts/listener.py create mode 100755 20151007/beginner_tutorials/scripts/simple_action_client.py create mode 100755 20151007/beginner_tutorials/scripts/talker.py create mode 100644 20151007/beginner_tutorials/src/add_two_ints_client.cpp create mode 100644 20151007/beginner_tutorials/src/add_two_ints_server.cpp create mode 100644 20151007/beginner_tutorials/src/listener.cpp create mode 100644 20151007/beginner_tutorials/src/simple_action_client.cpp create mode 100644 20151007/beginner_tutorials/src/talker.cpp diff --git a/20151007/beginner_tutorials/CMakeLists.txt b/20151007/beginner_tutorials/CMakeLists.txt new file mode 100644 index 00000000..64af561d --- /dev/null +++ b/20151007/beginner_tutorials/CMakeLists.txt @@ -0,0 +1,204 @@ +cmake_minimum_required(VERSION 2.8.3) +project(beginner_tutorials) + +## 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 + geometry_msgs + message_runtime + roscpp + rospy + std_msgs + message_generation + actionlib actionlib_msgs +) + +## System dependencies are found with CMake's conventions +# find_package(Boost REQUIRED COMPONENTS system) + + +## 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() + +################################################ +## Declare ROS messages, services and actions ## +################################################ + +## To declare and build messages, services or actions from within this +## package, follow these steps: +## * Let MSG_DEP_SET be the set of packages whose message types you use in +## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...). +## * In the file package.xml: +## * add a build_depend tag for "message_generation" +## * add a build_depend and a run_depend tag for each package in MSG_DEP_SET +## * If MSG_DEP_SET isn't empty the following dependency has been pulled in +## but can be declared for certainty nonetheless: +## * add a run_depend tag for "message_runtime" +## * In this file (CMakeLists.txt): +## * add "message_generation" and every package in MSG_DEP_SET to +## find_package(catkin REQUIRED COMPONENTS ...) +## * add "message_runtime" and every package in MSG_DEP_SET to +## catkin_package(CATKIN_DEPENDS ...) +## * uncomment the add_*_files sections below as needed +## and list every .msg/.srv/.action file to be processed +## * uncomment the generate_messages entry below +## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...) + +## Generate messages in the 'msg' folder +# add_message_files( +# FILES +# Message1.msg +# Message2.msg +# ) + +## Generate services in the 'srv' folder +# add_service_files( +# FILES +# Service1.srv +# Service2.srv +# ) + +## Generate actions in the 'action' folder +add_action_files(FILES DoDishes.action) +# add_action_files( +# FILES +# Action1.action +# Action2.action +# ) + +## Generate added messages and services with any dependencies listed here + generate_messages( + DEPENDENCIES + geometry_msgs actionlib_msgs# std_msgs + ) + +################################################ +## Declare ROS dynamic reconfigure parameters ## +################################################ + +## To declare and build dynamic reconfigure parameters within this +## package, follow these steps: +## * In the file package.xml: +## * add a build_depend and a run_depend tag for "dynamic_reconfigure" +## * In this file (CMakeLists.txt): +## * add "dynamic_reconfigure" to +## find_package(catkin REQUIRED COMPONENTS ...) +## * uncomment the "generate_dynamic_reconfigure_options" section below +## and list every .cfg file to be processed + +## Generate dynamic reconfigure parameters in the 'cfg' folder +# generate_dynamic_reconfigure_options( +# cfg/DynReconf1.cfg +# cfg/DynReconf2.cfg +# ) + +################################### +## catkin specific configuration ## +################################### +## The catkin_package macro generates cmake config files for your package +## Declare things to be passed to dependent projects +## INCLUDE_DIRS: uncomment this if you package contains header files +## LIBRARIES: libraries you create in this project that dependent projects also need +## CATKIN_DEPENDS: catkin_packages dependent projects also need +## DEPENDS: system dependencies of this project that dependent projects also need +#add_message_files(FILES Hello.msg) +#add_service_files(FILES AddTwoInts.srv) +#generate_messages(DEPENDENCIES geometry_msgs) +catkin_package( +# INCLUDE_DIRS include +# LIBRARIES beginner_tutorials +# CATKIN_DEPENDS geometry_msgs message_generation message_runtime roscpp rospy std_msgs +# DEPENDS system_lib +) + +########### +## Build ## +########### + +## Specify additional locations of header files +## Your package locations should be listed before other locations +# include_directories(include) +include_directories( + ${catkin_INCLUDE_DIRS} +) + +## Declare a C++ library +# add_library(beginner_tutorials +# src/${PROJECT_NAME}/beginner_tutorials.cpp +# ) + +## Add cmake target dependencies of the library +## as an example, code may need to be generated before libraries +## either from message generation or dynamic reconfigure +# add_dependencies(beginner_tutorials ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) + +## Declare a C++ executable +# add_executable(beginner_tutorials_node src/beginner_tutorials_node.cpp) + +## Add cmake target dependencies of the executable +## same as for the library above +# add_dependencies(beginner_tutorials_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) + +## Specify libraries to link a library or executable target against +# target_link_libraries(beginner_tutorials_node +# ${catkin_LIBRARIES} +# ) + +############# +## Install ## +############# + +# all install targets should use catkin DESTINATION variables +# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html + +## Mark executable scripts (Python etc.) for installation +## in contrast to setup.py, you can choose the destination +# install(PROGRAMS +# scripts/my_python_script +# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) + +## Mark executables and/or libraries for installation +# install(TARGETS beginner_tutorials beginner_tutorials_node +# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) + +## Mark cpp header files for installation +# install(DIRECTORY include/${PROJECT_NAME}/ +# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} +# FILES_MATCHING PATTERN "*.h" +# PATTERN ".svn" EXCLUDE +# ) + +## Mark other files for installation (e.g. launch and bag files, etc.) +# install(FILES +# # myfile1 +# # myfile2 +# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} +# ) + +############# +## Testing ## +############# + +## Add gtest based cpp test target and link libraries +# catkin_add_gtest(${PROJECT_NAME}-test test/test_beginner_tutorials.cpp) +# if(TARGET ${PROJECT_NAME}-test) +# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) +# endif() + +## Add folders to be run by python nosetests +# catkin_add_nosetests(test) + +add_executable(simple_action_client src/simple_action_client.cpp) +add_executable(simple_action_server src/simple_action_server.cpp) +target_link_libraries(simple_action_client ${catkin_LIBRARIES}) +target_link_libraries(simple_action_server ${catkin_LIBRARIES}) +add_dependencies(simple_action_server ${PROJECT_NAME}_generate_messages_cpp) +add_dependencies(simple_action_client ${PROJECT_NAME}_generate_messages_cpp) + diff --git a/20151007/beginner_tutorials/scripts/add_two_ints_client.py b/20151007/beginner_tutorials/scripts/add_two_ints_client.py new file mode 100755 index 00000000..e1436942 --- /dev/null +++ b/20151007/beginner_tutorials/scripts/add_two_ints_client.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +import roslib; roslib.load_manifest('beginner_tutorials') + +import sys + +import rospy +from beginner_tutorials.srv import * + +def add_two_ints_client(x, y): + rospy.wait_for_service('add_two_ints') + try: + add_two_ints = rospy.ServiceProxy('add_two_ints', AddTwoInts) + resp1 = add_two_ints(x,y) + 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) == 3: + x = int(sys.argv[1]) + y = int(sys.argv[2]) + else: + print usage() + sys.exit(1) + print "Requesting %s+%s"%(x, y) + print "%s + %s = %s"%(x, y, add_two_ints_client(x, y)) diff --git a/20151007/beginner_tutorials/scripts/add_two_ints_server.py b/20151007/beginner_tutorials/scripts/add_two_ints_server.py new file mode 100755 index 00000000..96bcc137 --- /dev/null +++ b/20151007/beginner_tutorials/scripts/add_two_ints_server.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python +import roslib; roslib.load_manifest('beginner_tutorials') + +from beginner_tutorials.srv import * +import rospy + +def handle_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('add_two_ints_server') + s = rospy.Service('add_two_ints', AddTwoInts, handle_add_two_ints) + print "Ready to add two ints." + rospy.spin() + +if __name__ == "__main__": + add_two_ints_server() diff --git a/20151007/beginner_tutorials/scripts/listener.py b/20151007/beginner_tutorials/scripts/listener.py new file mode 100755 index 00000000..4c679189 --- /dev/null +++ b/20151007/beginner_tutorials/scripts/listener.py @@ -0,0 +1,14 @@ +#!usr/bin/env python +import rospy +from std_msgs.msg import String + +def callback(data): + rospy.loginfo(rospy.get_name() + ": I heard %s" % data.data) + +def listener(); + rospy.init_node('listener', anonymous=True) + rospy.Subscriber("chatter", String, callback) + rospy.spin() + +if __name__ == '__main__': + listener() diff --git a/20151007/beginner_tutorials/scripts/simple_action_client.py b/20151007/beginner_tutorials/scripts/simple_action_client.py new file mode 100755 index 00000000..63b92f6b --- /dev/null +++ b/20151007/beginner_tutorials/scripts/simple_action_client.py @@ -0,0 +1,22 @@ +#! /usr/bin/env python + +import roslib; roslib.load_manifest('beginner_tutorials') +import rospy +import actionlib + +from beginner_tutorials.msg import * + +if __name__ == '__main__': + rospy.init_node('do_dishes_client') + client = actionlib.SimpleActionClient('do_dishes', DoDishesAction) + client.wait_for_server() + + goal = DoDishesGoal() + goal.dishwasher_id = 1 + print "Requesting dishwasher %d"%(goal.dishwasher_id) + # Fill in the goal here + client.send_goal(goal) + client.wait_for_result(rospy.Duration.from_sec(5.0)) + + result = client.get_result() + print "Resulting dishwasher %d"%(result.total_dishes_cleaned) diff --git a/20151007/beginner_tutorials/scripts/talker.py b/20151007/beginner_tutorials/scripts/talker.py new file mode 100755 index 00000000..b16ff496 --- /dev/null +++ b/20151007/beginner_tutorials/scripts/talker.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +import roslib +import rospy +from std_msgs.msg import String + +def talker(): + pub = rospy.Publisher('chatter',String) + rospy.init_node('talker') + while not rospy.is_shutdown(): + str = "hello world %s"%rospy.get_time() + rospy.loginfo(str) + pub.publish(String(str)) + rospy.sleep(1.0) +if __name__ == '__main__': + try: + talker() + except rospy.ROSInterruptException: pass diff --git a/20151007/beginner_tutorials/src/add_two_ints_client.cpp b/20151007/beginner_tutorials/src/add_two_ints_client.cpp new file mode 100644 index 00000000..ece302ff --- /dev/null +++ b/20151007/beginner_tutorials/src/add_two_ints_client.cpp @@ -0,0 +1,26 @@ +#include "ros/ros.h" +#include "beginner_tutorials/AddTwoInts.h" +#include + +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("add_two_ints"); + beginner_tutorials::AddTwoInts srv; + srv.request.a = atoll(argv[1]); + srv.request.b = atoll(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; +} + diff --git a/20151007/beginner_tutorials/src/add_two_ints_server.cpp b/20151007/beginner_tutorials/src/add_two_ints_server.cpp new file mode 100644 index 00000000..aeb81873 --- /dev/null +++ b/20151007/beginner_tutorials/src/add_two_ints_server.cpp @@ -0,0 +1,24 @@ +#include "ros/ros.h" +#include "beginner_tutorials/AddTwoInts.h" + +bool add(beginner_tutorials::AddTwoInts::Request &req, + beginner_tutorials::AddTwoInts::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_INFO("Ready to add two ints."); + ros::spin(); + + return 0; +} + diff --git a/20151007/beginner_tutorials/src/listener.cpp b/20151007/beginner_tutorials/src/listener.cpp new file mode 100644 index 00000000..3055741d --- /dev/null +++ b/20151007/beginner_tutorials/src/listener.cpp @@ -0,0 +1,16 @@ +#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(argc, argv, "listener"); + ros::NodeHandle n; + ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback); + ros::spin(); + return 0; +} diff --git a/20151007/beginner_tutorials/src/simple_action_client.cpp b/20151007/beginner_tutorials/src/simple_action_client.cpp new file mode 100644 index 00000000..e43e30e8 --- /dev/null +++ b/20151007/beginner_tutorials/src/simple_action_client.cpp @@ -0,0 +1,20 @@ +#include +#include + +typedef actionlib::SimpleActionClient Client; + +int main(int argc, char** argv) +{ + ros::init(argc, argv, "do_dishes_client"); + Client client("do_dishes", true); //true -> don't need ros::spin() + client.waitForServer(); + beginner_tutorials::DoDishesGoal goal; + // Fill in goal here + client.sendGoal(goal); + client.waitForResult(ros::Duration(5.0)); + if(client.getState() == actionlib::SimpleClientGoalState::SUCCEEDED) + printf("Yay! The deshes are now clean"); + printf("CUrrent State: %s\n", client.getState().toString().c_str()); + return 0; +} + diff --git a/20151007/beginner_tutorials/src/talker.cpp b/20151007/beginner_tutorials/src/talker.cpp new file mode 100644 index 00000000..f0899ac0 --- /dev/null +++ b/20151007/beginner_tutorials/src/talker.cpp @@ -0,0 +1,137 @@ +/* + * 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. + */ +// %Tag(FULLTEXT)% +// %Tag(ROS_HEADER)% +#include "ros/ros.h" +// %EndTag(ROS_HEADER)% +// %Tag(MSG_HEADER)% +#include "std_msgs/String.h" +// %EndTag(MSG_HEADER)% + +#include + +/** + * 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. + */ +// %Tag(INIT)% + ros::init(argc, argv, "talker"); +// %EndTag(INIT)% + + /** + * 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. + */ +// %Tag(NODEHANDLE)% + ros::NodeHandle n; +// %EndTag(NODEHANDLE)% + + /** + * 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. + */ +// %Tag(PUBLISHER)% + ros::Publisher chatter_pub = n.advertise("chatter", 1000); +// %EndTag(PUBLISHER)% + +// %Tag(LOOP_RATE)% + ros::Rate loop_rate(10); +// %EndTag(LOOP_RATE)% + + /** + * A count of how many messages we have sent. This is used to create + * a unique string for each message. + */ +// %Tag(ROS_OK)% + int count = 0; + while (ros::ok()) + { +// %EndTag(ROS_OK)% + /** + * This is a message object. You stuff it with data, and then publish it. + */ +// %Tag(FILL_MESSAGE)% + std_msgs::String msg; + + std::stringstream ss; + ss << "hello world " << count; + msg.data = ss.str(); +// %EndTag(FILL_MESSAGE)% + +// %Tag(ROSCONSOLE)% + ROS_INFO("%s", msg.data.c_str()); +// %EndTag(ROSCONSOLE)% + + /** + * 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. + */ +// %Tag(PUBLISH)% + chatter_pub.publish(msg); +// %EndTag(PUBLISH)% + +// %Tag(SPINONCE)% + ros::spinOnce(); +// %EndTag(SPINONCE)% + +// %Tag(RATE_SLEEP)% + loop_rate.sleep(); +// %EndTag(RATE_SLEEP)% + ++count; + } + + + return 0; +} +// %EndTag(FULLTEXT)% From eba813463aa8eead26cfd7a325748baa26c6d425 Mon Sep 17 00:00:00 2001 From: mech-user Date: Thu, 5 Nov 2015 16:54:29 +0900 Subject: [PATCH 3/6] add 2015-09-30 syukudai --- .../src/beginner_tutorials/CMakeLists.txt | 196 ++++++++++++++++++ 20150930/src/beginner_tutorials/msg/Hello.msg | 3 + 20150930/src/beginner_tutorials/package.xml | 60 ++++++ .../src/beginner_tutorials/scripts/talker.py | 16 ++ .../src/beginner_tutorials/scripts/talker2.py | 23 ++ .../src/beginner_tutorials/src/listener.cpp | 16 ++ .../src/beginner_tutorials/src/listener2.cpp | 17 ++ 7 files changed, 331 insertions(+) create mode 100644 20150930/src/beginner_tutorials/CMakeLists.txt create mode 100644 20150930/src/beginner_tutorials/msg/Hello.msg create mode 100644 20150930/src/beginner_tutorials/package.xml create mode 100755 20150930/src/beginner_tutorials/scripts/talker.py create mode 100755 20150930/src/beginner_tutorials/scripts/talker2.py create mode 100644 20150930/src/beginner_tutorials/src/listener.cpp create mode 100644 20150930/src/beginner_tutorials/src/listener2.cpp diff --git a/20150930/src/beginner_tutorials/CMakeLists.txt b/20150930/src/beginner_tutorials/CMakeLists.txt new file mode 100644 index 00000000..7ca9bd6a --- /dev/null +++ b/20150930/src/beginner_tutorials/CMakeLists.txt @@ -0,0 +1,196 @@ +cmake_minimum_required(VERSION 2.8.3) +project(beginner_tutorials) + +## 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 + geometry_msgs + message_generation + message_runtime + roscpp + rospy + std_msgs +) + +## System dependencies are found with CMake's conventions +# find_package(Boost REQUIRED COMPONENTS system) + + +## 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() + +################################################ +## Declare ROS messages, services and actions ## +################################################ + +## To declare and build messages, services or actions from within this +## package, follow these steps: +## * Let MSG_DEP_SET be the set of packages whose message types you use in +## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...). +## * In the file package.xml: +## * add a build_depend tag for "message_generation" +## * add a build_depend and a run_depend tag for each package in MSG_DEP_SET +## * If MSG_DEP_SET isn't empty the following dependency has been pulled in +## but can be declared for certainty nonetheless: +## * add a run_depend tag for "message_runtime" +## * In this file (CMakeLists.txt): +## * add "message_generation" and every package in MSG_DEP_SET to +## find_package(catkin REQUIRED COMPONENTS ...) +## * add "message_runtime" and every package in MSG_DEP_SET to +## catkin_package(CATKIN_DEPENDS ...) +## * uncomment the add_*_files sections below as needed +## and list every .msg/.srv/.action file to be processed +## * uncomment the generate_messages entry below +## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...) + +## Generate messages in the 'msg' folder +# add_message_files( +# FILES +# Message1.msg +# Message2.msg +# ) + +## Generate services in the 'srv' folder +# add_service_files( +# FILES +# Service1.srv +# Service2.srv +# ) + +## Generate actions in the 'action' folder +# add_action_files( +# FILES +# Action1.action +# Action2.action +# ) + +## Generate added messages and services with any dependencies listed here +# generate_messages( +# DEPENDENCIES +# geometry_msgs# std_msgs +# ) + +################################################ +## Declare ROS dynamic reconfigure parameters ## +################################################ + +## To declare and build dynamic reconfigure parameters within this +## package, follow these steps: +## * In the file package.xml: +## * add a build_depend and a run_depend tag for "dynamic_reconfigure" +## * In this file (CMakeLists.txt): +## * add "dynamic_reconfigure" to +## find_package(catkin REQUIRED COMPONENTS ...) +## * uncomment the "generate_dynamic_reconfigure_options" section below +## and list every .cfg file to be processed + +## Generate dynamic reconfigure parameters in the 'cfg' folder +# generate_dynamic_reconfigure_options( +# cfg/DynReconf1.cfg +# cfg/DynReconf2.cfg +# ) + +################################### +## catkin specific configuration ## +################################### +## The catkin_package macro generates cmake config files for your package +## Declare things to be passed to dependent projects +## INCLUDE_DIRS: uncomment this if you package contains header files +## LIBRARIES: libraries you create in this project that dependent projects also need +## CATKIN_DEPENDS: catkin_packages dependent projects also need +## DEPENDS: system dependencies of this project that dependent projects also need +catkin_package( +# INCLUDE_DIRS include +# LIBRARIES beginner_tutorials +# CATKIN_DEPENDS geometry_msgs message_generation message_runtime roscpp rospy std_msgs +# DEPENDS system_lib +) + +########### +## Build ## +########### + +## Specify additional locations of header files +## Your package locations should be listed before other locations +# include_directories(include) +include_directories( + ${catkin_INCLUDE_DIRS} +) + +## Declare a C++ library +# add_library(beginner_tutorials +# src/${PROJECT_NAME}/beginner_tutorials.cpp +# ) + +## Add cmake target dependencies of the library +## as an example, code may need to be generated before libraries +## either from message generation or dynamic reconfigure +# add_dependencies(beginner_tutorials ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) + +## Declare a C++ executable +# add_executable(beginner_tutorials_node src/beginner_tutorials_node.cpp) + +## Add cmake target dependencies of the executable +## same as for the library above +# add_dependencies(beginner_tutorials_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) + +## Specify libraries to link a library or executable target against +# target_link_libraries(beginner_tutorials_node +# ${catkin_LIBRARIES} +# ) + +############# +## Install ## +############# + +# all install targets should use catkin DESTINATION variables +# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html + +## Mark executable scripts (Python etc.) for installation +## in contrast to setup.py, you can choose the destination +# install(PROGRAMS +# scripts/my_python_script +# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) + +## Mark executables and/or libraries for installation +# install(TARGETS beginner_tutorials beginner_tutorials_node +# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) + +## Mark cpp header files for installation +# install(DIRECTORY include/${PROJECT_NAME}/ +# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} +# FILES_MATCHING PATTERN "*.h" +# PATTERN ".svn" EXCLUDE +# ) + +## Mark other files for installation (e.g. launch and bag files, etc.) +# install(FILES +# # myfile1 +# # myfile2 +# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} +# ) + +############# +## Testing ## +############# + +## Add gtest based cpp test target and link libraries +# catkin_add_gtest(${PROJECT_NAME}-test test/test_beginner_tutorials.cpp) +# if(TARGET ${PROJECT_NAME}-test) +# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) +# endif() + +## Add folders to be run by python nosetests +# catkin_add_nosetests(test) + +add_executable(listener src/listener.cpp) +target_link_libraries(listener ${catkin_LIBRARIES}) +add_executable(listener2 src/listener.cpp) +target_link_libraries(listener2 ${catkin_LIBRARIES}) diff --git a/20150930/src/beginner_tutorials/msg/Hello.msg b/20150930/src/beginner_tutorials/msg/Hello.msg new file mode 100644 index 00000000..f04a1a0b --- /dev/null +++ b/20150930/src/beginner_tutorials/msg/Hello.msg @@ -0,0 +1,3 @@ +Header header +string hello +geometry_msgs/Vector3 pos diff --git a/20150930/src/beginner_tutorials/package.xml b/20150930/src/beginner_tutorials/package.xml new file mode 100644 index 00000000..04f0f9df --- /dev/null +++ b/20150930/src/beginner_tutorials/package.xml @@ -0,0 +1,60 @@ + + + beginner_tutorials + 0.0.0 + The beginner_tutorials package + + + + + mech-user + + + + + + TODO + + + + + + + + + + + + + + + + + + + + + + + + + + catkin + geometry_msgs + message_generation + roscpp + rospy + std_msgs + geometry_msgs + message_runtime + roscpp + rospy + std_msgs + + + + + + + + \ No newline at end of file diff --git a/20150930/src/beginner_tutorials/scripts/talker.py b/20150930/src/beginner_tutorials/scripts/talker.py new file mode 100755 index 00000000..0697a9bc --- /dev/null +++ b/20150930/src/beginner_tutorials/scripts/talker.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python +import roslib +import rospy +from std_msgs.msg import String +def talker(): + pub = rospy.Publisher('chatter',String) + rospy.init_node('talker') + while not rospy.is_shutdown(): + str = "hello world %s"%rospy.get_time() + rospy.loginfo(str) + pub.publish(String(str)) + rospy.sleep(1.0) +if __name__ == '__main__': + try: + talker() + except rospy.ROSInterruptException: pass diff --git a/20150930/src/beginner_tutorials/scripts/talker2.py b/20150930/src/beginner_tutorials/scripts/talker2.py new file mode 100755 index 00000000..368811bb --- /dev/null +++ b/20150930/src/beginner_tutorials/scripts/talker2.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +import roslib +import rospy +from std_msgs.msg import String +from beginner_tutorials.msg import Hello + +def talker2(): + pub = rospy.Publisher('chatter2',Hello) + rospy.init_node('talker') + while not rospy.is_shutdown(): + str = "hello world %s"%rospy.get_time() + rospy.loginfo(str) + hello = Hello(); + hello.hello = "world" + hello.pos.x = 0; + hello.pos.y = 1; + hello.pos.z = 2; + pub.publish(hello); + rospy.sleep(1.0) +if __name__ == '__main__': + try: + talker2() + except rospy.ROSInterruptException: pass diff --git a/20150930/src/beginner_tutorials/src/listener.cpp b/20150930/src/beginner_tutorials/src/listener.cpp new file mode 100644 index 00000000..3055741d --- /dev/null +++ b/20150930/src/beginner_tutorials/src/listener.cpp @@ -0,0 +1,16 @@ +#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(argc, argv, "listener"); + ros::NodeHandle n; + ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback); + ros::spin(); + return 0; +} diff --git a/20150930/src/beginner_tutorials/src/listener2.cpp b/20150930/src/beginner_tutorials/src/listener2.cpp new file mode 100644 index 00000000..5cbcc881 --- /dev/null +++ b/20150930/src/beginner_tutorials/src/listener2.cpp @@ -0,0 +1,17 @@ +#include "ros/ros.h" +#include "std_msgs/String.h" +#include "beginner_tutorials/Hello.h" + +void chatterCallback(const std_msgs::String::ConstPtr& msg) +{ + ROS_INFO("I heard: [%s %f %f %f]", msg->data.c_str(), ); +} + +int main(int argc, char **argv) +{ + ros::init(argc, argv, "listener"); + ros::NodeHandle n; + ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback); + ros::spin(); + return 0; +} From 329f544bd8c7b0fac0202cad0eb59cee43f1204a Mon Sep 17 00:00:00 2001 From: mech-user Date: Thu, 5 Nov 2015 17:23:11 +0900 Subject: [PATCH 4/6] add 2015-09-30 syukudai --- 20150930/src/beginner_tutorials/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/20150930/src/beginner_tutorials/CMakeLists.txt b/20150930/src/beginner_tutorials/CMakeLists.txt index 7ca9bd6a..e1e62e00 100644 --- a/20150930/src/beginner_tutorials/CMakeLists.txt +++ b/20150930/src/beginner_tutorials/CMakeLists.txt @@ -102,6 +102,8 @@ find_package(catkin REQUIRED COMPONENTS ## LIBRARIES: libraries you create in this project that dependent projects also need ## CATKIN_DEPENDS: catkin_packages dependent projects also need ## DEPENDS: system dependencies of this project that dependent projects also need +add_message_files(FILES Hello.msg) +generate_messages(DEPENDENCIES geometry_msgs) catkin_package( # INCLUDE_DIRS include # LIBRARIES beginner_tutorials From e7418035e56310359af752ec64ba010f00769fdc Mon Sep 17 00:00:00 2001 From: mech-user Date: Fri, 6 Nov 2015 09:30:20 +0900 Subject: [PATCH 5/6] add 2015-10-07 syukudai --- 20151007/beginner_tutorials/README.md | 11 ++++ 20151007/beginner_tutorials/package.xml | 63 +++++++++++++++++++ .../scripts/simple_action_server.py | 23 +++++++ .../beginner_tutorials/scripts/talker.py~ | 18 ++++++ .../beginner_tutorials/scripts/talker2.py | 23 +++++++ .../beginner_tutorials/scripts/talker2.py~ | 16 +++++ 20151007/beginner_tutorials/src/listener2.cpp | 18 ++++++ .../beginner_tutorials/src/listener2.cpp~ | 18 ++++++ .../src/simple_action_server.cpp | 21 +++++++ 9 files changed, 211 insertions(+) create mode 100644 20151007/beginner_tutorials/README.md create mode 100644 20151007/beginner_tutorials/package.xml create mode 100755 20151007/beginner_tutorials/scripts/simple_action_server.py create mode 100755 20151007/beginner_tutorials/scripts/talker.py~ create mode 100755 20151007/beginner_tutorials/scripts/talker2.py create mode 100644 20151007/beginner_tutorials/scripts/talker2.py~ create mode 100644 20151007/beginner_tutorials/src/listener2.cpp create mode 100644 20151007/beginner_tutorials/src/listener2.cpp~ create mode 100644 20151007/beginner_tutorials/src/simple_action_server.cpp diff --git a/20151007/beginner_tutorials/README.md b/20151007/beginner_tutorials/README.md new file mode 100644 index 00000000..e8af91b6 --- /dev/null +++ b/20151007/beginner_tutorials/README.md @@ -0,0 +1,11 @@ +1-1, makeはMakefileに書かれた依存関係に則ってコンパイルするのに対し、catkin_makeでは独立してコンパイルが行われる。 + +1-2, catkin_makeにおいてはCmakeのルールに従ってコンパイルするから。 + +1-3, ros::Spin()はクローズまでros::SpinOnce()を呼び出す関数である。 + +1-4, msgファイルが生成される。 + +3, topic: motor_power, cmd_vel + message: linear_vel_step, linear_vel_max, angular_vel_step, angular_vel_max, wit_for_connection + diff --git a/20151007/beginner_tutorials/package.xml b/20151007/beginner_tutorials/package.xml new file mode 100644 index 00000000..98af2017 --- /dev/null +++ b/20151007/beginner_tutorials/package.xml @@ -0,0 +1,63 @@ + + + beginner_tutorials + 0.0.0 + The beginner_tutorials package + + + + + mech-user + + + + + + TODO + + + + + + + + + + + + + + + + + + + + + + + + + + catkin + geometry_msgs + message_generation + roscpp + rosp + std_msgs + actionlib + actionlib_msgs + geometry_msgs + message_runtime + roscpp + rosp + std_msgs + actionlib + actionlib_msgs + + + + + + + diff --git a/20151007/beginner_tutorials/scripts/simple_action_server.py b/20151007/beginner_tutorials/scripts/simple_action_server.py new file mode 100755 index 00000000..d318d250 --- /dev/null +++ b/20151007/beginner_tutorials/scripts/simple_action_server.py @@ -0,0 +1,23 @@ +#! /usr/bin/env python +import roslib; roslib.load_manifest('beginner_tutorials') +import rospy +import actionlib +from beginner_tutorials.msg import * + +class DoDishesServer: + def __init__(self): + self.server = actionlib.SimpleActionServer('do_dishes',DoDishesAction, self.execute, False) + self.server.start() + + def execute(self, goal): + #Do lots of awesome groundbreaking robot stuff here + print "Requesting dishwasher %d"%(goal.dishwasher_id) + result = self.server.get_default_result() + result.total_dishes_cleaned = 100 + print "Returning dishes_cleaned %d"%(result.total_dishes_cleaned) + self.server.set_succeeded(result) + +if __name__ == '__main__': + rospy.init_node('do_dishes_server') + server = DoDishesServer() + rospy.spin() diff --git a/20151007/beginner_tutorials/scripts/talker.py~ b/20151007/beginner_tutorials/scripts/talker.py~ new file mode 100755 index 00000000..f4437ba4 --- /dev/null +++ b/20151007/beginner_tutorials/scripts/talker.py~ @@ -0,0 +1,18 @@ + +#!/usr/bin/env python +import roslib +import rospy +from std_msgs.msg import String + +def talker(): + pub = rospy.Publisher('chatter',String) + rospy.init_node('talker') + while not rospy.is_shutdown(): + str = "hello world %s"%rospy.get_time() + rospy.loginfo(str) + pub.publish(String(str)) + rospy.sleep(1.0) +if __name__ == '__main__': + try: + talker() + except rospy.ROSInterruptException: pass diff --git a/20151007/beginner_tutorials/scripts/talker2.py b/20151007/beginner_tutorials/scripts/talker2.py new file mode 100755 index 00000000..8c30d1e5 --- /dev/null +++ b/20151007/beginner_tutorials/scripts/talker2.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +import roslib +import rospy +from std_msgs.msg import String +from beginner_tutorials.msgs import Hello + +def talker(): + pub = rospy.Publisher('chatter2',String) + rospy.init_node('talker') + while not rospy.is_shutdown(): + str = "hello world %s"%rospy.get_time() + rospy.loginfo(str) + hello = Hello(); + hello.hello = "world" + hello.pos.x = 0; + hello.pos.y = 1; + hello.pos.z = 2; + pub.publish(hello) + rospy.sleep(1.0) +if __name__ == '__main__': + try: + talker2() + except rospy.ROSInterruptException: pass diff --git a/20151007/beginner_tutorials/scripts/talker2.py~ b/20151007/beginner_tutorials/scripts/talker2.py~ new file mode 100644 index 00000000..a2103d0b --- /dev/null +++ b/20151007/beginner_tutorials/scripts/talker2.py~ @@ -0,0 +1,16 @@ +#!/usr/bin/env python +import roslib +import rospy +from std_msgs.msg import String +def talker(): + pub = rospy.Publisher('chatter',String) + rospy.init_node('talker') + while not rospy.is_shutdown(): + str = "hello world %s"%rospy.get_time() + rospy.loginfo(str) + pub.publish(String(str)) + rospy.sleep(1.0) +if __name__ == '__main__': + try: + talker() + except rospy.ROSInterruptException: pass diff --git a/20151007/beginner_tutorials/src/listener2.cpp b/20151007/beginner_tutorials/src/listener2.cpp new file mode 100644 index 00000000..40516b8d --- /dev/null +++ b/20151007/beginner_tutorials/src/listener2.cpp @@ -0,0 +1,18 @@ +#include "ros/ros.h" +#include "std_msgs/String.h" +#include "beginner_tutorials/Hello.h" + +void chatterCallback(const beginner_tutorials::Hello::ConstPtr& msg) +{ + ROS_INFO("I heard: [%s %f %f %f]", msg->hello.c_str(), + msg->pos.x, msg->pos.y, msg->pos.z); +} + +int main(int argc, char **argv) +{ + ros::init(argc, argv, "listener2"); + ros::NodeHandle n; + ros::Subscriber sub = n.subscribe("chatter2", 1000, chatterCallback); + ros::spin(); + return 0; +} diff --git a/20151007/beginner_tutorials/src/listener2.cpp~ b/20151007/beginner_tutorials/src/listener2.cpp~ new file mode 100644 index 00000000..d6ce5b75 --- /dev/null +++ b/20151007/beginner_tutorials/src/listener2.cpp~ @@ -0,0 +1,18 @@ +#include "ros/ros.h" +#include "std_msgs/String.h" +#include "beginner_tutorials/Hello.h" + +void chatterCallback(const std_msgs::String::ConstPtr& msg) +{ + ROS_INFO("I heard: [%s %f %f %f]", msg->hello.c_str(), + msg->pos.x, msg->pos.y, msg->pos.z); +} + +int main(int argc, char **argv) +{ + ros::init(argc, argv, "listener2"); + ros::NodeHandle n; + ros::Subscriber sub = n.subscribe("chatter2", 1000, chatterCallback); + ros::spin(); + return 0; +} diff --git a/20151007/beginner_tutorials/src/simple_action_server.cpp b/20151007/beginner_tutorials/src/simple_action_server.cpp new file mode 100644 index 00000000..2d259f4d --- /dev/null +++ b/20151007/beginner_tutorials/src/simple_action_server.cpp @@ -0,0 +1,21 @@ +#include +#include + +typedef actionlib::SimpleActionServer Server; + +void execute(const beginner_tutorials::DoDishesGoalConstPtr& goal, Server* as) +{ + // Do lots of awesome groundbreaking robot stuff here + as->setSucceeded(); +} + +int main(int argc, char** argv) +{ + ros::init(argc, argv, "do_dishes_server"); + ros::NodeHandle n; + Server server(n, "do_dishes", boost::bind(&execute, _1, &server), false); + server.start(); + ros::spin(); + return 0; +} + From 98cf43e8c484bd3519e79fbaf74dbf4a5902e5fd Mon Sep 17 00:00:00 2001 From: mech-user Date: Tue, 19 Jan 2016 16:37:03 +0900 Subject: [PATCH 6/6] 1014 syukudai --- .../src/enshu_20151014/euslisp/renshu-1.l | 6 ++-- .../src/enshu_20151014/euslisp/renshu-2.l | 31 ++++++++++++++++--- .../src/enshu_20151014/euslisp/renshu-3.l | 5 ++- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/20151014/src/enshu_20151014/euslisp/renshu-1.l b/20151014/src/enshu_20151014/euslisp/renshu-1.l index b1d9654f..64a1d687 100755 --- a/20151014/src/enshu_20151014/euslisp/renshu-1.l +++ b/20151014/src/enshu_20151014/euslisp/renshu-1.l @@ -6,11 +6,11 @@ ;; DO NOT EDIT BEFORE THIS LINE ;; 1 -(assert (eq (car (X (cdr '(a (b c) d)))) 'b) "mondai 1") +(assert (eq (car (car (cdr '(a (b c) d)))) 'b) "mondai 1") ;; 2 -(assert (eq (X 13 (/ 1 0)) 13) "mondai 2") +(assert (eq (quote 13 (/ 1 0)) 13) "mondai 2") ;; 3 -(assert (equal (X #'list 1 nil) '(1)) "mondai 3") +(assert (equal (apply #'list 1 nil) '(1)) "mondai 3") ;; ;; DO NOT EDIT AFTER THIS LINE diff --git a/20151014/src/enshu_20151014/euslisp/renshu-2.l b/20151014/src/enshu_20151014/euslisp/renshu-2.l index aa965dde..8b45465e 100755 --- a/20151014/src/enshu_20151014/euslisp/renshu-2.l +++ b/20151014/src/enshu_20151014/euslisp/renshu-2.l @@ -8,18 +8,41 @@ ;; 1 (defun dot-1 (n) - t) + (dotimes (i n) + (format t ".") +) +t) + + (defun dot-2 (n) - t) + (if (eq n 0) + nil + (progn (format t ".") + (dot-2 (- n 1)))) +t) + ;; (assert (dot-1 3) "mondai 1") (assert (dot-2 3) "mondai 1") ;; 2 (defun hasa-1 (lst) - 0) + (let (res) + (setq res 0) + (dolist (i lst) + (when (equal i 'a) + (setq res (+ res 1)))) + res)) + (defun hasa-2 (lst) - 0) + (hasa-22 0 lst) +) +(defun hasa-22 (i lst) + (if (equal lst nil) + i + (progn (if (equal 'a (car lst)) + (hasa-22 (+ i 1) (cdr lst)) + (hasa-22 i (cdr lst))))))) ;; (assert (eq (hasa-1 '(a b c d a)) 2) "mondai 2") (assert (eq (hasa-2 '(a b c d a)) 2) "mondai 2") diff --git a/20151014/src/enshu_20151014/euslisp/renshu-3.l b/20151014/src/enshu_20151014/euslisp/renshu-3.l index 602d3911..1b99402a 100755 --- a/20151014/src/enshu_20151014/euslisp/renshu-3.l +++ b/20151014/src/enshu_20151014/euslisp/renshu-3.l @@ -22,15 +22,18 @@ ;; (defun summit (lst) (remove nil lst) + (setq lst (remove nil lst)) (apply #'+ lst)) (assert (equal (summit '(1 2 nil 3 4 nil)) 10) "mondai 1") (defun summit (lst) + (if (null lst) + 0 (let ((x (car lst))) (if (null x) (summit (cdr lst)) - (+ x (summit (cdr lst)))))) + (+ x (summit (cdr lst))))))) (assert (equal (summit '(1 2 nil 3 4 nil)) 10) "mondai 1")