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

joint state controller with resource manager #109

Merged
merged 4 commits into from Dec 1, 2020
Merged

Conversation

Karsten1987
Copy link
Contributor

Needs ros-controls/ros2_control#236

The way to run it:

terminal1:

ros2 run controller_manager ros2_control_node --ros-args -p update_rate:=10 -p "robot_description:=`cat install/test_robot_hardware/share/test_robot_hardware/test_robot_hardware.urdf`" -p "joint_state_controller.type:=joint_state_controller/JointStateController"

terminal2:

ros2 control load joint_state_controller

@bmagyar bmagyar marked this pull request as ready for review November 25, 2020 12:09
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.

Looks good. Just some changes regarding standard constants and shared test data.

@@ -68,6 +65,7 @@ class JointStateController : public controller_interface::ControllerInterface

protected:
std::vector<std::string> joint_names_;
std::unordered_map<std::string, std::unordered_map<std::string, double>> name_if_value_mapping_;
Copy link
Member

Choose a reason for hiding this comment

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

Can you a short comment about this map?

Copy link
Member

Choose a reason for hiding this comment

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

Added comments, I've also grouped the joint-state-related stuff and the dynamic joint state-reltaed stuff together

Comment on lines 42 to 44
const auto kPositionName = "position";
const auto kVelocityName = "velocity";
const auto kEffortName = "effort";
Copy link
Member

Choose a reason for hiding this comment

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

I propose to use names from: hardware_interface/include/hardware_interface/types/hardware_interface_type_values.hpp

Suggested change
const auto kPositionName = "position";
const auto kVelocityName = "velocity";
const auto kEffortName = "effort";

Copy link
Member

Choose a reason for hiding this comment

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

at the time of first doing this, these values were not available. Replaced with this constants now

#include <vector>

#include "hardware_interface/joint_handle.hpp"
#include "hardware_interface/robot_hardware.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
Copy link
Member

Choose a reason for hiding this comment

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

Header for standardized names...

Suggested change
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "hardware_interface/types/hardware_interface_type_values.hpp"

Copy link
Member

Choose a reason for hiding this comment

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

thanks, added

// the rest will be ignored for this message
for (const auto name_ifv : name_if_value_mapping_) {
const auto & interfaces_and_values = name_ifv.second;
if (has_any_key(interfaces_and_values, {kPositionName, kVelocityName, kEffortName})) {
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
if (has_any_key(interfaces_and_values, {kPositionName, kVelocityName, kEffortName})) {
if (has_any_key(interfaces_and_values, {hardware_interface::HW_IF_POSITION,
hardware_interface::HW_IF_VELOCITY,
hardware_interface::HW_IF_EFFORT})) {

Maybe not the best formatting possible...

Copy link
Member

Choose a reason for hiding this comment

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

when working around linters and code formatters, there's only so much you can discuss about code style :D

removing the hardware_interface namespace by a couple of usings at the top of the file kept this a one-liner

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I mean my proposal was not the best formating possible.

Comment on lines 216 to 219
get_value(name_if_value_mapping_, joint_names_[i], kPositionName);
joint_state_msg_.velocity[i] =
get_value(name_if_value_mapping_, joint_names_[i], kVelocityName);
joint_state_msg_.effort[i] = get_value(name_if_value_mapping_, joint_names_[i], kEffortName);
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
get_value(name_if_value_mapping_, joint_names_[i], kPositionName);
joint_state_msg_.velocity[i] =
get_value(name_if_value_mapping_, joint_names_[i], kVelocityName);
joint_state_msg_.effort[i] = get_value(name_if_value_mapping_, joint_names_[i], kEffortName);
get_value(name_if_value_mapping_, joint_names_[i], hardware_interface::HW_IF_POSITION);
joint_state_msg_.velocity[i] =
get_value(name_if_value_mapping_, joint_names_[i], hardware_interface::HW_IF_VELOCITY);
joint_state_msg_.effort[i] = get_value(name_if_value_mapping_, joint_names_[i], hardware_interface::HW_IF_EFFORT);

Copy link
Member

Choose a reason for hiding this comment

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

ja


namespace joint_state_controller_testing
{
constexpr auto urdf =
Copy link
Member

Choose a reason for hiding this comment

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

I would propose to use descriptions.hpp header for this as proposed in #99 and ros-controls/ros2_control#247.
We should just move the file in test_robot_hardware as @Karsten1987 proposed.

Copy link
Member

Choose a reason for hiding this comment

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

#113 created follow-up issue

ASSERT_EQ(dynamic_joint_state_msg.interface_values[0].values[0], 1.1);
ASSERT_EQ(dynamic_joint_state_msg.interface_values[1].values[0], 2.1);
ASSERT_EQ(dynamic_joint_state_msg.interface_values[2].values[0], 3.1);
const auto INTERFACE_NAMES = {"position", "velocity", "effort"};
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
const auto INTERFACE_NAMES = {"position", "velocity", "effort"};
const auto INTERFACE_NAMES = {hardware_interface::HW_IF_POSITION,
hardware_interface::HW_IF_VELOCITY,
hardware_interface::HW_IF_EFFORT};

Copy link
Member

Choose a reason for hiding this comment

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

yup

Copy link
Member

Choose a reason for hiding this comment

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

there was another one of these, done that too


#include "hardware_interface/loaned_state_interface.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
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
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "hardware_interface/types/hardware_interface_type_values.hpp"

Copy link
Member

Choose a reason for hiding this comment

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

done

@v-lopez
Copy link
Contributor

v-lopez commented Nov 25, 2020

Looks good to me after @destogl suggestions are addressed.

@bmagyar
Copy link
Member

bmagyar commented Nov 30, 2020

ok guys, I've addressed all your comments, please verify/resolve discussions (I'm not going to resolve your discussion points)

@v-lopez
Copy link
Contributor

v-lopez commented Nov 30, 2020

I agree with how you addressed @destogl review, could be merged by me.

Copy link
Member

@bmagyar bmagyar left a comment

Choose a reason for hiding this comment

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

This wasn't my PR originally so I can still "review it"! After doing some major changes to it, the controller works and testing is mostly appropriate.

Patting myself on the shoulder in approval

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.

Looks good!

EDIT: My approvals are not counted anyway :)

@bmagyar bmagyar force-pushed the use_resource_manager branch 2 times, most recently from e600d36 to 6197903 Compare December 1, 2020 21:58
bmagyar and others added 3 commits December 1, 2020 22:15
* Forward command controller almost using resource manager
* Make forward command controller fully work and restore testing
* Use node namespace for topics
* Review fixes and linters
* Move CallbackReturn using to header

Co-authored-by: Bence Magyar <bence.magyar.robotics@gmail.com>
@bmagyar bmagyar merged commit 30612b1 into master Dec 1, 2020
@bmagyar bmagyar deleted the use_resource_manager branch December 1, 2020 22:51
gwalck pushed a commit to StoglRobotics-forks/ros2_controllers that referenced this pull request Jun 7, 2023
* Use gmock
* Add Bence as maintainer
* Test invalid handles
* Add handle validation to RobotHardware
* Test proper handles and double registering handles
* Test name and blanket handle getters
* Test named handle getters
* Refactor registering second handles in tests, add check for getting second name
* Check that returned pointers are not null
* Update ros2ci workflow versions
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

4 participants