diff --git a/ReadMe.md b/ReadMe.md new file mode 100644 index 0000000000000000000000000000000000000000..b6bae491baeb78575d6404251562a1645fe50040 --- /dev/null +++ b/ReadMe.md @@ -0,0 +1,78 @@ +IRI_ROS_SCRIPTS +============== + +## Description + +Set of scripts to easily generate driver and algorithm packages in ROS, and also a set of scripts to add topic publishers and subscribers, service clients and servers, action clients and servers and tf listeners and broadcasters to existing package nodes. + +- Create packages: the following scripts create a new ROS package containing a single ROS node (which inherits from IRI ROS base classes), a dynamic reconfigure file, sample launch files, LICENSE and README files. + - create_algorithm_package.sh: the created ROS node inherits from [iri_base_algorithm](https://gitlab.iri.upc.edu/labrobotica/ros/iri_core/iri_base_algorithm) class. + - create_driver_package.sh: the created ROS node inherits from [iri_base_driver](https://gitlab.iri.upc.edu/labrobotica/ros/iri_core/iri_base_driver) class. +- Add communication interfaces: the following scripts modify the node inside the target ROS package (which must have the IRI structure). They add the dependencies to the specified message types, the objects variables and callback functions if needed, and some commented code examples on how to use them. + - add_topic_publisher_subscriber.sh + - add_service_server_client.sh + - add_action_server_client.sh + - add_tf_listener_broadcaster.sh + +## Installation + +- Clone this repository + +- Install realpath: + + sudo apt-get install realpath + +- Source the setup.bash file contained in the repository. + + source /path/to/iri_ros_scripts/setup.bash + +- You can add that line to your `~/.bashrc` so it is automatically loaded. + + +## How to use it + +- Go to your ROS workspace source directory: + +``` +roscd; cd ../src; +``` + +``` +create_algorithm_package.sh -n node_name [-i][-p prefix] +``` +- **-n node\_name**: The node's name. It has a default 'iri\_' prefix. +- **-i**: (optional) Avoid adding the default iri_ prefix to the provided node name. +- **-p prefix**: (optional) Replaces default 'iri\_' prefix with specified 'prefix\_'. +``` +create_driver_package.sh -n node_name [-i][-p prefix] +``` +- **-n node\_name**: The node's name. It has a default 'iri\_' prefix. +- **-i**: (optional) Avoid adding the default iri_ prefix to the provided node name. +- **-p prefix**: (optional) Replaces default 'iri\_' prefix with specified 'prefix\_'. +``` +add_topic_publisher_subscriber.sh -o <publisher,subscriber> -p ros_pkg_name -t topic_name -m message.msg -b # +``` +- **-o \[publisher, subscriber\]**: To add a publisher or a subscriber. +- **-p ros\_pkg\_name**: The target ros package. +- **-t topic\_name**: The topic's name. **It must not have a backslash (\\) nor any whitespace characters**. +- **-m message**: The topic's message.msg. +- **-b buffer\_length**: The buffer's length (usually 1). +``` +add_service_server_client.sh -o <server,client> -p ros_pkg_name -s service_name -m service.srv +``` +- **-o \[server, client\]**: To add a service server or client. +- **-p ros\_pkg\_name**: The target ros package. +- **-s service\_name**: The service's name. **It must not have a backslash (\\) nor any whitespace characters**. +- **-m service**: The service's service.srv. +``` +add_action_server_client.sh -o <server,client> -p ros_pkg_name -a action_name -m action.action +``` +- **-o \[server, client\]**: To add an action server or client. +- **-p ros\_pkg\_name**: The target ros package. +- **-a action\_name**: The action's name. **It must not have a backslash (\\) nor any whitespace characters**. +- **-m message**: The action's message.action. +``` +add_tf_listener_broadcaster.sh -o <listener,broadcaster> -p ros_pkg_name +``` +- **-o \[listener, broadcaster\]**: To add a tf listener or broadcaster. +- **-p ros\_pkg\_name**: The target ros package. \ No newline at end of file diff --git a/add_action_server_client.sh b/add_action_server_client.sh index c98ff878bdfcb8fa3df7bd6d109b1f1fd46c0d83..ac6639ed98033e60737065cbba36758d599a7ab9 100755 --- a/add_action_server_client.sh +++ b/add_action_server_client.sh @@ -1,15 +1,17 @@ #!/bin/bash -# WET +echo "/*********************************************/" +echo "/* Creating New ROS Action */" +echo "/*********************************************/" # check wether the scripts path environment variable has been defined scripts_path=`echo "${IRI_ROS_SCRIPTS_PATH}"` if [[ -z "${scripts_path}" ]] then - echo "The scripts path environment variable has not been defined. Please see the wiki documentation for instructions on how to create it." + echo "ERROR: The scripts path environment variable has not been defined. Please see the wiki documentation for instructions on how to create it." exit -else - echo "The scripts path environment variable has been properly defined." +# else +# echo "The scripts path environment variable has been properly defined." fi source "${IRI_ROS_SCRIPTS_PATH}/libraries/scripts_library.sh" @@ -19,11 +21,6 @@ source "${IRI_ROS_SCRIPTS_PATH}/libraries/create_action_client.sh" check_libraries check_templates -echo "" -echo "/*********************************************/" -echo "/* Creating New ROS Action */" -echo "/*********************************************/" - server_client= ros_pkg= action_name= @@ -40,13 +37,18 @@ do ros_pkg=$OPTARG ;; a) - action_name=$OPTARG + if echo "$OPTARG" | grep -q "/"; then + kill_exit "ERROR: argument -$OPTION can't contain slash '/' characters" + exit + else + action_name=$OPTARG + fi ;; m) action_file=$OPTARG ;; ?) - echo "invalid input argument ${OPTION}" + echo "ERROR: invalid input argument ${OPTION}" kill_exit "Usage: add_action_server_client.sh -o [server,client] -p ros_pkg -a action_name -m message.action" exit ;; @@ -56,14 +58,14 @@ done #check if publisher name parameter is filled up if [ ! "${server_client}" ] || [ ! "${ros_pkg}" ] || [ ! "${action_name}" ] || [ ! "${action_file}" ] then - echo "Missing input parameters..." + echo "ERROR: Missing input parameters..." kill_exit "Usage: add_action_server_client.sh -o [server,client] -p ros_pkg -a action_name -m message.action" fi #check server client parameter if [[ ! "${server_client}" = "server" ]] && [[ ! "${server_client}" = "client" ]] then - kill_exit "First parameter must be either \"server\" or \"client\", aborting ..." + kill_exit "ERROR: First parameter must be either \"server\" or \"client\", aborting ..." fi #check if package exists @@ -72,7 +74,7 @@ if [[ ${pkg_exists} == true ]] then roscd ${ros_pkg} else - kill_exit "ROS package ${ros_pkg} does NOT exist yet, please first run iri_ros_create_package.sh" + kill_exit "ERROR: ROS package ${ros_pkg} does NOT exist yet, please first run iri_ros_create_package.sh" fi #validate file extension .action @@ -84,7 +86,7 @@ action_file=${action_file%.*} #check extension if [[ ! "${ext}" = "${act}" ]] then - kill_exit "Wrong file extension, please provide a .action file, aborting ..." + kill_exit "ERROR: Wrong file extension, please provide a .action file, aborting ..." fi #look for ACTION file @@ -94,8 +96,7 @@ then action_file=${my_file} echo "ACTION file ${action_file} found!" else - echo "ACTION file ${action_file} does NOT exist, please check if file is in valid directories" - kill_exit "Aborting ..." + kill_exit "ERROR. ACTION file ${action_file} does NOT exist, please check if file is in valid directories, aborting ..." fi #retrieve header and source files and pkg kind (algorithm/driver) @@ -107,7 +108,7 @@ echo "driver_alg=${driver_alg}" if [[ -z ${node_h} ]] || [[ -z ${node_c} ]] || [[ -z ${driver_alg} ]] then - kill_exit "Problems with headers and/or source files" + kill_exit "ERROR: Problems found with headers and/or source files" fi #go to package folder @@ -121,3 +122,5 @@ else create_action_client ${ros_pkg} ${action_name} ${action_file%.action} ${file_pkg} ${node_h} ${node_c} ${driver_alg} fi +type="action" +fill_readme_ros_interface ${type} ${server_client} ${ros_pkg} ${action_name} ${file_pkg} ${action_file}.action "false" \ No newline at end of file diff --git a/add_server_client.sh b/add_service_server_client.sh similarity index 62% rename from add_server_client.sh rename to add_service_server_client.sh index 6d72bcf2ef90c0cb0e3db57284512a9888294b5e..8d19a9f3a7c901260f58f75a8b56e86dbc889879 100755 --- a/add_server_client.sh +++ b/add_service_server_client.sh @@ -1,15 +1,17 @@ #!/bin/bash -# WET +echo "/*********************************************/" +echo "/* Creating New ROS Server/Client */" +echo "/*********************************************/" # check wether the scripts path environment variable has been defined scripts_path=`echo "${IRI_ROS_SCRIPTS_PATH}"` if [[ -z "${scripts_path}" ]] then - echo "The scripts path environment variable has not been defined. Please see the wiki documentation for instructions on how to create it." + echo "ERROR: The scripts path environment variable has not been defined. Please see the wiki documentation for instructions on how to create it." exit -else - echo "The scripts path environment variable has been properly defined." +# else +# echo "The scripts path environment variable has been properly defined." fi source "${IRI_ROS_SCRIPTS_PATH}/libraries/scripts_library.sh" @@ -19,11 +21,6 @@ source "${IRI_ROS_SCRIPTS_PATH}/libraries/create_client.sh" check_libraries check_templates -echo "" -echo "/*********************************************/" -echo "/* Creating New ROS Server/Client */" -echo "/*********************************************/" - server_client= ros_pkg= service_name= @@ -40,14 +37,19 @@ do ros_pkg=$OPTARG ;; s) - service_name=$OPTARG + if echo "$OPTARG" | grep -q "/"; then + kill_exit "ERROR: argument -$OPTION can't contain slash '/' characters" + exit + else + service_name=$OPTARG + fi ;; m) srv_file=$OPTARG ;; ?) - echo "invalid input argument ${OPTION}" - kill_exit "Usage: add_server_client.sh -o [server,client] -p ros_pkg -s service_name -m service.srv" + echo "ERROR: invalid input argument ${OPTION}" + kill_exit "Usage: add_service_server_client.sh -o [server,client] -p ros_pkg -s service_name -m service.srv" exit ;; esac @@ -56,14 +58,14 @@ done #check if publisher name parameter is filled up if [ ! "${server_client}" ] || [ ! "${ros_pkg}" ] || [ ! "${service_name}" ] || [ ! "${srv_file}" ] then - echo "Missing input parameters..." - kill_exit "Usage: add_server_client.sh -o [server,client] -p ros_pkg -s service_name -m service.srv" + echo "ERROR: Missing input parameters..." + kill_exit "Usage: add_service_server_client.sh -o [server,client] -p ros_pkg -s service_name -m service.srv" fi #check server client parameter if [[ ! "${server_client}" = "server" ]] && [[ ! "${server_client}" = "client" ]] then - kill_exit "First parameter must be either \"server\" or \"client\", aborting ..." + kill_exit "ERROR: First parameter must be either \"server\" or \"client\", aborting ..." fi #check if package exists @@ -72,7 +74,7 @@ if [[ ${pkg_exists} == true ]] then roscd ${ros_pkg} else - kill_exit "ROS package ${ros_pkg} does NOT exist yet, please first run iri_ros_create_package.sh" + kill_exit "ERROR: ROS package ${ros_pkg} does NOT exist yet, please first run iri_ros_create_package.sh" fi #validate file extension .srv @@ -83,7 +85,7 @@ ext=$(echo ${ext} | tr "[:upper:]" "[:lower:]") #check extension if [[ ! "${ext}" = "${srv}" ]] then - kill_exit "Wrong file extension, please provide a .srv file, aborting ..." + kill_exit "ERROR: Wrong file extension, please provide a .srv file, aborting ..." fi #look for SRV file @@ -93,8 +95,7 @@ then srv_file=${my_file} echo "SRV file ${srv_file} found!" else - echo "SRV file ${srv_file} does NOT exist, please check if file is in valid directories" - kill_exit "Aborting ..." + kill_exit "ERROR: SRV file ${srv_file} does NOT exist, please check if file is in valid directories, aborting ..." fi #retrieve header and source files and pkg kind (algorithm/driver) @@ -106,7 +107,7 @@ echo "driver_alg=${driver_alg}" if [[ -z ${node_h} ]] || [[ -z ${node_c} ]] || [[ -z ${driver_alg} ]] then - kill_exit "Problems with headers and/or source files" + kill_exit "ERROR: Problems found with headers and/or source files" fi #go to package folder @@ -119,3 +120,6 @@ then else create_client ${ros_pkg} ${service_name} ${srv_file%.srv} ${file_pkg} ${node_h} ${node_c} ${driver_alg} fi + +type="service" +fill_readme_ros_interface ${type} ${server_client} ${ros_pkg} ${service_name} ${file_pkg} ${srv_file} "false" \ No newline at end of file diff --git a/add_tf_listener_broadcaster.sh b/add_tf_listener_broadcaster.sh new file mode 100755 index 0000000000000000000000000000000000000000..dbf4b91f01f816c7ff90a876841cdfa4419440a7 --- /dev/null +++ b/add_tf_listener_broadcaster.sh @@ -0,0 +1,102 @@ +#!/bin/bash + +echo "/*********************************************/" +echo "/* Creating New ROS TF Listener broadcaster */" +echo "/*********************************************/" + +script_name="add_tf_listener_broadcaster" + +# check wether the scripts path environment variable has been defined +scripts_path=`echo "${IRI_ROS_SCRIPTS_PATH}"` +if [[ -z "${scripts_path}" ]] +then + echo "ERROR: The scripts path environment varibale has not been defined. Please see the wiki documentation for instructions on how to create it." + exit +# else +# echo "The scripts path environment variable has been properly defined." +fi + +source "${IRI_ROS_SCRIPTS_PATH}/libraries/scripts_library.sh" +source "${IRI_ROS_SCRIPTS_PATH}/libraries/create_tf_broadcaster.sh" +source "${IRI_ROS_SCRIPTS_PATH}/libraries/create_tf_listener.sh" + +check_libraries +check_templates + +pub_subs= +ros_pkg= + +#check for input project name paramenter +while getopts “:o:p:†OPTION +do + case $OPTION in + o) + pub_subs=$OPTARG + ;; + p) + ros_pkg=$OPTARG + ;; + + ?) + echo "ERROR: invalid input argument ${OPTION}" + kill_exit "Usage: ${script_name}.sh -o [broadcaster,listener] -p ros_pkg" + exit + ;; + esac +done + +#check if publisher name parameter is filled up +if [ ! "${pub_subs}" ] || [ ! "${ros_pkg}" ] +then + echo "ERROR: Missing input parameters..." + kill_exit "Usage: ${script_name}.sh -o [broadcaster,listener] -p ros_pkg" +fi + +#check publisher subscriber parameter +if [[ ! "${pub_subs}" = "broadcaster" ]] && [[ ! "${pub_subs}" = "listener" ]] +then + kill_exit "ERROR: First parameter must be either \"broadcaster\" or \"listener\", aborting ..." +fi + +#check if package exists +result=`roscd ${ros_pkg}` +if [[ -z "${result}" ]] +then + roscd ${ros_pkg} +else + kill_exit "ERROR: ROS package ${ros_pkg} does NOT exist or can't be found. Create it, or load the correct workspace." +fi + +check_package "${ros_pkg}" +if [[ ${pkg_exists} == true ]] +then + roscd ${ros_pkg} +else + kill_exit "ROS package ${ros_pkg} does NOT exist of can't be found. Create it, or load the correct workspace." +fi + +#retrieve header and source files and pkg kind (algorithm/driver) +get_h_cpp_files ${ros_pkg} +is_driver_or_alg_node ${ros_pkg} +echo "node_h=${node_h}" +echo "node_c=${node_c}" +echo "driver_alg=${driver_alg}" + +if [[ -z ${node_h} ]] || [[ -z ${node_c} ]] || [[ -z ${driver_alg} ]] +then + kill_exit "ERROR: Problems found with headers and/or source files" +fi + +#go to package folder +roscd "${ros_pkg}" + +#modify node files adding server/client parameters +if [[ "${pub_subs}" = "broadcaster" ]] +then + create_tf_broadcaster ${ros_pkg} ${node_h} ${node_c} ${driver_alg} +else + create_tf_listener ${ros_pkg} ${node_h} ${node_c} ${driver_alg} +fi + +type="topic" +fill_readme_ros_interface ${type} ${pub_subs} ${ros_pkg} "tf" "tf" "tfMessage" "true" \ No newline at end of file diff --git a/add_publisher_subscriber.sh b/add_topic_publisher_subscriber.sh similarity index 63% rename from add_publisher_subscriber.sh rename to add_topic_publisher_subscriber.sh index 4163f3cf7607a0bc38b888e352f8966adf8aebca..5504b8b21c6c89374fee801904e6f70b4e68c6d8 100755 --- a/add_publisher_subscriber.sh +++ b/add_topic_publisher_subscriber.sh @@ -1,15 +1,17 @@ #!/bin/bash -# WET +echo "/*********************************************/" +echo "/* Creating New ROS Publisher/Subscriber */" +echo "/*********************************************/" # check wether the scripts path environment variable has been defined scripts_path=`echo "${IRI_ROS_SCRIPTS_PATH}"` if [[ -z "${scripts_path}" ]] then - echo "The scripts path environment varibale has not been defined. Please see the wiki documentation for instructions on how to create it." + echo "ERROR: The scripts path environment varibale has not been defined. Please see the wiki documentation for instructions on how to create it." exit -else - echo "The scripts path environment variable has been properly defined." +# else +# echo "The scripts path environment variable has been properly defined." fi source "${IRI_ROS_SCRIPTS_PATH}/libraries/scripts_library.sh" @@ -19,11 +21,6 @@ source "${IRI_ROS_SCRIPTS_PATH}/libraries/create_subscriber.sh" check_libraries check_templates -echo "" -echo "/*********************************************/" -echo "/* Creating New ROS Publisher/Subscriber */" -echo "/*********************************************/" - pub_subs= ros_pkg= topic_name= @@ -41,7 +38,12 @@ do ros_pkg=$OPTARG ;; t) - topic_name=$OPTARG + if echo "$OPTARG" | grep -q "/"; then + kill_exit "ERROR: argument -$OPTION can't contain slash '/' characters" + exit + else + topic_name=$OPTARG + fi ;; m) msg_file=$OPTARG @@ -50,8 +52,8 @@ do buffer=$OPTARG ;; ?) - echo "invalid input argument ${OPTION}" - kill_exit "Usage: add_publisher_subscriber.sh -o [publisher,subscriber] -p ros_pkg -t topic_name -m message.msg -b 100" + echo "ERROR: invalid input argument ${OPTION}" + kill_exit "Usage: add_topic_publisher_subscriber.sh -o [publisher,subscriber] -p ros_pkg -t topic_name -m message.msg -b 1" exit ;; esac @@ -60,14 +62,14 @@ done #check if publisher name parameter is filled up if [ ! "${pub_subs}" ] || [ ! "${ros_pkg}" ] || [ ! "${topic_name}" ] || [ ! "${msg_file}" ] || [ ! "${buffer}" ] then - echo "Missing input parameters..." - kill_exit "Usage: add_publisher_subscriber.sh -o [publisher,subscriber] -p ros_pkg -t topic_name -m message.msg -b 100" + echo "ERROR: Missing input parameters..." + kill_exit "Usage: add_topic_publisher_subscriber.sh -o [publisher,subscriber] -p ros_pkg -t topic_name -m message.msg -b 1" fi #check publisher subscriber parameter if [[ ! "${pub_subs}" = "publisher" ]] && [[ ! "${pub_subs}" = "subscriber" ]] then - kill_exit "First parameter must be either \"publisher\" or \"subscriber\", aborting ..." + kill_exit "ERROR: First parameter must be either \"publisher\" or \"subscriber\", aborting ..." fi #check if package exists @@ -76,7 +78,7 @@ if [[ -z "${result}" ]] then roscd ${ros_pkg} else - kill_exit "ROS package ${ros_pkg} does NOT exist yet, please first run iri_ros_create_package.sh" + kill_exit "ERROR: ROS package ${ros_pkg} does NOT exist yet, please first run iri_ros_create_package.sh" fi check_package "${ros_pkg}" @@ -84,7 +86,7 @@ if [[ ${pkg_exists} == true ]] then roscd ${ros_pkg} else - kill_exit "ROS package ${ros_pkg} does NOT exist yet, please first run iri_ros_create_package.sh" + kill_exit "ERROR: ROS package ${ros_pkg} does NOT exist yet, please first run iri_ros_create_package.sh" fi #validate file extension .msg @@ -95,7 +97,7 @@ ext=$(echo ${ext} | tr "[:upper:]" "[:lower:]") #check extension if [[ ! "${ext}" = "${msg}" ]] then - kill_exit "Wrong file extension, please provide a .msg file, aborting ..." + kill_exit "ERROR: Wrong file extension, please provide a .msg file, aborting ..." fi #look for MSG file @@ -105,8 +107,7 @@ then msg_file=${my_file} echo "MSG file ${msg_file} found!" else - echo "MSG file ${msg_file} does NOT exist, please check if file is in valid directories" - kill_exit "Aborting ..." + kill_exit "ERROR: MSG file ${msg_file} does NOT exist, please check if file is in valid directories, aborting ..." fi # Sanitize input and assign to new variable @@ -117,7 +118,7 @@ if [ "$clean_buffer" ] && [ "$clean_buffer -gt 0" ] then echo "Setting buffer length to $clean_buffer" else - kill_exit "No buffer provided, aborting ..." + kill_exit "ERROR: No buffer provided, aborting ..." fi #retrieve header and source files and pkg kind (algorithm/driver) @@ -129,7 +130,7 @@ echo "driver_alg=${driver_alg}" if [[ -z ${node_h} ]] || [[ -z ${node_c} ]] || [[ -z ${driver_alg} ]] then - kill_exit "Problems with headers and/or source files" + kill_exit "ERROR: Problems found with headers and/or source files" fi #go to package folder @@ -143,3 +144,5 @@ else create_subscriber ${ros_pkg} ${topic_name} ${msg_file%.msg} ${file_pkg} ${buffer} ${node_h} ${node_c} ${driver_alg} fi +type="topic" +fill_readme_ros_interface ${type} ${pub_subs} ${ros_pkg} ${topic_name} ${file_pkg} ${msg_file} "false" \ No newline at end of file diff --git a/algorithm_templates/CMakeLists.txt b/algorithm_templates/CMakeLists.txt index 1566d7f3447db22049c1a87d7d57f0f040a8cfa1..bf2362d94e42268e95b10a1257abbf54c94f015b 100644 --- a/algorithm_templates/CMakeLists.txt +++ b/algorithm_templates/CMakeLists.txt @@ -76,7 +76,7 @@ catkin_package( # ******************************************************************** include_directories(include) include_directories(${catkin_INCLUDE_DIRS}) -# include_directories(${<dependency>_INCLUDE_DIR}) +# include_directories(${<dependency>_INCLUDE_DIRS}) ## Declare a cpp library # add_library(${PROJECT_NAME} <list of source files>) @@ -88,7 +88,7 @@ add_executable(${PROJECT_NAME} src/template_alg.cpp src/template_alg_node.cpp) # Add the libraries # ******************************************************************** target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES}) -# target_link_libraries(${PROJECT_NAME} ${<dependency>_LIBRARY}) +# target_link_libraries(${PROJECT_NAME} ${<dependency>_LIBRARIES}) # ******************************************************************** # Add message headers dependencies diff --git a/algorithm_templates/template_alg.cfg b/algorithm_templates/template_alg.cfg index ac1db9d0e7d4dea9520332db055f8876a7a10ceb..d370aef588f019bcc99e8c9d07e710b100c1f9c2 100644 --- a/algorithm_templates/template_alg.cfg +++ b/algorithm_templates/template_alg.cfg @@ -37,7 +37,7 @@ from dynamic_reconfigure.parameter_generator_catkin import * gen = ParameterGenerator() -# Name Type Reconfiguration level Description Default Min Max -#gen.add("velocity_scale_factor", double_t, 0, "Maximum velocity scale factor", 0.5, 0.0, 1.0) +# Name Type Reconf.level Description Default Min Max +gen.add("rate", double_t, 0, "Main loop rate (Hz)", 10.0, 0.1, 1000.0) -exit(gen.generate(PACKAGE, "TemplateAlg", "Template")) +exit(gen.generate(PACKAGE, "TemplateAlg", "Template")) \ No newline at end of file diff --git a/algorithm_templates/template_alg_node.cpp b/algorithm_templates/template_alg_node.cpp index 9039a65396705644749a01ee9f3f4d6578a88a57..9cfc745ed63a0bf526e96e1e23f78ed2f0fc53ee 100644 --- a/algorithm_templates/template_alg_node.cpp +++ b/algorithm_templates/template_alg_node.cpp @@ -4,7 +4,12 @@ TemplateNode::TemplateNode(void) : algorithm_base::IriBaseAlgorithm<TemplateAlg>() { //init class attributes if necessary - //this->loop_rate_ = 2;//in [Hz] + if(!this->private_node_handle_.getParam("rate", this->config_.rate)) + { + ROS_WARN("TemplateNode::TemplateNode: param 'rate' not found"); + } + else + this->setRate(this->config_.rate); // [init publishers] @@ -26,6 +31,9 @@ TemplateNode::~TemplateNode(void) void TemplateNode::mainNodeThread(void) { + //lock access to algorithm if necessary + this->alg_.lock(); + ROS_DEBUG("TemplateNode::mainNodeThread"); // [fill msg structures] // [fill srv structure and make request to the server] @@ -33,6 +41,8 @@ void TemplateNode::mainNodeThread(void) // [fill action structure and make request to the action server] // [publish messages] + + this->alg_.unlock(); } /* [subscriber callbacks] */ @@ -46,6 +56,8 @@ void TemplateNode::mainNodeThread(void) void TemplateNode::node_config_update(Config &config, uint32_t level) { this->alg_.lock(); + if(config.rate!=this->getRate()) + this->setRate(config.rate); this->config_=config; this->alg_.unlock(); } diff --git a/common_templates/LICENSE b/common_templates/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..65c5ca88a67c30becee01c5a8816d964b03862f9 --- /dev/null +++ b/common_templates/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/common_templates/README.md b/common_templates/README.md new file mode 100644 index 0000000000000000000000000000000000000000..fdc7a68530aa086a812a320114f31b92274a57f0 --- /dev/null +++ b/common_templates/README.md @@ -0,0 +1,25 @@ +# template + +## Description + +The template project description + +Developed at Institut de Robòtica i Informà tica Industrial (IRI, CSIC-UPC) (www.iri.upc.edu) +Contact: labrobotica@iri.upc.edu + +# ROS Interface + +### Parameters +- ~rate (Double; default: 10.0; min: 0.1; max: 1000) The main node thread loop rate in Hz. + +## Dependencies + +## Installation + +Clone the package inside a ROS workspace, although it will normally come within a rosinstall file. + +## How to use it + +- Standalone test + + `roslaunch template test.launch` \ No newline at end of file diff --git a/common_templates/node.launch b/common_templates/node.launch new file mode 100644 index 0000000000000000000000000000000000000000..8dd68bb77fff1a596976d42112ad382d69754e7a --- /dev/null +++ b/common_templates/node.launch @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<launch> + + <arg name="node_name" default="template"/> + <arg name="output" default="screen"/> + <arg name="launch_prefix" default=""/> + <arg name="config_file" default="$(find template)/config/params.yaml"/> + <!-- <arg name="topic_name" default="new_topic_name"/> --> + + <node name="$(arg node_name)" + pkg ="template" + type="template" + output="$(arg output)" + launch-prefix="$(arg launch_prefix)"> + <rosparam file="$(arg config_file)" command="load"/> + <!--<remap from="~/topic" to="$(arg topic_name)"/>--> + </node> + +</launch> \ No newline at end of file diff --git a/common_templates/params.yaml b/common_templates/params.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b0ca445c9073d619a64ce9fdb5d390018783d3cc --- /dev/null +++ b/common_templates/params.yaml @@ -0,0 +1 @@ +rate: 10 \ No newline at end of file diff --git a/common_templates/test.launch b/common_templates/test.launch new file mode 100644 index 0000000000000000000000000000000000000000..8be738778f4fdc0d8c47374c38da981a6ffcc973 --- /dev/null +++ b/common_templates/test.launch @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<launch> + + <arg name="output" default="screen"/> + <arg name="launch_prefix" default=""/> + <arg name="dr" default="true"/> + + <include file="$(find template)/launch/node.launch"> + <arg name="node_name" value="template"/> + <arg name="output" value="$(arg output)"/> + <arg name="launch_prefix" value="$(arg launch_prefix)"/> + </include> + + <node name="rqt_reconfigure_template" + pkg ="rqt_reconfigure" + type="rqt_reconfigure" + if ="$(arg dr)" + args="template"> + </node> + +</launch> \ No newline at end of file diff --git a/create_algorithm_package.sh b/create_algorithm_package.sh index 2e477ffe15a9db754d5b7925d66bc9af30a92447..b2333c1a4777e644169c0fe3cfbd4ab33d6de904 100755 --- a/create_algorithm_package.sh +++ b/create_algorithm_package.sh @@ -1,15 +1,17 @@ #!/bin/bash -# WET +echo "/**********************************************/" +echo "/* Creating New IRI_ROS Simple Algorithm Node */" +echo "/**********************************************/" # check wether the scripts path environment variable has been defined scripts_path=`echo "${IRI_ROS_SCRIPTS_PATH}"` if [[ -z "${scripts_path}" ]] then - echo "The scripts path environment variable has not been defined. Please see the wiki documentation for instructions on how to create it." + echo "ERROR: The scripts path environment variable has not been defined. Please see the wiki documentation for instructions on how to create it." exit -else - echo "The scripts path environment variable has been properly defined." +# else +# echo "The scripts path environment variable has been properly defined." fi source "${IRI_ROS_SCRIPTS_PATH}/libraries/scripts_library.sh" @@ -17,29 +19,30 @@ source "${IRI_ROS_SCRIPTS_PATH}/libraries/scripts_library.sh" check_libraries check_templates -echo "" -echo "/**********************************************/" -echo "/* Creating New IRI_ROS Simple Algorithm Node */" -echo "/**********************************************/" - -usage="Usage: create_algorithm_package.sh -n node_name [-i]\n +usage="Usage: create_algorithm_package.sh -n node_name [-i] [-p <prefix>]\n Parameters:\n -\t-i: avoid adding the iri_ prefix to the provided node name. By default it is always added." -input_name= -use_prefix=true +\t-i: avoid adding the default iri_ prefix to the provided node name.\n +\t-p <prefix>: replaces default iri_ prefix with specified <prefix>_." +input_name="" +use_iri_prefix=true +input_prefix="" #check for input project name paramenter -while getopts “:n:i†OPTION +while getopts “:n:ip:†OPTION do case $OPTION in n) input_name=$OPTARG ;; i) - use_prefix=false + use_iri_prefix=false + ;; + p) + use_iri_prefix=false + input_prefix=$OPTARG ;; ?) - echo "invalid argument $OPTION" + echo "ERROR: invalid argument $OPTION" kill_exit "${usage}" ;; esac @@ -48,7 +51,7 @@ done #check if project parameter is filled up if [ ! "${input_name}" ] then - echo "No project name provided, aborting ..." + echo "ERROR: No project name provided, aborting ..." kill_exit "${usage}" fi @@ -56,11 +59,16 @@ fi input_name=$(echo ${input_name} | tr "[:upper:]" "[:lower:]") #create alg filename -if [[ ${use_prefix} == true ]] +if [[ ${use_iri_prefix} == true ]] then project_name="iri_${input_name}" else - project_name="${input_name}" + if [[ "$input_prefix" != "" ]] + then + project_name="${input_prefix}_${input_name}" + else + project_name="${input_name}" + fi fi if [ -e "../${project_name}" ] @@ -77,6 +85,7 @@ then else exit 1; fi + #create alg filename alg_filename="${input_name}_alg" @@ -108,8 +117,7 @@ sed -e "s/template_alg/${alg_filename}/g" \ -e "s/TemplateConfig/${basename}Config/g" <${temps_folder}/template_alg.h >"${project_name}/include/${alg_filename}.h" sed -e "s/template_alg/${alg_filename}/g" \ -e "s/TemplateAlg/${alg_basename}/g" <${temps_folder}/template_alg.cpp >"${project_name}/src/${alg_filename}.cpp" -echo "Creating ${alg_filename} files..." -echo "" +echo "Creating ${alg_filename}.h/cpp files..." ################################################################################ @@ -129,8 +137,7 @@ sed -e "s/template_alg/${alg_filename}/g" \ sed -e "s/template_node/${node_filename}/g" \ -e "s/TemplateAlg/${alg_basename}/g" \ -e "s/TemplateNode/${node_basename}/g" <${temps_folder}/template_alg_node.cpp >"${project_name}/src/${node_filename}.cpp" -echo "Creating ${node_filename} files..." -echo "" +echo "Creating ${node_filename}.h/cpp files..." ################################################################################ @@ -139,8 +146,7 @@ echo "" sed -e "s/template_alg/${alg_filename}/g" \ -e "s/Template/${basename}/g" \ -e "s/template_node/${project_name}/g" <${temps_folder}/CMakeLists.txt >"${project_name}/CMakeLists.txt" -echo "Creating ${project_name} CMakeLists.txt file..." -echo "" +echo "Creating ${project_name}/CMakeLists.txt file..." ################################################################################ @@ -161,18 +167,35 @@ sed -e "s/template/${project_name}/g" \ -e "s/template_node/${node_filename}/g" \ -e "s/Template/${basename}/g" <${temps_folder}/template_alg.cfg >"${project_name}/cfg/${basename}.cfg" eval "chmod 775 ${project_name}/cfg/${basename}.cfg" -echo "Creating ${cfg_filename}.cfg file..." +echo "Creating ${cfg_dir}/${cfg_filename}.cfg file..." ################################################################################ -echo "" -echo "" -echo "Project ${project_name} has been successfully created!!" -pushd "${project_name}" -change_license_to_LGPL -popd +################################################################################ +#create launch/config directory +mkdir -p ${project_name}/launch/ -# WET -goto_catkin_workspace -catkin_make --only-pkg-with-deps ${project_name} +sed -e "s/template/${project_name}/g" <${IRI_ROS_SCRIPTS_PATH}/common_templates/node.launch >"${project_name}/launch/node.launch" +sed -e "s/template/${project_name}/g" <${IRI_ROS_SCRIPTS_PATH}/common_templates/test.launch >"${project_name}/launch/test.launch" +mkdir -p ${project_name}/config/ +cp ${IRI_ROS_SCRIPTS_PATH}/common_templates/params.yaml ${project_name}/config/params.yaml +################################################################################ + + +################################################################################ +#add license and readme +cp ${IRI_ROS_SCRIPTS_PATH}/common_templates/LICENSE ${project_name}/LICENSE + +sed -e "s/template/${project_name}/g" < ${IRI_ROS_SCRIPTS_PATH}/common_templates/README.md > "${project_name}/README.md" +################################################################################ +pushd "${project_name}" > /dev/null +change_license_to_LGPL +change_maintainer_email_domain_to_iri_upc_edu +popd > /dev/null +################################################################################ +echo "Project ${project_name} has been successfully created!!" +echo "" +echo "Compiling workspace with: catkin_make --only-pkg-with-deps $project_name" +goto_catkin_workspace +catkin_make --only-pkg-with-deps ${project_name} \ No newline at end of file diff --git a/create_driver_package.sh b/create_driver_package.sh index 823902e5301ed16f340d1030f33fb6deeb6beca5..f7f9956d2f0aff6ad4da59d4caabee59a29d3b52 100755 --- a/create_driver_package.sh +++ b/create_driver_package.sh @@ -1,16 +1,17 @@ #!/bin/bash -# WET +echo "/*********************************************/" +echo "/* Creating New IRI_ROS Driver Node */" +echo "/*********************************************/" # check wether the scripts path environment variable has been defined scripts_path=`echo "${IRI_ROS_SCRIPTS_PATH}"` -# check if scripts_path has size 0 if [[ -z "${scripts_path}" ]] then - echo "The scripts path environment variable has not been defined. Please see the wiki documentation for instructions on how to create it." + echo "ERROR: The scripts path environment variable has not been defined. Please see the wiki documentation for instructions on how to create it." exit -else - echo "The scripts path environment variable has been properly defined." +# else +# echo "The scripts path environment variable has been properly defined." fi source "${IRI_ROS_SCRIPTS_PATH}/libraries/scripts_library.sh" @@ -18,29 +19,30 @@ source "${IRI_ROS_SCRIPTS_PATH}/libraries/scripts_library.sh" check_libraries check_templates -echo "" -echo "/*********************************************/" -echo "/* Creating New IRI_ROS Driver Node */" -echo "/*********************************************/" - -usage="Usage: create_driver_package.sh -n node_name [-i] +usage="Usage: create_driver_package.sh -n node_name [-i] [-p <prefix]]\n Parameters:\n -\t-i: avoid adding the iri_ prefix to the provided node name. By default it is always added." -input_name= -use_prefix=true +\t-i: avoid adding the default iri_ prefix to the provided node name.\n +\t-p <prefix>: replaces default iri_ prefix with specified <prefix>_." +input_name="" +use_iri_prefix=true +input_prefix="" #check for input project name paramenter -while getopts “:n:i†OPTION +while getopts “:n:ip:†OPTION do case $OPTION in n) input_name=$OPTARG ;; i) - use_prefix=false + use_iri_prefix=false + ;; + p) + use_iri_prefix=false + input_prefix=$OPTARG ;; ?) - echo "invalid argument $OPTION" + echo "ERROR: invalid argument $OPTION" kill_exit "${usage}" ;; esac @@ -49,7 +51,7 @@ done #check if project parameter is filled up if [ ! "${input_name}" ] then - echo "No project name provided, aborting ..." + echo "ERROR: No project name provided, aborting ..." kill_exit "${usage}" fi @@ -57,16 +59,21 @@ fi input_name=$(echo ${input_name} | tr "[:upper:]" "[:lower:]") #create driver filename -if [[ ${use_prefix} == true ]] +if [[ ${use_iri_prefix} == true ]] then project_name="iri_${input_name}" else - project_name="${input_name}" + if [[ "$input_prefix" != "" ]] + then + project_name="${input_prefix}_${input_name}" + else + project_name="${input_name}" + fi fi if [ -e "../${project_name}" ] then - kill_exit "${project_name} package directory already exists, aborting ..." + kill_exit "ERROR: ${project_name} package directory already exists, aborting ..." else echo "Generating folder structure for project ${project_name} ..." fi @@ -81,25 +88,24 @@ fi #create driver filename driver_filename="${input_name}_driver" -#echo "driver_filename $driver_filename" #create node filename node_filename="${input_name}_driver_node" -#echo "node_filename $node_filename" #create cfg filename cfg_filename="${input_name}_driver_config" -#echo "cfg_filename $cfg_filename" #create basename from pkg name create_basename ${input_name} +#create templates folder path name +temps_folder="${IRI_ROS_SCRIPTS_PATH}/driver_templates/" + ################################################################################ # create template driver .h and .cpp files #create driver basename driver_basename="${basename}Driver" -#echo "driver_basename $driver_basename" mkdir -p ${project_name}/include/ mkdir -p ${project_name}/src/ @@ -107,13 +113,11 @@ mkdir -p ${project_name}/src/ #Set the filename and namespace on the template_driver files sed -e "s/template_driver/${driver_filename}/g" \ -e "s/TemplateDriver/${driver_basename}/g" \ - -e "s/template_node/${node_filename}/g" \ -e "s/template_namespace/${project_name}/g" \ - -e "s/TemplateConfig/${basename}Config/g" <${IRI_ROS_SCRIPTS_PATH}/driver_templates/template_driver.h >"${project_name}/include/${driver_filename}.h" + -e "s/TemplateConfig/${basename}Config/g" <${temps_folder}/template_driver.h >"${project_name}/include/${driver_filename}.h" sed -e "s/template_driver/${driver_filename}/g" \ - -e "s/TemplateDriver/${driver_basename}/g" <${IRI_ROS_SCRIPTS_PATH}/driver_templates/template_driver.cpp >"${project_name}/src/${driver_filename}.cpp" + -e "s/TemplateDriver/${driver_basename}/g" <${temps_folder}/template_driver.cpp >"${project_name}/src/${driver_filename}.cpp" echo "Creating ${driver_filename} files..." -echo "" ################################################################################ @@ -129,13 +133,12 @@ node_basename="${basename}DriverNode" sed -e "s/template_driver/${driver_filename}/g" \ -e "s/TemplateDriver/${driver_basename}/g" \ -e "s/template_node/${node_filename}/g" \ - -e "s/TemplateNode/${node_basename}/g" <${IRI_ROS_SCRIPTS_PATH}/driver_templates/template_driver_node.h >"${project_name}/include/${node_filename}.h" + -e "s/TemplateNode/${node_basename}/g" <${temps_folder}/template_driver_node.h >"${project_name}/include/${node_filename}.h" sed -e "s/template_driver/${driver_filename}/g" \ -e "s/TemplateDriver/${driver_basename}/g" \ -e "s/template_node/${node_filename}/g" \ - -e "s/TemplateNode/${node_basename}/g" <${IRI_ROS_SCRIPTS_PATH}/driver_templates/template_driver_node.cpp >"${project_name}/src/${node_filename}.cpp" + -e "s/TemplateNode/${node_basename}/g" <${temps_folder}/template_driver_node.cpp >"${project_name}/src/${node_filename}.cpp" echo "Creating ${node_filename} files..." -echo "" ################################################################################ @@ -143,9 +146,8 @@ echo "" #Set the filename and namespace on the CMakeLists.txt file sed -e "s/template_driver/${driver_filename}/g" \ -e "s/template_node/${project_name}/g" \ - -e "s/Template/${basename}/g" <${IRI_ROS_SCRIPTS_PATH}/driver_templates/CMakeLists.txt >"${project_name}/CMakeLists.txt" + -e "s/Template/${basename}/g" <${temps_folder}/CMakeLists.txt >"${project_name}/CMakeLists.txt" echo "Creating ${project_name} CMakeLists.txt file..." -echo "" ################################################################################ @@ -165,18 +167,37 @@ sed -e "s/template_driver/${driver_filename}/g" \ -e "s/template/${project_name}/g" \ -e "s/TemplateDriver/${driver_basename}/g" \ -e "s/template_node/${node_filename}/g" \ - -e "s/Template/${basename}/g" <${IRI_ROS_SCRIPTS_PATH}/driver_templates/template_driver.cfg >"${project_name}/cfg/${basename}.cfg" + -e "s/Template/${basename}/g" <${temps_folder}/template_driver.cfg >"${project_name}/cfg/${basename}.cfg" eval "chmod 775 ${project_name}/cfg/${basename}.cfg" echo "Creating ${basename}.cfg file..." ################################################################################ -echo "" -echo "" -echo "Project ${project_name} has been successfully created!!" -pushd "${project_name}" -change_license_to_LGPL -popd +################################################################################ +#create launch/config directory +mkdir -p ${project_name}/launch/ + +sed -e "s/template/${project_name}/g" <${IRI_ROS_SCRIPTS_PATH}/common_templates/node.launch >"${project_name}/launch/node.launch" +sed -e "s/template/${project_name}/g" <${IRI_ROS_SCRIPTS_PATH}/common_templates/test.launch >"${project_name}/launch/test.launch" + +mkdir -p ${project_name}/config/ +cp ${IRI_ROS_SCRIPTS_PATH}/common_templates/params.yaml ${project_name}/config/params.yaml +################################################################################ + +################################################################################ +#add license and readme +cp ${IRI_ROS_SCRIPTS_PATH}/common_templates/LICENSE ${project_name}/LICENSE + +sed -e "s/template/${project_name}/g" < ${IRI_ROS_SCRIPTS_PATH}/common_templates/README.md > "${project_name}/README.md" +################################################################################ +pushd "${project_name}" > /dev/null +change_license_to_LGPL +change_maintainer_email_domain_to_iri_upc_edu +popd > /dev/null +################################################################################ +echo "Project ${project_name} has been successfully created!!" +echo "" +echo "Compiling workspace with: catkin_make --only-pkg-with-deps $project_name" goto_catkin_workspace -catkin_make --only-pkg-with-deps ${project_name} +catkin_make --only-pkg-with-deps ${project_name} \ No newline at end of file diff --git a/driver_templates/CMakeLists.txt b/driver_templates/CMakeLists.txt index a5982ede66b7201ae7b8aa55856f1c7a89e50dc6..800a07b2189b46bc2764d3ea459ce36fc204afa5 100644 --- a/driver_templates/CMakeLists.txt +++ b/driver_templates/CMakeLists.txt @@ -76,7 +76,7 @@ catkin_package( # ******************************************************************** include_directories(include) include_directories(${catkin_INCLUDE_DIRS}) -# include_directories(${<dependency>_INCLUDE_DIR}) +# include_directories(${<dependency>_INCLUDE_DIRS}) ## Declare a cpp library # add_library(${PROJECT_NAME} <list of source files>) @@ -88,12 +88,14 @@ add_executable(${PROJECT_NAME} src/template_driver.cpp src/template_driver_node. # Add the libraries # ******************************************************************** target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES}) -# target_link_libraries(${PROJECT_NAME} ${<dependency>_LIBRARY}) +# target_link_libraries(${PROJECT_NAME} ${<dependency>_LIBRARIES}) # ******************************************************************** # Add message headers dependencies # ******************************************************************** # add_dependencies(${PROJECT_NAME} <msg_package_name>_generate_messages_cpp) +add_dependencies(${PROJECT_NAME} iri_base_driver_generate_messages_cpp) +add_dependencies(${PROJECT_NAME}_gencfg iri_base_driver_generate_messages_py) # ******************************************************************** # Add dynamic reconfigure dependencies # ******************************************************************** diff --git a/driver_templates/template_driver.cfg b/driver_templates/template_driver.cfg index a6e770487e344f24f450b6b3fb1d3056cc64809e..9fb9032377145d5eb9269965b3f9ac53f3562593 100644 --- a/driver_templates/template_driver.cfg +++ b/driver_templates/template_driver.cfg @@ -33,12 +33,12 @@ PACKAGE='template' -from driver_base.msg import SensorLevels +from iri_base_driver.msg import SensorLevels from dynamic_reconfigure.parameter_generator_catkin import * gen = ParameterGenerator() -# Name Type Reconfiguration level Description Default Min Max -#gen.add("velocity_scale_factor", double_t, SensorLevels.RECONFIGURE_STOP, "Maximum velocity scale factor", 0.5, 0.0, 1.0) +# Name Type Reconf.level Description Default Min Max +gen.add("rate", double_t, 0, "Main loop rate (Hz)", 10.0, 0.1, 1000.0) exit(gen.generate(PACKAGE, "TemplateDriver", "Template")) diff --git a/driver_templates/template_driver.cpp b/driver_templates/template_driver.cpp index 2a1a2c8905b4c237cb337e6446a9cd3cdb23524f..16f03be85e440cf298b73edd89c9e57e50326a9b 100644 --- a/driver_templates/template_driver.cpp +++ b/driver_templates/template_driver.cpp @@ -35,13 +35,13 @@ void TemplateDriver::config_update(Config& new_cfg, uint32_t level) // update driver with new_cfg data switch(this->getState()) { - case TemplateDriver::CLOSED: + case iri_base_driver::CLOSED: break; - case TemplateDriver::OPENED: + case iri_base_driver::OPENED: break; - case TemplateDriver::RUNNING: + case iri_base_driver::RUNNING: break; } diff --git a/driver_templates/template_driver_node.cpp b/driver_templates/template_driver_node.cpp index 5347b09267cd24e31ad538565d471d5fd6c9aed0..b76ed1252220cd9165a274a42cdf6f7be3a548ef 100644 --- a/driver_templates/template_driver_node.cpp +++ b/driver_templates/template_driver_node.cpp @@ -4,7 +4,12 @@ TemplateNode::TemplateNode(ros::NodeHandle &nh) : iri_base_driver::IriBaseNodeDriver<TemplateDriver>(nh) { //init class attributes if necessary - //this->loop_rate_ = 2;//in [Hz] + if(!this->private_node_handle_.getParam("rate", this->config_.rate)) + { + ROS_WARN("TemplateNode::TemplateNode: param 'rate' not found"); + } + else + this->setRate(this->config_.rate); // [init publishers] @@ -23,6 +28,7 @@ void TemplateNode::mainNodeThread(void) { //lock access to driver if necessary this->driver_.lock(); + ROS_DEBUG("TemplateNode::mainNodeThread"); // [fill msg Header if necessary] @@ -50,24 +56,21 @@ void TemplateNode::postNodeOpenHook(void) { } -void TemplateNode::addNodeDiagnostics(void) -{ -} - -void TemplateNode::addNodeOpenedTests(void) -{ -} - -void TemplateNode::addNodeStoppedTests(void) +void TemplateNode::preNodeCloseHook(void) { } -void TemplateNode::addNodeRunningTests(void) +void TemplateNode::addNodeDiagnostics(void) { } -void TemplateNode::reconfigureNodeHook(int level) +void TemplateNode::node_config_update(Config& new_cfg, uint32_t level) { + this->driver_.lock(); + if(new_cfg.rate!=this->getRate()) + this->setRate(new_cfg.rate); + this->config_=new_cfg; + this->driver_.unlock(); } TemplateNode::~TemplateNode(void) @@ -78,5 +81,5 @@ TemplateNode::~TemplateNode(void) /* main function */ int main(int argc,char *argv[]) { - return driver_base::main<TemplateNode>(argc, argv, "template_node"); + return iri_base_driver::main<TemplateNode>(argc, argv, "template_node"); } diff --git a/driver_templates/template_driver_node.h b/driver_templates/template_driver_node.h index 6841b516407606db0768a6c35dbee5efbb3217b2..a68cf5456883dec8330b78d12c484c9f9f7fc806 100644 --- a/driver_templates/template_driver_node.h +++ b/driver_templates/template_driver_node.h @@ -75,6 +75,8 @@ class TemplateNode : public iri_base_driver::IriBaseNodeDriver<TemplateDriver> */ void postNodeOpenHook(void); + void preNodeCloseHook(void); + public: /** * \brief constructor @@ -94,6 +96,14 @@ class TemplateNode : public iri_base_driver::IriBaseNodeDriver<TemplateDriver> * \param nh a reference to the node handle object to manage all ROS topics. */ TemplateNode(ros::NodeHandle& nh); + + /** + * \brief config variable + * + * This variable has all the driver parameters defined in the cfg config file. + * Is updated everytime function config_update() is called. + */ + Config config_; /** * \brief Destructor @@ -134,39 +144,6 @@ class TemplateNode : public iri_base_driver::IriBaseNodeDriver<TemplateDriver> // [driver test functions] - /** - * \brief open status driver tests - * - * In this function tests checking driver's functionallity when driver_base - * status=open can be added. Common use tests for all nodes are already called - * from IriBaseNodeDriver tests methods. For more details on how ROS tests work, - * please refer to the Self Test example in: - * http://www.ros.org/wiki/self_test/ - */ - void addNodeOpenedTests(void); - - /** - * \brief stop status driver tests - * - * In this function tests checking driver's functionallity when driver_base - * status=stop can be added. Common use tests for all nodes are already called - * from IriBaseNodeDriver tests methods. For more details on how ROS tests work, - * please refer to the Self Test example in: - * http://www.ros.org/wiki/self_test/ - */ - void addNodeStoppedTests(void); - - /** - * \brief run status driver tests - * - * In this function tests checking driver's functionallity when driver_base - * status=run can be added. Common use tests for all nodes are already called - * from IriBaseNodeDriver tests methods. For more details on how ROS tests work, - * please refer to the Self Test example in: - * http://www.ros.org/wiki/self_test/ - */ - void addNodeRunningTests(void); - /** * \brief specific node dynamic reconfigure * @@ -174,7 +151,7 @@ class TemplateNode : public iri_base_driver::IriBaseNodeDriver<TemplateDriver> * * \param level integer */ - void reconfigureNodeHook(int level); + void node_config_update(Config& new_cfg, uint32_t level); }; diff --git a/libraries/create_action_client.sh b/libraries/create_action_client.sh old mode 100644 new mode 100755 index df3cf2f2298af09e6aedecb9428bc491613a017e..dd857e8ce02971dc1a813a2223cb1aa895a5a2e3 --- a/libraries/create_action_client.sh +++ b/libraries/create_action_client.sh @@ -4,10 +4,10 @@ scripts_path=`echo "${IRI_ROS_SCRIPTS_PATH}"` if [[ -z "${scripts_path}" ]] then - echo "The scripts path environment variable has not been defined. Please see the wiki documentation for instructions on how to create it." + echo "ERROR: The scripts path environment variable has not been defined. Please see the wiki documentation for instructions on how to create it." exit -else - echo "The scripts path environment variable has been properly defined." +# else +# echo "The scripts path environment variable has been properly defined." fi source "${IRI_ROS_SCRIPTS_PATH}/libraries/scripts_library.sh" @@ -23,13 +23,13 @@ function check_action_client_file_integrity find_comment_in_file "${comment}" "${node_h}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[action server client headers\] from the header file ${node_h}" + kill_exit "ERROR: Missing \[action server client headers\] from the header file ${node_h}" fi comment="\[action client attributes\]" find_comment_in_file "${comment}" "${node_h}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[action client attributes\] from the header file ${node_h}" + kill_exit "ERROR: Missing \[action client attributes\] from the header file ${node_h}" fi # check node.cpp file @@ -37,21 +37,21 @@ function check_action_client_file_integrity find_comment_in_file "${comment}" "${node_c}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[fill action structure and make request to the action server\] from the source file ${node_c}" + kill_exit "ERROR: Missing \[fill action structure and make request to the action server\] from the source file ${node_c}" fi comment="\[action callbacks\]" find_comment_in_file "${comment}" "${node_c}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[action callbacks\] from the source file ${node_c}" + kill_exit "ERROR: Missing \[action callbacks\] from the source file ${node_c}" fi comment="\[action requests\]" find_comment_in_file "${comment}" "${node_c}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[action requests\] from the source file ${node_c}" + kill_exit "ERROR: Missing \[action requests\] from the source file ${node_c}" fi } @@ -72,42 +72,42 @@ function check_action_client_attributes_functions find_comment_in_file "${aux_line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "An ActionClient variable already exists with the same name in file ${node_h} line ${line_number}" + kill_exit "ERROR: An ActionClient variable already exists with the same name in file ${node_h} line ${line_number}" fi aux_line="${act_pkg}::${action_file}Goal ${act_goal};" find_comment_in_file "${aux_line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "An ActionClient goal message variable already exists with the same name in file ${node_h} line ${line_number}" + kill_exit "ERROR: An ActionClient goal message variable already exists with the same name in file ${node_h} line ${line_number}" fi aux_line="bool ${topic_name}MakeActionRequest();" find_comment_in_file "${aux_line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A MakeActionRequest function already exists with the same name in file ${node_h} line ${line_number}" + kill_exit "ERROR: A MakeActionRequest function already exists with the same name in file ${node_h} line ${line_number}" fi aux_line="void ${topic_name}Done(const actionlib::SimpleClientGoalState& state, const ${act_pkg}::${action_file}ResultConstPtr& result);" find_comment_in_file "${aux_line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A Done callback function already exists with the same name in file ${node_h} line ${line_number}" + kill_exit "ERROR: A Done callback function already exists with the same name in file ${node_h} line ${line_number}" fi aux_line="void ${topic_name}Active();" find_comment_in_file "${aux_line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "An Active callback function already exists with the same name in file ${node_h} line ${line_number}" + kill_exit "ERROR: An Active callback function already exists with the same name in file ${node_h} line ${line_number}" fi aux_line="void ${topic_name}Feedback(const ${act_pkg}::${action_file}FeedbackConstPtr& feedback);" find_comment_in_file "${aux_line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A Feedback callback function already exists with the same name in file ${node_h} line ${line_number}" + kill_exit "ERROR: A Feedback callback function already exists with the same name in file ${node_h} line ${line_number}" fi # check the node.c file @@ -115,35 +115,35 @@ function check_action_client_attributes_functions find_comment_in_file "${aux_line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The constructor for the Action client is already called in file ${node_c} line ${line_number}" + kill_exit "ERROR: The constructor for the Action client is already called in file ${node_c} line ${line_number}" fi aux_line="void ${class_name}::${topic_name}Done(const actionlib::SimpleClientGoalState& state, const ${act_pkg}::${action_file}ResultConstPtr& result)" find_comment_in_file "${aux_line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "An implementation for the Done callback function is already present in file ${node_c} line ${line_number}" + kill_exit "ERROR: An implementation for the Done callback function is already present in file ${node_c} line ${line_number}" fi aux_line="void ${class_name}::${topic_name}Active()" find_comment_in_file "${aux_line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "An implementation for the Active callback function is already present in file ${node_c} line ${line_number}" + kill_exit "ERROR: An implementation for the Active callback function is already present in file ${node_c} line ${line_number}" fi aux_line="void ${class_name}::${topic_name}Feedback(const ${act_pkg}::${action_file}FeedbackConstPtr& feedback)" find_comment_in_file "${aux_line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "An implementation for the Feedback callback function is already present in file ${node_c} line ${line_number}" + kill_exit "ERROR: An implementation for the Feedback callback function is already present in file ${node_c} line ${line_number}" fi aux_line="bool ${class_name}::${topic_name}MakeActionRequest()" find_comment_in_file "${aux_line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "An implementation for the MakeActionRequest function is already present in file ${node_c} line ${line_number}" + kill_exit "ERROR: An implementation for the MakeActionRequest function is already present in file ${node_c} line ${line_number}" fi } @@ -170,7 +170,7 @@ function create_action_client get_class_basename "${node_c}" if [[ -z ${class_name} ]] then - kill_exit "impossible to retrieve class basename" + kill_exit "ERROR: impossible to retrieve class basename" fi # echo "class_name=${class_name}" @@ -203,7 +203,8 @@ function create_action_client old_string="iri_base_algorithm" fi new_string="${old_string}\ ${actionlib_pkg}" - sed -i "s/${old_string}/${new_string}/g" "CMakeLists.txt" + sed -i -e "/find_package/ s/${old_string}/${new_string}/g" "CMakeLists.txt" + sed -i -e "/CATKIN_DEPENDS/ s/${old_string}/${new_string}/g" "CMakeLists.txt" fi add_cmake_dependencies "${driver_alg}" "${ros_pkg}" "${act_pkg}" @@ -245,7 +246,7 @@ function create_action_client ################################################################################ #modify Node.cpp - line="${client_name}(\"${topic_name}\", true)" + line="${client_name}(private_node_handle_,\"${topic_name}\", true)" # comment="${class_name}::${class_name}(" # sed -i "/${comment}/s|$|,|" "${node_c}" # add_line_to_file "\ \ ${line}" "${comment}" "${node_c}" @@ -290,25 +291,27 @@ function create_action_client add_line_to_file "${line}" "${comment}" "${node_c}" fi - aux_line="\ \ // variable to hold the state of the current goal on the server" + aux_line="\ \ //// variable to hold the state of the current goal on the server" line="${aux_line}\n" aux_line="\ \ //actionlib::SimpleClientGoalState ${topic_name}_state(actionlib::SimpleClientGoalState::PENDING);" line="${line}${aux_line}\n" - aux_line="\ \ // to get the state of the current goal" + aux_line="\ \ //// to get the state of the current goal" line="${line}${aux_line}\n" - aux_line="\ \ //${driver_alg}_.unlock();" + aux_line="\ \ ////this->${driver_alg}_.unlock();" line="${line}${aux_line}\n" aux_line="\ \ //${topic_name}_state=${topic_name}_client_.getState();" line="${line}${aux_line}\n" - aux_line="\ \ // Possible state values are: PENDING,ACTIVE,RECALLED,REJECTED,PREEMPTED,ABORTED,SUCCEEDED and LOST" + aux_line="\ \ //// Possible state values are: PENDING,ACTIVE,RECALLED,REJECTED,PREEMPTED,ABORTED,SUCCEEDED and LOST" line="${line}${aux_line}\n" - aux_line="\ \ //${driver_alg}_.lock();" + aux_line="\ \ ////this->${driver_alg}_.lock();" + line="${line}${aux_line}\n" + aux_line="\ \ //ROS_INFO(\"${class_name}::mainNodeThread: ${topic_name}_client_ action state = %s\", ${topic_name}_state.toString().c_str());;" line="${line}${aux_line}\n" aux_line="\ \ //if(${topic_name}_state==actionlib::SimpleClientGoalState::ABORTED)" line="${line}${aux_line}\n" aux_line="\ \ //{" line="${line}${aux_line}\n" - aux_line="\ \ // do something" + aux_line="\ \ //// do something" line="${line}${aux_line}\n" aux_line="\ \ //}" line="${line}${aux_line}\n" @@ -316,12 +319,21 @@ function create_action_client line="${line}${aux_line}\n" aux_line="\ \ //{" line="${line}${aux_line}\n" - aux_line="\ \ // do something else" + aux_line="\ \ //// do something else" line="${line}${aux_line}\n" aux_line="\ \ //}" line="${line}${aux_line}\n" - aux_line="\ \ //${topic_name}MakeActionRequest();" + aux_line="\ \ //static bool first=true;" + line="${line}${aux_line}\n" + aux_line="\ \ //if(first){" + line="${line}${aux_line}\n" + aux_line="\ \ // first=false;" line="${line}${aux_line}\n" + aux_line="\ \ // ${topic_name}MakeActionRequest();" + line="${line}${aux_line}\n" + aux_line="\ \ //}" + line="${line}${aux_line}\n" + comment="\[fill action structure and make request to the action server\]" add_line_to_file "${line}" "${comment}" "${node_c}" @@ -329,7 +341,7 @@ function create_action_client line="${aux_line}\n" aux_line="{" line="${line}${aux_line}\n" - aux_line="\ \ ${driver_alg}_.lock();" + aux_line="\ \ this->${driver_alg}_.lock();" line="${line}${aux_line}\n" aux_line="\ \ if( state == actionlib::SimpleClientGoalState::SUCCEEDED )" line="${line}${aux_line}\n" @@ -341,7 +353,7 @@ function create_action_client line="${line}${aux_line}\n\n" aux_line="\ \ //copy & work with requested result" line="${line}${aux_line}\n" - aux_line="\ \ ${driver_alg}_.unlock();" + aux_line="\ \ this->${driver_alg}_.unlock();" line="${line}${aux_line}\n" aux_line="}" line="${line}${aux_line}\n\n" @@ -349,11 +361,11 @@ function create_action_client line="${line}${aux_line}\n" aux_line="{" line="${line}${aux_line}\n" - aux_line="\ \ ${driver_alg}_.lock();" + aux_line="\ \ this->${driver_alg}_.lock();" line="${line}${aux_line}\n" aux_line="\ \ //ROS_INFO(\"${class_name}::${topic_name}Active: Goal just went active!\");" line="${line}${aux_line}\n" - aux_line="\ \ ${driver_alg}_.unlock();" + aux_line="\ \ this->${driver_alg}_.unlock();" line="${line}${aux_line}\n" aux_line="}" line="${line}${aux_line}\n\n" @@ -361,7 +373,7 @@ function create_action_client line="${line}${aux_line}\n" aux_line="{" line="${line}${aux_line}\n" - aux_line="\ \ ${driver_alg}_.lock();" + aux_line="\ \ this->${driver_alg}_.lock();" line="${line}${aux_line}\n" aux_line="\ \ //ROS_INFO(\"${class_name}::${topic_name}Feedback: Got Feedback!\");" line="${line}${aux_line}\n\n" @@ -383,7 +395,7 @@ function create_action_client line="${line}${aux_line}\n" aux_line="\ \ }" line="${line}${aux_line}\n" - aux_line="\ \ ${driver_alg}_.unlock();" + aux_line="\ \ this->${driver_alg}_.unlock();" line="${line}${aux_line}\n" aux_line="}" line="${line}${aux_line}\n" @@ -400,13 +412,15 @@ function create_action_client line="${line}${aux_line}\n" aux_line="\ \ // other thread (MainNodeThread)." line="${line}${aux_line}\n" + aux_line="\ \ bool ok;" + line="${line}${aux_line}\n" aux_line="\ \ // this->${driver_alg}_.unlock();" line="${line}${aux_line}\n" aux_line="\ \ if(${client_name}.isServerConnected())" line="${line}${aux_line}\n" aux_line="\ \ {" line="${line}${aux_line}\n" - aux_line="\ \ \ \ //ROS_DEBUG(\"${class_name}::${topic_name}MakeActionRequest: Server is Available!\");" + aux_line="\ \ \ \ //ROS_INFO(\"${class_name}::${topic_name}MakeActionRequest: Server is Available!\");" line="${line}${aux_line}\n" aux_line="\ \ \ \ //send a goal to the action server" line="${line}${aux_line}\n" @@ -420,9 +434,9 @@ function create_action_client line="${line}${aux_line}\n" aux_line="\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ boost::bind(&${class_name}::${topic_name}Feedback, this, _1));" line="${line}${aux_line}\n" - aux_line="\ \ \ \ // this->${driver_alg}_.lock();" + aux_line="\ \ \ \ ROS_INFO(\"${class_name}::${topic_name}MakeActionRequest: Goal Sent.\");" line="${line}${aux_line}\n" - aux_line="\ \ \ \ // ROS_DEBUG(\"${class_name}::${topipc_name}MakeActionRequest: Goal Sent.\");" + aux_line="\ \ \ \ // ok=true;" line="${line}${aux_line}\n" aux_line="\ \ \ \ return true;" line="${line}${aux_line}\n" @@ -432,14 +446,18 @@ function create_action_client line="${line}${aux_line}\n" aux_line="\ \ {" line="${line}${aux_line}\n" - aux_line="\ \ \ \ // this->${driver_alg}_.lock();" + aux_line="\ \ \ \ ROS_ERROR(\"${class_name}::${topic_name}MakeActionRequest: action server is not connected. Check remap or server presence.\");" line="${line}${aux_line}\n" - aux_line="\ \ \ \ // ROS_DEBUG(\"${class_name}::${topic_name}MakeActionRequest: HRI server is not connected\");" + aux_line="\ \ \ \ // ok=false;" line="${line}${aux_line}\n" aux_line="\ \ \ \ return false;" line="${line}${aux_line}\n" aux_line="\ \ }" line="${line}${aux_line}\n" + aux_line="\ \ \ \ // this->${driver_alg}_.lock();" + line="${line}${aux_line}\n" + aux_line="\ \ \ \ return ok;" + line="${line}${aux_line}\n" aux_line="}" line="${line}${aux_line}\n" comment="\[action requests\]" diff --git a/libraries/create_action_server.sh b/libraries/create_action_server.sh old mode 100644 new mode 100755 index 7005269cbf77fcbe94b43b481521d531ff955b11..ec94ef2881006f00601a06d9b28b493efd7968dd --- a/libraries/create_action_server.sh +++ b/libraries/create_action_server.sh @@ -4,10 +4,10 @@ scripts_path=`echo "${IRI_ROS_SCRIPTS_PATH}"` if [[ -z "${scripts_path}" ]] then - echo "The scripts path environment varibale has not been defined. Please see the wiki documentation for instructions on how to create it." + echo "ERROR: The scripts path environment varibale has not been defined. Please see the wiki documentation for instructions on how to create it." exit -else - echo "The scripts path environment variable has been properly defined." +# else +# echo "The scripts path environment variable has been properly defined." fi source "${IRI_ROS_SCRIPTS_PATH}/libraries/scripts_library.sh" @@ -23,13 +23,13 @@ function check_action_server_files_integrity find_comment_in_file "${comment}" "${node_h}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[action server client headers\] from the header file ${node_h}" + kill_exit "ERROR: Missing \[action server client headers\] from the header file ${node_h}" fi comment="\[action server attributes\]" find_comment_in_file "${comment}" "${node_h}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[action server attributes\] from the header file ${node_h}" + kill_exit "ERROR: Missing \[action server attributes\] from the header file ${node_h}" fi # check the node.cpp file @@ -37,19 +37,19 @@ function check_action_server_files_integrity find_comment_in_file "${comment}" "${node_c}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[init action servers\] from the source file ${node_c}" + kill_exit "ERROR: Missing \[init action servers\] from the source file ${node_c}" fi comment="\[action callbacks\]" find_comment_in_file "${comment}" "${node_c}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[action callbacks\] from the source file ${node_c}" + kill_exit "ERROR: Missing \[action callbacks\] from the source file ${node_c}" fi comment="\[fill action structure and make request to the action server\]" find_comment_in_file "${comment}" "${node_c}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[fill action structure and make request to the action server\] from the source file ${node_c}" + kill_exit "ERROR: Missing \[fill action structure and make request to the action server\] from the source file ${node_c}" fi } @@ -77,187 +77,187 @@ function check_action_server_attributes_functions find_comment_in_file "${aux_line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "An ActionServer variable already exists with the same name in file ${node_h} line ${line_number}" + kill_exit "ERROR: An ActionServer variable already exists with the same name in file ${node_h} line ${line_number}" fi aux_line="void ${act_start}(const ${act_pkg}::${action_file}GoalConstPtr& goal);" find_comment_in_file "${aux_line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A start callback function already exists with the same name in file ${node_h} line ${line_number}" + kill_exit "ERROR: A start callback function already exists with the same name in file ${node_h} line ${line_number}" fi aux_line="void ${act_stop}(void);" find_comment_in_file "${aux_line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A stop callback function already exists with the same name in file ${node_h} line ${line_number}" + kill_exit "ERROR: A stop callback function already exists with the same name in file ${node_h} line ${line_number}" fi aux_line="bool ${act_finish}(void);" find_comment_in_file "${aux_line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "An is finished callback function already exists with the same name in file ${node_h} line ${line_number}" + kill_exit "ERROR: An is finished callback function already exists with the same name in file ${node_h} line ${line_number}" fi aux_line="bool ${act_succeed}(void);" find_comment_in_file "${aux_line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A has succeeded callback function already exists with the same name in file ${node_h} line ${line_number}" + kill_exit "ERROR: A has succeeded callback function already exists with the same name in file ${node_h} line ${line_number}" fi aux_line="void ${act_result}(${act_pkg}::${action_file}ResultPtr& result);" find_comment_in_file "${aux_line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A get result callback function already exists with the same name in file ${node_h} line ${line_number}" + kill_exit "ERROR: A get result callback function already exists with the same name in file ${node_h} line ${line_number}" fi aux_line="void ${act_feedback}(${act_pkg}::${action_file}FeedbackPtr& feedback);" find_comment_in_file "${aux_line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A get feedback callback function already exists with the same name in file ${node_h} line ${line_number}" + kill_exit "ERROR: A get feedback callback function already exists with the same name in file ${node_h} line ${line_number}" fi aux_line="bool ${topic_name}_active;" find_comment_in_file "${aux_line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "An active boolean already exists with the same name in file ${node_h} line ${line_number}" + kill_exit "ERROR: An active boolean already exists with the same name in file ${node_h} line ${line_number}" fi aux_line="bool ${topic_name}_succeeded;" find_comment_in_file "${aux_line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A success boolean already exists with the same name in file ${node_h} line ${line_number}" + kill_exit "ERROR: A success boolean already exists with the same name in file ${node_h} line ${line_number}" fi aux_line="bool ${topic_name}_finished;" find_comment_in_file "${aux_line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A finished boolean already exists with the same name in file ${node_h} line ${line_number}" + kill_exit "ERROR: A finished boolean already exists with the same name in file ${node_h} line ${line_number}" fi # check the node.cpp file - aux_line="${server_name}(public_node_handle_, \"${topic_name}\")" + aux_line="${server_name}(private_node_handle_, \"${topic_name}\")" find_comment_in_file "${aux_line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The constructor for the Action server is already called in file ${node_c} line ${line_number}" + kill_exit "ERROR: The constructor for the Action server is already called in file ${node_c} line ${line_number}" fi aux_line="${server_name}.registerStartCallback" find_comment_in_file "${aux_line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The registration of the start callback function is already present in file ${node_c} line ${line_number}" + kill_exit "ERROR: The registration of the start callback function is already present in file ${node_c} line ${line_number}" fi aux_line="${server_name}.registerStopCallback" find_comment_in_file "${aux_line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The registration of the stop callback function is already present in file ${node_c} line ${line_number}" + kill_exit "ERROR: The registration of the stop callback function is already present in file ${node_c} line ${line_number}" fi aux_line="${server_name}.registerIsFinishedCallback" find_comment_in_file "${aux_line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The registration of the is finished callback function is already present in file ${node_c} line ${line_number}" + kill_exit "ERROR: The registration of the is finished callback function is already present in file ${node_c} line ${line_number}" fi aux_line="${server_name}.registerHasSucceedCallback" find_comment_in_file "${aux_line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The registration of the has succeeded callback function is already present in file ${node_c} line ${line_number}" + kill_exit "ERROR: The registration of the has succeeded callback function is already present in file ${node_c} line ${line_number}" fi aux_line="${server_name}.registerGetResultCallback" find_comment_in_file "${aux_line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The registration of the get result callback function is already present in file ${node_c} line ${line_number}" + kill_exit "ERROR: The registration of the get result callback function is already present in file ${node_c} line ${line_number}" fi aux_line="${server_name}.registerGetFeedbackCallback" find_comment_in_file "${aux_line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The registration of the get feedback callback function is already present in file ${node_c} line ${line_number}" + kill_exit "ERROR: The registration of the get feedback callback function is already present in file ${node_c} line ${line_number}" fi aux_line="${server_name}.start();" find_comment_in_file "${aux_line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The activation of the action server is already done in file ${node_c} line ${line_number}" + kill_exit "ERROR: The activation of the action server is already done in file ${node_c} line ${line_number}" fi line="void ${class_name}::${act_start}(const ${act_pkg}::${action_file}GoalConstPtr& goal)" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The implementation of the start callback function is already present in file ${node_c} line ${line_number}" + kill_exit "ERROR: The implementation of the start callback function is already present in file ${node_c} line ${line_number}" fi line="void ${class_name}::${act_stop}(void)" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The implementation of the stop callback function is already present in file ${node_c} line ${line_number}" + kill_exit "ERROR: The implementation of the stop callback function is already present in file ${node_c} line ${line_number}" fi line="bool ${class_name}::${act_finish}(void)" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The implementation of the is finished callback function is already present in file ${node_c} line ${line_number}" + kill_exit "ERROR: The implementation of the is finished callback function is already present in file ${node_c} line ${line_number}" fi line="bool ${class_name}::${act_succeed}(void)" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The implementation of the has succeeded callback function is already present in file ${node_c} line ${line_number}" + kill_exit "ERROR: The implementation of the has succeeded callback function is already present in file ${node_c} line ${line_number}" fi line="void ${class_name}::${act_result}(${act_pkg}::${action_file}ResultPtr& result)" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The implementation of the get result callback function is already present in file ${node_c} line ${line_number}" + kill_exit "ERROR: The implementation of the get result callback function is already present in file ${node_c} line ${line_number}" fi line="void ${class_name}::${act_feedback}(${act_pkg}::${action_file}FeedbackPtr& feedback)" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The implementation of the get feedback callback function is already present in file ${node_c} line ${line_number}" + kill_exit "ERROR: The implementation of the get feedback callback function is already present in file ${node_c} line ${line_number}" fi aux_line="this->${topic_name}_active=false;" find_comment_in_file "${aux_line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The active variable of the action server is already initialized in file ${node_c} line ${line_number}" + kill_exit "ERROR: The active variable of the action server is already initialized in file ${node_c} line ${line_number}" fi aux_line="this->${topic_name}_succeeded=false;" find_comment_in_file "${aux_line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The success variable of the action server is already initialized in file ${node_c} line ${line_number}" + kill_exit "ERROR: The success variable of the action server is already initialized in file ${node_c} line ${line_number}" fi aux_line="this->${topic_name}_finished=false;" find_comment_in_file "${aux_line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The finished variable of the action server is already initialized in file ${node_c} line ${line_number}" + kill_exit "ERROR: The finished variable of the action server is already initialized in file ${node_c} line ${line_number}" fi } @@ -291,7 +291,7 @@ function create_action_server get_class_basename "${node_c}" if [[ -z ${class_name} ]] then - kill_exit "impossible to retrieve class basename" + kill_exit "ERROR: impossible to retrieve class basename" fi # echo "class_name=${class_name}" @@ -341,7 +341,7 @@ function create_action_server ################################################################################ #modify Node.cpp - line="${server_name}(public_node_handle_, \"${topic_name}\")" + line="${server_name}(private_node_handle_, \"${topic_name}\")" #check if ':' are needed comment="${class_name}::${class_name}(" @@ -549,7 +549,8 @@ function create_action_server old_string="iri_base_algorithm" fi new_string="${old_string}\ iri_action_server" - sed -i "s/${old_string}/${new_string}/g" "CMakeLists.txt" + sed -i -e "/find_package/ s/${old_string}/${new_string}/g" "CMakeLists.txt" + sed -i -e "/CATKIN_DEPENDS/ s/${old_string}/${new_string}/g" "CMakeLists.txt" fi ################################################################################ diff --git a/libraries/create_client.sh b/libraries/create_client.sh index 1ebb01723883d4db9c713a96bb013d9ac4125861..3d6a1add634115c14d8c2ecb8df54484f1004bf2 100755 --- a/libraries/create_client.sh +++ b/libraries/create_client.sh @@ -4,10 +4,10 @@ scripts_path=`echo "${IRI_ROS_SCRIPTS_PATH}"` if [[ -z "${scripts_path}" ]] then - echo "The scripts path environment varibale has not been defined. Please see the wiki documentation for instructions on how to create it." + echo "ERROR: The scripts path environment varibale has not been defined. Please see the wiki documentation for instructions on how to create it." exit -else - echo "The scripts path environment variable has been properly defined." +# else +# echo "The scripts path environment variable has been properly defined." fi source "${IRI_ROS_SCRIPTS_PATH}/libraries/scripts_library.sh" @@ -23,26 +23,26 @@ function check_client_file_integrity find_comment_in_file "${comment}" "${node_h}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[service client headers\] from the header file ${node_h}" + kill_exit "ERROR: Missing \[service client headers\] from the header file ${node_h}" fi comment="\[client attributes\]" find_comment_in_file "${comment}" "${node_h}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[client attributes\] from the header file ${node_h}" + kill_exit "ERROR: Missing \[client attributes\] from the header file ${node_h}" fi # chekc the node.cpp file comment="\[init clients\]" find_comment_in_file "${comment}" "${node_c}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[init clients\] from the header file ${node_c}" + kill_exit "ERROR: Missing \[init clients\] from the header file ${node_c}" fi comment="\[fill srv structure and make request to the server\]" find_comment_in_file "${comment}" "${node_c}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[fill srv structure and make request to the server\] from the header file ${node_c}" + kill_exit "ERROR: Missing \[fill srv structure and make request to the server\] from the header file ${node_c}" fi } @@ -61,28 +61,28 @@ function check_client_attributes_functions find_comment_in_file "${line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A service client with the same name is already declared in file ${node_h} line ${line_number}" + kill_exit "ERROR: A service client with the same name is already declared in file ${node_h} line ${line_number}" fi line="${srv_pkg}::${srv_file} ${topic_name}_srv_;" find_comment_in_file "${line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A service message with the same name is already declared in file ${node_h} line ${line_number}" + kill_exit "ERROR: A service message with the same name is already declared in file ${node_h} line ${line_number}" fi # check the node.cpp file - line="${client_name} = this->public_node_handle_.serviceClient<${srv_pkg}::${srv_file}>(\"${topic_name}\");" + line="${client_name} = this->private_node_handle_.serviceClient<${srv_pkg}::${srv_file}>(\"${topic_name}\");" echo "${line}" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A service client with the same name is already initialized in file ${node_c} line ${line_number}" + kill_exit "ERROR: A service client with the same name is already initialized in file ${node_c} line ${line_number}" fi line="if (${client_name}.call(${topic_name}_srv_))" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A service with the same name is already called in file ${node_c} line ${line_number}" + kill_exit "ERROR: A service with the same name is already called in file ${node_c} line ${line_number}" fi } @@ -105,7 +105,7 @@ function create_client get_class_basename "${node_c}" if [[ -z ${class_name} ]] then - kill_exit "impossible to retrieve class basename" + kill_exit "ERROR: impossible to retrieve class basename" fi # echo "class_name=${class_name}" @@ -134,19 +134,21 @@ function create_client ################################################################################ #modify Node.cpp - line="${client_name} = this->public_node_handle_.serviceClient<${srv_pkg}::${srv_file}>(\"${topic_name}\");" + line="${client_name} = this->private_node_handle_.serviceClient<${srv_pkg}::${srv_file}>(\"${topic_name}\");" comment="\[init clients\]" add_line_to_file "\ \ ${line}\n" "${comment}" "${node_c}" aux_line="//${topic_name}_srv_.request.data = my_var;" line="\ \ ${aux_line}\n" - aux_line="\ \ //ROS_INFO(\"${class_name}:: Sending New Request!\");" + aux_line="\ \ //ROS_INFO(\"${class_name}:: Calling service ${client_name}!\");" line="${line}${aux_line}\n" aux_line="\ \ //if (${client_name}.call(${topic_name}_srv_))" line="${line}${aux_line}\n" aux_line="\ \ //{" line="${line}${aux_line}\n" - aux_line="\ \ \ \ //ROS_INFO(\"${class_name}:: Response: %s\", ${topic_name}_srv_.response.result);" + aux_line="\ \ //\ \ ROS_INFO(\"${class_name}:: ${client_name} received a response from service server\");" + line="${line}${aux_line}\n" + aux_line="\ \ ////\ \ ROS_INFO(\"${class_name}:: Response: %s\", ${topic_name}_srv_.response.somestringfield.c_str());" line="${line}${aux_line}\n" aux_line="\ \ //}" line="${line}${aux_line}\n" @@ -154,7 +156,7 @@ function create_client line="${line}${aux_line}\n" aux_line="\ \ //{" line="${line}${aux_line}\n" - aux_line="\ \ \ \ //ROS_INFO(\"${class_name}:: Failed to Call Server on topic ${topic_name} \");" + aux_line="\ \ //\ \ ROS_INFO(\"${class_name}:: Failed to call service on topic %s\",this->${topic_name}_client_.getService().c_str());" line="${line}${aux_line}\n" aux_line="\ \ //}" line="${line}${aux_line}\n" diff --git a/libraries/create_publisher.sh b/libraries/create_publisher.sh index 0592145343190c902b539439cd15932593698d97..437972a2bac2e85858e7345f680d3f7c4eb8d87e 100755 --- a/libraries/create_publisher.sh +++ b/libraries/create_publisher.sh @@ -4,10 +4,10 @@ scripts_path=`echo "${IRI_ROS_SCRIPTS_PATH}"` if [[ -z "${scripts_path}" ]] then - echo "The scripts path environment variable has not been defined. Please see the wiki documentation for instructions on how to create it." + echo "ERROR: The scripts path environment variable has not been defined. Please see the wiki documentation for instructions on how to create it." exit -else - echo "The scripts path environment variable has been properly defined." +# else +# echo "The scripts path environment variable has been properly defined." fi source "${IRI_ROS_SCRIPTS_PATH}/libraries/scripts_library.sh" @@ -23,13 +23,13 @@ function check_publisher_file_integrity find_comment_in_file "${comment}" "${node_h}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[publisher subscriber headers\] from the header file ${node_h}" + kill_exit "ERROR: Missing \[publisher subscriber headers\] from the header file ${node_h}" fi comment="\[publisher attributes\]" find_comment_in_file "${comment}" "${node_h}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[publisher attributes\] from the header file ${node_h}" + kill_exit "ERROR: Missing \[publisher attributes\] from the header file ${node_h}" fi # check the node.cpp file @@ -37,20 +37,20 @@ function check_publisher_file_integrity find_comment_in_file "${comment}" "${node_c}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[init publishers\] from the header file ${node_c}" + kill_exit "ERROR: Missing \[init publishers\] from the header file ${node_c}" fi comment="\[fill msg structures\]" find_comment_in_file "${comment}" "${node_c}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[fill msg structures\] from the header file ${node_c}" + kill_exit "ERROR: Missing \[fill msg structures\] from the header file ${node_c}" fi comment="\[publish messages\]" find_comment_in_file "${comment}" "${node_c}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[publish messages\] from the header file ${node_c}" + kill_exit "ERROR: Missing \[publish messages\] from the header file ${node_c}" fi } @@ -72,20 +72,20 @@ function check_publisher_attributes_functions find_comment_in_file "${line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A publisher with the same name is already declared in file ${node_h} line ${line_number}" + kill_exit "ERROR: A publisher with the same name is already declared in file ${node_h} line ${line_number}" fi line="camera_info_manager::CameraInfoManager ${topic_name}_camera_manager;" find_comment_in_file "${line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A camera manager with the same name is already declared in file ${node_h} line ${line_number}" + kill_exit "ERROR: A camera manager with the same name is already declared in file ${node_h} line ${line_number}" fi else line="ros::Publisher ${publisher_name};" find_comment_in_file "${line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A publisher with the same name is already declared in file ${node_h} line ${line_number}" + kill_exit "ERROR: A publisher with the same name is already declared in file ${node_h} line ${line_number}" fi fi @@ -93,7 +93,7 @@ function check_publisher_attributes_functions find_comment_in_file "${line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A message variable with the same name is already declared in file ${node_h} line ${line_number}" + kill_exit "ERROR: A message variable with the same name is already declared in file ${node_h} line ${line_number}" fi # check the node.cpp file @@ -103,50 +103,50 @@ function check_publisher_attributes_functions find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A camera manager with the same name is already initialized in file ${node_c} line ${line_number}" + kill_exit "ERROR: A camera manager with the same name is already initialized in file ${node_c} line ${line_number}" fi line="this->${publisher_name} = this->it.advertiseCamera(\"${topic_name}/image_raw\", ${buffer});" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A topic with the same name is already advertised in file ${node_c} line ${line_number}" + kill_exit "ERROR: A topic with the same name is already advertised in file ${node_c} line ${line_number}" fi line="this->${topic_name}_camera_manager.validateURL(${topic_name}_cal_file)" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The calibration file URL for a camera manager with the same name is already validated in file ${node_c} line ${line_number}" + kill_exit "ERROR: The calibration file URL for a camera manager with the same name is already validated in file ${node_c} line ${line_number}" fi line="this->${topic_name}_camera_manager.loadCameraInfo(${topic_name}_cal_file)" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The camera information for a camera manager with the same name is already loaded in file ${node_c} line ${line_number}" + kill_exit "ERROR: The camera information for a camera manager with the same name is already loaded in file ${node_c} line ${line_number}" fi line="sensor_msgs::CameraInfo ${topic_name}_camera_info=this->${topic_name}_camera_manager.getCameraInfo();" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "The camera info structure for a topic with the same name is already initialized in file ${node_c} line ${line_number}" + kill_exit "ERROR: The camera info structure for a topic with the same name is already initialized in file ${node_c} line ${line_number}" fi line="//this->${publisher_name}.publish(this->${topic_name}_${msg_file}_msg_,${topic_name}_camera_info);" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A message with the same name is already published in file ${node_c} line ${line_number}" + kill_exit "ERROR: A message with the same name is already published in file ${node_c} line ${line_number}" fi else - line="this->${publisher_name} = this->public_node_handle_.advertise<${msg_pkg}::${msg_file}>(\"${topic_name}\", ${buffer});" + line="this->${publisher_name} = this->private_node_handle_.advertise<${msg_pkg}::${msg_file}>(\"${topic_name}\", ${buffer});" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A publisher with the same name is already advertised in file ${node_c} line ${line_number}" + kill_exit "ERROR: A publisher with the same name is already advertised in file ${node_c} line ${line_number}" fi line="this->${publisher_name}.publish(this->${topic_name}_${msg_file}_msg_);" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A message with the same name is already published in file ${node_c} line ${line_number}" + kill_exit "ERROR: A message with the same name is already published in file ${node_c} line ${line_number}" fi fi } @@ -174,7 +174,7 @@ function create_publisher get_class_basename "${node_c}" if [[ -z ${class_name} ]] then - kill_exit "impossible to retrieve class basename" + kill_exit "ERROR: impossible to retrieve class basename" fi #check files integrity before making any changes @@ -251,7 +251,7 @@ function create_publisher # modify Node.cpp # if [[ "${msg_file}" = "Image" ]] then - line="it(this->public_node_handle_)" + line="it(this->private_node_handle_)" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "false" ]] then @@ -317,7 +317,7 @@ function create_publisher line="${line}${aux_line}\n" aux_line="\ \ //std::string ${topic_name}_cal_file;" line="${line}${aux_line}\n" - aux_line="\ \ //public_node_handle_.param<std::string>(\"<cal_file_param>\",${topic_name}_cal_file,\"\");" + aux_line="\ \ //private_node_handle_.param<std::string>(\"<cal_file_param>\",${topic_name}_cal_file,\"\");" line="${line}${aux_line}\n" aux_line="\ \ //if(this->${topic_name}_camera_manager.validateURL(${topic_name}_cal_file))" line="${line}${aux_line}\n" @@ -359,7 +359,7 @@ function create_publisher comment="\[publish messages\]" add_line_to_file "\ \ ${line}" "${comment}" "${node_c}" else - line="this->${publisher_name} = this->public_node_handle_.advertise<${msg_pkg}::${msg_file}>(\"${topic_name}\", ${buffer});" + line="this->${publisher_name} = this->private_node_handle_.advertise<${msg_pkg}::${msg_file}>(\"${topic_name}\", ${buffer});" comment="\[init publishers\]" add_line_to_file " ${line}" "${comment}" "${node_c}" aux_line="// Uncomment the following line to publish the topic message" diff --git a/libraries/create_server.sh b/libraries/create_server.sh index 2bd88752eba7e3b64f4ac7871fe0ebea927e936c..5eb7db04047a34d80175fc1ed93ee2f2bd797683 100755 --- a/libraries/create_server.sh +++ b/libraries/create_server.sh @@ -4,10 +4,10 @@ scripts_path=`echo "${IRI_ROS_SCRIPTS_PATH}"` if [[ -z "${scripts_path}" ]] then - echo "The scripts path environment variable has not been defined. Please see the wiki documentation for instructions on how to create it." + echo "ERROR: The scripts path environment variable has not been defined. Please see the wiki documentation for instructions on how to create it." exit -else - echo "The scripts path environment variable has been properly defined." +# else +# echo "The scripts path environment variable has been properly defined." fi source "${IRI_ROS_SCRIPTS_PATH}/libraries/scripts_library.sh" @@ -23,13 +23,13 @@ function check_server_file_integrity find_comment_in_file "${comment}" "${node_h}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[service client headers\] from the header file ${node_h}" + kill_exit "ERROR: Missing \[service client headers\] from the header file ${node_h}" fi comment="\[service attributes\]" find_comment_in_file "${comment}" "${node_h}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[service attributes\] from the header file ${node_h}" + kill_exit "ERROR: Missing \[service attributes\] from the header file ${node_h}" fi # check the node.cpp file @@ -37,19 +37,19 @@ function check_server_file_integrity find_comment_in_file "${comment}" "${node_c}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[init services\] from the header file ${node_c}" + kill_exit "ERROR: Missing \[init services\] from the header file ${node_c}" fi comment="\[service callbacks\]" find_comment_in_file "${comment}" "${node_c}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[service callbacks\] from the header file ${node_c}" + kill_exit "ERROR: Missing \[service callbacks\] from the header file ${node_c}" fi comment="\[free dynamic memory\]" find_comment_in_file "${comment}" "${node_c}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[free dynamic memory\] from the header file ${node_c}" + kill_exit "ERROR: Missing \[free dynamic memory\] from the header file ${node_c}" fi } @@ -71,69 +71,69 @@ function check_server_attributes_functions find_comment_in_file "${line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A service server with the same name is already declared in file ${node_h} line ${line_number}" + kill_exit "ERROR: A service server with the same name is already declared in file ${node_h} line ${line_number}" fi line="bool ${callback}(${srv_pkg}::${srv_file}::Request &req, ${srv_pkg}::${srv_file}::Response &res);" find_comment_in_file "${line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A service callback function with the same name is already declared in file ${node_h} line ${line_number}" + kill_exit "ERROR: A service callback function with the same name is already declared in file ${node_h} line ${line_number}" fi line="pthread_mutex_t ${mutex_name};" find_comment_in_file "${line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A mutex with the same name is already declared in file ${node_h} line ${line_number}" + kill_exit "ERROR: A mutex with the same name is already declared in file ${node_h} line ${line_number}" fi line="void ${mutex_name}enter(void);" find_comment_in_file "${line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A mutex enter function with the same name is already declared in file ${node_h} line ${line_number}" + kill_exit "ERROR: A mutex enter function with the same name is already declared in file ${node_h} line ${line_number}" fi line="void ${mutex_name}exit(void);" find_comment_in_file "${line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A mutex exit function with the same name is already declared in file ${node_h} line ${line_number}" + kill_exit "ERROR: A mutex exit function with the same name is already declared in file ${node_h} line ${line_number}" fi # check the node.cpp file - line="this->${server_name} = this->public_node_handle_.advertiseService(\"${topic_name}\", &${class_name}::${callback}, this);" + line="this->${server_name} = this->private_node_handle_.advertiseService(\"${topic_name}\", &${class_name}::${callback}, this);" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A service server with the same name is already initialized in file ${node_c} line ${line_number}" + kill_exit "ERROR: A service server with the same name is already initialized in file ${node_c} line ${line_number}" fi line="pthread_mutex_init(&this->${mutex_name},NULL);" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A mutex with the same name is already initialized in file ${node_c} line ${line_number}" + kill_exit "ERROR: A mutex with the same name is already initialized in file ${node_c} line ${line_number}" fi line="pthread_mutex_destroy(&this->${mutex_name});" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A mutex with the same name is already destroyed in file ${node_c} line ${line_number}" + kill_exit "ERROR: A mutex with the same name is already destroyed in file ${node_c} line ${line_number}" fi aux_line="bool ${class_name}::${callback}(${srv_pkg}::${srv_file}::Request &req, ${srv_pkg}::${srv_file}::Response &res)" find_comment_in_file "${aux_line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A service callback function with the same name is already implemented in file ${node_c} line ${line_number}" + kill_exit "ERROR: A service callback function with the same name is already implemented in file ${node_c} line ${line_number}" fi line="void ${class_name}::${mutex_name}enter(void)" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A mutex enter function with the same name is already implemented in file ${node_c} line ${line_number}" + kill_exit "ERROR: A mutex enter function with the same name is already implemented in file ${node_c} line ${line_number}" fi line="void ${class_name}::${mutex_name}exit(void)" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A mutex exit function with the same name is already implemented in file ${node_c} line ${line_number}" + kill_exit "ERROR: A mutex exit function with the same name is already implemented in file ${node_c} line ${line_number}" fi } @@ -158,7 +158,7 @@ function create_server get_class_basename "${node_c}" if [[ -z ${class_name} ]] then - kill_exit "impossible to retrieve class basename" + kill_exit "ERROR: impossible to retrieve class basename" fi # echo "class_name=${class_name}" @@ -192,7 +192,7 @@ function create_server ################################################################################ #modify Node.cpp - aux_line="this->${server_name} = this->public_node_handle_.advertiseService(\"${topic_name}\", &${class_name}::${callback}, this);" + aux_line="this->${server_name} = this->private_node_handle_.advertiseService(\"${topic_name}\", &${class_name}::${callback}, this);" line="\ \ ${aux_line}\n" aux_line="pthread_mutex_init(&this->${mutex_name},NULL);\n" line="${line}\ \ ${aux_line}" diff --git a/libraries/create_subscriber.sh b/libraries/create_subscriber.sh index 325f418ed2402f4d96e2079d22e6860b91600c77..1ebb5aef7baf10bd7e7aa230888632690247a3c4 100755 --- a/libraries/create_subscriber.sh +++ b/libraries/create_subscriber.sh @@ -4,10 +4,10 @@ scripts_path=`echo "${IRI_ROS_SCRIPTS_PATH}"` if [[ -z "${scripts_path}" ]] then - echo "The scripts path environment variable has not been defined. Please see the wiki documentation for instructions on how to create it." + echo "ERROR: The scripts path environment variable has not been defined. Please see the wiki documentation for instructions on how to create it." exit -else - echo "The scripts path environment variable has been properly defined." +# else +# echo "The scripts path environment variable has been properly defined." fi source "${IRI_ROS_SCRIPTS_PATH}/libraries/scripts_library.sh" @@ -23,13 +23,13 @@ function check_subscriber_file_integrity find_comment_in_file "${comment}" "${node_h}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[publisher subscriber headers\] from the header file ${node_h}" + kill_exit "ERROR: Missing \[publisher subscriber headers\] from the header file ${node_h}" fi comment="\[subscriber attributes\]" find_comment_in_file "${comment}" "${node_h}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[subscriber attributes\] from the header file ${node_h}" + kill_exit "ERROR: Missing \[subscriber attributes\] from the header file ${node_h}" fi # check node.cpp file @@ -37,19 +37,19 @@ function check_subscriber_file_integrity find_comment_in_file "${comment}" "${node_c}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[init subscribers\] from the header file ${node_c}" + kill_exit "ERROR: Missing \[init subscribers\] from the header file ${node_c}" fi comment="\[subscriber callbacks\]" find_comment_in_file "${comment}" "${node_c}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[subscriber callbacks\] from the header file ${node_c}" + kill_exit "ERROR: Missing \[subscriber callbacks\] from the header file ${node_c}" fi comment="\[free dynamic memory\]" find_comment_in_file "${comment}" "${node_c}" if [[ "${comment_found}" = "false" ]] then - kill_exit "Missing \[free dynamic memory\] from the header file ${node_c}" + kill_exit "ERROR: Missing \[free dynamic memory\] from the header file ${node_c}" fi } @@ -74,27 +74,27 @@ function check_subscriber_attributes_functions find_comment_in_file "${line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A subscriber with the same name is already declared in file ${node_h} line ${line_number}" + kill_exit "ERROR: A subscriber with the same name is already declared in file ${node_h} line ${line_number}" fi line="void ${callback}(const ${msg_pkg}::${msg_file}::ConstPtr& msg,const sensor_msgs::CameraInfoConstPtr& info);" find_comment_in_file "${line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A subscriber callback function with the same name is already declared in file ${node_h} line ${line_number}" + kill_exit "ERROR: A subscriber callback function with the same name is already declared in file ${node_h} line ${line_number}" fi else line="ros::Subscriber ${subscriber_name};" find_comment_in_file "${line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A subscriber with the same name is already declared in file ${node_h} line ${line_number}" + kill_exit "ERROR: A subscriber with the same name is already declared in file ${node_h} line ${line_number}" fi line="void ${callback}(const ${msg_pkg}::${msg_file}::ConstPtr& msg);" find_comment_in_file "${line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A subscriber callback function with the same name is already declared in file ${node_h} line ${line_number}" + kill_exit "ERROR: A subscriber callback function with the same name is already declared in file ${node_h} line ${line_number}" fi fi @@ -102,21 +102,21 @@ function check_subscriber_attributes_functions find_comment_in_file "${line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A mutex with the same name is already declared in file ${node_h} line ${line_number}" + kill_exit "ERROR: A mutex with the same name is already declared in file ${node_h} line ${line_number}" fi line="void ${mutex_name}enter(void);" find_comment_in_file "${line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A mutex enter function with the same name is already declared in file ${node_h} line ${line_number}" + kill_exit "ERROR: A mutex enter function with the same name is already declared in file ${node_h} line ${line_number}" fi line="void ${mutex_name}exit(void);" find_comment_in_file "${line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A mutex exit function with the same name is already declared in file ${node_h} line ${line_number}" + kill_exit "ERROR: A mutex exit function with the same name is already declared in file ${node_h} line ${line_number}" fi # check node.cpp file @@ -126,14 +126,14 @@ function check_subscriber_attributes_functions find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A subscriber with the same name is already subscribed in file ${node_c} line ${line_number}" + kill_exit "ERROR: A subscriber with the same name is already subscribed in file ${node_c} line ${line_number}" fi else - line="this->${subscriber_name} = this->public_node_handle_.subscribe(\"${topic_name}\", ${buffer}, &${class_name}::${callback}, this);" + line="this->${subscriber_name} = this->private_node_handle_.subscribe(\"${topic_name}\", ${buffer}, &${class_name}::${callback}, this);" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A subscriber with the same name is already subscribed in file ${node_c} line ${line_number}" + kill_exit "ERROR: A subscriber with the same name is already subscribed in file ${node_c} line ${line_number}" fi fi @@ -141,14 +141,14 @@ function check_subscriber_attributes_functions find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A mutex with the same name is already initialized in file ${node_c} line ${line_number}" + kill_exit "ERROR: A mutex with the same name is already initialized in file ${node_c} line ${line_number}" fi line="pthread_mutex_destroy(&this->${mutex_name});" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A mutex with the same name is already destroyed in file ${node_c} line ${line_number}" + kill_exit "ERROR: A mutex with the same name is already destroyed in file ${node_c} line ${line_number}" fi #look if callback is already defined in file @@ -158,27 +158,27 @@ function check_subscriber_attributes_functions find_comment_in_file "${aux_line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A subscriber callback function with the same name is already implemented in file ${node_c} line ${line_number}" + kill_exit "ERROR: A subscriber callback function with the same name is already implemented in file ${node_c} line ${line_number}" fi else aux_line="void ${class_name}::${callback}(const ${msg_pkg}::${msg_file}::ConstPtr& msg)" find_comment_in_file "${aux_line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A subscriber callback function with the same name is already implemented in file ${node_c} line ${line_number}" + kill_exit "ERROR: A subscriber callback function with the same name is already implemented in file ${node_c} line ${line_number}" fi fi line="void ${class_name}::${mutex_name}enter(void)" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A mutex enter function with the same name is already implemented in file ${node_c} line ${line_number}" + kill_exit "ERROR: A mutex enter function with the same name is already implemented in file ${node_c} line ${line_number}" fi line="void ${class_name}::${mutex_name}exit(void)" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A mutex exit function with the same name is already implemented in file ${node_c} line ${line_number}" + kill_exit "ERROR: A mutex exit function with the same name is already implemented in file ${node_c} line ${line_number}" fi } @@ -207,7 +207,7 @@ function create_subscriber get_class_basename "${node_c}" if [[ -z ${class_name} ]] then - kill_exit "impossible to retrieve class basename" + kill_exit "ERROR: impossible to retrieve class basename" fi # echo "class_name=${class_name}" @@ -282,7 +282,7 @@ function create_subscriber # modify Node.cpp # if [[ "${msg_file}" = "Image" ]] then - line="it(this->public_node_handle_)" + line="it(this->private_node_handle_)" find_comment_in_file "${line}" "${node_c}" if [[ "${comment_found}" = "false" ]] then @@ -316,7 +316,7 @@ function create_subscriber aux_line="this->${subscriber_name} = this->it.subscribeCamera(\"${topic_name}/image_raw\", ${buffer}, &${class_name}::${callback}, this);" line="${aux_line}\n" else - aux_line="this->${subscriber_name} = this->public_node_handle_.subscribe(\"${topic_name}\", ${buffer}, &${class_name}::${callback}, this);" + aux_line="this->${subscriber_name} = this->private_node_handle_.subscribe(\"${topic_name}\", ${buffer}, &${class_name}::${callback}, this);" line="${aux_line}\n" fi aux_line="\ \ pthread_mutex_init(&this->${mutex_name},NULL);" diff --git a/libraries/create_tf_broadcaster.sh b/libraries/create_tf_broadcaster.sh new file mode 100755 index 0000000000000000000000000000000000000000..b8992bd1601fdccdf46d0e6893219314fc4052f6 --- /dev/null +++ b/libraries/create_tf_broadcaster.sh @@ -0,0 +1,188 @@ +#!/bin/bash + +# check wether the scripts path environment variable has been defined +scripts_path=`echo "${IRI_ROS_SCRIPTS_PATH}"` +if [[ -z "${scripts_path}" ]] +then + echo "ERROR: The scripts path environment variable has not been defined. Please see the wiki documentation for instructions on how to create it." + exit +# else +# echo "The scripts path environment variable has been properly defined." +fi + +source "${IRI_ROS_SCRIPTS_PATH}/libraries/scripts_library.sh" + +function check_publisher_file_integrity +{ + local node_h=$1 + local node_c=$2 + local comment="" + + # check the node.h file + comment="\[publisher subscriber headers\]" + find_comment_in_file "${comment}" "${node_h}" + if [[ "${comment_found}" = "false" ]] + then + kill_exit "ERROR: Missing \[publisher subscriber headers\] from the header file ${node_h}" + fi + comment="\[publisher attributes\]" + find_comment_in_file "${comment}" "${node_h}" + if [[ "${comment_found}" = "false" ]] + then + kill_exit "ERROR: Missing \[publisher attributes\] from the header file ${node_h}" + fi + + # check the node.cpp file + comment="\[init publishers\]" + find_comment_in_file "${comment}" "${node_c}" + if [[ "${comment_found}" = "false" ]] + then + kill_exit "ERROR: Missing \[init publishers\] from the header file ${node_c}" + fi + comment="\[fill msg structures\]" + find_comment_in_file "${comment}" "${node_c}" + if [[ "${comment_found}" = "false" ]] + then + kill_exit "ERROR: Missing \[fill msg structures\] from the header file ${node_c}" + fi + + comment="\[publish messages\]" + find_comment_in_file "${comment}" "${node_c}" + if [[ "${comment_found}" = "false" ]] + then + kill_exit "ERROR: Missing \[publish messages\] from the header file ${node_c}" + fi +} + +function check_publisher_attributes_functions +{ + local node_h=$1 + local node_c=$2 + local broadcaster_name=$3 + local line="" + + # check the node.h file + line="tf::TransformBroadcaster ${broadcaster_name};" + find_comment_in_file "${line}" "${node_h}" + if [[ "${comment_found}" = "true" ]] + then + kill_exit "ERROR: A TF broadcaster with the same name is already declared in file ${node_h} line ${line_number}" + fi + + line="geometry_msgs::TransformStampd transform_msg_;" + find_comment_in_file "${line}" "${node_h}" + if [[ "${comment_found}" = "true" ]] + then + kill_exit "ERROR: A message variable with the same name is already declared in file ${node_h} line ${line_number}" + fi + + # check the node.cpp file + line="this->${broadcaster_name}.sendTransform(this->transform_msg_);" + find_comment_in_file "${line}" "${node_c}" + if [[ "${comment_found}" = "true" ]] + then + kill_exit "ERROR: A message with the same name is already published in file ${node_c} line ${line_number}" + fi +} + +function create_tf_broadcaster +{ + #read input params + local ros_pkg=$1 + local node_h=$2 + local node_c=$3 + local driver_alg=$4 + local broadcaster_name="tf_broadcaster_" + local line="" + local old_line="" + local aux_line="" + local comment="" + local old_string="" + local new_string="" + + #get class basename + get_class_basename "${node_c}" + if [[ -z ${class_name} ]] + then + kill_exit "ERROR: impossible to retrieve class basename" + fi + + #check files integrity before making any changes + check_package_file_integrity "${driver_alg}" + check_cmakelists_file_integrity "${driver_alg}" + check_publisher_file_integrity "${node_h}" "${node_c}" + check_publisher_attributes_functions "${node_h}" "${node_c}" "${broadcaster_name}" + +################################################################################ +# modify Node.h # + + #look for include files and add them if are not already there + line="#include <tf/transform_broadcaster.h>" + comment="\[publisher subscriber headers\]" + add_line_to_file "${line}" "${comment}" "${node_h}" + + # add the message type variable + aux_line="geometry_msgs::TransformStamped transform_msg_;" + line="\ \ \ \ ${aux_line}\n" + comment="\[publisher attributes\]" + add_line_to_file "${line}" "${comment}" "${node_h}" + + aux_line="tf::TransformBroadcaster tf_broadcaster_;" + line="\ \ \ \ ${aux_line}" + comment="\[publisher attributes\]" + add_line_to_file "${line}" "${comment}" "${node_h}" + + +################################################################################ +# modify Node.cpp # + + comment="\[publish messages\]" + + line="\n" + aux_line="/*" + line="${line}\ \ ${aux_line}\n" + aux_line="//tf_broadcaster example" + line="${line}\ \ ${aux_line}\n" + aux_line="this->transform_msg_.header.stamp = ros::Time::now();" + line="${line}\ \ ${aux_line}\n" + aux_line="this->transform_msg_.header.frame_id = \"parent_frame\";" + line="${line}\ \ ${aux_line}\n" + aux_line="this->transform_msg_.child_frame_id = \"child_frame\";" + line="${line}\ \ ${aux_line}\n" + aux_line="geometry_msgs::Transform t;" + line="${line}\ \ ${aux_line}\n" + aux_line="t.translation.x = 0.0;" + line="${line}\ \ ${aux_line}\n" + aux_line="t.translation.y = 0.0;" + line="${line}\ \ ${aux_line}\n" + aux_line="t.translation.z = 0.0;" + line="${line}\ \ ${aux_line}\n" + aux_line="t.rotation = tf::createQuaternionMsgFromYaw(0.0);" + line="${line}\ \ ${aux_line}\n" + aux_line="this->transform_msg_.transform = t;" + line="${line}\ \ ${aux_line}\n" + aux_line="this->tf_broadcaster_.sendTransform(this->transform_msg_);" + line="${line}\ \ ${aux_line}\n" + aux_line="///tf_broadcaster example" + line="${line}\ \ ${aux_line}\n" + aux_line="*/" + line="${line}\ \ ${aux_line}\n" + + add_line_to_file " ${line}" "${comment}" "${node_c}" + +################################################################################ +# Modify package.xml +# check if the message package is the current ros package + + add_build_run_dependencies "${driver_alg}" "${ros_pkg}" "tf" + +################################################################################ +# modify the CMakeLists.txt file + + add_cmake_dependencies "${driver_alg}" "${ros_pkg}" "tf" + +################################################################################ +#compile + goto_catkin_workspace + catkin_make --only-pkg-with-deps ${ros_pkg} +} diff --git a/libraries/create_tf_listener.sh b/libraries/create_tf_listener.sh new file mode 100644 index 0000000000000000000000000000000000000000..88edae8c376390f6eb559469ca01a4fb8cb18144 --- /dev/null +++ b/libraries/create_tf_listener.sh @@ -0,0 +1,235 @@ +#!/bin/bash + +# check wether the scripts path environment variable has been defined +scripts_path=`echo "${IRI_ROS_SCRIPTS_PATH}"` +if [[ -z "${scripts_path}" ]] +then + echo "ERROR: The scripts path environment variable has not been defined. Please see the wiki documentation for instructions on how to create it." + exit +# else +# echo "The scripts path environment variable has been properly defined." +fi + +source "${IRI_ROS_SCRIPTS_PATH}/libraries/scripts_library.sh" + +function check_subscriber_file_integrity +{ + local node_h=$1 + local node_c=$2 + local comment="" + + # check node.h file + comment="\[publisher subscriber headers\]" + find_comment_in_file "${comment}" "${node_h}" + if [[ "${comment_found}" = "false" ]] + then + kill_exit "ERROR: Missing \[publisher subscriber headers\] from the header file ${node_h}" + fi + comment="\[subscriber attributes\]" + find_comment_in_file "${comment}" "${node_h}" + if [[ "${comment_found}" = "false" ]] + then + kill_exit "ERROR: Missing \[subscriber attributes\] from the header file ${node_h}" + fi + + # check node.cpp file + comment="\[init subscribers\]" + find_comment_in_file "${comment}" "${node_c}" + if [[ "${comment_found}" = "false" ]] + then + kill_exit "ERROR: Missing \[init subscribers\] from the header file ${node_c}" + fi + comment="\[subscriber callbacks\]" + find_comment_in_file "${comment}" "${node_c}" + if [[ "${comment_found}" = "false" ]] + then + kill_exit "ERROR: Missing \[subscriber callbacks\] from the header file ${node_c}" + fi + comment="\[free dynamic memory\]" + find_comment_in_file "${comment}" "${node_c}" + if [[ "${comment_found}" = "false" ]] + then + kill_exit "ERROR: Missing \[free dynamic memory\] from the header file ${node_c}" + fi +} + +function check_subscriber_attributes_functions +{ + local node_h=$1 + local node_c=$2 + local listener_name=$3 + local class_name=$4 + local line="" + + # check node.h file + + line="tf::TransformListener ${listener_name};" + find_comment_in_file "${line}" "${node_h}" + if [[ "${comment_found}" = "true" ]] + then + kill_exit "ERROR: A TF listener with the same name is already declared in file ${node_h} line ${line_number}" + fi + + # check node.cpp file + +} + +function create_tf_listener +{ + #read input params + local ros_pkg=$1 + local node_h=$2 + local node_c=$3 + local driver_alg=$4 + local listener_name="tf_listener_" + local line="" + local old_line="" + local aux_line="" + local comment="" + local old_string="" + local new_string="" + + #get class basename + get_class_basename "${node_c}" + if [[ -z ${class_name} ]] + then + kill_exit "ERROR: impossible to retrieve class basename" + fi +# echo "class_name=${class_name}" + + #check files integrity before making any changes + check_package_file_integrity "${driver_alg}" + check_cmakelists_file_integrity "${driver_alg}" + check_subscriber_file_integrity "${node_h}" "${node_c}" + check_subscriber_attributes_functions "${node_h}" "${node_c}" "${listener_name}" "${class_name}" + + local obj="" + if [[ "${driver_alg}" = "driver" ]] + then + obj="this->driver_." + else + obj="this->alg_." + fi + +################################################################################ +# modify Node.h # + + line="#include <tf/transform_listener.h>" + comment="\[publisher subscriber headers\]" + add_line_to_file "${line}" "${comment}" "${node_h}" + + + aux_line="tf::TransformListener ${listener_name};" + line="\ \ \ \ ${aux_line}\n" + comment="\[subscriber attributes\]" + add_line_to_file "${line}" "${comment}" "${node_h}" + +################################################################################ +# modify Node.cpp # + + comment="\[fill msg structures\]" + + line="\n" + aux_line="/*" + line="${line}\ \ ${aux_line}\n" + aux_line="//tf_listener example BEGIN" + line="${line}\ \ ${aux_line}\n" + aux_line="try{" + line="${line}\ \ ${aux_line}\n" + aux_line=" std::string target_frame = \"child_frame\";" + line="${line}\ \ ${aux_line}\n" + aux_line=" std::string source_frame = \"parent_frame\";" + line="${line}\ \ ${aux_line}\n" + aux_line=" ros::Time time = ros::Time::now();" + line="${line}\ \ ${aux_line}\n" + aux_line=" ros::Duration timeout = ros::Duration(0.1);" + line="${line}\ \ ${aux_line}\n" + aux_line=" ros::Duration polling_sleep_duration = ros::Duration(0.01);" + line="${line}\ \ ${aux_line}\n" + + aux_line=" ${obj}unlock();" + line="${line}\ \ ${aux_line}\n" + + aux_line=" bool tf_exists = this->tf_listener_.waitForTransform(target_frame, source_frame, time, timeout, polling_sleep_duration);" + line="${line}\ \ ${aux_line}\n" + + aux_line=" ${obj}lock();" + line="${line}\ \ ${aux_line}\n" + + aux_line=" if(tf_exists){" + line="${line}\ \ ${aux_line}\n" + aux_line=" geometry_msgs::PoseStamped stamped_pose_in;" + line="${line}\ \ ${aux_line}\n" + aux_line=" stamped_pose_in.header.stamp = time;" + line="${line}\ \ ${aux_line}\n" + aux_line=" stamped_pose_in.header.frame_id = source_frame;" + line="${line}\ \ ${aux_line}\n" + aux_line=" stamped_pose_in.pose.position.x = 1.0;" + line="${line}\ \ ${aux_line}\n" + aux_line=" stamped_pose_in.pose.position.y = 0.0;" + line="${line}\ \ ${aux_line}\n" + aux_line=" stamped_pose_in.pose.position.z = 0.0;" + line="${line}\ \ ${aux_line}\n" + aux_line=" stamped_pose_in.pose.orientation = tf::createQuaternionMsgFromYaw(0.0);" + line="${line}\ \ ${aux_line}\n" + aux_line=" ROS_INFO(\"Original pose in '%s' frame, with (x,y,z)=[%f,%f,%f], yaw=[%f]\", stamped_pose_in.header.frame_id.c_str(), stamped_pose_in.pose.position.x, stamped_pose_in.pose.position.y, stamped_pose_in.pose.position.z, tf::getYaw(stamped_pose_in.pose.orientation));" + line="${line}\ \ ${aux_line}\n" + aux_line=" geometry_msgs::PoseStamped stamped_pose_out;" + line="${line}\ \ ${aux_line}\n" + aux_line=" this->tf_listener_.transformPose(target_frame, stamped_pose_in, stamped_pose_out);" + line="${line}\ \ ${aux_line}\n" + aux_line=" ROS_INFO(\"Transformed pose in '%s' frame, with (x,y,z)=[%f,%f,%f], yaw=[%f]\", stamped_pose_out.header.frame_id.c_str(), stamped_pose_out.pose.position.x, stamped_pose_out.pose.position.y, stamped_pose_out.pose.position.z, tf::getYaw(stamped_pose_out.pose.orientation));" + line="${line}\ \ ${aux_line}\n" + aux_line=" ROS_INFO(\"---\");" + line="${line}\ \ ${aux_line}\n" + aux_line="\n" + line="${line}\ \ ${aux_line}\n" + aux_line=" tf::StampedTransform tf_parent_child;" + line="${line}\ \ ${aux_line}\n" + aux_line=" tf::Transform tf_parent_point, tf_child_point;" + line="${line}\ \ ${aux_line}\n" + aux_line=" this->tf_listener_.lookupTransform(source_frame, target_frame, time, tf_parent_child);" + line="${line}\ \ ${aux_line}\n" + aux_line=" tf_parent_point.setOrigin(tf::Vector3(stamped_pose_in.pose.position.x, stamped_pose_in.pose.position.y, stamped_pose_in.pose.position.z));" + line="${line}\ \ ${aux_line}\n" + aux_line=" tf_parent_point.setRotation(tf::Quaternion(stamped_pose_in.pose.orientation.x, stamped_pose_in.pose.orientation.y, stamped_pose_in.pose.orientation.z, stamped_pose_in.pose.orientation.w));" + line="${line}\ \ ${aux_line}\n" + aux_line=" tf_child_point = tf_parent_child.inverse()*tf_parent_point;" + line="${line}\ \ ${aux_line}\n" + aux_line=" ROS_INFO(\"Transformed pose in '%s' frame, with (x,y,z)=[%f,%f,%f], yaw=[%f]\", target_frame.c_str(), tf_child_point.getOrigin().x(), tf_child_point.getOrigin().y(), tf_child_point.getOrigin().z(), tf::getYaw(tf_child_point.getRotation()));" + line="${line}\ \ ${aux_line}\n" + aux_line=" ROS_INFO(\"---\");" + line="${line}\ \ ${aux_line}\n" + + aux_line=" }else{" + line="${line}\ \ ${aux_line}\n" + aux_line=" ROS_WARN(\"No transform found from '%s' to '%s'\", source_frame.c_str(), target_frame.c_str()); }" + line="${line}\ \ ${aux_line}\n" + aux_line="}catch (tf::TransformException &ex){" + line="${line}\ \ ${aux_line}\n" + aux_line=" ROS_ERROR(\"TF Exception: %s\",ex.what()); }" + line="${line}\ \ ${aux_line}\n" + aux_line="///tf_listener example END" + line="${line}\ \ ${aux_line}\n" + aux_line="*/" + line="${line}\ \ ${aux_line}\n" + + add_line_to_file " ${line}" "${comment}" "${node_c}" + +################################################################################ +# Modify package.xml +# check if the message package is the current ros package + + add_build_run_dependencies "${driver_alg}" "${ros_pkg}" "tf" + +################################################################################ +# modify the CMakeLists.txt file +# check if the message package is the current ros package + + add_cmake_dependencies "${driver_alg}" "${ros_pkg}" "tf" + +################################################################################ +#compile + goto_catkin_workspace + catkin_make --only-pkg-with-deps ${ros_pkg} +} diff --git a/libraries/scripts_library.sh b/libraries/scripts_library.sh old mode 100644 new mode 100755 index 24cd2c3f67726a6b90ef82b3e842a32467b1916f..ad1748396783eacf175d3ca63b184368fe927a52 --- a/libraries/scripts_library.sh +++ b/libraries/scripts_library.sh @@ -1,6 +1,6 @@ #!/bin/bash -source "${ROS_ROOT}/../rosbash/rosbash" || kill_exit "ROS_ROOT Not found, try to install ROS again" +source "${ROS_ROOT}/../rosbash/rosbash" || kill_exit "ERROR: ROS_ROOT Not found, try to install ROS again" # kill_exit # prints string in $1 and exits script @@ -17,21 +17,21 @@ function kill_exit # not been found exits the script function check_libraries { - echo "checking libraries ..." + echo "Checking libraries ..." if [[ -d "${IRI_ROS_SCRIPTS_PATH}/libraries" ]] then - pushd "${IRI_ROS_SCRIPTS_PATH}/libraries" - if [[ -e "create_server.sh" ]] && [[ -e "create_client.sh" ]] && [[ -e "create_publisher.sh" ]] && [[ -e "create_subscriber.sh" ]] + pushd "${IRI_ROS_SCRIPTS_PATH}/libraries" > /dev/null + if [[ -e "create_server.sh" ]] && [[ -e "create_client.sh" ]] && [[ -e "create_publisher.sh" ]] && [[ -e "create_subscriber.sh" ]] && [[ -e "create_tf_broadcaster.sh" ]] && [[ -e "create_tf_listener.sh" ]] then echo "All library files available" - popd + popd > /dev/null else - popd - kill_exit "Missing some script files, please download IRI_ROS scripts again, aborting ..." + popd > /dev/null + kill_exit "ERROR: Missing some script files, please download IRI_ROS scripts again, aborting ..." fi else - popd - kill_exit "Missing libraries folder, please download IRI_ROS scripts again, aborting ..." + popd > /dev/null + kill_exit "ERROR: Missing libraries folder, please download IRI_ROS scripts again, aborting ..." fi } @@ -40,38 +40,38 @@ function check_libraries # missing then exits the script function check_templates { - echo "checking driver templates ..." + echo "Checking driver templates ..." if [[ -d "${IRI_ROS_SCRIPTS_PATH}/driver_templates" ]] then - pushd "${IRI_ROS_SCRIPTS_PATH}/driver_templates" + pushd "${IRI_ROS_SCRIPTS_PATH}/driver_templates" > /dev/null if [[ -e "CMakeLists.txt" ]] && [[ -e "template_driver.cfg" ]] && [[ -e "template_driver.h" ]] && [[ -e "template_driver.cpp" ]] && [[ -e "template_driver_node.h" ]] && [[ -e "template_driver_node.cpp" ]] then echo "Driver template files available" - popd + popd > /dev/null else - popd - kill_exit "Missing some driver template files, please download IRI_ROS scripts again, aborting ..." + popd > /dev/null + kill_exit "ERROR: Missing some driver template files, please download IRI_ROS scripts again, aborting ..." fi else - popd - kill_exit "Missing driver templates folder, please download IRI_ROS scripts again, aborting ..." + popd > /dev/null + kill_exit "ERROR: Missing driver templates folder, please download IRI_ROS scripts again, aborting ..." fi - echo "checking algorithm templates ..." + echo "Checking algorithm templates ..." if [[ -d "${IRI_ROS_SCRIPTS_PATH}/algorithm_templates" ]] then - pushd "${IRI_ROS_SCRIPTS_PATH}/algorithm_templates" + pushd "${IRI_ROS_SCRIPTS_PATH}/algorithm_templates" > /dev/null if [[ -e "CMakeLists.txt" ]] && [[ -e "template_alg.cfg" ]] && [[ -e "template_alg.cpp" ]] && [[ -e "template_alg.h" ]] && [[ -e "template_alg_node.cpp" ]] && [[ -e "template_alg_node.h" ]] then echo "Generic algorithm template files available" - popd + popd > /dev/null else - popd - kill_exit "Missing some generic algorithm template files, please download IRI_ROS scripts again, aborting ..." + popd > /dev/null + kill_exit "ERROR: Missing some generic algorithm template files, please download IRI_ROS scripts again, aborting ..." fi else - popd - kill_exit "Missing generic algorithm templates folder, please download IRI_ROS scripts again, aborting ..." + popd > /dev/null + kill_exit "ERROR: Missing generic algorithm templates folder, please download IRI_ROS scripts again, aborting ..." fi } @@ -82,7 +82,7 @@ function check_package { if [[ -z $1 ]] then - kill_exit "check_package: missing input parameters" + kill_exit "ERROR: check_package: missing input parameters" fi #save "roscd pkg" output @@ -104,7 +104,7 @@ function create_basename { if [[ -z $1 ]] then - kill_exit "create_basename: missing input parameters" + kill_exit "ERROR: create_basename: missing input parameters" fi local in_pkg=$1 @@ -129,7 +129,7 @@ function get_class_basename { if [[ -z $1 ]] then - kill_exit "create_basename: missing input parameters" + kill_exit "ERROR: get_class_basename missing input parameters" fi local source_file=$1 @@ -147,7 +147,7 @@ function browse_files { if [[ -z $1 ]] || [[ -z $2 ]] then - kill_exit "check_package: missing input parameters" + kill_exit "ERROR: browse_files missing input parameters" fi local my_file=$1 @@ -183,7 +183,7 @@ function find_ros_message { if [[ -z $1 ]] || [[ -z $2 ]] || [[ -z $3 ]] then - kill_exit "find_ros_message: missing input parameters" + kill_exit "ERROR: find_ros_message: missing input parameters" fi # read input parameters @@ -196,9 +196,14 @@ function find_ros_message if [[ ${ext} = "msg" ]] || [[ ${ext} = "srv" ]] then - my_file_tmp="${my_file%.*}" - ros_out=`eval "ros${ext} list | grep ${my_file_tmp}"` - #ros_out=`eval "ros${ext} show ${my_file}"` + if [[ ${my_file} == */* ]] + then + my_file_tmp="${my_file%.*}" #extract extension + ros_out=`eval "ros${ext} list | grep ${my_file_tmp}$"` + else + my_file_tmp="${my_file%.*}" #extract extension + ros_out=`eval "ros${ext} list | grep /${my_file_tmp}$"` + fi else #action file ros_out=`eval "rosmsg show ${my_file}Action"` @@ -225,7 +230,6 @@ function find_ros_message local parsed_name=$(echo ${my_file} | sed 's/\// /g') file_pkg=${parsed_name%% *} my_file=${parsed_name##* } - else file_pkg= fi @@ -233,52 +237,122 @@ function find_ros_message if [[ -z ${file_pkg} ]] then file_pkg=(`echo ${ros_out} | tr '[' ' ' | tr ']' ' ' | tr '/' ' '`) + lines_found=`echo "$ros_out" | wc -l` + if [[ $lines_found != 1 ]] + then + echo "WARNING: Found multiple packages ($lines_found) containing the same message filename ($my_file), using the one that appears first., ($file_pkg)" + fi fi - - echo "ros_pkg=${ros_pkg}" - echo "file_pkg=${file_pkg}" - #check if both packages are the same - if [[ ${ros_pkg} != ${file_pkg} ]] - then - #modify package.xml to add dependency - add_pkg_to_packagexml ${ros_pkg} ${file_pkg} - fi - else found_it=false fi } -# add_pkg_to_packagexml -# Adds $2 as dependency to $1 package.xml file. +# add_pkg_dependency_to_readme +# Adds $2 as dependency to README.md file. # - $1: current ros package # - $2: message ros package -function add_pkg_to_packagexml +function add_pkg_dependency_to_readme { if [[ -z $1 ]] || [[ -z $2 ]] then - kill_exit "add_pkg_to_packagexml: missing input parameters" + kill_exit "ERROR: add_pkg_dependency_to_readme: missing input parameters" fi - #get path where message is stored local ros_pkg=$1 local file_pkg=$2 #go to package folder roscd "${ros_pkg}" + + file=README.md + line="\- ${file_pkg}" + comment="## Dependencies" + add_line_to_file "${line}" "${comment}" "${file}" +} - #look for package in package.xml and add dependency if necessary - local pub="<build_depend>${file_pkg}<build_depend/>" - local pub1=$(grep "${pub}" "package.xml") - if [[ -z "${pub1}" ]] +# fill_readme_ros_interface +# Adds ROS interface type $1/$2 to README.md from $2 package, as a $3 name and $4/$5 type +# - $1: interface type: topic, service, action +# - $2: interface subtype: publisher/subscriber, client/server, client/server +# - $3: current ros package +# - $4: interface name +# - $5: interface package +# - $6: interface message +function fill_readme_ros_interface # ${type} ${pub_subs} ${ros_pkg} ${topic_name} ${file_pkg} ${msg_file} ${absolute_ns} +{ + if [[ -z $1 ]] || [[ -z $2 ]] || [[ -z $3 ]] || [[ -z $4 ]] || [[ -z $5 ]] || [[ -z $6 ]] then - echo "Adding package \"${file_pkg}\" as dependency..." - local comment="\"iri_base_" - pub="<build_depend>${file_pkg}<build_depend/>" - sed -i -e "/${comment}/a\\ ${pub}" "package.xml" + kill_exit "ERROR: fill_readme_ros_interface missing input parameters" + fi + + #echo "fill_readme_ros_interface $1 $2 $3 $4 $5 $6" + local if_type=$1 + local if_subtype=$2 + local ros_pkg=$3 + local if_name=$4 + local if_pkg=$5 + local if_msg=$6 + local absolute_ns=$7 + + roscd "${ros_pkg}" + + local file=README.md + local line="" + local comment="" + + echo "Filling $file with ROS Interfaces information..." + + if [ "$absolute_ns" = true ] + then + line=" - /$if_name ($if_pkg/$if_msg)" else - echo "Package \"${file_pkg}\" already added as dependency, skipping" + line=" - ~$if_name ($if_pkg/$if_msg)" fi + + case "$if_type" in + "topic") + + case "$if_subtype" in + "publisher") + comment="### Topic publishers" + ;; + "subscriber") + comment="### Topic subscribers" + ;; + "broadcaster") + comment="### Topic publishers" + ;; + "listener") + comment="### Topic subscribers" + ;; + esac + ;; + "service") + case "$if_subtype" in + "client") + comment="### Service clients" + ;; + "server") + comment="### Service servers" + ;; + esac + ;; + "action") + case "$if_subtype" in + "client") + comment="### Action clients" + ;; + "server") + comment="### Action servers" + ;; + esac + ;; + esac + + add_line_to_file "${comment}" "# ROS Interface" "${file}" + + add_line_to_file "${line}" "${comment}" "${file}" } # find_comment_in_file @@ -289,7 +363,7 @@ function find_comment_in_file { if [[ -z $1 ]] || [[ -z $2 ]] then - kill_exit "find_comment_in_file: missing input parameters" + kill_exit "ERROR: find_comment_in_file: missing input parameters" fi local comment_to_find=$1 @@ -306,6 +380,30 @@ function find_comment_in_file fi } +# text_found_in_file +# Searches for $1 in $2. text_found is true if found. +# - $1: text to be found in file +# - $2: text file name +function text_found_in_file +{ + if [[ -z $1 ]] || [[ -z $2 ]] + then + kill_exit "ERROR: text_found_in_file missing input parameters" + fi + + local text_to_find=$1 + local file=$2 + + #look for key line + local found=$(grep -n "${text_to_find}" "${file}") + if [[ -n "${found}" ]] + then + text_found="true" + else + text_found="false" + fi +} + # add_line_to_file # Looks for comment line $2 in $3 file. If found, places line $1 after comment. # If comment is not found, exits script. If $1 already exists, skips adding it @@ -315,9 +413,10 @@ function find_comment_in_file # - $3: text file name function add_line_to_file { + #echo "add_line_to_file $1 $2 $3" if [[ -z $1 ]] || [[ -z $2 ]] || [[ -z $3 ]] then - kill_exit "add_line_to_file: missing input parameters" + kill_exit "ERROR: add_line_to_file: missing input parameters" fi local line_to_add=$1 @@ -328,18 +427,16 @@ function add_line_to_file find_comment_in_file "${comment_to_find}" "${file}" if [[ "${comment_found}" = "false" ]] then - kill_exit "File ${file} needs to be restored, missing comment: \"${comment_to_find}\"" + kill_exit "ERROR: File ${file} needs to be restored, missing comment: \"${comment_to_find}\"" fi #check if line already exists in file - local line_found=$(grep "${line_to_add}" "${file}") + local line_found=$(grep "^${line_to_add}" "${file}") if [[ -z "${line_found}" ]] then - #add line to file -# echo "Modifying file ${file} with:" -# echo " ${line_to_add}" - sed -i -e "/${comment}/a\\${line_to_add}" "${file}" + #echo "Adding line after comment: ${line_to_add} after ${comment_to_find}" + sed -i -e "/${comment_to_find}/a\\${line_to_add}" "${file}" else #skip line echo "File ${file} already included the line, skipping..." @@ -356,7 +453,7 @@ function get_h_cpp_files { if [[ -z $1 ]] then - kill_exit "get_h_cpp_files: missing input parameters" + kill_exit "ERROR: get_h_cpp_files: missing input parameters" fi local ros_pkg=$1 @@ -368,7 +465,7 @@ function get_h_cpp_files then if [[ -z `ls -l "include/${ros_pkg}" | grep "^-" | grep "\.h$"` ]] then - kill_exit "no include files found!" + kill_exit "ERROR: no include files found!" else node_h=$( ls "include/${ros_pkg}" | grep "\node.h$" ) node_h="include/${ros_pkg}/${node_h}" @@ -386,7 +483,7 @@ function is_driver_or_alg_node { if [[ -z $1 ]] then - kill_exit "is_driver_or_alg_node: missing input parameters" + kill_exit "ERROR: is_driver_or_alg_node: missing input parameters" fi local ros_pkg=$1 @@ -410,7 +507,12 @@ function is_driver_or_alg_node function change_license_to_LGPL { - find . -name package.xml -exec sed -i -e 's:<license>.*</license>:<license>LGPL</license>:g' {} \; + find . -name package.xml -exec sed -i -e 's:<license>.*</license>:<license>LGPL</license>:g' {} \; +} + +function change_maintainer_email_domain_to_iri_upc_edu +{ + find . -name package.xml -exec sed -i -e 's:@todo.todo:@iri.upc.edu:g' {} \; } function goto_catkin_workspace @@ -430,38 +532,63 @@ function check_package_file_integrity { local driver_alg=$1 local comment="" - - # check the package.xml file + + local type + + local build_depend="false" + local run_depend="false" + local depend="false" + local exec_depend="false" + + if [[ "${driver_alg}" = "driver" ]] then - comment="<build_depend>iri_base_driver<\/build_depend>" - find_comment_in_file "${comment}" "package.xml" - if [[ "${comment_found}" = "false" ]] - then - kill_exit "<build_depend>iri_base_driver<\/build_depend> missing in package.xml file" - fi + type="driver" else - comment="<build_depend>iri_base_algorithm<\/build_depend>" - find_comment_in_file "${comment}" "package.xml" - if [[ "${comment_found}" = "false" ]] - then - kill_exit "<build_depend>iri_base_algorithm<\/build_depend> missing in package.xml file" - fi + type="algorithm" fi - if [[ "${driver_alg}" = "driver" ]] + + comment="<build_depend>iri_base_${type}</build_depend>" + text_found_in_file "${comment}" "package.xml" + if [[ "${text_found}" = "true" ]] then - comment="<run_depend>iri_base_driver<\/run_depend>" - find_comment_in_file "${comment}" "package.xml" - if [[ "${comment_found}" = "false" ]] - then - kill_exit "<run_depend>iri_base_driver<\/run_depend> missing in package.xml file" + build_depend=true + fi + + comment="<depend>iri_base_${type}</depend>" + text_found_in_file "${comment}" "package.xml" + if [[ "${text_found}" = "true" ]] + then + depend=true + fi + + comment="<exec_depend>iri_base_${type}</exec_depend>" + text_found_in_file "${comment}" "package.xml" + if [[ "${text_found}" = "true" ]] + then + exec_depend="true" + fi + + comment="<run_depend>iri_base_${type}</run_depend>" + text_found_in_file "${comment}" "package.xml" + if [[ "${text_found}" = "true" ]] + then + run_depend="true" + fi + + comment="<package format=\"2\">" + text_found_in_file "${comment}" "package.xml" + if [[ "${text_found}" = "true" ]] + then + if [[ $build_depend != "true" || $exec_depend != "true" ]]; then + if [[ "$depend"!="true" ]] + then + kill_exit "Exit. Missing iri_base_$type <build_depend> or <exec_depend> on package.xml (format 2)" + fi fi - else - comment="<run_depend>iri_base_algorithm<\/run_depend>" - find_comment_in_file "${comment}" "package.xml" - if [[ "${comment_found}" = "false" ]] - then - kill_exit "<run_depend>iri_base_algorithm<\/run_depend> missing in package.xml file" + else #format 1: <package> + if [ "$build_depend" != "true" ] || [ "$run_depend" != "true" ]; then + kill_exit "Exit. Missing iri_base_$type <build_depend> or <run_depend> on package.xml (format 1)" fi fi } @@ -500,44 +627,66 @@ function add_build_run_dependencies local new_pkg=$3 local line="" local comment="" + + local type= + local dep= + local dep2="build_depend" + local dep3="exec_depend" + + if [[ "${driver_alg}" = "driver" ]] + then + type="driver" + else + type="algorithm" + fi if [[ "${new_pkg}" != "${ros_pkg}" ]] then - line="<build_depend>${new_pkg}<\/build_depend>" - find_comment_in_file "${line}" "package.xml" - if [[ "${comment_found}" = "false" ]] + + comment="<package format=\"2\">" + text_found_in_file "${comment}" "package.xml" + if [[ "${text_found}" = "true" ]] then - if [[ "${driver_alg}" = "driver" ]] + dep="depend" + line="^\s*<${dep}>${new_pkg}</${dep}>" + find_comment_in_file "${line}" "package.xml" + if [[ "${comment_found}" = "false" ]] then - line="<build_depend>${new_pkg}<\/build_depend>" - comment="<build_depend>iri_base_driver<\/build_depend>" - add_line_to_file "\ \ ${line}" "${comment}" "package.xml" + echo "Adding $new_pkg $dep to package.xml" + line="\ \ <${dep}>${new_pkg}<\/${dep}>" + comment="<${dep3}>iri_base_${type}<\/${dep3}>" + add_line_to_file "${line}" "${comment}" "package.xml" else - line="<build_depend>${new_pkg}<\/build_depend>" - comment="<build_depend>iri_base_algorithm<\/build_depend>" - add_line_to_file "\ \ ${line}" "${comment}" "package.xml" + echo "$dep dependency for $new_pkg already included in package.xml" fi - else - echo "Build dependencies already included." - fi - - line="<run_depend>${new_pkg}<\/run_depend>" - find_comment_in_file "${line}" "package.xml" - if [[ "${comment_found}" = "false" ]] - then - if [[ "${driver_alg}" = "driver" ]] + else #format 1: <package> + dep="build_depend" + line="<${dep}>${new_pkg}</${dep}>" + find_comment_in_file "${line}" "package.xml" + if [[ "${comment_found}" = "false" ]] then - line="<run_depend>${new_pkg}<\/run_depend>" - comment="<run_depend>iri_base_driver<\/run_depend>" - add_line_to_file "\ \ ${line}" "${comment}" "package.xml" + line="\ \ <${dep}>${new_pkg}<\/${dep}>" + comment="<${dep2}>iri_base_${type}<\/${dep2}>" + add_line_to_file "${line}" "${comment}" "package.xml" else - line="<run_depend>${new_pkg}<\/run_depend>" - comment="<run_depend>iri_base_algorithm<\/run_depend>" - add_line_to_file "\ \ ${line}" "${comment}" "package.xml" + echo "$dep dependency for $new_pkg already included in package.xml" + fi + + dep="run_depend" + line="<${dep}>${new_pkg}</${dep}>" + find_comment_in_file "${line}" "package.xml" + if [[ "${comment_found}" = "false" ]] + then + line="\ \ <${dep}>${new_pkg}<\/${dep}>" + comment="<${dep2}>iri_base_${type}<\/${dep2}>" + add_line_to_file "${line}" "${comment}" "package.xml" + else + echo "$dep dependency for $new_pkg already included in package.xml" fi - else - echo "Run dependencies already included." fi + + add_pkg_dependency_to_readme $ros_pkg $new_pkg + fi } @@ -566,7 +715,8 @@ function add_cmake_dependencies old_string="iri_base_algorithm" fi new_string="${old_string}\ ${new_pkg}" - sed -i "s/${old_string}/${new_string}/g" "CMakeLists.txt" + sed -i -e "/find_package/ s/${old_string}/${new_string}/g" "CMakeLists.txt" + sed -i -e "/CATKIN_DEPENDS/ s/${old_string}/${new_string}/g" "CMakeLists.txt" fi line="add_dependencies(\${PROJECT_NAME} ${new_pkg}_generate_messages_cpp)" @@ -593,4 +743,4 @@ function add_cmake_dependencies # -w filename Check if file is writable # -x filename Check if file is executable # -n variable Check if variable is not null (contains one or more characaters) -# -z variable Check if variable is null (empty) +# -z variable Check if variable is null (empty) \ No newline at end of file