diff --git a/ReadMe.md b/ReadMe.md index 229427703bf60bc9b41cdd6bc33b9c4d31602d1c..358b66a6142052a184faa7f4d70c54f55fd84906 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,59 +1,71 @@ -Scripts-catkin +IRI_ROS_SCRIPTS ============== ## Description -Set of scripts to easily generate driver and algorithm packages in ROS, and also a set of scripts to add publishers, subscribers, service clients an servers and action clients and servers to an existing package. +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: `git clone ssh://git@gitlab.iri.upc.edu:2202/labrobotica/ros/iri_core/scripts-catkin.git -b kinetic_migration scripts` +- Clone this repository -- Install realpath:`sudo apt-get install realpath` +- Install realpath: -- ``echo "source `pwd`/scripts/setup.bash" >> ~/.bashrc`` + sudo apt-get install realpath -- `source ~/.bashrc` +- Source the setup.bash file contained in the repository. -## How to use it + source /path/to/iri_ros_scripts/setup.bash -### create_algorithm_package.sh and create_driver_package.sh +- You can add that line to your `~/.bashrc` so it is automatically loaded. -These scripts have the following arguments: +## How to use it +``` +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\_'. - -### add_topic_publisher_subscriber.sh - -This script has the following parameters: - +``` +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 - -This script has the following parameters: - +``` +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\]**: To add aaction server or client. +``` +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 ed0cf7b3063c9c15fc3981d7739f922611ca8584..f0c05835e6c5f935491632ac547796af8533de7e 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= @@ -51,7 +48,7 @@ do 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 ;; @@ -61,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 @@ -77,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 @@ -89,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 @@ -99,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) @@ -112,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 @@ -126,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 \ No newline at end of file diff --git a/add_service_server_client.sh b/add_service_server_client.sh index ee94f426c954ec0d9b776b61728584dc0856394d..bfb820f416c5f205f660498ad0c3f0d2a10533e1 100755 --- a/add_service_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= @@ -51,7 +48,7 @@ do srv_file=$OPTARG ;; ?) - echo "invalid input argument ${OPTION}" + 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 ;; @@ -61,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..." + 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 @@ -77,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 @@ -88,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 @@ -98,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) @@ -111,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 @@ -124,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} \ No newline at end of file diff --git a/add_tf_listener_broadcaster.sh b/add_tf_listener_broadcaster.sh index 8f8a9278b35abb535eb52bcac55cc5d140416145..263bff1671ab991e1b9dbad40e3a7641af307cf0 100755 --- a/add_tf_listener_broadcaster.sh +++ b/add_tf_listener_broadcaster.sh @@ -1,6 +1,8 @@ #!/bin/bash -# # WET +echo "/*********************************************/" +echo "/* Creating New ROS TF Listener broadcaster */" +echo "/*********************************************/" script_name="add_tf_listener_broadcaster" @@ -8,10 +10,10 @@ script_name="add_tf_listener_broadcaster" 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" @@ -21,11 +23,6 @@ source "${IRI_ROS_SCRIPTS_PATH}/libraries/create_tf_listener.sh" check_libraries check_templates -echo "" -echo "/*********************************************/" -echo "/* Creating New ROS TF Listener broadcaster */" -echo "/*********************************************/" - pub_subs= ros_pkg= @@ -41,7 +38,7 @@ do ;; ?) - echo "invalid input argument ${OPTION}" + echo "ERROR: invalid input argument ${OPTION}" kill_exit "Usage: ${script_name}.sh -o [broadcaster,listener] -p ros_pkg" exit ;; @@ -51,14 +48,14 @@ done #check if publisher name parameter is filled up if [ ! "${pub_subs}" ] || [ ! "${ros_pkg}" ] then - echo "Missing input parameters..." + 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 "First parameter must be either \"broadcaster\" or \"listener\", aborting ..." + kill_exit "ERROR: First parameter must be either \"broadcaster\" or \"listener\", aborting ..." fi #check if package exists @@ -67,7 +64,7 @@ if [[ -z "${result}" ]] then roscd ${ros_pkg} else - kill_exit "ROS package ${ros_pkg} does NOT exist or can't be found. Create it, or load the correct workspace." + 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}" @@ -87,7 +84,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 @@ -99,5 +96,4 @@ 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 - +fi \ No newline at end of file diff --git a/add_topic_publisher_subscriber.sh b/add_topic_publisher_subscriber.sh index 5a0614013de49475be043239828410a3832e125f..17a44615bdc82bc78a0f6646115ca7d8259a67c3 100755 --- a/add_topic_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= @@ -55,7 +52,7 @@ do buffer=$OPTARG ;; ?) - echo "invalid input argument ${OPTION}" + 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 ;; @@ -65,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..." + 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 @@ -81,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}" @@ -89,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 @@ -100,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 @@ -110,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 @@ -122,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) @@ -134,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 @@ -148,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} \ 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 9aaf175b9635de63a7384d5b432676790db19387..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->setRate(10);//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..c769329714cdb632c5734e4c0cfc6d44fbcb0e4b --- /dev/null +++ b/common_templates/README.md @@ -0,0 +1,37 @@ +# 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 + +### Topic subscribers + +### Topic publishers + +### Service servers + +### Service clients + +### Action servers + +### Action clients + +### 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 b7ad096a7fb46c8cf22915852433e73e8bff9c61..bc0af6dfcf47d2418f0010565bb27a06690a78b0 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,18 +19,13 @@ 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] [-p <prefix>]\n Parameters:\n \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= +input_name="" use_iri_prefix=true -input_prefix= +input_prefix="" #check for input project name paramenter while getopts “:n:ip:†OPTION @@ -45,7 +42,7 @@ do input_prefix=$OPTARG ;; ?) - echo "invalid argument $OPTION" + echo "ERROR: invalid argument $OPTION" kill_exit "${usage}" ;; esac @@ -54,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 @@ -66,7 +63,7 @@ if [[ ${use_iri_prefix} == true ]] then project_name="iri_${input_name}" else - if [[ "$input_prefix" != ":" ]] + if [[ "$input_prefix" != "" ]] then project_name="${input_prefix}_${input_name}" else @@ -88,6 +85,7 @@ then else exit 1; fi + #create alg filename alg_filename="${input_name}_alg" @@ -119,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..." ################################################################################ @@ -140,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..." ################################################################################ @@ -150,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..." ################################################################################ @@ -172,18 +167,34 @@ 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 +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 72a6d87c5de34568c4ecca87a541bab3920fc992..affdfe8c4a4088c5af299aa0c07d432c6fe9169f 100755 --- a/create_driver_package.sh +++ b/create_driver_package.sh @@ -1,15 +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}"` 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,32 +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 [other_prefix]] +usage="Usage: create_driver_package.sh -n node_name [-i] [-p <prefix]]\n Parameters:\n \t-i: avoid adding the default iri_ prefix to the provided node name.\n -\t-i other_prefix: replaces default iri_ prefix with specified other_prefix_." -input_name= +\t-p <prefix>: replaces default iri_ prefix with specified <prefix>_." +input_name="" use_iri_prefix=true -input_prefix= +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_iri_prefix=false + ;; + p) use_iri_prefix=false input_prefix=$OPTARG ;; ?) - echo "invalid argument $OPTION" + echo "ERROR: invalid argument $OPTION" kill_exit "${usage}" ;; esac @@ -51,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 @@ -63,7 +63,7 @@ if [[ ${use_iri_prefix} == true ]] then project_name="iri_${input_name}" else - if [[ "$input_prefix" != ":" ]] + if [[ "$input_prefix" != "" ]] then project_name="${input_prefix}_${input_name}" else @@ -73,7 +73,7 @@ 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 @@ -88,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/ @@ -114,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 "" ################################################################################ @@ -136,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 "" ################################################################################ @@ -150,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 "" ################################################################################ @@ -172,18 +167,36 @@ 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 +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 8cd199604b546a7165d1c354dfdfd84c9578e81f..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,7 +88,7 @@ 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 diff --git a/driver_templates/template_driver.cfg b/driver_templates/template_driver.cfg index e3f3bae720f4628831127f6b4e2388f21d1bf3e7..9fb9032377145d5eb9269965b3f9ac53f3562593 100644 --- a/driver_templates/template_driver.cfg +++ b/driver_templates/template_driver.cfg @@ -38,7 +38,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, 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_node.cpp b/driver_templates/template_driver_node.cpp index 091ae6985974cca2f100290596100982c3b2bd9c..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->setRate(10);//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] @@ -60,6 +66,11 @@ void TemplateNode::addNodeDiagnostics(void) 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) diff --git a/driver_templates/template_driver_node.h b/driver_templates/template_driver_node.h index 2b81b8f54eb04a2de1269b92d7b44da91b7d0552..a68cf5456883dec8330b78d12c484c9f9f7fc806 100644 --- a/driver_templates/template_driver_node.h +++ b/driver_templates/template_driver_node.h @@ -96,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 diff --git a/libraries/create_action_client.sh b/libraries/create_action_client.sh index a6ed38f571cdd17abe0f0962038ddc7a85372786..dd857e8ce02971dc1a813a2223cb1aa895a5a2e3 100755 --- 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}" diff --git a/libraries/create_action_server.sh b/libraries/create_action_server.sh index ccb4be139ceeb0a068cd68d31f9831abc1b5a5df..ec94ef2881006f00601a06d9b28b493efd7968dd 100755 --- 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,67 +77,67 @@ 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 @@ -145,119 +145,119 @@ function check_action_server_attributes_functions 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}" diff --git a/libraries/create_client.sh b/libraries/create_client.sh index dd8f10049700b1cd3069243d0f7f7a929b0e90de..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,13 +61,13 @@ 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 @@ -76,13 +76,13 @@ function check_client_attributes_functions 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}" diff --git a/libraries/create_publisher.sh b/libraries/create_publisher.sh index 39645fccec23367c08dfdb58f0cb26eb7fce1856..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->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 diff --git a/libraries/create_server.sh b/libraries/create_server.sh index fc7782fec1d81180182ebf9817134c0afa21d23b..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,31 +71,31 @@ 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 @@ -103,37 +103,37 @@ function check_server_attributes_functions 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}" diff --git a/libraries/create_subscriber.sh b/libraries/create_subscriber.sh index 892ad25face028db6f2443568c65159857268a7e..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->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}" diff --git a/libraries/create_tf_broadcaster.sh b/libraries/create_tf_broadcaster.sh index 19807c3a294a2452cf7a3900d1a3fdd8fa34f1eb..b8992bd1601fdccdf46d0e6893219314fc4052f6 100755 --- a/libraries/create_tf_broadcaster.sh +++ b/libraries/create_tf_broadcaster.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 } @@ -66,14 +66,14 @@ function check_publisher_attributes_functions find_comment_in_file "${line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A TF broadcaster with the same name is already declared in file ${node_h} line ${line_number}" + 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 "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 @@ -81,7 +81,7 @@ function check_publisher_attributes_functions 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 } @@ -104,7 +104,7 @@ function create_tf_broadcaster 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 diff --git a/libraries/create_tf_listener.sh b/libraries/create_tf_listener.sh index 828e2c3719acdf295e1219171374342781d41d76..88edae8c376390f6eb559469ca01a4fb8cb18144 100644 --- a/libraries/create_tf_listener.sh +++ b/libraries/create_tf_listener.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 } @@ -67,7 +67,7 @@ function check_subscriber_attributes_functions find_comment_in_file "${line}" "${node_h}" if [[ "${comment_found}" = "true" ]] then - kill_exit "A TF listener with the same name is already declared in file ${node_h} line ${line_number}" + 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 @@ -93,7 +93,7 @@ function create_tf_listener 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}" @@ -103,6 +103,14 @@ function create_tf_listener 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 # @@ -124,7 +132,7 @@ function create_tf_listener line="\n" aux_line="/*" line="${line}\ \ ${aux_line}\n" - aux_line="//tf_listener example" + aux_line="//tf_listener example BEGIN" line="${line}\ \ ${aux_line}\n" aux_line="try{" line="${line}\ \ ${aux_line}\n" @@ -138,8 +146,16 @@ function create_tf_listener 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;" @@ -193,7 +209,7 @@ function create_tf_listener line="${line}\ \ ${aux_line}\n" aux_line=" ROS_ERROR(\"TF Exception: %s\",ex.what()); }" line="${line}\ \ ${aux_line}\n" - aux_line="///tf_listener example" + aux_line="///tf_listener example END" line="${line}\ \ ${aux_line}\n" aux_line="*/" line="${line}\ \ ${aux_line}\n" diff --git a/libraries/scripts_library.sh b/libraries/scripts_library.sh index 6ca85e7e20592aff8fdc2197f03f7b6bfe9b584b..d96c2621d697a133a63e417f550aaa97999d4e94 100755 --- 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" + 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 @@ -230,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 @@ -238,52 +237,104 @@ 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} +{ + 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" - else - echo "Package \"${file_pkg}\" already added as dependency, skipping" + 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 + + roscd "${ros_pkg}" + + file=README.md + line=" - ~$if_name ($if_pkg/$if_msg)" + comment="" + + case "$if_type" in + "topic") + + case "$if_subtype" in + "publisher") + comment="### Topic publishers" + ;; + "subscriber") + 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 "${line}" "${comment}" "${file}" } # find_comment_in_file @@ -294,7 +345,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 @@ -319,7 +370,7 @@ function text_found_in_file { if [[ -z $1 ]] || [[ -z $2 ]] then - kill_exit "text_found_in_file missing input parameters" + kill_exit "ERROR: text_found_in_file missing input parameters" fi local text_to_find=$1 @@ -344,9 +395,10 @@ function text_found_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 @@ -357,11 +409,11 @@ 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 @@ -382,7 +434,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 @@ -394,7 +446,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}" @@ -412,7 +464,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 @@ -436,7 +488,7 @@ 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 goto_catkin_workspace @@ -555,6 +607,7 @@ function add_build_run_dependencies local type= local dep= local dep2="build_depend" + local dep3="exec_depend" if [[ "${driver_alg}" = "driver" ]] then @@ -571,15 +624,16 @@ function add_build_run_dependencies if [[ "${text_found}" = "true" ]] then dep="depend" - line="<${dep}>${new_pkg}</${dep}>" + line="^\s*<${dep}>${new_pkg}</${dep}>" find_comment_in_file "${line}" "package.xml" if [[ "${comment_found}" = "false" ]] then + echo "Adding $new_pkg $dep to package.xml" line="\ \ <${dep}>${new_pkg}<\/${dep}>" - comment="<${dep2}>iri_base_${type}<\/${dep2}>" + comment="<${dep3}>iri_base_${type}<\/${dep3}>" add_line_to_file "${line}" "${comment}" "package.xml" else - echo "$dep dependency already included." + echo "$dep dependency for $new_pkg already included in package.xml" fi else #format 1: <package> dep="build_depend" @@ -591,7 +645,7 @@ function add_build_run_dependencies comment="<${dep2}>iri_base_${type}<\/${dep2}>" add_line_to_file "${line}" "${comment}" "package.xml" else - echo "$dep dependency already included." + echo "$dep dependency for $new_pkg already included in package.xml" fi dep="run_depend" @@ -603,9 +657,11 @@ function add_build_run_dependencies comment="<${dep2}>iri_base_${type}<\/${dep2}>" add_line_to_file "${line}" "${comment}" "package.xml" else - echo "$dep dependency already included." + echo "$dep dependency for $new_pkg already included in package.xml" fi fi + + add_pkg_dependency_to_readme $ros_pkg $new_pkg fi } @@ -663,4 +719,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