Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dynamic reconfigure for PID gains #1

Merged
merged 13 commits into from
Jul 29, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 43 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,47 @@ if(USE_ROSBUILD)
rosbuild_init()
#rosbuild_genmsg()
rosbuild_gensrv()
rosbuild_add_library(control_toolbox
rosbuild_add_library(${PROJECT_NAME}
src/pid.cpp
src/pid_gains_setter.cpp
src/sine_sweep.cpp
src/dither.cpp
src/sinusoid.cpp
src/limited_proxy.cpp
)
target_link_libraries(control_toolbox tinyxml)
target_link_libraries(${PROJECT_NAME} tinyxml)

# rosbuild_add_executable(test_linear test/linear.cpp)

# Tests
rosbuild_add_gtest(test/pid_tests test/pid_tests.cpp)
target_link_libraries(test/pid_tests control_toolbox)
rosbuild_add_gtest(test/pid_tests test/pid_tests.cpp)
target_link_libraries(test/pid_tests ${PROJECT_NAME})

else()

# Load catkin and all dependencies required for this package
find_package(catkin REQUIRED COMPONENTS rosconsole message_generation tf roscpp angles)
find_package(catkin REQUIRED COMPONENTS
rosconsole
message_generation
tf
roscpp
angles
dynamic_reconfigure
realtime_tools
)

find_package(Boost REQUIRED COMPONENTS system thread)

include_directories(
include
${Boost_INCLUDE_DIR} ${catkin_INCLUDE_DIRS})
include
${catkin_INCLUDE_DIRS}
${Boost_INCLUDE_DIR}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be ${Boost_INCLUDE_DIR} or ${Boost_INCLUDE_DIRS} ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just did some googling but I couldn't find anything conclusive about which one is right... I think they both work? I searched through the my ROS workspace and lots of code uses the singular _DIR include:

./ros_control/controller_manager_tests/CMakeLists.txt:34:  include_directories(include ${Boost_INCLUDE_DIR} ${catkin_INCLUDE_DIRS})
./ros_control/controller_manager/CMakeLists.txt:21:  include_directories(include ${Boost_INCLUDE_DIR} ${catkin_INCLUDE_DIRS})
./gazebo_tutorials/CMakeLists.txt:18:include_directories(${Boost_INCLUDE_DIR} ${catkin_INCLUDE_DIRS} ${GAZEBO_INCLUDE_DIRS})
./control_toolbox/CMakeLists.txt:40:    ${Boost_INCLUDE_DIR}
./ros_controllers/joint_state_controller/CMakeLists.txt:19:  include_directories(include ${Boost_INCLUDE_DIR} ${catkin_INCLUDE_DIRS})
./ros_controllers/position_controllers/CMakeLists.txt:20:  include_directories(include ${Boost_INCLUDE_DIR} ${catkin_INCLUDE_DIRS})
./ros_controllers/effort_controllers/CMakeLists.txt:21:  include_directories(include ${Boost_INCLUDE_DIR} ${catkin_INCLUDE_DIRS})
./ros_controllers/imu_sensor_controller/CMakeLists.txt:18:  include_directories(include ${Boost_INCLUDE_DIR} ${catkin_INCLUDE_DIRS})
./ros_controllers/force_torque_sensor_controller/CMakeLists.txt:18:  include_directories(include ${Boost_INCLUDE_DIR} ${catkin_INCLUDE_DIRS})
./ros_controllers/velocity_controllers/CMakeLists.txt:19:  include_directories(include ${Boost_INCLUDE_DIR} ${catkin_INCLUDE_DIRS})
./realtime_tools/CMakeLists.txt:16:  include_directories(include ${Boost_INCLUDE_DIR} ${catkin_INCLUDE_DIRS})
./gazebo_ros_pkgs/gazebo_ros_control/CMakeLists.txt:29:  ${Boost_INCLUDE_DIR}

)

# Dynamics reconfigure
generate_dynamic_reconfigure_options(
cfg/Parameters.cfg
)

# Add services and generate them
add_service_files(
Expand All @@ -41,6 +58,20 @@ else()
DEPENDENCIES std_msgs
)

# Declare catkin package
catkin_package(
DEPENDS tinyxml
CATKIN_DEPENDS
rosconsole
tf
roscpp
angles
dynamic_reconfigure
realtime_tools
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
)

add_library(${PROJECT_NAME}
src/pid.cpp
src/pid_gains_setter.cpp
Expand All @@ -49,20 +80,14 @@ else()
src/sinusoid.cpp
src/limited_proxy.cpp
)
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_gencfg) # wait for dynamic reconfigure

target_link_libraries(control_toolbox tinyxml ${catkin_LIBRARIES})
add_dependencies(control_toolbox ${PROJECT_NAME}_gencpp)
target_link_libraries(${PROJECT_NAME} tinyxml ${catkin_LIBRARIES} ${Boost_LIBRARIES})

# Declare catkin package
catkin_package(
DEPENDS tinyxml
CATKIN_DEPENDS rosconsole tf roscpp angles
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
)
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_gencpp) # wait for msgs

# Tests
catkin_add_gtest(pid_tests test/pid_tests.cpp)
catkin_add_gtest(pid_tests test/pid_tests.cpp)
target_link_libraries(pid_tests ${catkin_LIBRARIES} ${PROJECT_NAME})

# add_executable(test_linear test/linear.cpp)
Expand All @@ -78,6 +103,6 @@ else()
)

install(DIRECTORY scripts/
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

endif()
54 changes: 54 additions & 0 deletions cfg/Parameters.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#! /usr/bin/env python
#*********************************************************************
#* Software License Agreement (BSD License)
#*
#* Copyright (c) 2013, Open Source Robotics Foundation
#* All rights reserved.
#*
#* Redistribution and use in source and binary forms, with or without
#* modification, are permitted provided that the following conditions
#* are met:
#*
#* * Redistributions of source code must retain the above copyright
#* notice, this list of conditions and the following disclaimer.
#* * Redistributions in binary form must reproduce the above
#* copyright notice, this list of conditions and the following
#* disclaimer in the documentation and/or other materials provided
#* with the distribution.
#* * Neither the name of the Open Source Robotics Foundation
#* nor the names of its contributors may be
#* used to endorse or promote products derived
#* from this software without specific prior written permission.
#*
#* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
#* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
#* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
#* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
#* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
#* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
#* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
#* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
#* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
#* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
#* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
#* POSSIBILITY OF SUCH DAMAGE.
#*********************************************************************/

# Author: Dave Coleman
# Desc: Allows PID parameters, etc to be tuned in realtime using dynamic reconfigure


PACKAGE='control_toolbox'

from dynamic_reconfigure.parameter_generator_catkin import *

gen = ParameterGenerator()

# Name Type Level Description Default Min Max
gen.add( "p_gain" , double_t, 1,"Proportional gain.", 10.0 , 0 , 1000)
gen.add( "i_gain" , double_t, 1,"Integral gain.", 10.0 , 0 , 100)
gen.add( "d_gain" , double_t, 1,"Derivative gain.", 10.0 , 0 , 100)
gen.add( "i_clamp_min" , double_t, 1,"Min bounds for the integral windup", 10.0 , 0 , 100)
gen.add( "i_clamp_max" , double_t, 1,"Max bounds for the integral windup", 10.0 , 0 , 100)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe dynamic_reconfigure interacts with the parameter server; it may be useful to give these the same names and defaults and their matching parameters.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mean the full path of the parameters on the parameter server, the Pid class doesn't know those before hand (it is passed a nodehandle at initialization).

If you mean we should name the gains "p", "i", and "d" - I tried that and wasted a lot of time debugging why it wasn't working. There is a bug that disallows you to name a dynamic reconfigure parameter "i" ros/dynamic_reconfigure#6

I documented the issue on the tutorial in the red box.

# PkgName #NodeName #Prefix for generated .h include file, e.g. ParametersConfig.py
exit(gen.generate(PACKAGE, "control_toolbox", "Parameters"))
Loading