diff --git a/20151021/src/enshu_20151021/CMakeLists.txt b/20150930/src/beginner_tutorials/CMakeLists.txt similarity index 69% rename from 20151021/src/enshu_20151021/CMakeLists.txt rename to 20150930/src/beginner_tutorials/CMakeLists.txt index 21487868..750670a1 100644 --- a/20151021/src/enshu_20151021/CMakeLists.txt +++ b/20150930/src/beginner_tutorials/CMakeLists.txt @@ -1,11 +1,16 @@ cmake_minimum_required(VERSION 2.8.3) -project(enshu_20151021) +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 - euslisp + geometry_msgs + message_generation + message_runtime + roscpp + rospy + std_msgs ) ## System dependencies are found with CMake's conventions @@ -26,10 +31,10 @@ find_package(catkin REQUIRED COMPONENTS ## * 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: +## * If MSG_DEP_SET isn't empty the following dependencies might have been +## pulled in transitively but can be declared for certainty nonetheless: +## * add a build_depend tag for "message_generation" ## * add a run_depend tag for "message_runtime" ## * In this file (CMakeLists.txt): ## * add "message_generation" and every package in MSG_DEP_SET to @@ -65,27 +70,7 @@ find_package(catkin REQUIRED COMPONENTS ## Generate added messages and services with any dependencies listed here # generate_messages( # DEPENDENCIES -# std_msgs # Or other packages containing 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 +# geometry_msgs# std_msgs # ) ################################### @@ -97,10 +82,14 @@ 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 enshu_20151021 -# CATKIN_DEPENDS euslisp +# LIBRARIES beginner_tutorials +# CATKIN_DEPENDS geometry_msgs message_generation message_runtime roscpp rospy std_msgs # DEPENDS system_lib ) @@ -115,25 +104,20 @@ include_directories( ${catkin_INCLUDE_DIRS} ) -## Declare a C++ library -# add_library(enshu_20151021 -# src/${PROJECT_NAME}/enshu_20151021.cpp +## Declare a cpp 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(enshu_20151021 ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) - -## Declare a C++ executable -# add_executable(enshu_20151021_node src/enshu_20151021_node.cpp) +## Declare a cpp 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(enshu_20151021_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) +## Add cmake target dependencies of the executable/library +## as an example, message headers may need to be generated before nodes +# add_dependencies(beginner_tutorials_node beginner_tutorials_generate_messages_cpp) ## Specify libraries to link a library or executable target against -# target_link_libraries(enshu_20151021_node +# target_link_libraries(beginner_tutorials_node # ${catkin_LIBRARIES} # ) @@ -152,7 +136,7 @@ include_directories( # ) ## Mark executables and/or libraries for installation -# install(TARGETS enshu_20151021 enshu_20151021_node +# 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} @@ -177,10 +161,15 @@ include_directories( ############# ## Add gtest based cpp test target and link libraries -# catkin_add_gtest(${PROJECT_NAME}-test test/test_enshu_20151021.cpp) +# 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..0a8b3331 --- /dev/null +++ b/20150930/src/beginner_tutorials/msg/Hello.msg @@ -0,0 +1,3 @@ +Header header +string hello +geometry_msgs/Vector3 pos \ No newline at end of file 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..a12c62c1 --- /dev/null +++ b/20150930/src/beginner_tutorials/scripts/talker.py @@ -0,0 +1,19 @@ +#!/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 ="hwllo 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..c301cb84 --- /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..1f0ee70b --- /dev/null +++ b/20150930/src/beginner_tutorials/src/listener.cpp @@ -0,0 +1,17 @@ +#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..11f91d7e --- /dev/null +++ b/20150930/src/beginner_tutorials/src/listener2.cpp @@ -0,0 +1,20 @@ +#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/src/beginner_tutorials/CMakeLists.txt b/20151007/src/beginner_tutorials/CMakeLists.txt new file mode 100644 index 00000000..1265f314 --- /dev/null +++ b/20151007/src/beginner_tutorials/CMakeLists.txt @@ -0,0 +1,185 @@ +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 + 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 and a run_depend tag for each package in MSG_DEP_SET +## * If MSG_DEP_SET isn't empty the following dependencies might have been +## pulled in transitively but can be declared for certainty nonetheless: +## * add a build_depend tag for "message_generation" +## * 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 +# ) +add_action_files(FILES DoDishes.action) +## Generate added messages and services with any dependencies listed here +# generate_messages( +# DEPENDENCIES +# geometry_msgs# std_msgs +# ) + +################################### +## 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_service_files(FILES AddTwoInts.srv) +generate_messages(DEPENDENCIES geometry_msgs actionlib_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 cpp library +# add_library(beginner_tutorials +# src/${PROJECT_NAME}/beginner_tutorials.cpp +# ) + +## Declare a cpp executable +# add_executable(beginner_tutorials_node src/beginner_tutorials_node.cpp) + +## Add cmake target dependencies of the executable/library +## as an example, message headers may need to be generated before nodes +# add_dependencies(beginner_tutorials_node beginner_tutorials_generate_messages_cpp) + +## 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(talker src/talker.cpp) +target_link_libraries(talker ${catkin_LIBRARIES}) +add_executable(listener src/listener.cpp) +target_link_libraries(listener ${catkin_LIBRARIES}) +add_executable(add_two_ints_server src/add_two_ints_server.cpp) +target_link_libraries(add_two_ints_server ${catkin_LIBRARIES}) +add_executable(add_two_ints_client src/add_two_ints_client.cpp) +target_link_libraries(add_two_ints_client ${catkin_LIBRARIES}) +add_dependencies(add_two_ints_server ${PROJECT_NAME}_generate_messages_cpp) +add_dependencies(add_two_ints_client ${PROJECT_NAME}_generate_messages_cpp) +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) \ No newline at end of file diff --git a/20151007/src/beginner_tutorials/CMakeLists.txt~ b/20151007/src/beginner_tutorials/CMakeLists.txt~ new file mode 100644 index 00000000..86367828 --- /dev/null +++ b/20151007/src/beginner_tutorials/CMakeLists.txt~ @@ -0,0 +1,179 @@ +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 + 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 and a run_depend tag for each package in MSG_DEP_SET +## * If MSG_DEP_SET isn't empty the following dependencies might have been +## pulled in transitively but can be declared for certainty nonetheless: +## * add a build_depend tag for "message_generation" +## * 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 +# ) +add_action_files(FILES DoDishes.action) +## Generate added messages and services with any dependencies listed here +# generate_messages( +# DEPENDENCIES +# geometry_msgs# std_msgs +# ) + +################################### +## 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_service_files(FILES AddTwoInts.srv) +generate_messages(DEPENDENCIES geometry_msgs actionlib_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 cpp library +# add_library(beginner_tutorials +# src/${PROJECT_NAME}/beginner_tutorials.cpp +# ) + +## Declare a cpp executable +# add_executable(beginner_tutorials_node src/beginner_tutorials_node.cpp) + +## Add cmake target dependencies of the executable/library +## as an example, message headers may need to be generated before nodes +# add_dependencies(beginner_tutorials_node beginner_tutorials_generate_messages_cpp) + +## 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(talker src/talker.cpp) +target_link_libraries(talker ${catkin_LIBRARIES}) +add_executable(listener src/listener.cpp) +target_link_libraries(listener ${catkin_LIBRARIES}) +add_executable(add_two_ints_server src/add_two_ints_server.cpp) +target_link_libraries(add_two_ints_server ${catkin_LIBRARIES}) +add_executable(add_two_ints_client src/add_two_ints_client.cpp) +target_link_libraries(add_two_ints_client ${catkin_LIBRARIES}) +add_dependencies(add_two_ints_server ${PROJECT_NAME}_generate_messages_cpp) +add_dependencies(add_two_ints_client ${PROJECT_NAME}_generate_messages_cpp) diff --git a/20151007/src/beginner_tutorials/action/DoDishes.action b/20151007/src/beginner_tutorials/action/DoDishes.action new file mode 100644 index 00000000..2e97c4e8 --- /dev/null +++ b/20151007/src/beginner_tutorials/action/DoDishes.action @@ -0,0 +1,8 @@ +# Define the goal +uint32 dishwasher_id # Specify which dishwasher we want to use +--- +# Define the result +uint32 total_dishes_cleaned +--- +# Define a feedback message +float32 percent_complete \ No newline at end of file diff --git a/20151007/src/beginner_tutorials/package.xml b/20151007/src/beginner_tutorials/package.xml new file mode 100644 index 00000000..22483c6e --- /dev/null +++ b/20151007/src/beginner_tutorials/package.xml @@ -0,0 +1,64 @@ + + + beginner_tutorials + 0.0.0 + The beginner_tutorials package + + + + + mech-user + + + + + + TODO + + + + + + + + + + + + + + + + + + + + + + + + + + catkin + geometry_msgs + message_generation + roscpp + rospy + std_msgs + actionlib + actionlib_msgs + geometry_msgs + message_runtime + roscpp + rospy + std_msgs + actionlib + actionlib_msgs + + + + + + + + diff --git a/20151007/src/beginner_tutorials/package.xml~ b/20151007/src/beginner_tutorials/package.xml~ new file mode 100644 index 00000000..04f0f9df --- /dev/null +++ b/20151007/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/20151007/src/beginner_tutorials/scripts/#add_two_ints_client.py# b/20151007/src/beginner_tutorials/scripts/#add_two_ints_client.py# new file mode 100644 index 00000000..bb7e4702 --- /dev/null +++ b/20151007/src/beginner_tutorials/scripts/#add_two_ints_client.py# @@ -0,0 +1,30 @@ +#!/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/src/beginner_tutorials/scripts/#simple_action_server.py# b/20151007/src/beginner_tutorials/scripts/#simple_action_server.py# new file mode 100644 index 00000000..1e9f0c9f --- /dev/null +++ b/20151007/src/beginner_tutorials/scripts/#simple_action_server.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 * + +class DoDishesServer: + def __init__(self): + self.server = actionlib.SimpleActionServer('do_dishes', DoDishesAction, selfexecute, False) ++ self.server.start() ++ ++ def execute(self, goal): ++ 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/src/beginner_tutorials/scripts/add_two_ints_client.py b/20151007/src/beginner_tutorials/scripts/add_two_ints_client.py new file mode 100755 index 00000000..b6a55370 --- /dev/null +++ b/20151007/src/beginner_tutorials/scripts/add_two_ints_client.py @@ -0,0 +1,30 @@ +#!/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/src/beginner_tutorials/scripts/add_two_ints_server.py b/20151007/src/beginner_tutorials/scripts/add_two_ints_server.py new file mode 100755 index 00000000..8db6598e --- /dev/null +++ b/20151007/src/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/src/beginner_tutorials/scripts/add_two_ints_server.py~ b/20151007/src/beginner_tutorials/scripts/add_two_ints_server.py~ new file mode 100644 index 00000000..2ea0021c --- /dev/null +++ b/20151007/src/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): + pront "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/src/beginner_tutorials/scripts/listener.py b/20151007/src/beginner_tutorials/scripts/listener.py new file mode 100755 index 00000000..f9d51868 --- /dev/null +++ b/20151007/src/beginner_tutorials/scripts/listener.py @@ -0,0 +1,15 @@ +#!/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/src/beginner_tutorials/scripts/listener.py~ b/20151007/src/beginner_tutorials/scripts/listener.py~ new file mode 100755 index 00000000..25aacdb1 --- /dev/null +++ b/20151007/src/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/src/beginner_tutorials/scripts/simple_action_client.py b/20151007/src/beginner_tutorials/scripts/simple_action_client.py new file mode 100755 index 00000000..975f934b --- /dev/null +++ b/20151007/src/beginner_tutorials/scripts/simple_action_client.py @@ -0,0 +1,21 @@ +#! /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) + 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/src/beginner_tutorials/scripts/simple_action_client.py~ b/20151007/src/beginner_tutorials/scripts/simple_action_client.py~ new file mode 100644 index 00000000..874e19d7 --- /dev/null +++ b/20151007/src/beginner_tutorials/scripts/simple_action_client.py~ @@ -0,0 +1,21 @@ +#! /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) ++ 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/src/beginner_tutorials/scripts/simple_action_server.py b/20151007/src/beginner_tutorials/scripts/simple_action_server.py new file mode 100755 index 00000000..8cfe2649 --- /dev/null +++ b/20151007/src/beginner_tutorials/scripts/simple_action_server.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 * + +class DoDishesServer: + def __init__(self): + self.server = actionlib.SimpleActionServer('do_dishes', DoDishesAction, self.execute, False) + self.server.start() + + def execute(self, goal): + 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/src/beginner_tutorials/scripts/simple_action_server.py~ b/20151007/src/beginner_tutorials/scripts/simple_action_server.py~ new file mode 100644 index 00000000..bd483933 --- /dev/null +++ b/20151007/src/beginner_tutorials/scripts/simple_action_server.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 * ++ ++class DoDishesServer: ++ def __init__(self): ++ self.server = actionlib.SimpleActionServer('do_dishes', DoDishesAction, self.execute, False) ++ self.server.start() ++ ++ def execute(self, goal): ++ 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/src/beginner_tutorials/scripts/talker.py b/20151007/src/beginner_tutorials/scripts/talker.py new file mode 100755 index 00000000..40a95a6d --- /dev/null +++ b/20151007/src/beginner_tutorials/scripts/talker.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python +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/src/beginner_tutorials/scripts/talker.py~ b/20151007/src/beginner_tutorials/scripts/talker.py~ new file mode 100755 index 00000000..7fea4e09 --- /dev/null +++ b/20151007/src/beginner_tutorials/scripts/talker.py~ @@ -0,0 +1,19 @@ +#!/usr/bin/env python +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/src/beginner_tutorials/src/add_two_ints_client.cpp b/20151007/src/beginner_tutorials/src/add_two_ints_client.cpp new file mode 100644 index 00000000..2eaeedb3 --- /dev/null +++ b/20151007/src/beginner_tutorials/src/add_two_ints_client.cpp @@ -0,0 +1,24 @@ +#include "ros/ros.h" +#include "beginner_tutorials/AddTwoInts.h" +#include + +int main(int argc, char **argv) +{ + ros::init(argc, argv, "add_two_ints_clinet"); + if (argc != 3) { + ROS_INFO("usage: add_two_ints_clinet 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_INFO("Failed to call service add_two_ints"); + return 1; + } + return 0; + } diff --git a/20151007/src/beginner_tutorials/src/add_two_ints_server.cpp b/20151007/src/beginner_tutorials/src/add_two_ints_server.cpp new file mode 100644 index 00000000..1ba4e00f --- /dev/null +++ b/20151007/src/beginner_tutorials/src/add_two_ints_server.cpp @@ -0,0 +1,23 @@ +#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/src/beginner_tutorials/src/add_two_ints_server.cpp~ b/20151007/src/beginner_tutorials/src/add_two_ints_server.cpp~ new file mode 100644 index 00000000..b3b2f6de --- /dev/null +++ b/20151007/src/beginner_tutorials/src/add_two_ints_server.cpp~ @@ -0,0 +1,18 @@ +#include +#include + +typedef actionlib::SimpleActionClient Client; + +int main(int argc, char** argv) +{ + ros::init(argc, argv, "do_dishes_client"); + Client client("do_dishes", true); + client.waitForServer(); + beginner_tutorials::DoDishesGoal goal; + client.sendGoal(goal); + client.waitForResult(ros::Duration(5.0)); + if (client.getState() == actionlib::SimpleClientGoalState::SUCCEEDED) + printf("Yay! The dishes are now clean"); + printf("Current State: %s\n", client.getState().toString().c_str()); + return 0; +} diff --git a/20151007/src/beginner_tutorials/src/listener.cpp b/20151007/src/beginner_tutorials/src/listener.cpp new file mode 100644 index 00000000..4be4f5d9 --- /dev/null +++ b/20151007/src/beginner_tutorials/src/listener.cpp @@ -0,0 +1,93 @@ +/* + * 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)% +#include "ros/ros.h" +#include "std_msgs/String.h" + +/** + * This tutorial demonstrates simple receipt of messages over the ROS system. + */ +// %Tag(CALLBACK)% +void chatterCallback(const std_msgs::String::ConstPtr& msg) +{ + ROS_INFO("I heard: [%s]", msg->data.c_str()); +} +// %EndTag(CALLBACK)% + +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. + */ + // %Tag(SUBSCRIBER)% + ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback); + // %EndTag(SUBSCRIBER)% + + /** + * 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. + */ + // %Tag(SPIN)% + ros::spin(); + // %EndTag(SPIN)% + + return 0; +} +// %EndTag(FULLTEXT)% diff --git a/20151007/src/beginner_tutorials/src/simple_action_client.cpp b/20151007/src/beginner_tutorials/src/simple_action_client.cpp new file mode 100644 index 00000000..d8c8ed3e --- /dev/null +++ b/20151007/src/beginner_tutorials/src/simple_action_client.cpp @@ -0,0 +1,18 @@ +#include +#include + +typedef actionlib::SimpleActionClient Client; + +int main(int argc, char** argv) +{ + ros::init(argc, argv, "do_dishes_client"); + Client client("do_dishes", true); + client.waitForServer(); + beginner_tutorials::DoDishesGoal goal; + client.sendGoal(goal); + client.waitForResult(ros::Duration(5.0)); + if (client.getState() == actionlib::SimpleClientGoalState::SUCCEEDED) + printf("Yay! The dishes are now clean"); + printf("Current State: %s\n", client.getState().toString().c_str()); + return 0; +} diff --git a/20151007/src/beginner_tutorials/src/simple_action_client.cpp~ b/20151007/src/beginner_tutorials/src/simple_action_client.cpp~ new file mode 100644 index 00000000..e9897918 --- /dev/null +++ b/20151007/src/beginner_tutorials/src/simple_action_client.cpp~ @@ -0,0 +1,18 @@ +#include ++#include ++ ++typedef actionlib::SimpleActionClient Client; ++ ++int main(int argc, char** argv) ++{ + + ros::init(argc, argv, "do_dishes_client"); + + Client client("do_dishes", true); + + client.waitForServer(); + + beginner_tutorials::DoDishesGoal goal; + + client.sendGoal(goal); + + client.waitForResult(ros::Duration(5.0)); + + if (client.getState() == actionlib::SimpleClientGoalState::SUCCEEDED) + + printf("Yay! The dishes are now clean"); + + printf("Current State: %s\n", client.getState().toString().c_str()); + + return 0; + +} diff --git a/20151007/src/beginner_tutorials/src/simple_action_server.cpp b/20151007/src/beginner_tutorials/src/simple_action_server.cpp new file mode 100644 index 00000000..f2781d35 --- /dev/null +++ b/20151007/src/beginner_tutorials/src/simple_action_server.cpp @@ -0,0 +1,20 @@ +#include +#include + +typedef actionlib::SimpleActionServer Server; + +void execute(const beginner_tutorials::DoDishesGoalConstPtr& goal, Server* as) +{ + // Do lots of awesome groundbreadking robot stuff here + as->setSucceeded(); +} + +int main(int argc, char** argv) +{ + ros::init(argc, argv, "do_dishes_sever"); + ros::NodeHandle n; + Server server(n, "do_dishes", boost::bind(&execute, _1, &server), false); + server.start(); + ros::spin(); + return 0; +} diff --git a/20151007/src/beginner_tutorials/src/simple_action_server.cpp~ b/20151007/src/beginner_tutorials/src/simple_action_server.cpp~ new file mode 100644 index 00000000..6fdf2e5f --- /dev/null +++ b/20151007/src/beginner_tutorials/src/simple_action_server.cpp~ @@ -0,0 +1,20 @@ +#include ++#include ++ ++typedef actionlib::SimpleActionServer Server; ++ ++void execute(const beginner_tutorials::DoDishesGoalConstPtr& goal, Server* as) ++{ + + // Do lots of awesome groundbreadking robot stuff here + + as->setSucceeded(); + +} ++ ++int main(int argc, char** argv) ++{ + + ros::init(argc, argv, "do_dishes_sever"); + + ros::NodeHandle n; + + Server server(n, "do_dishes", boost::bind(&execute, _1, &server), false); + + server.start(); + + ros::spin(); + + return 0; + +} diff --git a/20151007/src/beginner_tutorials/src/talker.cpp b/20151007/src/beginner_tutorials/src/talker.cpp new file mode 100644 index 00000000..048de8e5 --- /dev/null +++ b/20151007/src/beginner_tutorials/src/talker.cpp @@ -0,0 +1,104 @@ +#include "ros/ros.h" + +#include "std_msgs/String.h" + +#include + + 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(1); + // %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)% diff --git a/20151007/src/beginner_tutorials/src/talker.cpp~ b/20151007/src/beginner_tutorials/src/talker.cpp~ new file mode 100644 index 00000000..e1c1dbe9 --- /dev/null +++ b/20151007/src/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(1); + // %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)% diff --git a/20151007/src/beginner_tutorials/srv/AddTwoInts.srv b/20151007/src/beginner_tutorials/srv/AddTwoInts.srv new file mode 100644 index 00000000..3bef7230 --- /dev/null +++ b/20151007/src/beginner_tutorials/srv/AddTwoInts.srv @@ -0,0 +1,4 @@ +int64 a +int64 b +--- +int64 sum \ No newline at end of file diff --git a/20151014/check1.test b/20151014/check1.test deleted file mode 100644 index 1e5f0b59..00000000 --- a/20151014/check1.test +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/20151014/src/enshu_20151014/euslisp/our-menber.l b/20151014/src/enshu_20151014/euslisp/our-menber.l new file mode 100644 index 00000000..e5b866a1 --- /dev/null +++ b/20151014/src/enshu_20151014/euslisp/our-menber.l @@ -0,0 +1,7 @@ + +(defun our-menber(obj lst) + (if (null lst) + nil + (if (eql (car lst) obj) + lst + (our-menber obj (cdr lst))))) 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-1.l~ b/20151014/src/enshu_20151014/euslisp/renshu-1.l~ new file mode 100755 index 00000000..7df21938 --- /dev/null +++ b/20151014/src/enshu_20151014/euslisp/renshu-1.l~ @@ -0,0 +1,22 @@ +;#!/usr/bin/env irteusgl + +;(load "lib/llib/unittest.l") +;(init-unit-test) +;(send *unit-test* :clear-result) +;; DO NOT EDIT BEFORE THIS LINE + +;; 1 +(assert (eq (car (car (cdr '(a (b c) d)))) 'b) "mondai 1") +;; 2 +(assert (eq (quote 13 (/ 1 0)) 13) "mondai 2") +;; 3 +(assert (equal (apply #'list 1 nil) '(1)) "mondai 3") +;; + +;; DO NOT EDIT AFTER THIS LINE +;(send *unit-test* :print-result) +;(exit 1) + + + + diff --git a/20151014/src/enshu_20151014/euslisp/renshu-2.l b/20151014/src/enshu_20151014/euslisp/renshu-2.l index aa965dde..676c500e 100755 --- a/20151014/src/enshu_20151014/euslisp/renshu-2.l +++ b/20151014/src/enshu_20151014/euslisp/renshu-2.l @@ -1,15 +1,23 @@ -#!/usr/bin/env irteusgl +;#!/usr/bin/env irteusgl -(load "lib/llib/unittest.l") -(init-unit-test) -(send *unit-test* :clear-result) +;(load "lib/llib/unittest.l") +;(init-unit-test) +;(send *unit-test* :clear-result) ;; DO NOT EDIT BEFORE THIS LINE ;; 1 (defun dot-1 (n) + (do ((i 1 (+ i 1))) + ((> i n) 'done) + (format t ".")) t) + (defun dot-2 (n) + (if (< n 1) + 'done + (progn (format t ".") + (dot-2 (- n 1)))) t) ;; (assert (dot-1 3) "mondai 1") @@ -17,16 +25,25 @@ ;; 2 (defun hasa-1 (lst) - 0) + (let (sum) + (setq sum 0) + (dolist (i lst) + (when (eq i 'a) + (setq sum (+ sum 1))))sum)) + (defun hasa-2 (lst) - 0) + (if (null lst) + 0 + (if (eq (car lst) 'a) + (+ 1 (hasa-2 (cdr lst))) + (hasa-2 (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") ;; DO NOT EDIT AFTER THIS LINE -(send *unit-test* :print-result) -(exit 1) +;(send *unit-test* :print-result) +;(exit 1) diff --git a/20151014/src/enshu_20151014/euslisp/renshu-2.l~ b/20151014/src/enshu_20151014/euslisp/renshu-2.l~ new file mode 100755 index 00000000..04b35976 --- /dev/null +++ b/20151014/src/enshu_20151014/euslisp/renshu-2.l~ @@ -0,0 +1,49 @@ +;#!/usr/bin/env irteusgl + +;(load "lib/llib/unittest.l") +;(init-unit-test) +;(send *unit-test* :clear-result) +;; DO NOT EDIT BEFORE THIS LINE + + +;; 1 +(defun dot-1 (n) + (do ((i 1 (+ i 1))) + ((> i n) 'done) + (format t ".")) + t) + +(defun dot-2 (n) + (if (< n 1) + 'done + (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) + (let (sum) + (setq sum 0) + (dolist (i lst) + (when (eq i 'a) + (setq sum (+ sum 1))))sum)) +(defun hasa-2 (lst) + (if (null lst) + 0 + (if (eq (car lst) 'a) + (+ 1 hasa-2 (cdr lst)) + (hasa-2 (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") + +;; DO NOT EDIT AFTER THIS LINE +;(send *unit-test* :print-result) +;(exit 1) + + + + diff --git a/20151014/src/enshu_20151014/euslisp/renshu-3.l b/20151014/src/enshu_20151014/euslisp/renshu-3.l index 602d3911..c4386b38 100755 --- a/20151014/src/enshu_20151014/euslisp/renshu-3.l +++ b/20151014/src/enshu_20151014/euslisp/renshu-3.l @@ -1,43 +1,45 @@ -#!/usr/bin/env irteusgl +;#!/usr/bin/env irteusgl -(load "lib/llib/unittest.l") -(init-unit-test) -(send *unit-test* :clear-result) +;(load "lib/llib/unittest.l") +;(init-unit-test) +;(send *unit-test* :clear-result) ;; DO NOT EDIT BEFORE THIS LINE -(defun unittest-error (code msg1 form &optional (msg2)) - (format *error-output* "~C[1;3~Cm~A unittest-error: ~A" - #x1b (+ 1 48) *program-name* msg1) - (if msg2 (format *error-output* " ~A" msg2)) - (if form (format *error-output* " in ~s" form)) - (format *error-output* ", exitting...~C[0m~%" #x1b) - (when code - (format *error-output* "~C[3~Cm[ERROR] test ~A failed" #x1b 49 form) - (format *error-output* " ... (~A ~A)" msg1 code) - (format *error-output* ".~C[0m~%" #x1b)) - (exit 1)) - -(lisp::install-error-handler 'unittest-error) - +;(defun unittest-error (code msg1 form &optional (msg2)) +; (format *error-output* "~C[1;3~Cm~A unittest-error: ~A" +; #x1b (+ 1 48) *program-name* msg1) + ; (if msg2 (format *error-output* " ~A" msg2)) +; (if form (format *error-output* " in ~s" form)) + ; (format *error-output* ", exitting...~C[0m~%" #x1b) +; (when code + ;(format *error-output* "~C[3~Cm[ERROR] test ~A failed" #x1b 49 form) + ; (format *error-output* " ... (~A ~A)" msg1 code) + ; (format *error-output* ".~C[0m~%" #x1b)) + ; (exit 1)) + +;(lisp::install-error-handler 'unittest-error) +; ;; (defun summit (lst) - (remove nil lst) + (setq lst (remove nil lst));remove関数では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") ;; ;; DO NOT EDIT AFTER THIS LINE -(send *unit-test* :print-result) -(exit 1) +;(send *unit-test* :print-result) +;(exit 1) diff --git a/20151014/src/enshu_20151014/euslisp/renshu-3.l~ b/20151014/src/enshu_20151014/euslisp/renshu-3.l~ new file mode 100755 index 00000000..602d3911 --- /dev/null +++ b/20151014/src/enshu_20151014/euslisp/renshu-3.l~ @@ -0,0 +1,46 @@ +#!/usr/bin/env irteusgl + +(load "lib/llib/unittest.l") +(init-unit-test) +(send *unit-test* :clear-result) +;; DO NOT EDIT BEFORE THIS LINE + +(defun unittest-error (code msg1 form &optional (msg2)) + (format *error-output* "~C[1;3~Cm~A unittest-error: ~A" + #x1b (+ 1 48) *program-name* msg1) + (if msg2 (format *error-output* " ~A" msg2)) + (if form (format *error-output* " in ~s" form)) + (format *error-output* ", exitting...~C[0m~%" #x1b) + (when code + (format *error-output* "~C[3~Cm[ERROR] test ~A failed" #x1b 49 form) + (format *error-output* " ... (~A ~A)" msg1 code) + (format *error-output* ".~C[0m~%" #x1b)) + (exit 1)) + +(lisp::install-error-handler 'unittest-error) + +;; +(defun summit (lst) + (remove nil lst) + (apply #'+ lst)) + +(assert (equal (summit '(1 2 nil 3 4 nil)) 10) "mondai 1") + +(defun summit (lst) + (let ((x (car lst))) + (if (null x) + (summit (cdr lst)) + (+ x (summit (cdr lst)))))) + +(assert (equal (summit '(1 2 nil 3 4 nil)) 10) "mondai 1") + +;; +;; DO NOT EDIT AFTER THIS LINE +(send *unit-test* :print-result) +(exit 1) + + + + + + diff --git a/20151021/check1.test b/20151021/check1.test deleted file mode 100644 index dc5a3634..00000000 --- a/20151021/check1.test +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/20151021/check2.test b/20151021/check2.test deleted file mode 100644 index abf14574..00000000 --- a/20151021/check2.test +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/20151021/check3.test b/20151021/check3.test deleted file mode 100644 index 9afd4098..00000000 --- a/20151021/check3.test +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/20151021/src/enshu_20151021/euslisp/renshu-1.l b/20151021/src/enshu_20151021/euslisp/renshu-1.l deleted file mode 100755 index fba162da..00000000 --- a/20151021/src/enshu_20151021/euslisp/renshu-1.l +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env irteusgl - -(load "lib/llib/unittest.l") -(init-unit-test) -(send *unit-test* :clear-result) -;; DO NOT EDIT BEFORE THIS LINE - -;; 1) -;; 太陽,地球,月のモデルをつくり,太陽の周りを地球が,地球の周りを月が回っているアニメーションを作成せよ - -;; DO NOT EDIT AFTER THIS LINE -(send *unit-test* :print-result) -(exit 1) - - - - diff --git a/20151021/src/enshu_20151021/euslisp/renshu-2.l b/20151021/src/enshu_20151021/euslisp/renshu-2.l deleted file mode 100755 index 77a52c3b..00000000 --- a/20151021/src/enshu_20151021/euslisp/renshu-2.l +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env irteusgl - -(load "lib/llib/unittest.l") -(init-unit-test) -(send *unit-test* :clear-result) -;; DO NOT EDIT BEFORE THIS LINE - -;; 2) -;; サーボモジュールを参考に直動ジョイント(linear-joint)を使ったアクチュエータを作ってみよ. - -;; DO NOT EDIT AFTER THIS LINE -(send *unit-test* :print-result) -(exit 1) - - - - diff --git a/20151021/src/enshu_20151021/euslisp/renshu-3.l b/20151021/src/enshu_20151021/euslisp/renshu-3.l deleted file mode 100755 index 45064247..00000000 --- a/20151021/src/enshu_20151021/euslisp/renshu-3.l +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env irteusgl - -(load "lib/llib/unittest.l") -(init-unit-test) -(send *unit-test* :clear-result) -;; DO NOT EDIT BEFORE THIS LINE - -;; 3) -;; ascaded-linkを使ったモデルを作成せよ.ロボットに限らず可動構造を持つものであれば(例えば家具等)何でもよい. - -;; DO NOT EDIT AFTER THIS LINE -(send *unit-test* :print-result) -(exit 1) - - - - diff --git a/20151021/src/enshu_20151021/euslisp/renshu-4.l b/20151021/src/enshu_20151021/euslisp/renshu-4.l deleted file mode 100755 index 88ce7813..00000000 --- a/20151021/src/enshu_20151021/euslisp/renshu-4.l +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env irteusgl - -(load "lib/llib/unittest.l") -(init-unit-test) -(send *unit-test* :clear-result) -;; DO NOT EDIT BEFORE THIS LINE - -;; 4) -;; cascaded-linkを使ったモデルを用いてアニメーションさせてみよ.その際必ず2つ以上の物体を画面に配置し,assoc/dissocが行われること. - -;; DO NOT EDIT AFTER THIS LINE -(send *unit-test* :print-result) -(exit 1) - - - - - diff --git a/20151021/src/enshu_20151021/euslisp/renshu-5.l b/20151021/src/enshu_20151021/euslisp/renshu-5.l deleted file mode 100755 index f56c3c37..00000000 --- a/20151021/src/enshu_20151021/euslisp/renshu-5.l +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env irteusgl - -(load "lib/llib/unittest.l") -(init-unit-test) -(send *unit-test* :clear-result) -;; DO NOT EDIT BEFORE THIS LINE - -;; 5) -;; 6自由度以上のアームを作りrotation-axis(や冗長自由度)を利用したサンプルプログラムを書いてみよ. - -;; DO NOT EDIT AFTER THIS LINE -(send *unit-test* :print-result) -(exit 1) - - - - diff --git a/20151021/src/enshu_20151021/euslisp/renshu-6.l b/20151021/src/enshu_20151021/euslisp/renshu-6.l deleted file mode 100755 index 60514acb..00000000 --- a/20151021/src/enshu_20151021/euslisp/renshu-6.l +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env irteusgl - -(load "lib/llib/unittest.l") -(init-unit-test) -(send *unit-test* :clear-result) -;; DO NOT EDIT BEFORE THIS LINE - -;; 6) -;; ロボットや環境のモデルファイルを利用して,日常生活空間で作業するロボットのプログラムを書いてみよ. - -;; DO NOT EDIT AFTER THIS LINE -(send *unit-test* :print-result) -(exit 1) - - - - - diff --git a/20151021/src/enshu_20151021/euslisp/send_goal.py b/20151021/src/enshu_20151021/euslisp/send_goal.py new file mode 100755 index 00000000..f1693c18 --- /dev/null +++ b/20151021/src/enshu_20151021/euslisp/send_goal.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +import rospy, actionlib +from move_base_msgs.msg import * + +if __name__ == '__main__': + try: + rospy.init_node('send_goal', anonymous=True) + client = actionlib.SimpleActionClient('move_base', MoveBaseAction) + client.wait_for_server() + + goal = MoveBaseGoal() + goal.target_pose.header.stamp = rospy.Time.now() + goal.target_pose.header.frame_id = "/map" + goal.target_pose.pose.position.x = 32 + goal.target_pose.pose.position.y = 34 + goal.target_pose.pose.orientation.w = 1 + print goal + client.send_goal(goal) + print client.wait_for_result() + except rospy.ROSInterruptException: pass diff --git a/20151021/src/enshu_20151021/euslisp/send_vel.py b/20151021/src/enshu_20151021/euslisp/send_vel.py new file mode 100755 index 00000000..d6886d7b --- /dev/null +++ b/20151021/src/enshu_20151021/euslisp/send_vel.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +import rospy +from geometry_msgs.msg import Twist + +import sys, select, termios, tty +def getKey(): + tty.setraw(sys.stdin.fileno()) + select.select([sys.stdin], [], [], 0) + key = sys.stdin.read(1) + termios.tcsetattr(sys.stdin, termios.TCSADRAIN, settings) + return key + +move = { + 'w' : lambda : (1, 0, 0), + 'a' : lambda : (0, 1, 0), + 's' : lambda : (-1, 0, 0), + 'd' : lambda : (0, -1, 0), + 'q' : lambda : (0, 0, 1), + 'e' : lambda : (0, 0, -1), +} + +if __name__ == '__main__': + print """ +Reading from keyboard +---------------------------- +Use 'wsad' to translate +Use 'e' to yaw +Press 'Enter' to run +Press 'q' to quit +""" + settings = termios.tcgetattr(sys.stdin) + try: + rospy.init_node('send_velocity', anonymous=True) + pub = rospy.Publisher('cmd_vel', Twist, queue_size=100); + r = rospy.Rate(10) + while not rospy.is_shutdown(): + key = getKey() + print key + if key in ['q', 27]: + break + elif key in move.keys(): + print key, move[key]() + cmd = Twist() + cmd.linear.x = move[key]()[0] + cmd.linear.y = move[key]()[1] + cmd.angular.z = move[key]()[2] + print "publish ",cmd + pub.publish(cmd) + r.sleep() + except rospy.ROSInterruptException: pass diff --git a/20151021/src/enshu_20151021/test/check_topic.py b/20151021/src/enshu_20151021/test/check_topic.py deleted file mode 100755 index 2432284f..00000000 --- a/20151021/src/enshu_20151021/test/check_topic.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env python - -import rospy -import sys, time -import unittest -from rostopic import _rostopic_info - -## A sample python unit test -class TestCheckTopic(unittest.TestCase): - def test_check_topic(self): - time.sleep(3) - topic = rospy.get_param("/test/topic") - info = _rostopic_info(topic) - self.assertTrue(not info) - -if __name__ == '__main__': - import rostest - rostest.rosrun('enshu_20151021', 'test_check_topic', TestCheckTopic) diff --git a/20151118/src/enshu_20151118/add-two-ints-server-lambda.l b/20151118/src/enshu_20151118/add-two-ints-server-lambda.l new file mode 100644 index 00000000..7df463ab --- /dev/null +++ b/20151118/src/enshu_20151118/add-two-ints-server-lambda.l @@ -0,0 +1,29 @@ +#!/usr/bin/env roseus +;;; +;;; euslisp version of ros_tutorials/rospy_tutorials/005_add_two_ints +;;; +(ros::load-ros-manifest "roseus") + +;;; +;;(defun add-two-ints (req) +;; (let ((m (send req :response))) + ;; (format *error-output* "Returning [~d + ~d = ~d]~%" + ;; (send req :a) (send req :b) + ;; (+ (send req :a) (send req :b))) + ;;(send m :sum (+ (send req :a) (send req :b))) + ;;m)) +;;; +;;; +(ros::roseus "add_two_ints_server") + + +(ros::advertise-service "add_two_ints" roseus::AddTwoInts + #'(lambda (req) + (let ((m (send req :response))) + (format *error-output* "Returning [~d + ~d = ~d]~%" + (send req :a) (send req :b) + (+ (send req :a) (send req :b))) + (send m :sum (+ (send req :a) (send req :b))) + m))) +(do-until-key + (ros::spin-once)) diff --git a/20151118/src/enshu_20151118/add-two-ints-server-lambda.l~ b/20151118/src/enshu_20151118/add-two-ints-server-lambda.l~ new file mode 100644 index 00000000..6b726963 --- /dev/null +++ b/20151118/src/enshu_20151118/add-two-ints-server-lambda.l~ @@ -0,0 +1,27 @@ +#!/usr/bin/env roseus +;;; +;;; euslisp version of ros_tutorials/rospy_tutorials/005_add_two_ints +;;; +(ros::load-ros-manifest "roseus") + +;;; +;;(defun add-two-ints (req) +;; (let ((m (send req :response))) + ;; (format *error-output* "Returning [~d + ~d = ~d]~%" + ;; (send req :a) (send req :b) + ;; (+ (send req :a) (send req :b))) + ;;(send m :sum (+ (send req :a) (send req :b))) + ;;m)) +;;; +;;; +(ros::roseus "add_two_ints_server") +(ros::advertise-service "add_two_ints" roseus::AddTwoInts + #'(lambda (req) + (let ((m (send req :response))) + (format *error-output* "Returning [~d + ~d = ~d]~%" + (send req :a) (send req :b) + (+ (send req :a) (send req :b))) + (send m :sum (+ (send req :a) (send req :b))) + m))) +(do-until-key + (ros::spin-once)) diff --git a/20151118/src/enshu_20151118/add-two-ints-server-member.l b/20151118/src/enshu_20151118/add-two-ints-server-member.l new file mode 100644 index 00000000..16dd0b13 --- /dev/null +++ b/20151118/src/enshu_20151118/add-two-ints-server-member.l @@ -0,0 +1,41 @@ +#!/usr/bin/env roseus +;;; +;;; euslisp version of ros_tutorials/rospy_tutorials/005_add_two_ints +;;; +(ros::load-ros-manifest "roseus") + +;;; +#|(defun add-two-ints (req) + (let ((m (send req :response))) + (format *error-output* "Returning [~d + ~d = ~d]~%" + (send req :a) (send req :b) + (+ (send req :a) (send req :b))) + (send m :sum (+ (send req :a) (send req :b))) + m))|# +;;; +;;; + +(ros::roseus "add_two_ints_server") + +(defclass add-two-ints-class + :super propertied-object + :slots () +) + +(defmethod add-two-ints-class + (:init + () + (ros::advertise-service "add_two_ints" roseus::AddTwoInts #'send self :add-two-ints)) + (:add-two-ints (req) + (let ((m (send req :response))) + (format *error-output* "Returning [~d + ~d = ~d]~%" + (send req :a) (send req :b) + (+ (send req :a) (send req :b))) + (send m :sum (+ (send req :a) (send req :b))) + m))) + +(setq *ints* (instance add-two-ints-class :init)) +;;(ros::roseus "add_two_ints_server") +;;(ros::advertise-service "add_two_ints" roseus::AddTwoInts #'add-two-ints) +(do-until-key + (ros::spin-once)) diff --git a/20151118/src/enshu_20151118/echo-common.c b/20151118/src/enshu_20151118/echo-common.c new file mode 100644 index 00000000..7457f6e6 --- /dev/null +++ b/20151118/src/enshu_20151118/echo-common.c @@ -0,0 +1,91 @@ +/* + * This file was generated by orbit-idl-2 - DO NOT EDIT! + */ + +#include +#define ORBIT2_STUBS_API +#define ORBIT_IDL_C_COMMON +#define echo_COMMON +#include "echo.h" + + +static const CORBA_unsigned_long ORBit_zero_int = 0; + + +#ifndef ORBIT_IDL_C_IMODULE_echo +void _ORBIT_skel_small_EchoApp_Echo_echoString(POA_EchoApp_Echo *_o_servant, gpointer _o_retval,gpointer *_o_args,CORBA_Context _o_ctx,CORBA_Environment *_o_ev, + void (*_impl_echoString)(PortableServer_Servant _servant, const CORBA_char * input, CORBA_Environment *ev)) { + _impl_echoString (_o_servant, *(const CORBA_char * *)_o_args[0], _o_ev); +} + + +#endif +#if ( (TC_IMPL_TC_EchoApp_Echo_0 == 'e') \ + && (TC_IMPL_TC_EchoApp_Echo_1 == 'c') \ + && (TC_IMPL_TC_EchoApp_Echo_2 == 'h') \ + && (TC_IMPL_TC_EchoApp_Echo_3 == 'o') \ + ) && !defined(TC_DEF_TC_EchoApp_Echo) +#define TC_DEF_TC_EchoApp_Echo 1 +#ifdef ORBIT_IDL_C_IMODULE_echo +static +#endif +ORBIT2_MAYBE_CONST struct CORBA_TypeCode_struct TC_EchoApp_Echo_struct = { + {&ORBit_TypeCode_epv, ORBIT_REFCOUNT_STATIC}, + CORBA_tk_objref, + 0, + 0, + ORBIT_ALIGNOF_CORBA_POINTER, + 0, +0 + , + NULL, + CORBA_OBJECT_NIL, + (char *)"Echo", + (char *)"IDL:EchoApp/Echo:1.0", + NULL, + NULL, + -1, + 0, + 0, 0 +}; +#endif + + +#ifndef ORBIT_IDL_C_IMODULE_echo +CORBA_unsigned_long EchoApp_Echo__classid = 0; +#endif + + +/* Interface type data */ + + +static ORBit_IArg EchoApp_Echo_echoString__arginfo [] = { + { TC_CORBA_string, ORBit_I_ARG_IN , (char *)"input" } +}; + + +#ifdef ORBIT_IDL_C_IMODULE_echo +static +#endif + +ORBit_IMethod EchoApp_Echo__imethods [] = { + { + { 1, 1, EchoApp_Echo_echoString__arginfo, FALSE }, + { 0, 0, NULL, FALSE }, + { 0, 0, NULL, FALSE }, + TC_void, (char *)"echoString", 10, + 0 + } +}; + +static CORBA_string EchoApp_Echo__base_itypes[] = { + (char *)"IDL:omg.org/CORBA/Object:1.0" +}; +#ifdef ORBIT_IDL_C_IMODULE_echo +static +#endif + +ORBit_IInterface EchoApp_Echo__iinterface = { + TC_EchoApp_Echo,{1, 1, EchoApp_Echo__imethods, FALSE}, + {1, 1, EchoApp_Echo__base_itypes, FALSE} +}; diff --git a/20151118/src/enshu_20151118/echo-skelimpl.c b/20151118/src/enshu_20151118/echo-skelimpl.c new file mode 100644 index 00000000..d06896bc --- /dev/null +++ b/20151118/src/enshu_20151118/echo-skelimpl.c @@ -0,0 +1,126 @@ +/* This is a template file generated by command */ +/* orbit-idl-2 --skeleton-impl echo.idl */ +/* User must edit this file, inserting servant */ +/* specific code between markers. */ + +#include "echo.h" + +/*** App-specific servant structures ***/ + +#if !defined(_typedef_impl_POA_EchoApp_Echo_) +#define _typedef_impl_POA_EchoApp_Echo_ 1 +typedef struct { + POA_EchoApp_Echo servant; + PortableServer_POA poa; + /* ------ add private attributes here ------ */ + /* ------ ---------- end ------------ ------ */ +} impl_POA_EchoApp_Echo; +#endif + + +/*** Implementation stub prototypes ***/ + +#if !defined(_decl_impl_EchoApp_Echo__destroy_) +#define _decl_impl_EchoApp_Echo__destroy_ 1 +static void impl_EchoApp_Echo__destroy(impl_POA_EchoApp_Echo *servant, + CORBA_Environment *ev); +#endif + +#if !defined(_decl_impl_EchoApp_Echo_echoString_) +#define _decl_impl_EchoApp_Echo_echoString_ 1 +static void +impl_EchoApp_Echo_echoString(impl_POA_EchoApp_Echo *servant, + const CORBA_char * input, + CORBA_Environment *ev); +#endif + + +/*** epv structures ***/ + +#if !defined(_impl_EchoApp_Echo_base_epv_) +#define _impl_EchoApp_Echo_base_epv_ 1 +static PortableServer_ServantBase__epv impl_EchoApp_Echo_base_epv = { + NULL, /* _private data */ + (gpointer) & impl_EchoApp_Echo__destroy, /* finalize routine */ + NULL, /* default_POA routine */ +}; +#endif + +#if !defined(_impl_EchoApp_Echo_epv_) +#define _impl_EchoApp_Echo_epv_ 1 +static POA_EchoApp_Echo__epv impl_EchoApp_Echo_epv = { + NULL, /* _private */ + (gpointer)&impl_EchoApp_Echo_echoString, +}; +#endif + + +/*** vepv structures ***/ + +#if !defined(_impl_EchoApp_Echo_vepv_) +#define _impl_EchoApp_Echo_vepv_ 1 +static POA_EchoApp_Echo__vepv impl_EchoApp_Echo_vepv = { + &impl_EchoApp_Echo_base_epv, + &impl_EchoApp_Echo_epv, +}; +#endif + + +/*** Stub implementations ***/ + +#if !defined(_impl_EchoApp_Echo__create_) +#define _impl_EchoApp_Echo__create_ 1 +static EchoApp_Echo impl_EchoApp_Echo__create(PortableServer_POA poa, CORBA_Environment *ev) +{ + EchoApp_Echo retval; + impl_POA_EchoApp_Echo *newservant; + PortableServer_ObjectId *objid; + + newservant = g_new0(impl_POA_EchoApp_Echo, 1); + newservant->servant.vepv = &impl_EchoApp_Echo_vepv; + newservant->poa = (PortableServer_POA) CORBA_Object_duplicate((CORBA_Object)poa, ev); + POA_EchoApp_Echo__init((PortableServer_Servant)newservant, ev); + /* Before servant is going to be activated all + * private attributes must be initialized. */ + + /* ------ init private attributes here ------ */ + /* ------ ---------- end ------------- ------ */ + + objid = PortableServer_POA_activate_object(poa, newservant, ev); + CORBA_free(objid); + retval = PortableServer_POA_servant_to_reference(poa, newservant, ev); + + return retval; +} +#endif + +#if !defined(_impl_EchoApp_Echo__destroy_) +#define _impl_EchoApp_Echo__destroy_ 1 +static void +impl_EchoApp_Echo__destroy(impl_POA_EchoApp_Echo *servant, CORBA_Environment *ev) +{ + CORBA_Object_release ((CORBA_Object) servant->poa, ev); + + /* No further remote method calls are delegated to + * servant and you may free your private attributes. */ + /* ------ free private attributes here ------ */ + /* ------ ---------- end ------------- ------ */ + + POA_EchoApp_Echo__fini((PortableServer_Servant)servant, ev); + + g_free (servant); +} +#endif + +#if !defined(_impl_EchoApp_Echo_echoString_) +#define _impl_EchoApp_Echo_echoString_ 1 +static void +impl_EchoApp_Echo_echoString(impl_POA_EchoApp_Echo *servant, + const CORBA_char * input, + CORBA_Environment *ev) +{ + /* ------ insert method code here ------ */ + g_print(">> %s\n", input); + /* ------ ---------- end ------------ ------ */ +} +#endif diff --git a/20151118/src/enshu_20151118/echo-skels.c b/20151118/src/enshu_20151118/echo-skels.c new file mode 100644 index 00000000..38750567 --- /dev/null +++ b/20151118/src/enshu_20151118/echo-skels.c @@ -0,0 +1,38 @@ +/* + * This file was generated by orbit-idl-2 - DO NOT EDIT! + */ + +#include +#define ORBIT2_STUBS_API +#include "echo.h" + +static ORBitSmallSkeleton get_skel_small_EchoApp_Echo(POA_EchoApp_Echo *servant, + const char *opname,gpointer *m_data, gpointer *impl) +{ + switch(opname[0]) { + case 'e': + if(strcmp((opname + 1), "choString")) break; + *impl = (gpointer)servant->vepv->EchoApp_Echo_epv->echoString; + {ORBit_IInterface *volatile _t_=&EchoApp_Echo__iinterface;*m_data = (gpointer)&_t_->methods._buffer [0];} + return (ORBitSmallSkeleton)_ORBIT_skel_small_EchoApp_Echo_echoString; + break; + default: break; + } + return NULL; +} + +void POA_EchoApp_Echo__init(PortableServer_Servant servant, + CORBA_Environment *env) +{ + static PortableServer_ClassInfo class_info = {NULL, (ORBit_small_impl_finder)&get_skel_small_EchoApp_Echo, "IDL:EchoApp/Echo:1.0", &EchoApp_Echo__classid, NULL, &EchoApp_Echo__iinterface}; + PortableServer_ServantBase__init ( ((PortableServer_ServantBase *)servant), env); + ORBit_skel_class_register (&class_info, + (PortableServer_ServantBase *)servant, POA_EchoApp_Echo__fini, + ORBIT_VEPV_OFFSET (POA_EchoApp_Echo__vepv, EchoApp_Echo_epv), + (CORBA_unsigned_long) 0);} + +void POA_EchoApp_Echo__fini(PortableServer_Servant servant, + CORBA_Environment *env) +{ + PortableServer_ServantBase__fini(servant, env); +} diff --git a/20151118/src/enshu_20151118/echo-stubs.c b/20151118/src/enshu_20151118/echo-stubs.c new file mode 100644 index 00000000..bef3e8d7 --- /dev/null +++ b/20151118/src/enshu_20151118/echo-stubs.c @@ -0,0 +1,17 @@ +/* + * This file was generated by orbit-idl-2 - DO NOT EDIT! + */ + +#include +#define ORBIT2_STUBS_API +#include "echo.h" + + + +void EchoApp_Echo_echoString(EchoApp_Echo _obj, const CORBA_char * input, CORBA_Environment *ev){ + gpointer _args[1]; + _args[0] = (gpointer)&input; + ORBit_c_stub_invoke (_obj, &EchoApp_Echo__iinterface.methods, 0, NULL, _args, NULL, ev, EchoApp_Echo__classid, G_STRUCT_OFFSET (POA_EchoApp_Echo__epv, echoString), + (ORBitSmallSkeleton) _ORBIT_skel_small_EchoApp_Echo_echoString); + +} diff --git a/20151118/src/enshu_20151118/echo.h b/20151118/src/enshu_20151118/echo.h new file mode 100644 index 00000000..ea7ef4b0 --- /dev/null +++ b/20151118/src/enshu_20151118/echo.h @@ -0,0 +1,101 @@ +/* + * This file was generated by orbit-idl-2 - DO NOT EDIT! + */ + +#ifndef echo_H +#define echo_H 1 +#include +#define ORBIT_IDL_SERIAL 20 +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + + /** typedefs **/ +#if !defined(ORBIT_DECL_EchoApp_Echo) && !defined(_EchoApp_Echo_defined) +#define ORBIT_DECL_EchoApp_Echo 1 +#define _EchoApp_Echo_defined 1 +#define EchoApp_Echo__freekids CORBA_Object__freekids + typedef CORBA_Object EchoApp_Echo; + extern CORBA_unsigned_long EchoApp_Echo__classid; +#if !defined(TC_IMPL_TC_EchoApp_Echo_0) +#define TC_IMPL_TC_EchoApp_Echo_0 'e' +#define TC_IMPL_TC_EchoApp_Echo_1 'c' +#define TC_IMPL_TC_EchoApp_Echo_2 'h' +#define TC_IMPL_TC_EchoApp_Echo_3 'o' +#ifdef ORBIT_IDL_C_IMODULE_echo +static +#else +extern +#endif +ORBIT2_MAYBE_CONST struct CORBA_TypeCode_struct TC_EchoApp_Echo_struct; +#define TC_EchoApp_Echo ((CORBA_TypeCode)&TC_EchoApp_Echo_struct) +#endif +#endif + + /** POA structures **/ +#ifndef _defined_POA_EchoApp_Echo +#define _defined_POA_EchoApp_Echo 1 + typedef struct { + void *_private; + void (*echoString)(PortableServer_Servant _servant, const CORBA_char * input, CORBA_Environment *ev); + } POA_EchoApp_Echo__epv; + typedef struct { + PortableServer_ServantBase__epv *_base_epv; + POA_EchoApp_Echo__epv *EchoApp_Echo_epv; + } POA_EchoApp_Echo__vepv; + typedef struct { + void *_private; + POA_EchoApp_Echo__vepv *vepv; + } POA_EchoApp_Echo; + extern void POA_EchoApp_Echo__init(PortableServer_Servant servant, CORBA_Environment *ev); + extern void POA_EchoApp_Echo__fini(PortableServer_Servant servant, CORBA_Environment *ev); +#endif /* _defined_POA_EchoApp_Echo */ + + /** skel prototypes **/ + void _ORBIT_skel_small_EchoApp_Echo_echoString(POA_EchoApp_Echo *_ORBIT_servant, gpointer _ORBIT_retval, gpointer *_ORBIT_args, CORBA_Context ctx,CORBA_Environment *ev, void (*_impl_echoString)(PortableServer_Servant _servant, const CORBA_char * input, CORBA_Environment *ev)); + + /** stub prototypes **/ + void EchoApp_Echo_echoString(EchoApp_Echo _obj, const CORBA_char * input, CORBA_Environment *ev); +#include + +#ifdef ORBIT_IDL_C_IMODULE_echo +static +#else +extern +#endif +ORBit_IInterface EchoApp_Echo__iinterface; +#define EchoApp_Echo_IMETHODS_LEN 1 +#ifdef ORBIT_IDL_C_IMODULE_echo +static +#else +extern +#endif +ORBit_IMethod EchoApp_Echo__imethods[EchoApp_Echo_IMETHODS_LEN]; + + /** IMethods index */ + +#ifndef __EchoApp_Echo__imethods_index +#define __EchoApp_Echo__imethods_index + typedef enum { + EchoApp_Echo_echoString__imethods_index + } EchoApp_Echo__imethods_index; +#endif /* __EchoApp_Echo__imethods_index */ + +#ifndef __ORBIT_IMETHODS_INDEX +#define __ORBIT_IMETHODS_INDEX +#define ORBIT_IMETHODS_INDEX(m) (m ## __imethods_index) +#endif /* __ORBIT_IMETHODS_INDEX */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#ifndef EXCLUDE_ORBIT_H +#include + +#endif /* EXCLUDE_ORBIT_H */ +#endif +#undef ORBIT_IDL_SERIAL diff --git a/20151202/src/enshu_20151202/src/GCTest.class b/20151202/src/enshu_20151202/src/GCTest.class new file mode 100644 index 00000000..d5873ece Binary files /dev/null and b/20151202/src/enshu_20151202/src/GCTest.class differ diff --git a/20151202/src/enshu_20151202/src/GCTest.cpp b/20151202/src/enshu_20151202/src/GCTest.cpp index 4c3fd214..5be9540f 100644 --- a/20151202/src/enshu_20151202/src/GCTest.cpp +++ b/20151202/src/enshu_20151202/src/GCTest.cpp @@ -5,6 +5,7 @@ #include #include #include +#include using namespace std; @@ -40,8 +41,8 @@ bool do_delete = true; typedef vector Elem; -typedef vector* ElemPtr; -typedef vector* ElemPtrVec; +typedef boost::shared_ptr > ElemPtr; +typedef boost::shared_ptr > ElemPtrVec; class Mutator : public Thread { bool loop; @@ -52,7 +53,7 @@ class Mutator : public Thread { } void Execute(){ while (loop) { - ElemPtrVec v = ElemPtrVec(new vector()); + ElemPtrVec v = ElemPtrVec(vector()); // mutator for (int k = 0; k < 2000; k++) { v->push_back(ElemPtr(new Elem(1000000))); diff --git a/20151202/src/enshu_20151202/src/GCTest.gc.log b/20151202/src/enshu_20151202/src/GCTest.gc.log new file mode 100644 index 00000000..1db021f1 --- /dev/null +++ b/20151202/src/enshu_20151202/src/GCTest.gc.log @@ -0,0 +1,9 @@ +0.148: [GC 62976K->50510K(241408K), 0.0457450 secs] +0.256: [GC 113486K->101194K(304384K), 0.0640170 secs] +0.448: [GC 227146K->99065K(304384K), 0.0071250 secs] +0.578: [GC 225017K->203340K(455296K), 0.0946890 secs] +0.673: [Full GC 203340K->112333K(596032K), 1.3467490 secs] +2.274: [GC 364237K->321105K(596032K), 0.1755510 secs] +2.450: [Full GC 321105K->124453K(774592K), 1.3916600 secs] +4.086: [GC 376357K->331958K(1002880K), 0.1647780 secs] +4.356: [GC 607286K->358480K(1049664K), 0.1744930 secs] diff --git a/20151202/src/enshu_20151202/src/GCTest.incgc.log b/20151202/src/enshu_20151202/src/GCTest.incgc.log new file mode 100644 index 00000000..353adaa0 --- /dev/null +++ b/20151202/src/enshu_20151202/src/GCTest.incgc.log @@ -0,0 +1,15 @@ +0.143: [GC 67200K->71959K(243520K), 0.2785610 secs] +0.450: [GC 103165K(243520K), 0.0253630 secs] +0.513: [GC 139159K->147548K(243520K), 0.0908010 secs] +0.672: [GC 214748K->224774K(292480K), 0.0957630 secs] +0.836: [GC 291974K->302479K(370048K), 0.1036070 secs] +1.008: [GC 369679K->380157K(447808K), 0.1273320 secs] +1.210: [GC 447357K->457610K(525376K), 0.1202740 secs] +1.405: [GC 524810K->535021K(602752K), 0.1086590 secs] +1.589: [GC 602221K->612559K(680320K), 0.1032830 secs] +1.770: [GC 679759K->690012K(757696K), 0.1094440 secs] +1.953: [GC 757212K->767577K(835264K), 0.1024290 secs] +2.130: [GC 834777K->845037K(912832K), 0.1202070 secs] +2.331: [GC 912237K->921846K(989440K), 0.1163310 secs] +2.512: [GC 989046K->998157K(1065856K), 0.1040720 secs] +2.681: [GC 1065357K->1074175K(1141888K), 0.0981850 secs] diff --git a/20151202/src/enshu_20151202/src/Mutator.class b/20151202/src/enshu_20151202/src/Mutator.class new file mode 100644 index 00000000..030c328a Binary files /dev/null and b/20151202/src/enshu_20151202/src/Mutator.class differ diff --git a/20151202/src/enshu_20151202/src/Sort.class b/20151202/src/enshu_20151202/src/Sort.class new file mode 100644 index 00000000..bb0be4b2 Binary files /dev/null and b/20151202/src/enshu_20151202/src/Sort.class differ diff --git a/20151209/check1.test b/20151209/check1.test new file mode 100644 index 00000000..2956036b --- /dev/null +++ b/20151209/check1.test @@ -0,0 +1,4 @@ + + + diff --git a/20151209/src/enshu_20151209/CMakeLists.txt b/20151209/src/enshu_20151209/CMakeLists.txt new file mode 100644 index 00000000..398dbd89 --- /dev/null +++ b/20151209/src/enshu_20151209/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 2.8.3) +project(enshu_20151209) + +find_package(catkin REQUIRED COMPONENTS) +catkin_package() + +add_executable(graphsearch src/graphsearch.cpp) diff --git a/20151209/src/enshu_20151209/data/romania.dat b/20151209/src/enshu_20151209/data/romania.dat new file mode 100644 index 00000000..0b302c0c --- /dev/null +++ b/20151209/src/enshu_20151209/data/romania.dat @@ -0,0 +1,23 @@ +# Romanian Cities and Road Network Graph +# (See Russell & Norvig Chapter 3 ) +# +Oradea Zerind Sibiu +Arad Zerind Sibiu Timisoara +Zerind Arad Oradea +Timisoara Arad Lugoj +Sibiu Oradea Arad Fagaras Rimnicu-Vilcea +Lugoj Timisoara Mehadia +Mehadia Lugoj Dobreta +Dobreta Mehadia Craiova +Craiova Rimnicu-Vilcea Pitesti Dobreta +Pitesti Rimnicu-Vilcea Craiova Bucharest +Rimnicu-Vilcea Sibiu Craiova Pitesti +Fagaras Sibiu Bucharest +Bucharest Fagaras Giurgiu Urziceni Pitesti +Giurgiu Bucharest +Urziceni Bucharest Hirsova Vaslui +Vaslui Iasi Urziceni +Iasi Neamt Vaslui +Neamt Iasi +Hirsova Urziceni Eforie +Eforie Hirsova diff --git a/20151021/src/enshu_20151021/package.xml b/20151209/src/enshu_20151209/package.xml similarity index 92% rename from 20151021/src/enshu_20151021/package.xml rename to 20151209/src/enshu_20151209/package.xml index 5954b4ce..8d19d59b 100644 --- a/20151021/src/enshu_20151021/package.xml +++ b/20151209/src/enshu_20151209/package.xml @@ -1,8 +1,8 @@ - enshu_20151021 + enshu_20151209 0.0.0 - The enshu_20151021 package + The enshu_20151209 package @@ -19,7 +19,7 @@ - + diff --git a/20151209/src/enshu_20151209/src/astar.py b/20151209/src/enshu_20151209/src/astar.py new file mode 100644 index 00000000..93fc98aa --- /dev/null +++ b/20151209/src/enshu_20151209/src/astar.py @@ -0,0 +1,176 @@ +# -*- coding: utf-8 -*- + +import time + +OPEN = 0 +CLOSE = 1 +FORE = 0 +BACK = 1 + +def upheap(buff, n): + while True: + p = (n - 1) / 2 + if p < 0 or buff[p] <= buff[n]: break + temp = buff[n] + buff[n] = buff[p] + buff[p] = temp + n = p + +def downheap(buff, n): + size = len(buff) + while True: + c = 2 * n + 1 + if c >= size: break + if c + 1 < size: + if buff[c] > buff[c + 1]: c += 1 + if buff[n] <= buff[c]: break + temp = buff[n] + buff[n] = buff[c] + buff[c] = temp + n = c + +class PQueue: + def __init__(self, buff = []): + self.buff = buff[:] + for n in xrange(len(self.buff) / 2 - 1, -1, -1): + downheap(self.buff, n) + + def push(self, data): + self.buff.append(data) + upheap(self.buff, len(self.buff) - 1) + + def pop(self): + if len(self.buff) == 0: raise IndexError + value = self.buff[0] + last = self.buff.pop() + if len(self.buff) > 0: + self.buff[0] = last + downheap(self.buff, 0) + return value + + def peek(self): + if len(self.buff) == 0: raise IndexError + return self.buff[0] + + def isEmpty(self): return len(self.buff) == 0 + +adjacent = ( + (1, 3), + (0, 2, 4), + (1, 5), + (0, 4, 6), + (1, 3, 5, 7), + (2, 4, 8), + (3, 7), + (4, 6, 8), + (5, 7) +) + +def make_distance_table(board, wide): + size = len(board) + table = [[0] * size for _ in xrange(size)] + for i in xrange(size): + p = board[i] + if p == 0: continue + x1 = i / wide + y1 = i % wide + for j in xrange(size): + x2 = j / wide + y2 = j % wide + table[p][j] += max(x1 - x2, x2 - x1) + table[p][j] += max(y1 - y2, y2 - y1) + return table + +def get_distance(board, distance): + v = 0 + for x in xrange(9): + p = board[x] + if p == 0: continue + v += distance[p][x] + return v + +class State: + def __init__(self, board, space, prev, move, dir, kind = OPEN): + self.board = board + self.space = space + self.prev = prev + self.move = move + self.dir = dir + self.kind = kind + if dir == FORE: + dt = start_distance + else: + dt = goal_distance + if prev is None: + self.cost = move + get_distance(board, dt) + else: + p = board[prev.space] + self.cost = prev.cost + 1 - dt[p][space] + dt[p][prev.space] + + def __cmp__(x, y): + return x.cost - y.cost + +def astar(start, goal): + global start_distance, goal_distance + q = PQueue() + table ={} + start_distance = make_distance_table(goal, 3) + a = State(start, start.index(0), None, 0, FORE) + q.push(a) + table[tuple(start)] = a + goal_distance = make_distance_table(start, 3) + a = State(goal, goal.index(0), None, 0, BACK) + q.push(a) + table[tuple(goal)] = a + while not q.isEmpty(): + a = q.pop() + if a.kind == CLOSE: continue + for x in adjacent[a.space]: + b = a.board[:] + b[a.space] = b[x] + b[x] = 0 + key = tuple(b) + if key in table: + c = table[key] + if a.dir != c.dir: + if a.dir == FORE: + print_answer(a) + print_answer_goal(c) + else: + print_answer(c) + print_answer_goal(a) + return + if c.move > a.move + 1: + if c.kind == OPEN: + c.kind = CLOSE + c = State(b, x, a, a.move + 1, a.dir) + table[key] = c + else: + c.prev = a + c.cost = c.cost - c.move + a.move + 1 + c.move = a.move + 1 + c.kind = OPEN + q.push(c) + else: + c = State(b, x, a, a.move + 1, a.dir) + q.push(c) + table[key] = c + a.kind = CLOSE + +def print_answer(x): + if x is not None: + print_answer(x.prev) + print x.board + +def print_answer_goal(x): + while x is not None: + print x.board + x = x.prev +if __name__ == '__main__': + a = [2,5,6,3,7,4,8,1,0] + goal = [1,2,3,4,5,6,7,8,0] + + s = time.clock() + astar(a, goal) + e = time.clock() + print "%.3f" % (e - s) diff --git a/20151209/src/enshu_20151209/src/astar.pyc b/20151209/src/enshu_20151209/src/astar.pyc new file mode 100644 index 00000000..54407e4c Binary files /dev/null and b/20151209/src/enshu_20151209/src/astar.pyc differ diff --git a/20151209/src/enshu_20151209/src/astar.py~ b/20151209/src/enshu_20151209/src/astar.py~ new file mode 100644 index 00000000..a664a172 --- /dev/null +++ b/20151209/src/enshu_20151209/src/astar.py~ @@ -0,0 +1,176 @@ +# -*- coding: utf-8 -*- + +import time + +OPEN = 0 +CLOSE = 1 +FORE = 0 +BACK = 1 + +def _downheap(buff, n): + size = len(buff) + while True: + c = 2 * n + 1 + if c >= size: break + if c + 1 < size: + if buff[c] > buff[c + 1]: c += 1 + if buff[n] <= buff[c]: break + temp = buff[n] + buff[n] = buff[c] + buff[c] = temp + n = c + +def _upheap(buff, n): + while True: + p = (n - 1) / 2 + if p < 0 or buff[p] <= buff[n]: break + temp = buff[n] + buff[n] = buff[p] + buff[p] = temp + n = p + +class PQueue: + def __init__(self, buff = []): + self.buff = buff[:] + for n in xrange(len(self.buff) / 2 - 1, -1, -1): + _downheap(self.buff, n) + + def push(self, data): + self.buff.append(data) + _upheap(self.buff, len(self.buff) - 1) + + def pop(self): + if len(self.buff) == 0: raise IndexError + value = self.buff[0] + last = self.buff.pop() + if len(self.buff) > 0: + self.buff[0] = last + _downheap(self.buff, 0) + return value + + def peek(self): + if len(self.buff) == 0: raise IndexError + return self.buff[0] + + def isEmpty(self): return len(self.buff) == 0 + +adjacent = ( + (1, 3), + (0, 2, 4), + (1, 5), + (0, 4, 6), + (1, 3, 5, 7), + (2, 4, 8), + (3, 7), + (4, 6, 8), + (5, 7) +) + +def make_distance_table(board, wide): + size = len(board) + table = [[0] * size for _ in xrange(size)] + for i in xrange(size): + p = board[i] + if p == 0: continue + x1 = i / wide + y1 = i % wide + for j in xrange(size): + x2 = j / wide + y2 = j % wide + table[p][j] += max(x1 - x2, x2 - x1) + table[p][j] += max(y1 - y2, y2 - y1) + return table + +def get_distance(board, distance): + v = 0 + for x in xrange(9): + p = board[x] + if p == 0: continue + v += distance[p][x] + return v + +class State: + def __init__(self, board, space, prev, move, dir, kind = OPEN): + self.board = board + self.space = space + self.prev = prev + self.move = move + self.dir = dir + self.kind = kind + if dir == FORE: + dt = start_distance + else: + dt = goal_distance + if prev is None: + self.cost = move + get_distance(board, dt) + else: + p = board[prev.space] + self.cost = prev.cost + 1 - dt[p][space] + dt[p][prev.space] + + def __cmp__(x, y): + return x.cost - y.cost + +def a_star_search(start, goal): + global start_distance, goal_distance + q = PQueue() + table ={} + start_distance = make_distance_table(goal, 3) + a = State(start, start.index(0), None, 0, FORE) + q.push(a) + table[tuple(start)] = a + goal_distance = make_distance_table(start, 3) + a = State(goal, goal.index(0), None, 0, BACK) + q.push(a) + table[tuple(goal)] = a + while not q.isEmpty(): + a = q.pop() + if a.kind == CLOSE: continue + for x in adjacent[a.space]: + b = a.board[:] + b[a.space] = b[x] + b[x] = 0 + key = tuple(b) + if key in table: + c = table[key] + if a.dir != c.dir: + if a.dir == FORE: + print_answer(a) + print_answer_goal(c) + else: + print_answer(c) + print_answer_goal(a) + return + if c.move > a.move + 1: + if c.kind == OPEN: + c.kind = CLOSE + c = State(b, x, a, a.move + 1, a.dir) + table[key] = c + else: + c.prev = a + c.cost = c.cost - c.move + a.move + 1 + c.move = a.move + 1 + c.kind = OPEN + q.push(c) + else: + c = State(b, x, a, a.move + 1, a.dir) + q.push(c) + table[key] = c + a.kind = CLOSE + +def print_answer(x): + if x is not None: + print_answer(x.prev) + print x.board + +def print_answer_goal(x): + while x is not None: + print x.board + x = x.prev + +a = [2,5,6,3,7,4,8,1,0] +goal = [1,2,3,4,5,6,7,8,0] + +s = time.clock() +a_star_search(a, goal) +e = time.clock() +print "%.3f" % (e - s) diff --git a/20151209/src/enshu_20151209/src/graphsearch.cpp b/20151209/src/enshu_20151209/src/graphsearch.cpp new file mode 100644 index 00000000..28b03374 --- /dev/null +++ b/20151209/src/enshu_20151209/src/graphsearch.cpp @@ -0,0 +1,451 @@ +/*--------------------------------------------- + * + * A Tree Search kit for experimenting with graph + * formulated or network problems such as the + * Romanian road network problem as described in + * Russell and Norvig, Chapter 3. + * + * Last Modified: 28.7.04, KAH + * + * $Id: graphsearch.cpp,v 1.1 2010-01-22 03:35:47 k-okada Exp $ + *---------------------------------------------*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +class Node { +public: + + int state; + // previous or parent node instance in the search tree + Node *parentptr; + // not yet used - could be used as child index + int action; + //depth in the tree root is 1 + int depth; + // same as depth at present + int pathCost; + // normal constructor + Node(int s, Node * p) { + state = s; + parentptr = p; + if (parentptr == NULL) { + depth = 1; + } else { + depth = parentptr->depth + 1; + } + } + ~Node() { + } // destructor + Node(const Node & node) { // copy constructor + state = node.state; + parentptr = node.parentptr; + depth = node.depth; + } + Node * parent() { + // return a pointer to this instance's parent instance + if (parentptr != NULL) + return parentptr; + + else + return this; + } + // count of all instances created by factory + static int count; + // all factory-created instances + static vector < Node * >all; + static Node *factory() { + return factory(-1, NULL); + } + static Node *factory(int s) { + return factory(s, NULL); + } + static Node *factory(int s, Node * p) { + Node * retval = new Node(s, p); + all.push_back(retval); + count++; + return retval; + } + + // free up memory from all factory-created instances + static void freeall() { + for (int i = 0; i < all.size(); i++) + delete all[i]; + all.clear(); + } + + bool operator==(const Node & n) { + return (state == n.state); + } + bool operator!=(const Node & n) { + return (state == n.state); + } +}; +int Node::count = 0; +// internal list of all factory-created instances +vector < Node * >Node::all; + +/*------------------------------------------------*/ +// Suitable for a graph like proble such as +// the Romanian road network problem such as +// in Russell and Norvig, 2nd Edition, Chapter 3. +class Problem { + // map of string-names to integer indices i=map[string] + public:map < string, int >indices; + // names of the vertices (cities) string=names[i] + vector < string > names; + // k=successors[i][j] is jth successor of ith vertex + vector < vector < int > > successors; + // w=weights[i][j] is jth weight of arc to ith vertex + vector < vector < int > > weights; + + // number of vertices (cities) in the graph (roadnetwork) + int n() { + return names.size(); + } + int nSuccessors(int i) { + return successors[i].size(); + } // out-degree of ith vertex + Problem() { + } // constructor + ~Problem() { + } // destructor + void addSuccessor(string src, string dst, int w) { + successors[indices[src]].push_back(indices[dst]); + weights[indices[src]].push_back(w); + } + + void addSuccessorPair(string a, string b, int w) { + addSuccessor(a, b, w); + addSuccessor(b, a, w); + } + + void readFile(string filename) { + // currently wired with test data + + // first pass to get city names only: + ifstream in(filename.c_str()); + assert(in); + names.clear(); + char line[1024]; + while (in.getline(line, sizeof(line), '\n')) { + // ignore comment lines in the file + if (line[0] != '#') { + // whitespace possible delimiters + char *delimiters = " \t\n"; + int wordcount = 0; + char *wordptr; + // tokenize string + wordptr = strtok(line, delimiters); + string source(wordptr); + addName(source); // add if it exists + while ((wordptr = strtok(NULL, delimiters)) + != NULL) { + wordcount++; + string destination(wordptr); + addName(destination); // add if it exists + } + } + } + in.close(); + for (int i = 0; i < names.size(); i++) { + indices[names[i]] = i; + } vector < int >dummy; // an empty vector + // sets up 1st dimension with n() copies of dummy + successors.assign(n(), dummy); + // sets up 1st dimension with n() copies of dummy + weights.assign(n(), dummy); + + // second pass to get arcs: + ifstream in2(filename.c_str()); + assert(in2); + while (in2.getline(line, sizeof(line), '\n')) { + // ignore comment lines in the file + if (line[0] != '#') { + // whitespace possible delimiters + char *delimiters = " \t\n"; + int wordcount = 0; + char *wordptr; + // tokenize string + wordptr = strtok(line, delimiters); + string source(wordptr); + // should already exist + assert(nameExists(source)); + while ((wordptr = strtok(NULL, delimiters)) != NULL) { + wordcount++; + string destination(wordptr); + // should already exist + assert(nameExists(destination)); + addSuccessor(source, destination, 1); + } + } + } + in2.close(); + } + bool nameExists(string name) { + // does a name alredy exist in vocabulary of names? + for (vector < string >::iterator it = names.begin(); + it != names.end(); it++) { + if (name == *it) + return true; + } + return false; + } + void addName(string name) { // add name to names only if it is + // not already in vocabulary + if (!nameExists(name)) { + names.push_back(name); + } + } + void testProblem() { + addName(string("Arad")); // get all the city names on first pass + addName(string("Zerend")); + addName(string("Oradea")); + addName(string("Sibiu")); + addName(string("Fagaras")); + addName(string("Bucharest")); + for (int i = 0; i < names.size(); i++) { + indices[names[i]] = i; + } + vector < int >dummy; // an empty vector + +// sets up 1st dimension with n() copies of dummy + successors.assign(n(), dummy); + // sets up 1st dimension with n() copies of dummy + weights.assign(n(), dummy); + + // uniform (unity) for the weights + addSuccessor(string("Arad"), string("Zerend"), 1); + addSuccessor(string("Arad"), string("Sibiu"), 1); + addSuccessor(string("Zerend"), string("Arad"), 1); + addSuccessor(string("Zerend"), string("Oradea"), 1); + addSuccessor(string("Oradea"), string("Zerend"), 1); + addSuccessor(string("Oradea"), string("Sibiu"), 1); + addSuccessor(string("Sibiu"), string("Arad"), 1); + addSuccessor(string("Sibiu"), string("Oradea"), 1); + addSuccessor(string("Sibiu"), string("Fagaras"), 1); + addSuccessor(string("Fagaras"), string("Sibiu"), 1); + addSuccessor(string("Fagaras"), string("Bucharest"), 1); + addSuccessor(string("Bucharest"), string("Fagaras"), 1); + } + // printout problem graph for check purposes - writes out each + // vertex, its out-degree, and its list of successor vertices. + void print() { + int bmax = 0; + for (int i = 0; i < n(); i++) { + cout << names[i] << " (" << nSuccessors(i) << "):: "; + bmax = bmax > nSuccessors(i) ? bmax : nSuccessors(i); + for (int j = 0; j < nSuccessors(i); j++) { + cout << names[successors[i][j]] << ","; + } cout << endl; + } cout << "Max breadth b " << bmax << endl; + } +}; + + +/*------------------------------------------------*/ +class Queue:public deque < Node * > { +public:virtual Node * First() { +}; + virtual void Insert(Node * n) { + }; + virtual Node * RemoveFirst() { + }; +}; + +class FIFOQueue:public Queue { + // a FIFO Queue +public:Node * First() { + return back(); +} + void Insert(Node * n) { + return push_front(n); + } + Node * RemoveFirst() { + Node * r = First(); + pop_back(); + return r; + } +}; + +class LIFOQueue:public Queue { + // a LIFO Queue +public:Node * First() { + return front(); +} + void Insert(Node * n) { + return push_front(n); + } + Node * RemoveFirst() { + Node * r = First(); + pop_front(); + return r; + } +}; + + +/*------------------------------------------------*/ +int main(int argc, char *argv[]) +{ + int c; + char *fname = NULL; + enum { BFS, DFS, DLS, IDS } search_algorithm = BFS; + bool recursive_check = false; + int depth_limit = 1; + while ((c = getopt(argc, argv, "f:bdl:igr")) != -1) { + switch (c) { + case 'f': + fname = optarg; + break; + case 'b': + search_algorithm = BFS; + break; + case 'd': + search_algorithm = DFS; + break; + case 'l': + search_algorithm = DLS; + depth_limit = atoi(optarg); + break; + case 'i': + search_algorithm = IDS; + break; + case 'r': + recursive_check = true; + break; + default: + cerr << "Unknown option " << c << endl; + exit(1); + } + } + cout << ";; Selecting "; + switch (search_algorithm) { + case BFS: + cout << "Breadth-first Search"; + break; + case DFS: + cout << "Depth-first Searach"; + break; + case DLS: + cout << "Depth-limited Search " << depth_limit; + break; + case IDS: + cout << "Iterative Deppting Search"; + break; + } + cout << endl << endl;; + Problem problem; + if (fname) { + problem.readFile(string(fname)); + } else { + problem.testProblem(); + } + problem.print(); + cout << endl; + string goalName("Bucharest"); + string startName("Arad"); + Queue * fringe; + switch (search_algorithm) { + case BFS: + fringe = new FIFOQueue(); + break; + case DFS: + case DLS: + case IDS: + fringe = new LIFOQueue(); + break; + } + vector < Node > closed; + IDS_RESTART: + Node * nodeptr = + (Node::factory(problem.indices[startName])); + fringe->Insert(nodeptr); + bool success = false; + while (!success) { + if (fringe->empty()) + break; // IF-EMPTY -> FAILURE + nodeptr = fringe->RemoveFirst(); // REMOVE-FIRST + cout << "considering " << + problem.names[nodeptr->state] << endl; + + // GOAL-TEST + int i = nodeptr->state; + if (problem.names[i] == goalName) { + success = true; + break; + } + + // DEPTH-TEST + if ((search_algorithm == DLS || + search_algorithm == IDS) + &&nodeptr->depth >= depth_limit) { + success = false; + break; + } + + // state is not in cloased + if (recursive_check == false + || find(closed.begin(), closed.end(), + *nodeptr) == closed.end()) { + closed.push_back(*nodeptr); + for (int j = 0; j < problem.nSuccessors(i); j++) { // EXPAND + Node *nextnode = + Node::factory(problem.successors[i][j], + nodeptr); + // diagnostics + cout << " " + << problem.names[problem.successors[i][j]] + << " from " + << problem.names[i] <Insert(nextnode); + } + } + } if (search_algorithm == IDS && !success) { + closed.clear(); + depth_limit++; + cerr << ">> Deeping ... " << depth_limit << endl; + goto IDS_RESTART; + } + + // report on the solution path found by back tracing parent pointers + if (!success) { + cout << "Failure!" << endl; + } else { + cout << endl << "Solution: " << endl; + while (problem.names[nodeptr->state] != startName) { + cout << problem.names[nodeptr-> + state] << "(depth " << nodeptr-> + depth << ")" << endl; + nodeptr = (nodeptr->parent()); + } + cout << startName << "(depth " << nodeptr->depth << ")" << endl; + } + Node::freeall(); // free up space + cout << endl << Node::all.size() << " Nodes left" << endl; + cout << endl << Node::count << " Nodes created" << endl; +} + + +/*------------------------------------------------ + Development Notes: + + The C++ STL queue with pop and front implements + a FIFO queue. This gives a BFS tree search. + + The C++ Stack is a LIFO - use top and pop. + + Both implement push which pushes onto end of the Queue. + + @KAH 2004--------------------------------------*/ +