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

HW interface switch feature with unit tests #200

Merged

Conversation

mathias-luedtke
Copy link
Contributor

As promised in #197 I have implemented a new version of the HW interface switch.

The RobotHW class got new members as discussed beforehand:

virtual bool canSwitch(const std::list<ControllerInfo> &start_list,
                       const std::list<ControllerInfo> &stop_list) const;

virtual void doSwitch(const std::list<ControllerInfo> &start_list,
                      const std::list<ControllerInfo> &stop_list);

These should check and execute the switches on the hardware.

The switchController filters the start and stop list as follows:

  • filter all restarts (make start_list and stop_list disjoint)
  • filter stops of stopped controllers (raise an error for strict checking)
  • filter starts (not restarts) of started controllers (raise an error for strict checking)

I have put a lot of effort into the unit tests, they should cover most cases, including the filters, resource and inter-controller mode conflicts.
The SwitchBot only allows direct (in one function call) switches if new_hwi >= old_hwi (string comparison).

@ipa-fxm will implement a gazebo plugin again, I will test it with https://github.com/ipa320/ros_canopen.

@davetcoleman
Copy link
Member

+1 thanks for putting the effort into the unit tests. i'd really like to see this feature merged, its been nearly 2 years since i made the first implementation

@@ -440,6 +472,16 @@ bool ControllerManager::switchController(const std::vector<std::string>& start_c
return false;
}

if (!robot_hw_->canSwitch(start_list, stop_list))
{
ROS_ERROR("Could not switch controllers, due to mode conflicts");
Copy link
Member

Choose a reason for hiding this comment

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

I see that you try to maintain parallelism with the resource conflict message, but I find the error message not so clear. Now there's no explicit notion of modes, or what a mode conflict is. Here's some alternatives.

More explicit in blaming the robot for the failure:

"Could not switch controllers, requested controller state cannot be realized by robot"

Less explicit, more compact:

"Could not switch controllers, requested controller state is unfeasible"

Most verbose:

"Could not switch controllers. The resource combination for the requested controller state is unfeasible"

@adolfo-rt
Copy link
Member

Please add your affiliation to the copyright statement of the affected files.

@@ -0,0 +1,380 @@
#include <gtest/gtest.h>
Copy link
Member

Choose a reason for hiding this comment

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

Add license statement with copyright

@adolfo-rt
Copy link
Member

All my comments are minor. A great +1 to this PR.

@mathias-luedtke
Copy link
Contributor Author

Thanks for the review!
It will take some time to do all the beautifying (=find a suitable auto code styler ;)) and correct the c&p errors.

I will use "hardware interface switching" (as in the PR title) throughout the code and docs, because this is the view of the controller_manager.
"Mode switching" might be the necessary action for specific RobotHW implementations.

@fmessmer
Copy link

The gazebo plugin that uses the stricht_hwi_switch API proposed in this PR can be found here.
According documentation is included in the package README

@mathias-luedtke
Copy link
Contributor Author

I have just updated the code based on your remarks.
I will squash the new commits after the final review; this way it is easier to track the changes.

@adolfo-rt
Copy link
Member

This is looking good. Go ahead and squash the commits, and let's merge this one!

@mathias-luedtke
Copy link
Contributor Author

Squashed :)

adolfo-rt pushed a commit that referenced this pull request Apr 17, 2015
HW interface switch feature with unit tests
@adolfo-rt adolfo-rt merged commit 0f647a0 into ros-controls:indigo-devel Apr 17, 2015
@adolfo-rt
Copy link
Member

Merged, at last!

@davetcoleman
Copy link
Member

giphy 2

I thought this would never happen!

@fmessmer
Copy link

Haha, awesome!

rethink-imcmahon pushed a commit to RethinkRobotics/baxter_simulator that referenced this pull request May 21, 2015
A Pull Request to ros_controls enforced STRICT controller switching to
mean that already stopped controllers cannot be stopped again:
ros-controls/ros_control#200

Passing in a value of STRICT to the controller manager didn't matter
before because it was never properly implemented. According to the
service Request definition:

  * STRICT means that switching will fail if anything goes wrong (an invalid
    controller name, a controller that failed to start, etc. )
  * BEST_EFFORT means that even when something goes wrong with on controller,
    the service will still try to start/stop the remaining controllers

We were relying on STRICT functionality not being fully implemented.
Instead, we will use BEST_EFFORT for a more forgiving controller
switching strategy. This design decision should be revisited in the
development cycle.
rethink-imcmahon pushed a commit to RethinkRobotics/baxter_simulator that referenced this pull request May 21, 2015
As reported in Issue #49
**ros_control upgrade breaks baxter_gazebo simulation**

A pull request to ros_controls enforced STRICT controller switching to
mean that already stopped controllers cannot be stopped again:
ros-controls/ros_control#200

This resulted in baxter_simulator being unable to start any controllers
since it preemptively closes controllers whether or not they have been
started. This was caused by the chosen strategy for switching controllers.

Passing in a value of STRICT to the controller manager didn't matter
before because it was never properly implemented. According to the
service Request definition:

  * STRICT means that switching will fail if anything goes wrong (an invalid
    controller name, a controller that failed to start, etc. )
  * BEST_EFFORT means that even when something goes wrong with on controller,
    the service will still try to start/stop the remaining controllers

We were relying on STRICT functionality not being fully implemented.
Instead, we will use BEST_EFFORT for a more forgiving controller
switching strategy. This design decision should be revisited in the
development cycle.
rethink-imcmahon pushed a commit to RethinkRobotics/baxter_simulator that referenced this pull request Jun 1, 2015
As reported in Issue #49
**ros_control upgrade breaks baxter_gazebo simulation**

A pull request to ros_controls enforced STRICT controller switching to
mean that already stopped controllers cannot be stopped again:
ros-controls/ros_control#200

This resulted in baxter_simulator being unable to start any controllers
since it preemptively closes controllers whether or not they have been
started. This was caused by the chosen strategy for switching controllers.

Passing in a value of STRICT to the controller manager didn't matter
before because it was never properly implemented. According to the
service Request definition:

  * STRICT means that switching will fail if anything goes wrong (an invalid
    controller name, a controller that failed to start, etc. )
  * BEST_EFFORT means that even when something goes wrong with on controller,
    the service will still try to start/stop the remaining controllers

We were relying on STRICT functionality not being fully implemented.
Instead, we will use BEST_EFFORT for a more forgiving controller
switching strategy. This design decision should be revisited in the
development cycle.

(cherry picked from commit 535cbb1)
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.

4 participants