Skip to content

Commit

Permalink
Extend controller templates, update hardware templates and update scr…
Browse files Browse the repository at this point in the history
…ipts to be easier to use (StoglRobotics#48)

* Update templates for controller
* Added template for chained controllers.
* Update hardware templates and make nice output to the hardware generation script.
  • Loading branch information
destogl authored Jun 19, 2022
1 parent 06f8060 commit 41e08cf
Show file tree
Hide file tree
Showing 24 changed files with 1,782 additions and 272 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
with:
python-version: '3.9.7'
cache: 'pip'
- name: Install clang-format-10
run: sudo apt-get install clang-format-11
- name: Install clang-format-12
run: sudo apt-get install clang-format-12
- uses: pre-commit/[email protected]
with:
extra_args: --all-files --hook-stage manual
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ repos:
- id: clang-format
name: clang-format
description: Format files with ClangFormat.
entry: clang-format-10
entry: clang-format-12
language: system
files: \.(c|cc|cxx|cpp|frag|glsl|h|hpp|hxx|ih|ispc|ipp|java|js|m|proto|vert)$
args: ['-fallback-style=none', '-i']
Expand Down
7 changes: 5 additions & 2 deletions scripts/_RosTeamWs_Defines.bash
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ function RosTeamWS_setup_exports {
export RAW_TERMINAL_COLOR_LIGHT_GRAY=$'\e[0;37m'
export RAW_TERMINAL_COLOR_WHITE=$'\e[1;37m'

export TERMINAL_COLOR_USER_NOTICE=${TERMINAL_COLOR_YELLOW}
export TERMINAL_COLOR_USER_INPUT_DECISION=${TERMINAL_COLOR_PURPLE}
export TERMINAL_COLOR_USER_CONFIRMATION=${TERMINAL_COLOR_BLUE}
}

# TODO(denis): add this into setup.bash
Expand Down Expand Up @@ -247,8 +250,8 @@ function framework_default_paths {
PACKAGE_TEMPLATES="$FRAMEWORK_PACKAGE_PATH/templates/package"
ROBOT_DESCRIPTION_TEMPLATES="$FRAMEWORK_PACKAGE_PATH/templates/robot_description"
ROS2_CONTROL_TEMPLATES="$FRAMEWORK_PACKAGE_PATH/templates/ros2_control"
ROS2_CONTROL_HW_ITF_TEMPLATES="$FRAMEWORK_PACKAGE_PATH/templates/ros2_control/hardware"
ROS2_CONTROL_CONTROLLER_TEMPLATES="$FRAMEWORK_PACKAGE_PATH/templates/ros2_control/controller"
ROS2_CONTROL_HW_ITF_TEMPLATES="$ROS2_CONTROL_TEMPLATES/hardware"
ROS2_CONTROL_CONTROLLER_TEMPLATES="$ROS2_CONTROL_TEMPLATES/controller"
LICENSE_TEMPLATES="$FRAMEWORK_PACKAGE_PATH/templates/licenses"
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/_Team_Defines.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ DEFAULT_ROS_VERSION=2
# TODO(denis): We have two example teams. On is working with industrial and other with mobile robots
# TEAM_TEAM_NAMES=("Industrial" "Mobile")

TEAM_LICENSE="Apache License 2.0"
TEAM_LICENSE="Apache-2.0"

TEAM_REPOSITORY_SERVER="https://github.com"

Expand Down
40 changes: 23 additions & 17 deletions scripts/create-new-package.bash
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,28 @@ check_ros_distro ${ROS_DISTRO}

PKG_NAME=$1
if [ -z "$1" ]; then
print_and_exit "Package name is not defined. Nothing to do, exiting..." "$usage"
print_and_exit "Package name is not defined. Nothing to do 😯" "$usage"
fi

PKG_DESCRIPTION=$2
if [ -z "$2" ]; then
print_and_exit "Package description is not defined. Nothing to do, exiting..." "$usage"
print_and_exit "Package description is not defined. Nothing to do 😯" "$usage"
fi

echo ""
echo "Your path is `pwd`. Is this your workspace source folder?"
read -p "If so press <ENTER> otherwise <CTRL>+C and start the script again from your source folder."
echo -e "${TERMINAL_COLOR_USER_NOTICE}Your path is `pwd`. Is this your workspace source folder?${TERMINAL_COLOR_NC}"
echo -e "${TERMINAL_COLOR_USER_CONFIRMATION}If so press <ENTER> otherwise <CTRL>+C and start the script again from your source folder.${TERMINAL_COLOR_NC}"
read

read -p "What type of package you want to create? (0 - standard, 1 - metapackage, 2 - subpackage) [0]:" META
echo -n -e "${TERMINAL_COLOR_USER_INPUT_DECISION}What type of package you want to create? (0 - standard, 1 - metapackage, 2 - subpackage) [0]:${TERMINAL_COLOR_NC}"
read META
META=${META:=0}

CREATE_PARAMS=""

case "$META" in
"1")
echo "Meta-package '$PKG_NAME' will be created!"
echo -e "${TERMINAL_COLOR_USER_NOTICE}Meta-package '$PKG_NAME' will be created!${TERMINAL_COLOR_NC}"
CREATE_PARAMS="--meta"
mkdir $PKG_NAME
cd $PKG_NAME
Expand All @@ -42,16 +44,17 @@ case "$META" in
if [[ ! -d $META_NAME ]]; then
echo "ERROR: metapackage with the name '$META_NAME' does not exist! Exiting..."
fi
echo "Subpackage '$PKG_NAME' will be created in the metapackage '$META_NAME'!"
echo -e "${TERMINAL_COLOR_USER_NOTICE}Subpackage '$PKG_NAME' will be created in the metapackage '$META_NAME'!${TERMINAL_COLOR_NC}"
cd $META_NAME
# TODO: read licence of the meta-package
;;
*)
echo "Package '$PKG_NAME' will be created!"
echo -e "${TERMINAL_COLOR_USER_NOTICE}Package '$PKG_NAME' will be created!${TERMINAL_COLOR_NC}"
esac


read -p "Do you want to enter name and email address of the maintainer? If not, data from git configuration will be used. (y/n) [n]: " choice
echo -n -e "${TERMINAL_COLOR_USER_INPUT_DECISION}Do you want to enter name and email address of the maintainer? If not, data from git configuration will be used. (y/n) [n]: ${TERMINAL_COLOR_NC}"
read choice
choice=${choice:="n"}

case "$choice" in
Expand All @@ -73,15 +76,17 @@ case "$choice" in
esac

# License
read -p "How do you want to licence your package? ['$TEAM_LICENSE']: " LICENSE
echo -n -e "${TERMINAL_COLOR_USER_INPUT_DECISION}How do you want to licence your package? ['$TEAM_LICENSE']: ${TERMINAL_COLOR_NC}"
read LICENSE
LICENSE=${LICENSE:=$TEAM_LICENSE}

if [[ $ros_version == 1 ]]; then
BUILD_TYPE="catkin"

elif [[ $ros_version == 2 ]]; then
# Build type
read -p "Please choose your package build type (1 - ament_cmake, 2 - ament_python, 3 - cmake) [1]:" choice
echo -n -e "${TERMINAL_COLOR_USER_INPUT_DECISION}Please choose your package build type (1 - ament_cmake, 2 - ament_python, 3 - cmake) [1]:${TERMINAL_COLOR_NC}"
read choice

case "$choice" in
"2")
Expand All @@ -96,9 +101,9 @@ elif [[ $ros_version == 2 ]]; then
fi

echo ""
echo "ATTENTION: Creating package '$PKG_NAME' in '`pwd`' with description '$PKG_DESCRIPTION', licence '$LICENSE', build type '$BUILD_TYPE' and maintainer '$MAINTAINER_NAME <$MAINTAINER_EMAIL>'"
read -p "If correct press <ENTER>, otherwise <CTRL>+C and start the script again from your source folder."

echo -e "${TERMINAL_COLOR_USER_INPUT_DECISION}ATTENTION: Creating package '$PKG_NAME' in '`pwd`' with description '$PKG_DESCRIPTION', licence '$LICENSE', build type '$BUILD_TYPE' and maintainer '$MAINTAINER_NAME <$MAINTAINER_EMAIL>'${TERMINAL_COLOR_NC}"
echo -e "${TERMINAL_COLOR_USER_CONFIRMATION}If correct press <ENTER>, otherwise <CTRL>+C and start the script again from your source folder.${TERMINAL_COLOR_NC}"
read

if [[ $ros_version == 1 ]]; then
catkin_create_pkg $CREATE_PARAMS $PKG_NAME -V 0.0.1 -l "$LICENSE" -D "$PKG_DESCRIPTION"
Expand All @@ -121,8 +126,9 @@ elif [[ $ros_version == 2 ]]; then
fi
fi

read -p "Do you want to setup/update repository with the new package configuration? (y/n) [y]: " choice
choice=${choice:="y"}
echo -n -e "${TERMINAL_COLOR_USER_INPUT_DECISION}Do you want to setup/update repository with the new package configuration? (y/n) [n]: ${TERMINAL_COLOR_NC}"
read choice
choice=${choice:="n"}

case "$choice" in
"y")
Expand Down Expand Up @@ -187,5 +193,5 @@ case "$choice" in
fi
;;
"n")
echo "Repository configuration is _not_ updated!"
echo -e "${TERMINAL_COLOR_USER_NOTICE}Repository configuration is _not_ updated!${TERMINAL_COLOR_NC}"
esac
79 changes: 57 additions & 22 deletions scripts/ros2_control/setup-controller-package.bash
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ check_ros_distro ${ROS_DISTRO}

FILE_NAME=$1
if [ -z "$1" ]; then
print_and_exit "ERROR: You should provide the file name!" "$usage"
print_and_exit "You should provide the file name! Nothing to do 😯" "$usage"
fi
if [ -f src/$FILE_NAME.cpp ]; then
print_and_exit "ERROR:The file '$FILE_NAME' already exist!" "$usage"
print_and_exit "ERROR:The file '$FILE_NAME' already exist! 😱!" "$usage"
fi

echo "" # Adds empty line

CLASS_NAME=$2
if [ -z "$2" ]; then
delimiter='_'
Expand All @@ -43,25 +45,28 @@ if [ -z "$2" ]; then
s=${s#*"$delimiter"}
CLASS_NAME="$CLASS_NAME${part^}"
done
echo "ClassName guessed from the '$FILE_NAME': '$CLASS_NAME'. Is this correct? If not, provide it as the second parameter."
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 "Package name guessed from the current path is '$PKG_NAME'. Is this correct? If not provide it as the third parameter."
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 "Which license-header do you want to use? [1]"
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"
echo "(1) Apache-2.0"
echo "(2) Propiatery"
echo -n -e "${TERMINAL_COLOR_NC}"
read choice
choice=${choice:="1"}

if [ "$choice" != 0 ]; then
read -p "Insert your company or personal name (copyright): " NAME_ON_LICENSE
echo -n -e "${TERMINAL_COLOR_USER_INPUT_DECISION}Insert your company or personal name (copyright): ${TERMINAL_COLOR_NC}"
read NAME_ON_LICENSE
NAME_ON_LICENSE=${NAME_ON_LICENSE=""}
YEAR_ON_LICENSE=$(date +%Y)
fi
Expand All @@ -75,13 +80,31 @@ case "$choice" in
LICENSE_HEADER="$LICENSE_TEMPLATES/propriatery_company_cpp.txt"
esac

read -p "Is package already configured (is in there a working controller already)? (yes/no) [no] " package_configured
echo -n -e "${TERMINAL_COLOR_USER_INPUT_DECISION}Is package already configured (is in there a working controller already)? (yes/no) [no] ${TERMINAL_COLOR_NC}"
read package_configured
package_configured=${package_configured:="no"}

echo -e "${TERMINAL_COLOR_USER_INPUT_DECISION}Do you want to setup a 'normal' or 'chainable' controller? [1]"
echo "(1) normal (single-level control)"
echo "(2) chainable"
echo -n -e "${TERMINAL_COLOR_NC}"
read choice
choice=${choice:="1"}

CONTROLLER_TYPE=""
case "$choice" in
"1")
CONTROLLER_TYPE="normal (single-level control)"
;;
"2")
CONTROLLER_TYPE="chainable"
esac

echo ""
echo "ATTENTION: Setting up ros2_control controller files with following parameters: file name '$FILE_NAME', class '$CLASS_NAME', package/namespace '$PKG_NAME'. Those will be placed in folder '`pwd`'."
echo -e "${TERMINAL_COLOR_USER_NOTICE}ATTENTION: Setting up ros2_control controller files with following parameters: file name '$FILE_NAME', class '$CLASS_NAME', package/namespace '$PKG_NAME', type '$CONTROLLER_TYPE'. Those will be placed in folder '`pwd`'.${TERMINAL_COLOR_NC}"
echo ""
read -p "If correct press <ENTER>, otherwise <CTRL>+C and start the script again from the package folder and/or with correct controller name."
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 controller name.${TERMINAL_COLOR_NC}"
read

# Add folders if deleted
ADD_FOLDERS=("include/$PKG_NAME" "src" "test")
Expand All @@ -101,16 +124,26 @@ TEST_HPP="test/test_$FILE_NAME.hpp"

# Copy files
if [[ ! -f "$VC_H" ]]; then
cp -n $ROS2_CONTROL_HW_ITF_TEMPLATES/visibility_control.h $VC_H
cp -n $ROS2_CONTROL_CONTROLLER_TEMPLATES/dummy_package_namespace/visibility_control.h $VC_H
fi
cat $ROS2_CONTROL_CONTROLLER_TEMPLATES/dummy_controller_pluginlib.xml >> $PLUGIN_XML
cp -n $ROS2_CONTROL_CONTROLLER_TEMPLATES/dummy_package_namespace/dummy_controller.hpp $CTRL_HPP
cp -n $ROS2_CONTROL_CONTROLLER_TEMPLATES/dummy_controller.cpp $CTRL_CPP

if [[ "$CONTROLLER_TYPE" == "chainable" ]]; then
cp -n $ROS2_CONTROL_CONTROLLER_TEMPLATES/dummy_package_namespace/dummy_chainable_controller.hpp $CTRL_HPP
cp -n $ROS2_CONTROL_CONTROLLER_TEMPLATES/dummy_chainable_controller.cpp $CTRL_CPP
cp -n $ROS2_CONTROL_CONTROLLER_TEMPLATES/test_dummy_chainable_controller.cpp $TEST_CPP
cp -n $ROS2_CONTROL_CONTROLLER_TEMPLATES/test_dummy_chainable_controller.hpp $TEST_HPP
cat $ROS2_CONTROL_CONTROLLER_TEMPLATES/dummy_chainable_controller_pluginlib.xml >> $PLUGIN_XML
else
cp -n $ROS2_CONTROL_CONTROLLER_TEMPLATES/dummy_package_namespace/dummy_controller.hpp $CTRL_HPP
cp -n $ROS2_CONTROL_CONTROLLER_TEMPLATES/dummy_controller.cpp $CTRL_CPP
cp -n $ROS2_CONTROL_CONTROLLER_TEMPLATES/test_dummy_controller.cpp $TEST_CPP
cp -n $ROS2_CONTROL_CONTROLLER_TEMPLATES/test_dummy_controller.hpp $TEST_HPP
cat $ROS2_CONTROL_CONTROLLER_TEMPLATES/dummy_controller_pluginlib.xml >> $PLUGIN_XML
fi

cp -n $ROS2_CONTROL_CONTROLLER_TEMPLATES/test_load_dummy_controller.cpp $LOAD_TEST_CPP
cp -n $ROS2_CONTROL_CONTROLLER_TEMPLATES/test_dummy_controller.cpp $TEST_CPP
cp -n $ROS2_CONTROL_CONTROLLER_TEMPLATES/test_dummy_controller.hpp $TEST_HPP

echo "Template files copied."
echo -e "${TERMINAL_COLOR_USER_NOTICE}Template files copied.${TERMINAL_COLOR_NC}"

# TODO(anyone): fuse this with hardware interface package creating.

Expand Down Expand Up @@ -139,11 +172,11 @@ FILES_TO_SED+=("$PLUGIN_XML")

for SED_FILE in "${FILES_TO_SED[@]}"; do
sed -i "s/TEMPLATES__ROS2_CONTROL__CONTROLLER__DUMMY_PACKAGE_NAMESPACE/${PKG_NAME^^}/g" $SED_FILE # package name for include guard
sed -i "s/TEMPLATES__ROS2_CONTROL__CONTROLLER/${PKG_NAME^^}/g" $SED_FILE # package name for include guard
sed -i "s/TEMPLATES__ROS2_CONTROL__HARDWARE/${PKG_NAME^^}/g" $SED_FILE # package name for include guard from hardware
sed -i "s/dummy_package_namespace/${PKG_NAME}/g" $SED_FILE # package name for includes
sed -i "s/dummy_controller/${FILE_NAME}/g" $SED_FILE # file name
sed -i "s/dummy_chainable_controller/${FILE_NAME}/g" $SED_FILE # file name
sed -i "s/DUMMY_CONTROLLER/${FILE_NAME^^}/g" $SED_FILE # file name for include guard
sed -i "s/DUMMY_CHAINABLE_CONTROLLER/${FILE_NAME^^}/g" $SED_FILE # file name for include guard
sed -i "s/DummyClassName/${CLASS_NAME}/g" $SED_FILE # class name
sed -i "s/dummy_interface_type/${INTERFACE_TYPE}/g" $SED_FILE # interface type for includes
sed -i "s/Dummy_Interface_Type/${INTERFACE_TYPE^}/g" $SED_FILE # Interface type in namespace resolution
Expand Down Expand Up @@ -188,6 +221,7 @@ echo " pluginlib" >> $TMP_FILE
echo " rclcpp" >> $TMP_FILE
echo " rclcpp_lifecycle" >> $TMP_FILE
echo " realtime_tools" >> $TMP_FILE
echo " std_srvs" >> $TMP_FILE
echo ")" >> $TMP_FILE

if [[ "$package_configured" == "no" ]]; then
Expand Down Expand Up @@ -270,6 +304,7 @@ if [[ "$package_configured" == "no" ]]; then
echo " rclcpp" >> $TMP_FILE
echo " rclcpp_lifecycle" >> $TMP_FILE
echo " realtime_tools" >> $TMP_FILE
echo " std_srvs" >> $TMP_FILE
echo ")" >> $TMP_FILE

fi
Expand All @@ -281,7 +316,7 @@ tail -n +$TEST_LINE CMakeLists.txt | tail -n +$CUT_LINE >> $TMP_FILE
mv $TMP_FILE CMakeLists.txt

# CMakeLists.txt & package.xml: Add dependencies if they not exist
DEP_PKGS=("realtime_tools" "rclcpp_lifecycle" "rclcpp" "pluginlib" "hardware_interface" "controller_interface" "control_msgs")
DEP_PKGS=("std_srvs" "realtime_tools" "rclcpp_lifecycle" "rclcpp" "pluginlib" "hardware_interface" "controller_interface" "control_msgs")

for DEP_PKG in "${DEP_PKGS[@]}"; do

Expand Down Expand Up @@ -339,7 +374,7 @@ if [ -f README.md ]; then

fi

echo "Template files are adjusted."
echo -e "${TERMINAL_COLOR_USER_NOTICE}Template files were adjusted.${TERMINAL_COLOR_NC}"

git add .
# git commit -m "RosTeamWS: ros2_control skeleton files for $ROBOT_NAME generated."
Expand All @@ -350,4 +385,4 @@ git add .
compile_and_source_package $PKG_NAME "yes"

echo ""
echo "FINISHED: Your package is set and the tests should be finished without any errors. (linter errors possible!)"
echo -e "${TERMINAL_COLOR_USER_NOTICE}FINISHED: Your package is set and the tests should be finished without any errors. (linter errors possible!)${TERMINAL_COLOR_NC}"
Loading

0 comments on commit 41e08cf

Please sign in to comment.