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

✨ Add stop_configuration_service #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
<exec_depend>rospy</exec_depend>
<exec_depend>python-rospkg</exec_depend>
<exec_depend>metacontrol_msgs</exec_depend>
<exec_depend>std_srvs</exec_depend>

</package>

18 changes: 14 additions & 4 deletions src/mc_rosgraph_manipulator/rosgraph_manipulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from roslib.message import get_message_class
from pyparsing import ParseResults
from importlib import import_module
from std_srvs.srv import Empty, EmptyResponse


roslib.load_manifest('rosparam')
rospack = rospkg.RosPack()
Expand Down Expand Up @@ -90,6 +92,9 @@ def __init__(self, name, configFilePath):
'action_msg_type {0} - {1}'.format(action_msg_type[0],
action_msg_type[1]))

self.stop_configuration_service = rospy.Service('stop_configuration',
Empty, self.stop_configuration)

self._as = actionlib.SimpleActionServer(
self.reconfiguration_action_name, MvpReconfigurationAction,
execute_cb=self.reconfiguration_action_cb, auto_start=False)
Expand All @@ -104,17 +109,22 @@ def __init__(self, name, configFilePath):
def callback(self, goal_msg):
self.last_saved_goal = goal_msg.goal

def stop_configuration(self, req):
for node in self.kill_nodes:
kill_node(node)
rospy.loginfo("Stopping node %s" % str(node))
rospy.sleep(2)

return EmptyResponse()

def reconfiguration_action_cb(self, goal):
rospy.loginfo(
'Rosgraph Manipulator Action Server received goal %s' % str(goal))
self._result.result = 1
desired_configuration = goal.desired_configuration_name

if (desired_configuration in self.configurations):
for node in self.kill_nodes:
kill_node(node)
rospy.loginfo("Stopping node %s" % str(node))
rospy.sleep(2)
self.stop_configuration()
Copy link
Collaborator

Choose a reason for hiding this comment

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

wouldn't this fail because the req argument is missing?

maybe create a separate function for the service callback, and then just call the stop_configuration() so it's not conflicting

rospy.loginfo('Launching new configuration')
self.command = self.configurations.get(desired_configuration)
rospy.loginfo('Launching new configuration, command %s' %
Expand Down