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

Cartesian twist controller #300

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

livanov93
Copy link
Contributor

PR info:

TODOs:

  • add tests

Comment on lines 74 to 81
if (command_interfaces_.size() != 6)
{
RCLCPP_ERROR_THROTTLE(
get_node()->get_logger(), *node_->get_clock(), 1000,
"Twist controller needs does not match number of interfaces needed 6, given (%zu) interfaces",
command_interfaces_.size());
return controller_interface::return_type::ERROR;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

(edit) should this should be checked in on_configure(..)?

Copy link
Member

@malapatiravi malapatiravi left a comment

Choose a reason for hiding this comment

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

looks good to me. someone else must approve.

Copy link
Member

@aprotyas aprotyas left a comment

Choose a reason for hiding this comment

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

Looks mostly fine to me, but I've left a few nits in-line.

I think you need to rebase your branch on ros-controls:master for CI to pass, since your branch doesn't have ros2_controllers_test_nodes (e7d0517) yet.

Also, looks like the linter is unhappy.

<maintainer email="lovro.ivanov@gmail.com">Lovro Ivanov</maintainer>
<license>Apache-2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>
Copy link
Member

Choose a reason for hiding this comment

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

Since find_package(ament_cmake_ros REQUIRED) was introduced in 1f1fefc:

Suggested change
<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>ament_cmake_ros</buildtool_depend>

Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't like this pacakge needs ament_cmake_ros I'll remove from the CMakeLists.txt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't add it, remove it from CMakeLists.txt

}
catch (const std::exception & e)
{
fprintf(stderr, "Exception thrown during init stage with message: %s \n", e.what());
Copy link
Member

Choose a reason for hiding this comment

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

Pardon my ignorance here, but could this not be logged with RCLCPP_ERROR_* instead?

Copy link
Member

Choose a reason for hiding this comment

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

This is actually quite often a pattern in these use-cases.

Comment on lines 82 to 87
command_interfaces_[0].set_value((*twist_commands)->twist.linear.x);
command_interfaces_[1].set_value((*twist_commands)->twist.linear.y);
command_interfaces_[2].set_value((*twist_commands)->twist.linear.z);
command_interfaces_[3].set_value((*twist_commands)->twist.angular.x);
command_interfaces_[4].set_value((*twist_commands)->twist.angular.y);
command_interfaces_[5].set_value((*twist_commands)->twist.angular.z);
Copy link
Member

Choose a reason for hiding this comment

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

Nit. Not that it matters, but purely for brevity. Feel free to ignore:

Suggested change
command_interfaces_[0].set_value((*twist_commands)->twist.linear.x);
command_interfaces_[1].set_value((*twist_commands)->twist.linear.y);
command_interfaces_[2].set_value((*twist_commands)->twist.linear.z);
command_interfaces_[3].set_value((*twist_commands)->twist.angular.x);
command_interfaces_[4].set_value((*twist_commands)->twist.angular.y);
command_interfaces_[5].set_value((*twist_commands)->twist.angular.z);
auto command = (*twist_commands)->twist;
command_interfaces_[0].set_value(command.linear.x);
command_interfaces_[1].set_value(command.linear.y);
command_interfaces_[2].set_value(command.linear.z);
command_interfaces_[3].set_value(command.angular.x);
command_interfaces_[4].set_value(command.angular.y);
command_interfaces_[5].set_value(command.angular.z);

moriarty added a commit to livanov93/ros2_controllers that referenced this pull request May 1, 2023
This Commit builds on a rebased PR ros-controls#300

The Original author @livanov93 was in 2022 open sourcing part of a
PickNik package form 2021.

This commit brings the internal picknik and previously open PR ros-controls#300 back
in sync and rebases the open PR onto humble.
@moriarty
Copy link
Contributor

moriarty commented May 1, 2023

@livanov93 I've rebased this branch onto Humble and brought it in sync with the internal version from PickNik for open sourcing.
livanov93@19a6068

Should we force push onto this PR or close this one out and open a new one?

@livanov93
Copy link
Contributor Author

@moriarty Feel free to force-push here.

@mergify
Copy link
Contributor

mergify bot commented May 2, 2023

This pull request is in conflict. Could you fix it @livanov93?

@moriarty
Copy link
Contributor

moriarty commented May 2, 2023

@livanov93 I've rebased this branch onto Humble and brought it in sync with the internal version from PickNik for open sourcing. livanov93@19a6068

Should we force push onto this PR or close this one out and open a new one?

I've forced pushed but the internal version was targeting humble so that's what I'd rebased on.
To bring it up to date with master I'll need to first do a bit more testing.

livanov93 and others added 6 commits May 2, 2023 11:18
This Commit builds on a rebased PR ros-controls#300

The Original author @livanov93 was in 2022 open sourcing part of a
PickNik package form 2021.

This commit brings the internal picknik and previously open PR ros-controls#300 back
in sync and rebases the open PR onto humble.
Signed-off-by: Alex Moriarty <alex.moriarty@picknik.ai>
Unclear what the state of these tests were from original PR and if they
were finished because it was marked as Work in Progress.
This change makes the tests pass

Signed-off-by: Alex Moriarty <alex.moriarty@picknik.ai>
@@ -43,7 +43,7 @@ TEST_F(TwistControllerTest, joint_names_parameter_not_set)
ASSERT_TRUE(controller_->joint_name_.empty());
ASSERT_TRUE(controller_->interface_names_.empty());

controller_->get_node()->set_parameter({"joint", joint_name_});
controller_->get_node()->set_parameter({"interface_names", interface_names_});
Copy link
Contributor

Choose a reason for hiding this comment

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

This test was called joint_names_parameter_not_set but was setting the joint param.
The following test was called interface_parameter_not_set but was setting interface_name parameter.

These two tests just check to it isn't possible to configure the controller with missing mandatory parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is correct, could be that additional work was required.

Copy link
Member

Choose a reason for hiding this comment

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

We have to swith to generate_parameter_library anyway and then those tests get partially obsolete.

ASSERT_EQ(wait_for(controller_->twist_command_subscriber_), rclcpp::WaitResultKind::Ready);

// process callbacks
rclcpp::spin_some(controller_->get_node()->get_node_base_interface());
ASSERT_TRUE(controller_->wait_for_commands(executor));
Copy link
Contributor

Choose a reason for hiding this comment

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

This wait_for resulted in rclcpp throwing an exception, there was a wait_for_commands which looks like it was intended for this. A similar pattern exists in the other controller tests.

publish_commands();
ASSERT_TRUE(controller_->wait_for_commands(executor));

@moriarty
Copy link
Contributor

moriarty commented May 3, 2023

looks good to me. someone else must approve.

@malapatiravi

Looks mostly fine to me, but I've left a few nits in-line.

I think you need to rebase your branch on ros-controls:master for CI to pass, since your branch doesn't have ros2_controllers_test_nodes (e7d0517) yet.

Also, looks like the linter is unhappy.

@aprotyas

I've taken over this Branch & PR from @livanov93 and it's ready for another review.
I'm unable to re-request reviews or remove the [WIP] because I didn't open the PR.
The tests should be passing, but if someone could trigger CI that would be great then I can take a look at any failures

@livanov93 livanov93 changed the title [WIP] Cartesian twist controller Cartesian twist controller May 3, 2023
Signed-off-by: Alex Moriarty <alex.moriarty@picknik.ai>
Copy link
Contributor Author

@livanov93 livanov93 left a comment

Choose a reason for hiding this comment

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

@moriarty Looks fine, please take a look on the suggestions. Although I can't approve as PR owner


# find dependencies
find_package(ament_cmake REQUIRED)
find_package(ament_cmake_ros REQUIRED)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not needed I think

Copy link
Contributor

Choose a reason for hiding this comment

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

yes I removed in 87717e7


# find dependencies
find_package(ament_cmake REQUIRED)
find_package(ament_cmake_ros REQUIRED)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
find_package(ament_cmake_ros REQUIRED)

<maintainer email="lovro.ivanov@gmail.com">Lovro Ivanov</maintainer>
<license>Apache-2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't add it, remove it from CMakeLists.txt

@@ -43,7 +43,7 @@ TEST_F(TwistControllerTest, joint_names_parameter_not_set)
ASSERT_TRUE(controller_->joint_name_.empty());
ASSERT_TRUE(controller_->interface_names_.empty());

controller_->get_node()->set_parameter({"joint", joint_name_});
controller_->get_node()->set_parameter({"interface_names", interface_names_});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is correct, could be that additional work was required.

@codecov-commenter
Copy link

Codecov Report

Merging #300 (87717e7) into master (e7f9962) will decrease coverage by 3.36%.
The diff coverage is 26.44%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master     #300      +/-   ##
==========================================
- Coverage   35.78%   32.43%   -3.36%     
==========================================
  Files         189        7     -182     
  Lines       17570      666   -16904     
  Branches    11592      358   -11234     
==========================================
- Hits         6287      216    -6071     
+ Misses        994      157     -837     
+ Partials    10289      293    -9996     
Flag Coverage Δ
unittests 32.43% <26.44%> (-3.36%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ontroller/test/test_load_diff_drive_controller.cpp 11.11% <0.00%> (ø)
diff_drive_controller/src/odometry.cpp 42.16% <11.11%> (ø)
diff_drive_controller/src/speed_limiter.cpp 46.55% <11.11%> (ø)
...ive_controller/test/test_diff_drive_controller.cpp 17.62% <12.08%> (ø)
...troller/include/diff_drive_controller/odometry.hpp 20.00% <20.00%> (ø)
...iff_drive_controller/src/diff_drive_controller.cpp 39.22% <35.50%> (ø)
...de/diff_drive_controller/diff_drive_controller.hpp 100.00% <100.00%> (ø)

... and 189 files with indirect coverage changes

@moriarty
Copy link
Contributor

moriarty commented May 3, 2023

@moriarty Looks fine, please take a look on the suggestions. Although I can't approve as PR owner

👍 and as I am not PR owner I can't mark any comments as resolved 😆

I will run the fixup the formatting. The Rolling - ABI compatibility is known to be broken. I noticed it when testing locally and had to clone control_msgs to get ros-controls/control_msgs#86 and it is causing a lot of CI jobs to fail #565 (comment)

Signed-off-by: Alex Moriarty <alex.moriarty@picknik.ai>
Copy link
Member

@destogl destogl left a comment

Choose a reason for hiding this comment

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

Recommend renaming the controller to ForwardTwistController

@bmagyar should we then add those into forwarding_controllers package? We should probably create one then. Then we can also clean a bit of a mess with position_controllers, velocity_controllers and so on. Which are mostly forwarding controllers anyway. IMHO we have too many packages, and can reduce the amount of code by large putting all those controllers together.

Copy link
Member

Choose a reason for hiding this comment

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

Please update file according to current standard of other controllers

@@ -0,0 +1,72 @@
// Copyright 2021, PickNik Inc.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Copyright 2021, PickNik Inc.
// Copyright 2023, PickNik Inc.

Copy link
Contributor

Choose a reason for hiding this comment

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

2021 is correct, its the date this file was created.

realtime_tools::RealtimeBuffer<std::shared_ptr<CmdType>> rt_command_ptr_;
rclcpp::Subscription<CmdType>::SharedPtr twist_command_subscriber_;

std::string logger_name_;
Copy link
Member

Choose a reason for hiding this comment

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

We don't use this anymore. We rather use get_node()->get_logger() to get an appropriate logger name. This is a pattern in other controllers.

@@ -0,0 +1,49 @@
// Copyright 2021, PickNik Inc.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Copyright 2021, PickNik Inc.
// Copyright 2023, PickNik Inc.

@@ -0,0 +1,149 @@
// Copyright 2021, PickNik Inc.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Copyright 2021, PickNik Inc.
// Copyright 2023, PickNik Inc.

{
try
{
auto_declare<std::vector<std::string>>("interface_names", std::vector<std::string>());
Copy link
Member

Choose a reason for hiding this comment

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

Please convert this to use generate_parameter_library

}
catch (const std::exception & e)
{
fprintf(stderr, "Exception thrown during init stage with message: %s \n", e.what());
Copy link
Member

Choose a reason for hiding this comment

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

This is actually quite often a pattern in these use-cases.

}

twist_command_subscriber_ = get_node()->create_subscription<CmdType>(
"~/commands", rclcpp::SystemDefaultsQoS(),
Copy link
Member

Choose a reason for hiding this comment

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

We use reference now. See this file

Suggested change
"~/commands", rclcpp::SystemDefaultsQoS(),
"~/reference", rclcpp::SystemDefaultsQoS(),

@@ -43,7 +43,7 @@ TEST_F(TwistControllerTest, joint_names_parameter_not_set)
ASSERT_TRUE(controller_->joint_name_.empty());
ASSERT_TRUE(controller_->interface_names_.empty());

controller_->get_node()->set_parameter({"joint", joint_name_});
controller_->get_node()->set_parameter({"interface_names", interface_names_});
Copy link
Member

Choose a reason for hiding this comment

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

We have to swith to generate_parameter_library anyway and then those tests get partially obsolete.

nuclearsandwich pushed a commit to ros/rosdistro that referenced this pull request Jun 24, 2023
* Add picknik_controllers

The purpose of picknik_controllers repository is hold controllers that
we are in the process of open sourcing and upstreaming.

The controllers in this repository have been prefixed with `picknik_` so
that if they are accepted upstream we will drop the prefix and release
the prefixed versions with deprication warnings.

- picknik_reset_fault_controller has been discussed here https://roscontrol.slack.com/archives/C01HA09KDLH/p1686332900429009
- picknik_twist_controller ros-controls/ros2_controllers#300

These do not have a gbp-release package and have not been release they are currently source only.

Following the steps outlined here: https://docs.ros.org/en/rolling/How-To-Guides/Releasing/First-Time-Release.html
This PR is for step 2

1. Be part of a release team: ros2-gbp/ros2-gbp-github-org#281
2. https://docs.ros.org/en/rolling/How-To-Guides/Releasing/Release-Team-Repository.html#create-a-new-release-repository

Signed-off-by: Alex Moriarty <alex.moriarty@picknik.ai>

* fixup: remove the release

Signed-off-by: Alex Moriarty <alex.moriarty@picknik.ai>

* fixup repo typo

- PickNikRobots -> PickNikRobotics

Signed-off-by: Alex Moriarty <alex.moriarty@picknik.ai>

---------

Signed-off-by: Alex Moriarty <alex.moriarty@picknik.ai>
moriarty added a commit to moriarty/rosdistro that referenced this pull request Jul 11, 2023
Increasing version of package(s) in repository `picknik_controllers` to `0.0.1-1`:

- upstream repository: https://github.com/PickNikRobotics/picknik_controllers.git
- release repository: https://github.com/ros2-gbp/picknik_controllers-release.git
- distro file: `rolling/distribution.yaml`
- bloom version: `0.11.2`
- previous version for package: `null`

```
* Initial Release of picknik_reset_fault_controller
  * Originally this was used internally and there was an attempt to release it to ros2_controllers
  * After discussion with the ros2 controllers WG over slack we have decided to open source it here first
  * The goal is to still move this upstream but it can be worked on here first and moved in the future
* fault_controller -> picknik_reset_fault_controller (ros#2 <PickNikRobotics/picknik_controllers#2>)
  * fault_controller -> picknik_reset_fault_controller
  This commit does two things:
  1) renames fault_controller to reset_fault_controller
  2) prefixes with picknik_
  The first change, is to be more specific what this controller is used
  for.
  The second change is because we want to move this controller into
  ros2_controllers and when that is complete we can drop the picknik_ and
  depricate this version allowing for a transition period.
  ---------
* Contributors: Alexander Moriarty @moriarty, Anthony Baker @abake48, @livanov93, @destogl, @MarqRazz, @Abishalini, @JafarAbdi
```

```
* Initial Release of picknik_twist_controller
  * Originally this was used internally and there was an attempt to release it to ros2_controllers here: ros-controls/ros2_controllers#300
  * The goal is to still move this upstream but it needs to be refactored before going upstream.
* twist_controller -> picknik_twist_controller (ros#3 <PickNikRobotics/picknik_controllers#3>)
  * twist_controller -> picknik_twist_controller
  1. prefix twist_controller with picknik_twist_controller
  When we merge twist_controller into ros2_controllers we can depricate
  this one and not have naming conflicts as users migrate
  * cmake: 3.8 -> 3.16
  bump to oldest version used on Ubuntu Focal + ROS 2 Humble
  https://www.ros.org/reps/rep-2000.html#humble-hawksbill-may-2022-may-2027
  ---------
* Contributors: Alexander Moriarty @moriarty, Anthony Baker @abake48, @livanov93, @destogl, @MarqRazz, @Abishalini, @JafarAbdi
```

Signed-off-by: Alexander Moriarty <alex.moriarty@picknik.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants