mock_robot.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 from actionlib import SimpleActionServer, SimpleActionClient
5 
6 from nodelet.srv import NodeletLoad, NodeletUnload
7 from stdr_msgs.msg import SpawnRobotAction, SpawnRobotResult
8 from stdr_msgs.msg import RegisterRobotAction, RegisterRobotGoal
9 from stdr_msgs.srv import MoveRobot, MoveRobotResponse
10 
11 import threading
12 
13 class MockRobot():
14 
15  def __init__(self):
16  self.load_nodelet = rospy.Service('robot_manager/load_nodelet',
17  NodeletLoad, self.load_nodelet_cb)
18 
19  self.unload_nodelet = rospy.Service('robot_manager/unload_nodelet',
20  NodeletUnload, self.unload_nodelet_cb)
21 
23  SimpleActionClient('stdr_server/register_robot', RegisterRobotAction)
24  self.register_robot_client.wait_for_server()
25 
26  self.name = None
27 
28  def load_nodelet_cb(self, request):
29  rospy.loginfo('Requested new robot')
30  # Spawn a new thread, as this service has to return first
31  req_thread = threading.Thread(target=self.register_robot, args=(request.name,))
32  req_thread.start()
33  return True
34 
35  def unload_nodelet_cb(self, request):
36  rospy.loginfo('Request to delete "%s"' % request.name)
37  self.move_service.shutdown()
38  return True
39 
40  def register_robot(self, name):
41  rospy.sleep(1)
42  rospy.loginfo('Register "%s" to server' % name)
43  register_goal = RegisterRobotGoal()
44  register_goal.name = name
45  self.register_robot_client.send_goal(register_goal)
46  self.name = name
47  # Spawn move robot service
48  self.move_service = rospy.Service(name + '/replace', MoveRobot,
49  self.move_robot)
50 
51  def move_robot(self, req):
52  rospy.loginfo('Request to move %s' % self.name)
53  return MoveRobotResponse()
54 
55 if __name__ == '__main__':
56  rospy.init_node('mock_robot', anonymous=True)
57  robot = MockRobot()
58  rospy.spin()
def register_robot(self, name)
Definition: mock_robot.py:40
def move_robot(self, req)
Definition: mock_robot.py:51
def __init__(self)
Definition: mock_robot.py:15
def load_nodelet_cb(self, request)
Definition: mock_robot.py:28
def unload_nodelet_cb(self, request)
Definition: mock_robot.py:35


stdr_server
Author(s): Chris Zalidis
autogenerated on Mon Jun 10 2019 15:15:07