RaspberryPi/CollectingTrainingData/server_steerAngles.py
def ExecuteCommand(self, data, tripQueue):
        '''
        executes the commands from data recieved in socket server, also
        changes boolean values representing the movement of car
        :param data: data recieved from socket server
        '''
        # cmds = []
        if data is None:
            return
        for i in range(len(data) - 1):
            if data[i] == ',':  # STOP ALL MOTORS
                # self.driver.StopAll()
                self._stopAllMotors()
                print("stop all")
                # cmds.append(Commands.STOP_ALL_MOTORS.value)
                self.isMovingForward = False
            elif data[i][0:2] == 'SS':
                self.speed = int(data[i][2:])  # get second half of data with the number for speed
                print("Speed: {}".format(self.speed))
                if (self.isMovingForward):
                    self.backMotor.Forward(self.speed)
                # elif (self.isMovingBackward):
                #     self.twoMotorDriver.Reverse(self.speed)
                # self.driver.Speed(int(speed))
                #todo: add speed command to training data
            elif data[i][0:2] == 'SA': #Steering Angle Change
                self.steerDegree = int(data[i][2:]) #get second half of data with the number for steer angle
                self.steerMotor.turn(self.steerDegree*10)
                # self.steerMotor.offMotor()
                print("Steer Degree: {}".format(self.steerDegree))
            elif data[i] == 'FF':
                print("forward")
                self.backMotor.Forward(self.speed)
                self.isMovingForward = True;
            # elif data[i] == 'BB':
            #     print("Back")
            #     self.backMotor.Reverse(self.speed)
            #     self.isMovingForward = False
            elif data[i] == '@': #PAUSE Training
                self.isPaused = True  #Pauses videorecorder
                # self.driver.StopAll()
                self._stopAllMotors()
                print("------PAUSED---")
            elif data[i] == '#': #UNPAUSE TRAINING
                self.isPaused = False; #unpauses videorecorder
                print("------UNPAUSED---")
            elif data[i] == '*': #SAVE Training - sent after paused
                t0 = time.time()
                print("tripQueue size = {}".format(tripQueue.qsize()))
                # tempQ = queue.Queue()  # make copy of queue to save
                # for i in tripQueue.queue:  # transfer elements to new queue
                #     tempQ.put(i)
                tripList = [item for item in self.qdumper(self.tripQueue)];
                start_new_thread(self.SaveToPickle,(tripList, self.pickle_filename.format(self.getTimeStamp()),));
                self.pickleSaveCount += 1
                with tripQueue.mutex:  # thread safe for clearing
                    tripQueue.queue.clear()
                t1 = time.time()
                print("\t{0:.2f} Seconds for 300 Frames".format(t1 - t0))
            elif data[i] == '&': #DISCARD Training
                t0 = time.time()
                print("--------DISCARDING DATA ----\ntripQueue size = {}".format(tripQueue.qsize()))
                # tempQ = queue.Queue()  # make copy of queue to save
                # for i in tripQueue.queue:  # transfer elements to new queue
                #     tempQ.put(i)
                #start_new_thread(self.SaveToPickle,(tempQ, self.discardPickle_filename.format(self.getTimeStamp()),));
                #DELETE DISCARDED QUEUE
                with tripQueue.mutex:  # thread safe for clearing
                    tripQueue.queue.clear()
                # self.pickleSaveCount += 1

                t1 = time.time()
                print("\t{0:.2f} Seconds for 500 Frames".format(t1 - t0))
            elif data[i] ==':': #START TRAINING
                self.startClicks += 1
                # self.isMovingForward = True; #TODO; should i do this?????
                if(self.startClicks == 1): #if first time pressing start
                    start_new_thread(self.record, ()) #start new recording thread
                else:
                    self.isPaused = False;  # unpauses videorecorder
                    print("------UNPAUSED---FROM START CMD")
            else:
                print("Bad Command")
            # return cmds

        executes the commands from data recieved in socket server, also
        changes boolean values representing the movement of car
        :param data: data recieved from socket server
        
executes the commands from data recieved in socket server, also
changes boolean values representing the movement of car
executes the commands from data recieved in socket server also changes boolean values representing the movement of car
def ExecuteCommand(self, data, tripQueue):
        if data is None:
            return
        for i in range(len(data) - 1):
            if data[i] == ',':  
                self._stopAllMotors()
                print("stop all")
                self.isMovingForward = False
            elif data[i][0:2] == 'SS':
                self.speed = int(data[i][2:])  
                print("Speed: {}".format(self.speed))
                if (self.isMovingForward):
                    self.backMotor.Forward(self.speed)
            elif data[i][0:2] == 'SA': 
                self.steerDegree = int(data[i][2:]) 
                self.steerMotor.turn(self.steerDegree*10)
                print("Steer Degree: {}".format(self.steerDegree))
            elif data[i] == 'FF':
                print("forward")
                self.backMotor.Forward(self.speed)
                self.isMovingForward = True;
            elif data[i] == '@': 
                self.isPaused = True  
                self._stopAllMotors()
                print("------PAUSED---")
            elif data[i] == '#': 
                self.isPaused = False; 
                print("------UNPAUSED---")
            elif data[i] == '*': 
                t0 = time.time()
                print("tripQueue size = {}".format(tripQueue.qsize()))
                tripList = [item for item in self.qdumper(self.tripQueue)];
                start_new_thread(self.SaveToPickle,(tripList, self.pickle_filename.format(self.getTimeStamp()),));
                self.pickleSaveCount += 1
                with tripQueue.mutex:  
                    tripQueue.queue.clear()
                t1 = time.time()
                print("\t{0:.2f} Seconds for 300 Frames".format(t1 - t0))
            elif data[i] == '&': 
                t0 = time.time()
                print("--------DISCARDING DATA ----\ntripQueue size = {}".format(tripQueue.qsize()))
                with tripQueue.mutex:  
                    tripQueue.queue.clear()
                t1 = time.time()
                print("\t{0:.2f} Seconds for 500 Frames".format(t1 - t0))
            elif data[i] ==':': 
                self.startClicks += 1
                if(self.startClicks == 1): 
                    start_new_thread(self.record, ()) 
                else:
                    self.isPaused = False;  
                    print("------UNPAUSED---FROM START CMD")
            else:
                print("Bad Command")
def ExecuteCommand ( self , data , tripQueue ) : if data is None : return for i in range ( len ( data ) - 1 ) : if data [ i ] == ',' : self . _stopAllMotors ( ) print ( "stop all" ) self . isMovingForward = False elif data [ i ] [ 0 : 2 ] == 'SS' : self . speed = int ( data [ i ] [ 2 : ] ) print ( "Speed: {}" . format ( self . speed ) ) if ( self . isMovingForward ) : self . backMotor . Forward ( self . speed ) elif data [ i ] [ 0 : 2 ] == 'SA' : self . steerDegree = int ( data [ i ] [ 2 : ] ) self . steerMotor . turn ( self . steerDegree * 10 ) print ( "Steer Degree: {}" . format ( self . steerDegree ) ) elif data [ i ] == 'FF' : print ( "forward" ) self . backMotor . Forward ( self . speed ) self . isMovingForward = True ; elif data [ i ] == '@' : self . isPaused = True self . _stopAllMotors ( ) print ( "------PAUSED---" ) elif data [ i ] == '#' : self . isPaused = False ; print ( "------UNPAUSED---" ) elif data [ i ] == '*' : t0 = time . time ( ) print ( "tripQueue size = {}" . format ( tripQueue . qsize ( ) ) ) tripList = [ item for item in self . qdumper ( self . tripQueue ) ] ; start_new_thread ( self . SaveToPickle , ( tripList , self . pickle_filename . format ( self . getTimeStamp ( ) ) , ) ) ; self . pickleSaveCount += 1 with tripQueue . mutex : tripQueue . queue . clear ( ) t1 = time . time ( ) print ( "\t{0:.2f} Seconds for 300 Frames" . format ( t1 - t0 ) ) elif data [ i ] == '&' : t0 = time . time ( ) print ( "--------DISCARDING DATA ----\ntripQueue size = {}" . format ( tripQueue . qsize ( ) ) ) with tripQueue . mutex : tripQueue . queue . clear ( ) t1 = time . time ( ) print ( "\t{0:.2f} Seconds for 500 Frames" . format ( t1 - t0 ) ) elif data [ i ] == ':' : self . startClicks += 1 if ( self . startClicks == 1 ) : start_new_thread ( self . record , ( ) ) else : self . isPaused = False ; print ( "------UNPAUSED---FROM START CMD" ) else : print ( "Bad Command" )
executes the commands from data recieved in socket server, also
changes boolean values representing the movement of car
executes the commands from data recieved in socket server also changes boolean values representing the movement of car
'''
        executes the commands from data recieved in socket server, also
        changes boolean values representing the movement of car
        :param data: data recieved from socket server
        ''' # cmds = [] # STOP ALL MOTORS # self.driver.StopAll() # cmds.append(Commands.STOP_ALL_MOTORS.value) # get second half of data with the number for speed # elif (self.isMovingBackward): #     self.twoMotorDriver.Reverse(self.speed) # self.driver.Speed(int(speed)) #todo: add speed command to training data #Steering Angle Change #get second half of data with the number for steer angle # self.steerMotor.offMotor() # elif data[i] == 'BB': #     print("Back") #     self.backMotor.Reverse(self.speed) #     self.isMovingForward = False #PAUSE Training #Pauses videorecorder # self.driver.StopAll() #UNPAUSE TRAINING #unpauses videorecorder #SAVE Training - sent after paused # tempQ = queue.Queue()  # make copy of queue to save # for i in tripQueue.queue:  # transfer elements to new queue #     tempQ.put(i) # thread safe for clearing #DISCARD Training # tempQ = queue.Queue()  # make copy of queue to save # for i in tripQueue.queue:  # transfer elements to new queue #     tempQ.put(i) #start_new_thread(self.SaveToPickle,(tempQ, self.discardPickle_filename.format(self.getTimeStamp()),)); #DELETE DISCARDED QUEUE # thread safe for clearing # self.pickleSaveCount += 1 #START TRAINING # self.isMovingForward = True; #TODO; should i do this????? #if first time pressing start #start new recording thread # unpauses videorecorder # return cmds
self
data
data recieved from socket server
data recieved from socket server
tripQueue