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

[Bug] gz_ros2_control command_mode_switch: When unsetting ControlMode bits for stop_interfaces all bits get unset #307

Open
baconbrot opened this issue May 15, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@baconbrot
Copy link

Describe the bug
When inspecting the gz_ros2_control code - in particular the GazeboSimSystem::perform_command_mode_switch method in gz_systems.cpp
I found a potential bug:

The ControlMethod enum

enum ControlMethod_
 {
   NONE      = 0,
   POSITION  = (1 << 0),
   VELOCITY  = (1 << 1),
   EFFORT    = (1 << 2),
 };

typedef SafeEnum<enum ControlMethod_> ControlMethod;

holds information on active command modes of an joint.

When performing a GazeboSimSystem::perform_command_mode_switch

// Clear joint control method bits corresponding to stop interfaces
if (interface_name == (this->dataPtr->joints_[j].name + "/" +
  hardware_interface::HW_IF_POSITION))
{
  this->dataPtr->joints_[j].joint_control_method &= static_cast<ControlMethod_>(VELOCITY & EFFORT);
}

then according to the given comment

// Clear joint control method bits corresponding to stop interfaces

only the POSITION bit should get unset.
But because of the & in VELOCITY & EFFORT every bit in the ControlMethod is set to zero.

Expected behavior
When the & would be replaced by | then only the desired flag would be unset, e.g. stopping POSITION in the following code fragment would only stop position (unset position bit) and not set all bits to zero:

if (interface_name == (this->dataPtr->joints_[j].name + "/" +
        hardware_interface::HW_IF_POSITION))
{
        this->dataPtr->joints_[j].joint_control_method &=
          static_cast<ControlMethod_>(VELOCITY **|** EFFORT);
}

Is this a bug or desired behavior?

Environment:

  • Branch: Master
@baconbrot baconbrot added the bug Something isn't working label May 15, 2024
@christophfroehlich christophfroehlich transferred this issue from ros-controls/ros2_control May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant