Skip to content

Commit

Permalink
Extend controller templates with additional tests (StoglRobotics#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
destogl authored May 1, 2021
1 parent 949648b commit df10cb4
Show file tree
Hide file tree
Showing 17 changed files with 765 additions and 283 deletions.
2 changes: 1 addition & 1 deletion scripts/create-new-package.bash
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ read -p "If correct press <ENTER>, otherwise <CTRL>+C and start the script again


if [[ $ros_version == 1 ]]; then
catkin_create_pkg $CREATE_PARAMS $PKG_NAME -V 0.0.1 -l $LICENSE -D "$PKG_DESCRIPTION"
catkin_create_pkg $CREATE_PARAMS $PKG_NAME -V 0.0.1 -l "$LICENSE" -D "$PKG_DESCRIPTION"
catkin b -c
source ~/.bashrc
elif [[ $ros_version == 2 ]]; then
Expand Down
80 changes: 35 additions & 45 deletions scripts/ros2_control/setup-controller-package.bash
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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> otherise <CTRL>+C and start the script again from the bringup folder."
# read -p "If so press <ENTER> otherwise <CTRL>+C and start the script again from the bringup folder."

# Load Framework defines
script_own_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )"
Expand All @@ -30,7 +30,7 @@ if [ -z "$1" ]; then
print_and_exit "ERROR: You should provide the file name!" "$usage"
fi
if [ -f src/$FILE_NAME.cpp ]; then
print_and_exit "ERROR:The file '$FILE_NAME' alread exist!" "$usage"
print_and_exit "ERROR:The file '$FILE_NAME' already exist!" "$usage"
fi

CLASS_NAME=$2
Expand Down Expand Up @@ -81,7 +81,7 @@ package_configured=${package_configured:="no"}
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 ""
read -p "If correct press <ENTER>, otherwise <CTRL>+C and start the script again from the package folder and/or with correct robot name."
read -p "If correct press <ENTER>, otherwise <CTRL>+C and start the script again from the package folder and/or with correct controller name."

# Add folders if deleted
ADD_FOLDERS=("include/$PKG_NAME" "src" "test")
Expand All @@ -95,7 +95,9 @@ VC_H="include/$PKG_NAME/visibility_control.h"
CTRL_HPP="include/$PKG_NAME/$FILE_NAME.hpp"
CTRL_CPP="src/$FILE_NAME.cpp"
PLUGIN_XML="$PKG_NAME.xml"
TEST_CPP="test/test_load_$FILE_NAME.cpp"
LOAD_TEST_CPP="test/test_load_$FILE_NAME.cpp"
TEST_CPP="test/test_$FILE_NAME.cpp"
TEST_HPP="test/test_$FILE_NAME.hpp"

# Copy files
if [[ ! -f "$VC_H" ]]; then
Expand All @@ -104,18 +106,16 @@ fi
cat $ROS2_CONTROL_CONTROLLER_TEMPLATES/controller_pluginlib.xml >> $PLUGIN_XML
cp -n $ROS2_CONTROL_CONTROLLER_TEMPLATES/controller.hpp $CTRL_HPP
cp -n $ROS2_CONTROL_CONTROLLER_TEMPLATES/controller.cpp $CTRL_CPP
cp -n $ROS2_CONTROL_CONTROLLER_TEMPLATES/test_load_controller.cpp $TEST_CPP
cp -n $ROS2_CONTROL_CONTROLLER_TEMPLATES/test_load_controller.cpp $LOAD_TEST_CPP
cp -n $ROS2_CONTROL_CONTROLLER_TEMPLATES/test_controller.cpp $TEST_CPP
cp -n $ROS2_CONTROL_CONTROLLER_TEMPLATES/test_controller.hpp $TEST_HPP

echo "Template files copied."

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

# Add license header to the files
# TODO: When Propiatery then add the follwing before ament_lint_auto_find_test_dependencies()
# list(APPEND AMENT_LINT_AUTO_EXCLUDE
# ament_cmake_copyright
# )
FILES_TO_LICENSE=("$CTRL_HPP" "$CTRL_CPP" "$TEST_CPP")
FILES_TO_LICENSE=("$CTRL_HPP" "$CTRL_CPP" "$LOAD_TEST_CPP" "$TEST_CPP" "$TEST_HPP")
if [[ "$package_configured" == "no" ]]; then
FILES_TO_LICENSE+=("$VC_H")
fi
Expand Down Expand Up @@ -174,17 +174,20 @@ echo ")" >> $TMP_FILE
echo "target_include_directories(" >> $TMP_FILE
echo " $PKG_NAME" >> $TMP_FILE
echo " PUBLIC" >> $TMP_FILE
echo " include" >> $TMP_FILE
echo " $<BUILD_INTERFACE:\${CMAKE_CURRENT_SOURCE_DIR}/include>" >> $TMP_FILE
echo " $<INSTALL_INTERFACE:include>" >> $TMP_FILE
echo ")" >> $TMP_FILE

# TODO(anyone): Add this dependencies in a loop
echo "ament_target_dependencies(" >> $TMP_FILE
echo " $PKG_NAME" >> $TMP_FILE
echo " control_msgs" >> $TMP_FILE
echo " controller_interface" >> $TMP_FILE
echo " hardware_interface" >> $TMP_FILE
echo " pluginlib" >> $TMP_FILE
echo " rclcpp" >> $TMP_FILE
echo " rclcpp_lifecycle" >> $TMP_FILE
echo " realtime_tools" >> $TMP_FILE
echo ")" >> $TMP_FILE

# TODO(anyone): Delete after Foxy!!!
Expand Down Expand Up @@ -223,14 +226,25 @@ END_TEST_LINE=`tail -n +$TEST_LINE CMakeLists.txt | awk '$1 == "endif()" { print
let CUT_LINE=$END_TEST_LINE-1
tail -n +$TEST_LINE CMakeLists.txt | head -$CUT_LINE >> $TMP_FILE

echo "" >> $TMP_FILE
echo " ament_add_gmock(test_load_$FILE_NAME $LOAD_TEST_CPP)" >> $TMP_FILE
echo " target_include_directories(test_load_$FILE_NAME PRIVATE include)" >> $TMP_FILE
echo " ament_target_dependencies(" >> $TMP_FILE
echo " test_load_$FILE_NAME" >> $TMP_FILE
echo " controller_manager" >> $TMP_FILE
echo " hardware_interface" >> $TMP_FILE
echo " ros2_control_test_assets" >> $TMP_FILE
echo " )" >> $TMP_FILE
echo ""

echo "" >> $TMP_FILE
echo " ament_add_gmock(test_$FILE_NAME $TEST_CPP)" >> $TMP_FILE
echo " target_include_directories(test_$FILE_NAME PRIVATE include)" >> $TMP_FILE
echo " target_link_libraries(test_$FILE_NAME $FILE_NAME)" >> $TMP_FILE
echo " ament_target_dependencies(" >> $TMP_FILE
echo " test_$FILE_NAME" >> $TMP_FILE
echo " controller_manager" >> $TMP_FILE
echo " controller_interface" >> $TMP_FILE
echo " hardware_interface" >> $TMP_FILE
echo " ros2_control_test_assets" >> $TMP_FILE
echo " )" >> $TMP_FILE
echo ""

Expand All @@ -250,11 +264,13 @@ if [[ "$package_configured" == "no" ]]; then

# TODO(anyone): use this from a list so its the same as above
echo "ament_export_dependencies(" >> $TMP_FILE
echo " control_msgs" >> $TMP_FILE
echo " controller_interface" >> $TMP_FILE
echo " hardware_interface" >> $TMP_FILE
echo " pluginlib" >> $TMP_FILE
echo " rclcpp" >> $TMP_FILE
echo " rclcpp_lifecycle" >> $TMP_FILE
echo " realtime_tools" >> $TMP_FILE
echo ")" >> $TMP_FILE

fi
Expand All @@ -266,7 +282,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=("rclcpp_lifecycle" "rclcpp" "pluginlib" "hardware_interface" "controller_interface")
DEP_PKGS=("realtime_tools" "rclcpp_lifecycle" "rclcpp" "pluginlib" "hardware_interface" "controller_interface" "control_msgs")

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

Expand Down Expand Up @@ -310,6 +326,10 @@ for DEP_PKG in "${TEST_DEP_PKGS[@]}"; do
fi
done

# Remove lint dependencies because they should be not included into build
sed -i "/ament_lint_auto_find_test_dependencies()/d" CMakeLists.txt
sed -i "/<test_depend>ament_lint_common<\/test_depend>/d" package.xml

# extend README with general instructions
if [ -f README.md ]; then

Expand All @@ -323,40 +343,10 @@ fi
git add .
# git commit -m "RosTeamWS: ros2_control skeleton files for $ROBOT_NAME generated."

ament_uncrustify --reformat
# ament_uncrustify --reformat

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

echo ""
echo "FINISHED: Your package is set and the tests should be finished without any errors."






























36 changes: 3 additions & 33 deletions scripts/ros2_control/setup-hardware-interface-package.bash
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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> otherise <CTRL>+C and start the script again from the bringup folder."
# read -p "If so press <ENTER> otherwise <CTRL>+C and start the script again from the bringup folder."

# Load Framework defines
script_own_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )"
Expand All @@ -30,7 +30,7 @@ if [ -z "$1" ]; then
print_and_exit "ERROR: You should provide the file name!" "$usage"
fi
if [ -f src/$FILE_NAME.cpp ]; then
print_and_exit "ERROR:The file '$FILE_NAME' alread exist!" "$usage"
print_and_exit "ERROR:The file '$FILE_NAME' already exist!" "$usage"
fi

CLASS_NAME=$2
Expand Down Expand Up @@ -120,7 +120,7 @@ cp -n $ROS2_CONTROL_HW_ITF_TEMPLATES/test_robot_hardware_interface.cpp $TEST_CPP
echo "Template files copied."

# Add license header to the files
# TODO: When Propiatery then add the follwing before ament_lint_auto_find_test_dependencies()
# TODO: When Propiatery then add the following before ament_lint_auto_find_test_dependencies()
# list(APPEND AMENT_LINT_AUTO_EXCLUDE
# ament_cmake_copyright
# )
Expand Down Expand Up @@ -322,33 +322,3 @@ compile_and_source_package $PKG_NAME "yes"

echo ""
echo "FINISHED: Your package is set and the tests should be finished without any errors."






























Loading

0 comments on commit df10cb4

Please sign in to comment.