ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

I finally found a way to simplify my approach. If you pass --stopped as an argument to the spawner, you can load a controller without starting it. So I ended up spawning the position controller as usual and the effort controller with the --stopped argument. No I can switch from one controller to the other by just calling the switch_controller service.

Now, my launch file has these two lines in it:

<node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false" ns="/mybot" args="flipper_position_controller"/>

<node name="controller_spawner_stopped" pkg="controller_manager" type="spawner" respawn="false" ns="/mybot" args="--stopped flipper_effort_controller"/>

The code to switch from position controller to effort controller looks like that:

from controller_manager_msgs.srv import SwitchController
...
rospy.wait_for_service('/mybot/controller_manager/switch_controller')
try:
   switch_controller = rospy.ServiceProxy(
                                  '/mybot/controller_manager/switch_controller', SwitchController)
   ret = switch_controller(['flipper_effort_controller'], ['flipper_position_controller'], 2)
   except rospy.ServiceException, e:
      print "Service call failed: %s"%e

I finally found a way to simplify my approach. If you pass --stopped as an argument to the spawner, you can load a controller without starting it. So I ended up spawning the position controller as usual and the effort controller with the --stopped argument. No I can switch from one controller to the other by just calling the switch_controller service.

Now, my launch file has these two lines in it:

<node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false" ns="/mybot" args="flipper_position_controller"/>

args="flipper_position_controller"/> <node name="controller_spawner_stopped" pkg="controller_manager" type="spawner" respawn="false" ns="/mybot" args="--stopped flipper_effort_controller"/>

The code to switch from position controller to effort controller looks like that:

from controller_manager_msgs.srv import SwitchController
...
rospy.wait_for_service('/mybot/controller_manager/switch_controller')
try:
   switch_controller = rospy.ServiceProxy(
                        '/mybot/controller_manager/switch_controller', SwitchController)
   ret = switch_controller(['flipper_effort_controller'],  ['flipper_position_controller'], 2)
   except rospy.ServiceException, e:
      print "Service call failed: %s"%e

I finally found a way to simplify my approach. If you pass --stopped as an argument to the spawner, you can load a controller without starting it. So I ended up spawning the position controller as usual and the effort controller with the --stopped argument. No I can switch from one controller to the other by just calling the switch_controller service.

Now, my launch file has these two lines in it:

 <node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false" ns="/mybot" args="flipper_position_controller"/>

<node name="controller_spawner_stopped" pkg="controller_manager" type="spawner" respawn="false" ns="/mybot" args="--stopped flipper_effort_controller"/>

The code to switch from position controller to effort controller looks like that:

 from controller_manager_msgs.srv import SwitchController
...
rospy.wait_for_service('/mybot/controller_manager/switch_controller')
try:
   switch_controller = rospy.ServiceProxy(
                       '/mybot/controller_manager/switch_controller', SwitchController)
   ret = switch_controller(['flipper_effort_controller'], 
                           ['flipper_position_controller'], 2)
   except rospy.ServiceException, e:
      print "Service call failed: %s"%e

I finally found a way to simplify my approach. If you pass --stopped as an argument to the spawner, you can load a controller without starting it. So I ended up spawning the position controller as usual and the effort controller with the --stopped argument. No Now I can switch from one controller to the other by just calling the switch_controller service.

Now, I needed to add the following two lines to my launch file has these two lines in it:file:


<node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false" ns="/mybot" args="flipper_position_controller"/>

<node name="controller_spawner_stopped" pkg="controller_manager" type="spawner" respawn="false" ns="/mybot" args="--stopped flipper_effort_controller"/>

The code to switch from position controller to effort controller looks like that:


from controller_manager_msgs.srv import SwitchController
...
rospy.wait_for_service('/mybot/controller_manager/switch_controller')
try:
   switch_controller = rospy.ServiceProxy(
                       '/mybot/controller_manager/switch_controller', SwitchController)
   ret = switch_controller(['flipper_effort_controller'], 
                           ['flipper_position_controller'], 2)
   except rospy.ServiceException, e:
      print "Service call failed: %s"%e