Skip to content

Commit

Permalink
Update setup_controller.rst (StoglRobotics#14)
Browse files Browse the repository at this point in the history
* Update create controller manual and scripts
  • Loading branch information
destogl authored May 5, 2021
1 parent df10cb4 commit cd83934
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 27 deletions.
29 changes: 19 additions & 10 deletions docs/use-cases/ros2_control/setup_controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ ros2_control: Setup controller package
.. _uc-setup-ros2-controller:

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

``ros2_control_setup-controller-package`` script accepts the file name of the controller and, optionally, class name and the package name.
The file name should use standard ROS format <my_cool_controller>.
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 script **has to be executed** from the folder where the package should be generated.
The scripts uses template files from ``templates/ros2_control/controller`` folder.
The script creates a complete skeleton of a controller with plugin description and tests for loading controller and checking its basic functionality.

**Note**: it is recomended to setup your package using :ref:`setup-new-package <uc-new-package>` scritpt.

The scripts copies template files from the ``templates/ros2_control/controller`` folder, rename the files, and replaces the placeholders.
The scripts adds also a plugin description and simple test checking if the plugin can be loaded.
**IMPORTANT**: The script has to be executed from the folder where files should be generated.

Usage
------

.. code-block:: bash
:caption: Usage of script for setting up a controller.
Expand All @@ -24,4 +21,16 @@ The scripts adds also a plugin description and simple test checking if the plugi
ros2_control_setup-controller-package FILE_NAME [CLASS_NAME] [PKG_NAME]
After all files are copied and placeholders set, a commit can be automatically created.
Parameters:

- ``FILE_NAME`` file name used for controller's ``.cpp`` and ``.hpp`` files.
It assumes standard ROS format, e.g, "my_cool_controller".

- ``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 you for some additional input.
18 changes: 11 additions & 7 deletions scripts/_RosTeamWs_Defines.bash
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,17 @@ function compile_and_source_package {
fi
bn=`basename "$PWD"`
path=$bn
# while [[ "$bn" != "src" ]]; do
# cd ..
# bn=`basename "$PWD"`
# path="$bn/$path"
# done
# cd ..
cd $ROS_WS
if [[ -v $ROS_WS ]]; then
cd $ROS_WS
else
while [[ "$bn" != "src" ]]; do
cd ..
bn=`basename "$PWD"`
path="$bn/$path"
done
cd ..
fi
echo "Trying to compile a newly created package. If you get an error try to do this manually."
colcon build --symlink-install --packages-up-to $pkg_name
source install/setup.bash
if [[ "$test" == "yes" ]]; then
Expand Down
23 changes: 13 additions & 10 deletions scripts/ros2_control/setup-controller-package.bash
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ case "$choice" in
LICENSE_HEADER="$LICENSE_TEMPLATES/propriatery_company_cpp.txt"
esac

read -p "Is package already configured? (yes/no) [no] " package_configured
# read -p "Is package already configured? (yes/no) [no] " package_configured
package_configured=${package_configured:="no"}

echo ""
Expand Down Expand Up @@ -166,21 +166,21 @@ head -$CUT_LINE CMakeLists.txt >> $TMP_FILE

# Add Plugin library stuff inside
echo "add_library(" >> $TMP_FILE
echo " $PKG_NAME" >> $TMP_FILE
echo " $FILE_NAME" >> $TMP_FILE
echo " SHARED" >> $TMP_FILE
echo " $CTRL_CPP" >> $TMP_FILE
echo ")" >> $TMP_FILE

echo "target_include_directories(" >> $TMP_FILE
echo " $PKG_NAME" >> $TMP_FILE
echo " $FILE_NAME" >> $TMP_FILE
echo " PUBLIC" >> $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 " $FILE_NAME" >> $TMP_FILE
echo " control_msgs" >> $TMP_FILE
echo " controller_interface" >> $TMP_FILE
echo " hardware_interface" >> $TMP_FILE
Expand All @@ -192,7 +192,7 @@ echo ")" >> $TMP_FILE

# TODO(anyone): Delete after Foxy!!!
echo "# prevent pluginlib from using boost" >> $TMP_FILE
echo "target_compile_definitions($PKG_NAME PUBLIC \"PLUGINLIB__DISABLE_BOOST_FUNCTIONS\")" >> $TMP_FILE
echo "target_compile_definitions($FILE_NAME PUBLIC \"PLUGINLIB__DISABLE_BOOST_FUNCTIONS\")" >> $TMP_FILE

if [[ "$package_configured" == "no" ]]; then

Expand All @@ -204,7 +204,7 @@ if [[ "$package_configured" == "no" ]]; then
echo "" >> $TMP_FILE
echo "install(" >> $TMP_FILE
echo " TARGETS" >> $TMP_FILE
echo " $PKG_NAME" >> $TMP_FILE
echo " $FILE_NAME" >> $TMP_FILE
echo " RUNTIME DESTINATION bin" >> $TMP_FILE
echo " ARCHIVE DESTINATION lib" >> $TMP_FILE
echo " LIBRARY DESTINATION lib" >> $TMP_FILE
Expand Down Expand Up @@ -258,10 +258,13 @@ if [[ "$package_configured" == "no" ]]; then
echo " include" >> $TMP_FILE
echo ")" >> $TMP_FILE

echo "ament_export_libraries(" >> $TMP_FILE
echo " $PKG_NAME" >> $TMP_FILE
echo ")" >> $TMP_FILE
fi

echo "ament_export_libraries(" >> $TMP_FILE
echo " $FILE_NAME" >> $TMP_FILE
echo ")" >> $TMP_FILE

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
Expand Down Expand Up @@ -334,7 +337,7 @@ sed -i "/<test_depend>ament_lint_common<\/test_depend>/d" package.xml
if [ -f README.md ]; then

echo "" >> README.md
echo "Pluginlib-Library: $PKG_NAME" >> README.md
echo "Pluginlib-Library: $FILE_NAME" >> README.md
echo ""
echo "Plugin: $PKG_NAME/${CLASS_NAME} (controller_interface::ControllerInterface)" >> README.md

Expand Down
1 change: 1 addition & 0 deletions templates/ros2_control/controller/controller.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$LICENSE$

#include <limits>
#include <memory>
#include <string>
#include <vector>

Expand Down
1 change: 1 addition & 0 deletions templates/ros2_control/controller/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#ifndef $PACKAGE_NAME$__$FILE_NAME$_HPP_
#define $PACKAGE_NAME$__$FILE_NAME$_HPP_

#include <memory>
#include <string>
#include <vector>

Expand Down
1 change: 1 addition & 0 deletions templates/ros2_control/controller/test_controller.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$LICENSE$

#include <memory>
#include <string>
#include <utility>
#include <vector>

Expand Down
3 changes: 3 additions & 0 deletions templates/ros2_control/controller/test_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include <chrono>
#include <memory>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#include "$package_name$/$package_name$.hpp"
#include "gmock/gmock.h"
Expand Down

0 comments on commit cd83934

Please sign in to comment.