Skip to content

Commit bd830b8

Browse files
committed
Pull upstream/ros2-master commits
2 parents d669c37 + 4218a6d commit bd830b8

6 files changed

Lines changed: 50 additions & 89 deletions

File tree

control_toolbox/CHANGELOG.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,9 @@ Changelog for package control_toolbox
357357
* catkinizing, could still be cleaned up
358358
* Fixing doc errors in PID
359359
* Changing @ commands to \ commands
360-
* Enforcing i_min_ <= 0 and i_max_ >= 0 in integral bound parameters, reducing duplicated code
360+
* Enforcing ``i_min_`` <= 0 and ``i_max_`` >= 0 in integral bound parameters, reducing duplicated code
361361
* Merge pull request `#14 <https://github.com/ros-controls/control_toolbox/issues/14>`_ from bobholmberg/fix-PID-unbounded-i_error
362-
Using zero i_gain_ to turn off integral control did unsavory things.
362+
Using zero ``i_gain_`` to turn off integral control did unsavory things.
363363
* Adding alternative name for new pid command computation API
364364
* Fixing merge error
365365
* Merge branch 'fix-pid-backwards-compatibility' into fix-PID-unbounded-i_error
@@ -376,13 +376,13 @@ Changelog for package control_toolbox
376376
* Specifying div-by-zero test, adding other integral term tests
377377
* Merge branch 'test-bad-integral-bounds' into fix-PID-unbounded-i_error
378378
* Adding test to expose Pid class zero-division vulnerability
379-
* If the user did not want integral control and set i_gain_ to zero,
380-
then dividing by i_gain_ would set i_error_ to NaN. This is not
381-
desired. Instead, replace the use of division to create i_term
382-
with direct integration of i_term_.
383-
Replace private member i_error_ with i_term_.
384-
In getCurrentPIDErrors() create & return i_error_ with the same old meaning and units.
385-
NOTE: i_error_ is not needed internally anywhere else.
379+
* If the user did not want integral control and set ``i_gain_`` to zero,
380+
then dividing by ``i_gain_`` would set ``i_error_`` to NaN. This is not
381+
desired. Instead, replace the use of division to create ``i_term``
382+
with direct integration of ``i_term_``.
383+
Replace private member ``i_error_`` with ``i_term_``.
384+
In ``getCurrentPIDErrors()`` create & return ``i_error_`` with the same old meaning and units.
385+
NOTE: ``i_error_`` is not needed internally anywhere else.
386386
* Cleaning up documentation, making argument names in function declaration match those in the implementation
387387
* adding doxygen deprecation flags
388388
* Fixing documentation

control_toolbox/include/control_filters/gravity_compensation.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
#include "filters/filter_base.hpp"
2424
#include "geometry_msgs/msg/vector3_stamped.hpp"
25-
#include "tf2_ros/buffer.h"
26-
#include "tf2_ros/transform_listener.h"
25+
#include "tf2_ros/buffer.hpp"
26+
#include "tf2_ros/transform_listener.hpp"
2727

2828
#include "control_toolbox/gravity_compensation_filter_parameters.hpp"
2929

control_toolbox/src/pid_ros.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,17 @@ bool PidROS::initialize_from_ros_parameters()
275275
all_params_available &=
276276
get_double_param(param_prefix_ + "tracking_time_constant", tracking_time_constant);
277277

278+
bool saturation = std::isfinite(u_max) || std::isfinite(u_min);
279+
get_boolean_param(param_prefix_ + "saturation", saturation);
280+
if (!saturation)
281+
{
282+
u_max = MAX_INFINITY;
283+
u_min = -MAX_INFINITY;
284+
}
278285
get_string_param(param_prefix_ + "antiwindup_strategy", antiwindup_strat_str);
279286
declare_param(param_prefix_ + "save_i_term", rclcpp::ParameterValue(false));
287+
declare_param(
288+
param_prefix_ + "activate_state_publisher", rclcpp::ParameterValue(rt_state_pub_ != nullptr));
280289

281290
if (all_params_available)
282291
{
@@ -348,7 +357,9 @@ bool PidROS::initialize_from_args(
348357
rclcpp::ParameterValue(antiwindup_strat.tracking_time_constant));
349358
declare_param(
350359
param_prefix_ + "error_deadband", rclcpp::ParameterValue(antiwindup_strat.error_deadband));
351-
declare_param(param_prefix_ + "saturation", rclcpp::ParameterValue(true));
360+
declare_param(
361+
param_prefix_ + "saturation",
362+
rclcpp::ParameterValue(std::isfinite(gains.u_max_) || std::isfinite(gains.u_min_)));
352363
declare_param(
353364
param_prefix_ + "antiwindup_strategy",
354365
rclcpp::ParameterValue(gains.antiwindup_strat_.to_string()));

control_toolbox/test/control_filters/test_gravity_compensation.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,24 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "test_gravity_compensation.hpp"
15+
#include "test_filter_util.hpp"
1616

17+
#include <memory>
1718
#include <vector>
1819

19-
TEST_F(GravityCompensationTest, TestGravityCompensationFilterThrowsUnconfigured)
20+
#include "control_filters/gravity_compensation.hpp"
21+
#include "geometry_msgs/msg/wrench_stamped.hpp"
22+
#include "gmock/gmock.h"
23+
24+
TEST_F(FilterTest, TestGravityCompensationFilterThrowsUnconfigured)
2025
{
2126
std::shared_ptr<filters::FilterBase<geometry_msgs::msg::WrenchStamped>> filter_ =
2227
std::make_shared<control_filters::GravityCompensation<geometry_msgs::msg::WrenchStamped>>();
2328
geometry_msgs::msg::WrenchStamped in, out;
2429
ASSERT_THROW(filter_->update(in, out), std::runtime_error);
2530
}
2631

27-
TEST_F(GravityCompensationTest, TestGravityCompensationMissingParameters)
32+
TEST_F(FilterTest, TestGravityCompensationMissingParameters)
2833
{
2934
std::shared_ptr<filters::FilterBase<geometry_msgs::msg::WrenchStamped>> filter_ =
3035
std::make_shared<control_filters::GravityCompensation<geometry_msgs::msg::WrenchStamped>>();
@@ -40,7 +45,7 @@ TEST_F(GravityCompensationTest, TestGravityCompensationMissingParameters)
4045
*/
4146
}
4247

43-
TEST_F(GravityCompensationTest, TestGravityCompensationInvalidThenFixedParameter)
48+
TEST_F(FilterTest, TestGravityCompensationInvalidThenFixedParameter)
4449
{
4550
std::shared_ptr<filters::FilterBase<geometry_msgs::msg::WrenchStamped>> filter_ =
4651
std::make_shared<control_filters::GravityCompensation<geometry_msgs::msg::WrenchStamped>>();
@@ -67,7 +72,7 @@ TEST_F(GravityCompensationTest, TestGravityCompensationInvalidThenFixedParameter
6772
node_->get_node_parameters_interface()));
6873
}
6974

70-
TEST_F(GravityCompensationTest, TestGravityCompensationMissingTransform)
75+
TEST_F(FilterTest, TestGravityCompensationMissingTransform)
7176
{
7277
std::shared_ptr<filters::FilterBase<geometry_msgs::msg::WrenchStamped>> filter_ =
7378
std::make_shared<control_filters::GravityCompensation<geometry_msgs::msg::WrenchStamped>>();
@@ -86,7 +91,7 @@ TEST_F(GravityCompensationTest, TestGravityCompensationMissingTransform)
8691
ASSERT_FALSE(filter_->update(in, out));
8792
}
8893

89-
TEST_F(GravityCompensationTest, TestGravityCompensationComputation)
94+
TEST_F(FilterTest, TestGravityCompensationComputation)
9095
{
9196
std::shared_ptr<filters::FilterBase<geometry_msgs::msg::WrenchStamped>> filter_ =
9297
std::make_shared<control_filters::GravityCompensation<geometry_msgs::msg::WrenchStamped>>();

control_toolbox/test/control_filters/test_gravity_compensation.hpp

Lines changed: 0 additions & 63 deletions
This file was deleted.

control_toolbox/test/pid_ros_parameters_tests.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -572,22 +572,22 @@ TEST(PidParametersTest, GetParametersTest)
572572
TEST(PidParametersTest, GetParametersFromParams)
573573
{
574574
rclcpp::Node::SharedPtr node = std::make_shared<rclcpp::Node>("pid_parameters_test");
575-
576-
TestablePidROS pid(node, "", "", false);
575+
const bool ACTIVATE_STATE_PUBLISHER = false;
576+
TestablePidROS pid(node, "", "", ACTIVATE_STATE_PUBLISHER);
577577

578578
ASSERT_TRUE(pid.initialize_from_ros_parameters());
579579

580580
rclcpp::Parameter param_p;
581581
ASSERT_TRUE(node->get_parameter("p", param_p));
582-
ASSERT_TRUE(std::isnan(param_p.get_value<double>()));
582+
EXPECT_TRUE(std::isnan(param_p.get_value<double>()));
583583

584584
rclcpp::Parameter param_i;
585585
ASSERT_TRUE(node->get_parameter("i", param_i));
586-
ASSERT_TRUE(std::isnan(param_i.get_value<double>()));
586+
EXPECT_TRUE(std::isnan(param_i.get_value<double>()));
587587

588588
rclcpp::Parameter param_d;
589589
ASSERT_TRUE(node->get_parameter("d", param_d));
590-
ASSERT_TRUE(std::isnan(param_d.get_value<double>()));
590+
EXPECT_TRUE(std::isnan(param_d.get_value<double>()));
591591

592592
rclcpp::Parameter param_i_clamp_max;
593593
ASSERT_TRUE(node->get_parameter("i_clamp_max", param_i_clamp_max));
@@ -599,15 +599,23 @@ TEST(PidParametersTest, GetParametersFromParams)
599599

600600
rclcpp::Parameter param_u_clamp_max;
601601
ASSERT_TRUE(node->get_parameter("u_clamp_max", param_u_clamp_max));
602-
ASSERT_TRUE(std::isinf(param_u_clamp_max.get_value<double>()));
602+
EXPECT_TRUE(std::isinf(param_u_clamp_max.get_value<double>()));
603603

604604
rclcpp::Parameter param_u_clamp_min;
605605
ASSERT_TRUE(node->get_parameter("u_clamp_min", param_u_clamp_min));
606-
ASSERT_TRUE(std::isinf(param_u_clamp_min.get_value<double>()));
606+
EXPECT_TRUE(std::isinf(param_u_clamp_min.get_value<double>()));
607+
608+
rclcpp::Parameter param_saturation;
609+
ASSERT_TRUE(node->get_parameter("saturation", param_saturation));
610+
EXPECT_FALSE(param_saturation.get_value<bool>());
607611

608612
rclcpp::Parameter param_tracking_time_constant;
609613
ASSERT_TRUE(node->get_parameter("tracking_time_constant", param_tracking_time_constant));
610-
ASSERT_TRUE(std::isnan(param_tracking_time_constant.get_value<double>()));
614+
EXPECT_TRUE(std::isnan(param_tracking_time_constant.get_value<double>()));
615+
616+
rclcpp::Parameter param_activate_state_publisher;
617+
ASSERT_TRUE(node->get_parameter("activate_state_publisher", param_activate_state_publisher));
618+
EXPECT_EQ(param_activate_state_publisher.get_value<bool>(), ACTIVATE_STATE_PUBLISHER);
611619
}
612620

613621
TEST(PidParametersTest, MultiplePidInstances)

0 commit comments

Comments
 (0)