def __init__(self): self.server_robot = ServerRobot() rospy.init_node('robot_server', anonymous=False) rospy.Subscriber('robot_command_json', MsgRobotCommand, self.callback, queue_size=None)
def __init__(self): rospy.init_node('robot_service_server', anonymous=False) self.service = rospy.Service('robot_send_command', SrvRobotCommand, self.cb_robot_command) robot_ip = rospy.get_param('~robot_ip', '192.168.30.4') self.server_robot = ServerRobot() self.server_robot.connect(robot_ip) rospy.on_shutdown(self.server_robot.disconnect) rospy.spin()
def __init__(self): rospy.init_node('robot_service_server', anonymous=False) self.service = rospy.Service( 'robot_send_command', SrvRobotCommand, self.cb_robot_command) robot_ip = rospy.get_param('~robot_ip', '192.168.30.4') self.server_robot = ServerRobot() self.server_robot.connect(robot_ip) rospy.on_shutdown(self.server_robot.disconnect) rospy.spin()
class NdRobotServer(): def __init__(self): rospy.init_node('robot_service_server', anonymous=False) self.service = rospy.Service( 'robot_send_command', SrvRobotCommand, self.cb_robot_command) robot_ip = rospy.get_param('~robot_ip', '192.168.30.4') self.server_robot = ServerRobot() self.server_robot.connect(robot_ip) rospy.on_shutdown(self.server_robot.disconnect) rospy.spin() def cb_robot_command(self, data): rospy.loginfo(rospy.get_caller_id() + " I heard %s", data.command) if data.command[2:10] == 'get_pose': pose_rob = self.server_robot.proc_command(data.command) return SrvRobotCommandResponse(str(pose_rob)) self.server_robot.proc_command(data.command) return SrvRobotCommandResponse("OK")
class NdRobotServer(): def __init__(self): rospy.init_node('robot_service_server', anonymous=False) self.service = rospy.Service('robot_send_command', SrvRobotCommand, self.cb_robot_command) robot_ip = rospy.get_param('~robot_ip', '192.168.30.4') self.server_robot = ServerRobot() self.server_robot.connect(robot_ip) rospy.on_shutdown(self.server_robot.disconnect) rospy.spin() def cb_robot_command(self, data): rospy.loginfo(rospy.get_caller_id() + " I heard %s", data.command) if data.command[2:10] == 'get_pose': pose_rob = self.server_robot.proc_command(data.command) return SrvRobotCommandResponse(str(pose_rob)) self.server_robot.proc_command(data.command) return SrvRobotCommandResponse("OK")
class SubRobotServer(): def __init__(self): self.server_robot = ServerRobot() rospy.init_node('robot_server', anonymous=False) rospy.Subscriber('robot_command_json', MsgRobotCommand, self.callback, queue_size=None) def callback(self, data): rospy.loginfo(rospy.get_caller_id() + " I heard %s", data.command) self.server_robot.proc_command(data.command) rospy.loginfo(rospy.get_caller_id() + " Processed %s", data.command) def connect(self, ip="172.20.0.32"): if rospy.has_param("configuration/robot_ip"): ip = rospy.get_param("configuration/robot_ip") self.server_robot.connect(ip) def listener(self): # spin() simply keeps python from exiting until this node is stopped rospy.spin() def close_connection(self): self.server_robot.disconnect()