ProgramQueue.py
Go to the documentation of this file.
00001 import roslib;
00002 roslib.load_manifest('program_queue')
00003 roslib.load_manifest('slider_gui')
00004 import rospy;
00005 
00006 import program_queue.msg
00007 import program_queue.srv
00008 
00009 from slider_gui.srv import *
00010 
00011 class ProgramQueue():
00012 
00013     def __init__(self, username, password):
00014         self._username = username
00015         self._password = password
00016         self._token = None
00017         self._next_serial = 1
00018 
00019     def login(self):
00020         # log in
00021         print 'logging in...'
00022         user = self._client('login', program_queue.srv.Login)(self._username, self._password)
00023         token = user.token
00024         if token == 0:
00025             print 'Failed to log in'
00026             self._token = None
00027             return False
00028         self._token = token
00029         return True
00030 
00031     def logout(self):
00032         # log out
00033         print 'logging out...'
00034         self._client('logout', program_queue.srv.Logout)(self._token)
00035         self._token = None
00036 
00037     def upload_program(self, program_data, label=None):
00038         if self._token is None:
00039             return False
00040 
00041         if label is None:
00042             label = 'program%d' % self._next_serial
00043             self._next_serial += 1
00044         print 'ProgramQueue.upload_program() %s' % label
00045 
00046         # create empty program
00047         print 'creating program...'
00048         program = self._client('create_program', program_queue.srv.CreateProgram)(self._token)
00049         program_id = program.id
00050 
00051         # upload program data
00052         print 'uploading program...'
00053         program_info = program_queue.msg.ProgramInfo(program_id, label, program_queue.msg.ProgramInfo.SLIDER, self._username)
00054         program = program_queue.msg.Program(program_info, program_data)
00055         self._client('update_program', program_queue.srv.UpdateProgram)(self._token, program)
00056 
00057         # add to queue
00058         print 'adding to queue...'
00059         self._client('queue_program', program_queue.srv.QueueProgram)(self._token, program_id)
00060 
00061         return program_id
00062 
00063     def run_program(self, program_id):
00064         if self._token is None:
00065             return False
00066 
00067         # run program
00068         print 'running program...'
00069         self._client('run_program', program_queue.srv.RunProgram)(self._token, program_id)
00070 
00071         return True
00072 
00073     def _client(self, name, type):
00074        rospy.wait_for_service(name, 3)
00075        return rospy.ServiceProxy(name, type)


slider_gui
Author(s): Dirk Thomas
autogenerated on Wed Aug 26 2015 15:37:50