Skip to content

Commit

Permalink
[Use-cases scripts] Remove PKG_NAME argument (StoglRobotics#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
muritane authored Mar 9, 2023
1 parent 6ef1a75 commit 78fcdaa
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 92 deletions.
4 changes: 2 additions & 2 deletions docs/tutorials/quick-start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ For more details check :ref:`use-case description <uc-setup-robot-description>`.
source <path to your ROS workspace>/install/setup.bash
cd <src folder of your ROS workspace>/<package_name>
setup-robot-description <my_cool_robot_name> <package_name>
setup-robot-description <my_cool_robot_name>
Create robot bringup package
Expand All @@ -54,7 +54,7 @@ For more details check :ref:`use-case description <uc-setup-robot-bringup>`.
source <path to your ROS workspace>/install/setup.bash
cd <src folder of your ROS workspace>/<package_name>
setup-robot-bringup <my_cool_robot_name> <package_name>
setup-robot-bringup <my_cool_robot_name> <my_cool_robot_description_package_name>
Setup ros2_control control hardware
Expand Down
7 changes: 3 additions & 4 deletions docs/use-cases/ros2_control/setup_controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Usage
:caption: Usage of script for setting up a controller.
:name: ros2_control_setup-controller-package
ros2_control_setup-controller-package FILE_NAME [CLASS_NAME] [PKG_NAME]
ros2_control_setup-controller-package FILE_NAME [CLASS_NAME]
Parameters:
Expand All @@ -29,10 +29,9 @@ Parameters:
- ``CLASS_NAME`` optional name used for controller class.
If not set, it is guessed by camel-casing the file name.

- ``PKG_NAME`` name of the controller's package.
If not set, it is guessed from the current path using the folder's name.


The script will ask for some additional input.

The package name is obtained from the 'package.xml' file.

After all files are copied and placeholders set, changes are automatically staged in git.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ ros2_control: Setup robot's hardware package

This use-case describes how to set up a robot's hardware interface for the ros2_control framework using scripts from ROS Team Workspace (RosTeamWS) framework.

``ros2_control_setup-hardware-interface-package`` script accepts the file name of the robot's hardware interfacea and, optionally, class name and the package name.
``ros2_control_setup-hardware-interface-package`` script accepts the file name of the robot's hardware interfacea and, optionally, class name.
The file name should use standard ROS format <my_cool_robot_hardware>.
A ``.cpp`` and ``.hpp`` files will added using this name.
If the class name is not set, it is guessed by camel-casing the file name.
If the package name is not set, it is guessed from the current path using the folder's name.
The package name is obtained from the 'package.xml' file.
The script **has to be executed** from the package folder where the package should be generated.

**Note**: it is recommended to setup your package using :ref:`setup-new-package <uc-new-package>` script.
Expand All @@ -21,7 +21,7 @@ The scripts adds also a plugin description and simple test checking if the plugi
:caption: Usage of script for setting up the robot bringup.
:name: ros2_control_setup-hardware-interface-package
ros2_control_setup-hardware-interface-package FILE_NAME [CLASS_NAME] [PKG_NAME]
ros2_control_setup-hardware-interface-package FILE_NAME [CLASS_NAME]
After all files are copied and placeholders set, a commit can be automatically created.
After all files are copied and placeholders set, changes are automatically staged in git.
7 changes: 2 additions & 5 deletions docs/use-cases/ros_packages/create_package.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ The script supports the following options and opportunities for data entry:

- If subpackage, then you will need to enter the name of its metapackage

#. License (string) - enter a full name to add into package.xml
#. Manual input of the maintainer or using data from git-config - (y/n)

- If *yes* then you should enter the full name and email address of the maintainer

#. License (string) - choose a license to add into package.xml - multiple choice
#. Maintainer info: name and email (user input, local git, global git) - multiple choice
#. Package build type (ament_cmake, ament_python, cmake) - multiple choice
#. Create/Update repository with CI configuration - (y/n)

Expand Down
10 changes: 5 additions & 5 deletions docs/use-cases/ros_packages/setup_robot_bringup_package.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ The package follows as far as possible best practices for `robot support package
Script for Setting up Description Package
============================================

``setup-robot-bringup`` script accepts the robot name and, optionally, the package name.
If the package name is not set, it is guessed from the current path using the folder's name.
``setup-robot-bringup`` script accepts the robot name and the robot description package name.
The package name is obtained from the 'package.xml' file.
The script **has to be executed** from the folder where the bringup should be generated.

.. note:: it is recommended to setup your package using :ref:`setup-new-package <uc-new-package>` script.

The scripts copies template files from the ``templates/robot_bringup`` folder, rename the files, and replaces the placeholders.
The scripts copies template files from the ``templates/robot_bringup`` folder, renames the files, and replaces the placeholders.

.. code-block:: bash
:caption: Usage of script for setting up the robot bringup.
:name: setup-robot-bringup
setup-robot-bringup ROBOT_NAME [PKG_NAME]
setup-robot-bringup ROBOT_NAME DESCRIPTION_PKG_NAME
After all files are copied and placeholders set, a commit is automatically created.
After all files are copied and placeholders set, changes are automatically staged in git.
10 changes: 5 additions & 5 deletions docs/use-cases/ros_packages/setup_robot_description_package.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ The package follows as far as possible best practices for `robot support package
Script for Setting up Description Package
============================================

``setup-robot-description`` script accepts the robot name and, optionally, the package name.
If the package name is not set, it is guessed from the current path using the folder's name.
``setup-robot-description`` script accepts the robot name.
The package name is obtained from the 'package.xml' file.
The script **has to be executed** from the package folder where the description should be generated.

.. note:: it is recommended to setup your package using :ref:`create-new-package <uc-new-package>` script.

The scripts copies template files from the ``templates/robot_description`` folder, rename the files, and replaces the placeholders.
The scripts copies template files from the ``templates/robot_description`` folder, renames the files, and replaces the placeholders.

.. code-block:: bash
:caption: Usage of script for setting up the robot description.
:name: setup-robot-description
setup-robot-description ROBOT_NAME [PKG_NAME]
setup-robot-description ROBOT_NAME
After all files are copied and placeholders set, a commit is automatically created.
After all files are copied and placeholders set, changes are automatically staged in git.

To test the generated files compile and source your workspace and execute:

Expand Down
19 changes: 6 additions & 13 deletions scripts/ros2_control/setup-controller-package.bash
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

usage="setup-controller-package.bash FILE_NAME [CLASS_NAME] [PKG_NAME]"

# echo ""
# echo "Your path is `pwd`. Is this your package folder where to setup robot's bringup?"
# read -p "If so press <ENTER> otherwise <CTRL>+C and start the script again from the bringup folder."
usage="setup-controller-package.bash FILE_NAME [CLASS_NAME]"

# Load Framework defines
script_own_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )"
Expand All @@ -34,6 +30,11 @@ if [ -f src/$FILE_NAME.cpp ]; then
print_and_exit "ERROR:The file '$FILE_NAME' already exist! 😱!" "$usage"
fi

if [ ! -f "package.xml" ]; then
print_and_exit "ERROR: 'package.xml' not found. You should execute this script at the top level of your package folder. Nothing to do 😯" "$usage"
fi
PKG_NAME="$(grep -Po '(?<=<name>).*?(?=</name>)' package.xml | sed -e 's/[[:space:]]//g')"

echo "" # Adds empty line

CLASS_NAME=$2
Expand All @@ -49,14 +50,6 @@ if [ -z "$2" ]; then
echo -e "${TERMINAL_COLOR_USER_CONFIRMATION}ClassName guessed from the '$FILE_NAME': '$CLASS_NAME'. Is this correct? If not, provide it as the second parameter.${TERMINAL_COLOR_NC}"
fi

PKG_NAME=$3
if [ -z "$3" ]; then
current=$(pwd)
PKG_NAME=$(basename "$current")
echo -e "${TERMINAL_COLOR_USER_CONFIRMATION}Package name guessed from the current path is '$PKG_NAME'. Is this correct? If not provide it as the third parameter.${TERMINAL_COLOR_NC}"
fi
read

echo -e "${TERMINAL_COLOR_USER_INPUT_DECISION}Which license-header do you want to use? [1]"
echo "(0) None"
echo "(1) Apache-2.0"
Expand Down
18 changes: 6 additions & 12 deletions scripts/ros2_control/setup-hardware-interface-package.bash
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

usage="setup-robot-ros2-control-hardware.bash FILE_NAME [CLASS_NAME] [PKG_NAME]"

# echo ""
# echo "Your path is `pwd`. Is this your package folder where to setup robot's bringup?"
# read -p "If so press <ENTER> otherwise <CTRL>+C and start the script again from the bringup folder."
usage="ros2_control_setup-hardware-interface-package FILE_NAME [CLASS_NAME]"

# Load Framework defines
script_own_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )"
Expand All @@ -34,6 +30,11 @@ if [ -f src/$FILE_NAME.cpp ]; then
print_and_exit "ERROR:The file '$FILE_NAME' already exist! 😱!" "$usage"
fi

if [ ! -f "package.xml" ]; then
print_and_exit "ERROR: 'package.xml' not found. You should execute this script at the top level of your package folder. Nothing to do 😯" "$usage"
fi
PKG_NAME="$(grep -Po '(?<=<name>).*?(?=</name>)' package.xml | sed -e 's/[[:space:]]//g')"

echo "" # Adds empty line

CLASS_NAME=$2
Expand All @@ -49,13 +50,6 @@ if [ -z "$2" ]; then
echo -e "${TERMINAL_COLOR_USER_CONFIRMATION}ClassName guessed from the '$FILE_NAME': '$CLASS_NAME'. Is this correct? If not provide it as the second parameter.${TERMINAL_COLOR_NC}"
fi

PKG_NAME=$3
if [ -z "$3" ]; then
current=`pwd`
PKG_NAME=$(basename "$current")
echo -e "${TERMINAL_COLOR_USER_CONFIRMATION}Package name guessed from the current path is '$PKG_NAME'. Is this correct? If not provide it as the third parameter.${TERMINAL_COLOR_NC}"
fi

echo -e "${TERMINAL_COLOR_USER_INPUT_DECISION}Which license-header do you want to use? [1]"
echo "(0) None"
echo "(1) Apache 2.0 License"
Expand Down
35 changes: 14 additions & 21 deletions scripts/setup-robot-bringup.bash
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,33 @@
# See the License for the specific language governing permissions and
# limitations under the License.

usage="setup-robot-bringup.bash ROBOT_NAME DESCRIPTION_PKG [PKG_NAME]"

# echo ""
# echo "Your path is `pwd`. Is this your package folder where to setup robot's bringup?"
# read -p "If so press <ENTER> otherwise <CTRL>+C and start the script again from the bringup folder."
usage="setup-robot-bringup ROBOT_NAME DESCRIPTION_PKG_NAME"

# Load Framework defines
script_own_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )"
source $script_own_dir/../setup.bash
check_and_set_ros_distro_and_version "${ROS_DISTRO}"

ROBOT_NAME=$1
if [ -z "$1" ]; then
echo "You should provide robot name!"
exit 0
if [ -z "$ROBOT_NAME" ]; then
print_and_exit "ERROR: You should provide robot name! Nothing to do 😯" "$usage"
fi

DESCR_PKG_NAME=$2
if [ -z "$2" ]; then
echo "You should provide description package name!"
exit 0
if [ -z "$DESCR_PKG_NAME" ]; then
print_and_exit "ERROR: You should provide description package name! Nothing to do 😯" "$usage"
fi

PKG_NAME=$3
if [ -z "$3" ]; then
current=`pwd`
PKG_NAME=$(basename "$current")
echo "Package name guessed from the current path is '$PKG_NAME' is this correct? If not provide it as second parameter."
if [ ! -f "package.xml" ]; then
print_and_exit "ERROR: 'package.xml' not found. You should execute this script at the top level of your package folder. Nothing to do 😯" "$usage"
fi
PKG_NAME="$(grep -Po '(?<=<name>).*?(?=</name>)' package.xml | sed -e 's/[[:space:]]//g')"


echo ""
echo "ATTENTION: Setting up bringup configuration for robot '$ROBOT_NAME' in package '$PKG_NAME' in folder '`pwd`'."
echo ""
read -p "If correct press <ENTER>, otherwise <CTRL>+C and start the script again from the package folder and/or with correct robot name."
echo -e "${TERMINAL_COLOR_USER_NOTICE}ATTENTION: Setting up bringup configuration for robot '$ROBOT_NAME' in package '$PKG_NAME' in folder '`pwd`' with robot description package '$DESCR_PKG_NAME'.${TERMINAL_COLOR_NC}"
echo -e "${TERMINAL_COLOR_USER_CONFIRMATION}If correct press <ENTER>, otherwise <CTRL>+C and start the script again from the package folder and/or with correct robot name.${TERMINAL_COLOR_NC}"
read

# Remove include and src folders - in this package should be no source
RM_FOLDERS=("include" "src")
Expand Down Expand Up @@ -114,10 +107,10 @@ fi
# TODO: Add license checks

git add .
git commit -m "RosTeamWS: Bringup files for $ROBOT_NAME generated."
# git commit -m "RosTeamWS: Bringup files for $ROBOT_NAME generated."

# Compile and add new package the to the path
compile_and_source_package $PKG_NAME

echo ""
echo "FINISHED: You can test the configuration by executing 'ros2 launch $PKG_NAME test_${ROBOT_NAME}_bringup.launch.py'"
echo -e "${TERMINAL_COLOR_USER_NOTICE}FINISHED: You can test the configuration by executing 'ros2 launch $PKG_NAME test_${ROBOT_NAME}_bringup.launch.py'${TERMINAL_COLOR_NC}"
32 changes: 11 additions & 21 deletions scripts/setup-robot-description.bash
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,30 @@
# See the License for the specific language governing permissions and
# limitations under the License.

usage="setup-robot-description.bash ROBOT_NAME [PKG_NAME]"

# echo ""
# echo "Your path is `pwd`. Is this your package folder where to setup robot's description?"
# read -p "If so press <ENTER> otherwise <CTRL>+C and start the script again from the description folder."
usage="setup-robot-description ROBOT_NAME"

# Load Framework defines
script_own_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )"
source $script_own_dir/../setup.bash
check_and_set_ros_distro_and_version ${ROS_DISTRO}

ROBOT_NAME=$1
if [ -z "$1" ]; then
echo "You should provide robot name!"
exit 0
if [ -z "$ROBOT_NAME" ]; then
print_and_exit "ERROR: You should provide robot name! Nothing to do 😯" "$usage"
fi

PKG_NAME=$2
if [ -z "$2" ]; then
current=$(pwd)
PKG_NAME=$(basename "$current")
user_decision "Package name guessed from the current path is '$PKG_NAME' is this correct?"
if [[ " ${negative_answers[*]} " =~ " ${user_answer} " ]]; then
print_and_exit "Please provide the package name as second parameter."
fi
if [ ! -f "package.xml" ]; then
print_and_exit "ERROR: 'package.xml' not found. You should execute this script at the top level of your package folder. Nothing to do 😯" "$usage"
fi
PKG_NAME="$(grep -Po '(?<=<name>).*?(?=</name>)' package.xml | sed -e 's/[[:space:]]//g')"

echo ""
echo "ATTENTION: Setting up description configuration for robot '$ROBOT_NAME' in package '$PKG_NAME' in folder '`pwd`'."
echo ""
read -p "If correct press <ENTER>, otherwise <CTRL>+C and start the script again from the package folder and/or with correct robot name."
echo -e "${TERMINAL_COLOR_USER_NOTICE}ATTENTION: Setting up description configuration for robot '$ROBOT_NAME' in package '$PKG_NAME' in folder '`pwd`'.${TERMINAL_COLOR_NC}"
echo -e "${TERMINAL_COLOR_USER_CONFIRMATION}If correct press <ENTER>, otherwise <CTRL>+C and start the script again from the package folder and/or with correct robot name.${TERMINAL_COLOR_NC}"
read

# Create folders for meshes
F_NAME="meshes/${ROBOT_NAME}/visual"
F_NAME="meshes/${ROBOT_NAME}/collision"
mkdir -p $F_NAME
touch $F_NAME/.gitkeep

Expand Down Expand Up @@ -124,4 +114,4 @@ git commit -m "RosTeamWS: Description files for $ROBOT_NAME generated."
compile_and_source_package $PKG_NAME

echo ""
echo "FINISHED: You can test the configuration by executing 'ros2 launch $PKG_NAME view_${ROBOT_NAME}.launch.py'"
echo -e "${TERMINAL_COLOR_USER_NOTICE}FINISHED: You can test the configuration by executing 'ros2 launch $PKG_NAME view_${ROBOT_NAME}.launch.py'${TERMINAL_COLOR_NC}"

0 comments on commit 78fcdaa

Please sign in to comment.