Ejemplo n.º 1
0
 def __init__ (self, name = "Object", port = 0):
     Pyro.core.ObjBase.__init__(self)
                                
     #instatiates an instace of communication and starts it        
     self.comm = Communications()
     self.serverName = "ObjectGenNOc"
     self.PORT = port
     
     #if invalid returns 0
     self.status = self.comm.initialize(self, self.PORT)            
     self.comm.start()       
     #instantiate an empty waypoint list
                                     
     #instantiate empty packets
     self.vehiclePacket = []
     self.groundPacket1 = []
     self.groundPacket2 = []
     self.wayListForValidating = []
     
     #!!!added my own waylist, no waylist manager
     self.jimmyWayList = []
     
     #instantiate variables to 0 so errors do not occur when GUI calls them
     self.curWaypoint = None
     self.isHandshaken = None
     self.targetLat = 0
     self.targetLong = 0
     self.planeLat = 0
     self.planeLong = 0
     self.planeHeading = 99
     self.mode = "waypoint"
     self.navStat = True
     self.gpsStat = True
     self.commStat = True
     self.GPSErrorType = ""
Ejemplo n.º 2
0

if __name__ == '__main__':
    from Utilities import Utilities
    import platform
    from Communications import Communications
    pygame.init()

    DISPLAYSURF = pygame.display.set_mode((1200, 800))
    FONT = pygame.font.Font('freesansbold.ttf', 16)
    BIGFONT = pygame.font.Font('freesansbold.ttf', 32)
    pygame.display.set_caption('Flippy')
    utilities = Utilities(DISPLAYSURF, BIGFONT)
    name = 'laptop' if (platform.system() == 'Windows') else 'pi7'
    target = 'pi7' if (platform.system() == 'Windows') else 'laptop'
    comm = Communications('messages', 'localhost', name)
    comm.connectBroker()
    comm.setTarget(target)
    utilities.comm = comm

    line = TextBox('Enter exit to quit')
    pos = line.draw()
    line = TextBox('Chat:')
    pos = line.draw(pos)

    pygame.display.flip()
    run = True
    lastMsg = ''
    line = None
    while run:
        (event, data, addr) = utilities.getKeyOrMqtt()
Ejemplo n.º 3
0
        return ssids

    def showLabel(self, msg, x, y):
        (surface, rect) = self.createLabel(msg, x, y)
        self.displaySurface.blit(surface, rect)


if __name__ == "__main__":
    print("pygame.init")
    pygame.init()
    BIGFONT = pygame.font.Font('freesansbold.ttf', 32)
    DISPLAYSURF = pygame.display.set_mode((1200, 800))
    utilities = Utilities(DISPLAYSURF, BIGFONT)
    from Communications import Communications

    comm = Communications('messages', 'localhost', 'laptop')
    if comm.connectBroker():
        comm.setTarget('pi7')
        utilities.comm = comm

        sprites = utilities.showImages(['quit.jpg'], [(400, 500)])
        pygame.display.update()

        quit = False
        while not quit:
            (event, data, addr) = utilities.getKeyOrMqtt()
            if utilities.message != '':
                print('[message]: [' + utilities.message + ']')
                utilities.message = ''

            # Use data above to determine sprite click?
Ejemplo n.º 4
0
BROWN = (174, 94, 0)
RED = (255, 0, 0)

TEXTBGCOLOR1 = BRIGHTBLUE
TEXTBGCOLOR2 = GREEN
GRIDLINECOLOR = BLACK
TEXTCOLOR = WHITE
HINTCOLOR = BROWN

tcpSocket = None
tcpConnection = None
client = None

print("pygame.init")
pygame.init()
print("get the clock")
MAINCLOCK = pygame.time.Clock()

DISPLAYSURF = pygame.display.set_mode((1200, 800))
FONT = pygame.font.Font('freesansbold.ttf', 16)
BIGFONT = pygame.font.Font('freesansbold.ttf', 32)
#pygame.display.toggle_fullscreen()
pygame.display.set_caption('Flippy')
utilities = Utilities(DISPLAYSURF, BIGFONT)
pages = Pages(DISPLAYSURF, utilities, platform.system() == 'Windows')
name = 'laptop' if (platform.system() == 'Windows') else 'pi7'
comm = Communications('messages', 'localhost', name)  # '192.168.4.1', name )
comm.connectBroker()
utilities.comm = comm
pages.comm = comm
pages.mainPage()
Ejemplo n.º 5
0
 def __init__(self):
     self._Personality = PersonaliPy()
     self._Brain = Brain()
     self._Communications = Communications()
     self._Peripherals = Peripherals()
Ejemplo n.º 6
0
class Bot():

    ## This does most of the communicating with the database.
    ## Also this will perform calculations.
    _Brain = None
    ## This is how bot is feeling.
    _Personality = None
    ## These are is/are the way(s) to communicate with bot
    _Communications = None
    ## These are like bot's four other senses.
    ## I gave so much to communications I decided to split it off.
    _Peripherals = None

    ## This is what tells bot to die.
    _terminate = False
    ## This is for debugging mostly.
    _verbose = False

    def __init__(self):
        self._Personality = PersonaliPy()
        self._Brain = Brain()
        self._Communications = Communications()
        self._Peripherals = Peripherals()

    def act(self, action):
        ## Perform action
        # Communicate back to orinigating communication.
        # Communicate back to originating periphereal.
        pass

    def actRandomly(self, moodLevel):
        log("Acting randomly...")
        action = self._Brain.processAction(moodLevel)
        self.act(action)

    def checkInputs(self):
        log("Checking inputs...")
        signals = self._Peripherals.checkAll()
        communication = self._Communications.getEvents()
        return signals

    def getMood(self):
        return self._Personality.getMood()

    def react(self, signal, moodLevel):
        ## Check signal here to see what we're doing
        action = self._Brain.processReaction(signal, moodLevel)
        self.act(action)

    def terminate(self):
        self._terminate = True

    def startup(self):
        """
            Starts all modules and connectetions.
            
            @type self: Object
            @param self: Parent instance.
            @rtype: boolean
            @return True/False
        """
        pass

    def run(self):
        """
            Calls I{self}.startup() and begins main loop.
            
            @type self: Object
            @param self: Parent instance.
            @rtype: None
            @return None
        """
        self.startup()
        while not self._terminate:
            # Check Mood
            moodLevel = self.getMood()
            # Check Inputs
            # if input: respond; else: commit random act
            signal = self.checkInputs()
            if signal:
                self.react(signal, moodLevel)
Ejemplo n.º 7
0
class ObjectGenNOc(Pyro.core.ObjBase):
    
    def __init__ (self, name = "Object", port = 0):
        Pyro.core.ObjBase.__init__(self)
                                   
        #instatiates an instace of communication and starts it        
        self.comm = Communications()
        self.serverName = "ObjectGenNOc"
        self.PORT = port
        
        #if invalid returns 0
        self.status = self.comm.initialize(self, self.PORT)            
        self.comm.start()       
        #instantiate an empty waypoint list
                                        
        #instantiate empty packets
        self.vehiclePacket = []
        self.groundPacket1 = []
        self.groundPacket2 = []
        self.wayListForValidating = []
        
        #!!!added my own waylist, no waylist manager
        self.jimmyWayList = []
        
        #instantiate variables to 0 so errors do not occur when GUI calls them
        self.curWaypoint = None
        self.isHandshaken = None
        self.targetLat = 0
        self.targetLong = 0
        self.planeLat = 0
        self.planeLong = 0
        self.planeHeading = 99
        self.mode = "waypoint"
        self.navStat = True
        self.gpsStat = True
        self.commStat = True
        self.GPSErrorType = ""

    navigator = None
    wayList = []
    #sends the handshake to comm
    #sets the flags to true     
    def setHandshake(self):
        self.comm.handshake()      
        self.isHandshaken = True       
        
        #!!!do not start navigator
        #!!!if self.navigator == None:
            #!!!self.navigator = Navigator(self)
            #!!!self.wayList = self.navigator.waylist 
            
        return "12345"
        #!!!return a dummy key to gui, no more multiple guis
        #!!!return self.navigator.obstacleManager.subscribe() 
           
    def completeHandShake(self):
        self.shakeFlag = False
            
    def getHandshake(self):
        return self.isHandshaken
    
    #returns the lost packet information/status
    def getLostPacketStats(self):
        return self.comm.getLostPacketStats()
    

    def getPacketB(self):
        self.comm.getPacketB()
        
    def getPacketA(self):
        self.comm.getPacketA()   

    def setTelError(self,error):
        self.packetError = error;

    def getTelError(self):
        return self.packetError
        
    #Method called by comm to push a packet to the object 
    #packetNum determines which packet it is
    #Then it copys that packet list to be stored by the object   
    def pushPacket(self, packetNum, dataList):
        if(packetNum == 1):
            self.groundPacket1 = dataList 
            #print "packet A stuff:" + str(dataList['battery_voltage'])                      
        if(packetNum == 2):
            self.groundPacket2 = dataList            
            
        if(packetNum == 3):            
            self.vehiclePacket = dataList
            #print "packet B stuff: " + str(dataList['latitude'])
        
        if(packetNum == 4):    #waylist for validating
            self.wayListForValidating = dataList
        #pushes information to navigator every time a packet is pushed
        #!!!do not send navigator interpret 
        #!!!try:
            #!!!self.navigator.obstacleManager.interpretTruckSensors(self.vehiclePacket['latitude'], self.vehiclePacket['longitude'], self.vehiclePacket['heading'], self.vehiclePacket['range'])
        #!!!except Exception, e:
            #!!!print e
            
    #method to validate waylists   
    def ValidateWaylist(self):
        self.tmpSystemList = self.getWaypointList()        #get system waylist
        self.tmpCorrectCount = 0                            #count of correct waylists
        self.tmpTruckCount =  (self.wayListForValidating).__len__()  #size of truck list
        for w in tmpSystemList:                                    #test if waypoints are equal
            if(w.equals(self.wayListForValidating.pop(tmpTruckCount=tmpTruckCount - 1))):
                self.tmpCorrectCount = self.tmpCorrectCount +1
                
        if(self.tmpCorrectCount!=(self.getWaypointList()).__len__()  ):    #if correct waypoints match size of list
            return False
        else:
            return True   
            
        
            
            
#####Getter methods for GROUND STATION#########   

    #if the packet is empty we return dummy variables
    #when the packet is filled by comm we return the actual numbers     
    def getGroundVersion(self):
        if self.groundPacket1 == []:
            return 0
        return str(self.groundPacket1['version'])    
    def getGroundTimeAlive(self):        
        if self.groundPacket1 == []:
            return 0
        return str(self.groundPacket1['alive'])
    def getGroundBat(self):
        if self.groundPacket1 == []:
            return 0
        return str(self.groundPacket1['battery_voltage'])
    def getGroundLat(self):
        if self.groundPacket2 == []:
            return 0
        return str(self.groundPacket2['latitude'])
    def getGroundLong(self):
        if self.groundPacket2 == []:
            return 0
        return str(self.groundPacket2['longitude'])
    def getGroundAlt(self):
        if self.groundPacket2 == []:
            return 0
        return str(self.groundPacket2['air_pressure'])
    def getGroundXpos(self):
        if self.groundPacket2 == []:
            return 0
        return 0
        #return str(self.groundPacket2['xpos'])
        #hardware has not yet finished this functionality       
    def getGroundYpos(self):
        if self.groundPacket2 == []:
            return 0
        return 0
        #return str(self.groundPacket2['ypos'])
        #hardware has not yet finished this functionality
    def getGroundHeading(self):
        if self.groundPacket2 == []:
            return 0
        return (str(self.groundPacket2['heading']))
                    
        
######Getter methods for VEHICLE###########

    #if the packet is empty we return 0
    #when the packet is filled by comm we return the actual numbers         
    def getVehicleLatitude(self):
        if self.vehiclePacket == []:
            return 0
        if str(self.vehiclePacket['latitude']) == '^':
            return 00
        return str(self.vehiclePacket['latitude'])         
    def getVehicleLongitude(self):
        if self.vehiclePacket == []:
            return 0 
        if str(self.vehiclePacket['longitude']) == '^':
            return 00       
        return str(self.vehiclePacket['longitude']) 
    def getVehicleSpeed(self):
        if self.vehiclePacket == []:
            return 0
        return str(self.vehiclePacket['speed'])  
    def getVehicleHeading(self):
        if self.vehiclePacket == []:
            return 0
        return str(self.vehiclePacket['heading'])  
    def getVehicleMode(self):
        if self.vehiclePacket == []:
            return 0
        return str(self.vehiclePacket['mode'])
    def getVehicleTemperature(self):
        if self.vehiclePacket == []:
            return 0
        return str(self.vehiclePacket['temperature'])  
    def getVehicleVoltage(self): 
        if self.vehiclePacket == []:
            return 0
        return str(self.vehiclePacket['battery_voltage'])  
    def getVehicleRange(self): 
        if self.vehiclePacket == []:
            return 0
        return str(self.vehiclePacket['range'])     
    
        
        
###################iteration5##################### 
 #Adds the waypoint to the list
    #Sets the current waypoint to the latest  
    #Validates the waypoint with Control
    #Sends the updated waypoint list to comm
    def addWaypoint(self, waypoint):                  
        self.curWaypoint = waypoint
        #!!!self.wayList.append(self.curWaypoint)        
        self.jimmyWayList.append(waypoint) 
        self.sendWaylist(jimmyWayList)                 
     
     #returns the current waypoint   
    def getWaypoint(self): 
        return self.curWaypoint    
     
    #sends the entire waypoint list to comm to be updated to truck
    def sendWaylist(self, list = None):
        if list == None: list = self.jimmyWayList[:]       
        self.comm.addWaypoint(list)
        
    #deletes a waypoint by index number    
    def deleteWaypoint(self,index):
        print "deleting waypoint"
        print len(self.jimmyWayList)
        #!!!self.wayList.remove(index) 
        self.jimmyWayList.remove(index)
        self.sendWaylist(jimmyWayList)         
    
    #clears the entire waylist
    def clearWaylist(self):        
        #self.wayList.clear()
        self.jimmyWayList = []
        self.sendWaylist(jimmyWayList)   
        
    #modifys a waypoint by deleteing the old vale
    #and reinserting the new given value into the olds place
    def modifyWaypoint(self,waypoint,index):
        print "modify waypoint"
        print len(self.jimmyWayList)
        #!!!self.wayList.update(index,waypoint) 
        del self.jimmyWayList[index]
        self.jimmyWayList.insertWaypoint(waypoint,index-1)
         
    
    #inserts a waypoint AFTER the index 
    #moves all other waypoints down the waypoint list
    def insertWaypoint(self, waypoint, index):
        print "inserting waypoint"
        print len(self.wayList)        
        self.jimmyWayList.inset(index+1, waypoint)
        self.sendWaylist(jimmyWayList)  
        
###################iteration6#####################
    
    #sets the mode
    #calls the method to set the mode in control
    def setMode(self,string):
        self.mode = string
        #!!!self.navigator.mode = string      
    
    #returns the mode from control 
    def getMode(self):
        #!!!return self.navigator.mode
        return self.mode

    #returns the current waypoint list
    def getWaypointList(self):        
        return self.jimmyWayList[:]    
       
    #return the Obstacle Manager
    def getObstacleManager(self):
        return None
        #!!!return self.navigator.getObstacleManager()
    
    #returns the Obstacle grid 
    def getObjectGrid(self,lat,long,lat2,long2):
        return None
        #!!!return self.navigator.getObsManager().getGrid(lat,long,lat2,long2)
   
    
    #allows to add a Line to the ObstacleManager
    def addLineObject(self,lat,long,lat2,long2):
        return None
        #!!!self.navigator.obstacleManager.addLine(lat, long, lat2, long2)
        #Calls controls method to add line object
        
    #allows to add a Circle to the ObstacleManager
    def addCircleObject(self,lat,long, radiusLong, radiusLat):
        return None
        #!!!self.navigator.obstacleManager.addCircle(lat, long, radiusLat, radiusLong)        
        #Calls controls method to add circle object
        
    #returns the update queue from control to the caller
    def getObstacleUpdateList(self, key):        
        return []
        #!!!return self.navigator.obstacleManager.getUpdates(key)
    
    def checkArea(self, degreesLat, degreesLong, degreesLat2, degreesLong2, key):
        return None
        #!!!self.navigator.obstacleManager.checkArea(degreesLat, degreesLong, degreesLat2, degreesLong2, key)
        
    def clearArea(self, degreesLat, degreesLong, degreesLat2, degreesLong2):
        return None
        #!!!self.navigator.obstacleManager.clearArea(degreesLat, degreesLong, degreesLat2, degreesLong2)

    def unsubscribe(self, key):
        return None
        #!!!self.navigator.obstacleManager.unsubscribe(key) 
        
    def setHaltMode(self):   
        self.comm.setHaltMode()
        
    def setResumeMode(self):
        #!!!self.navigator.resume()
        print "Dmitri called me"
        self.comm.setWaypointMode()
    
    #sends the truck to the waypoint index    
    def setGoTo(self, index):        
        print "GOTO" 
        print index       
        #!!!self.navigator.goToUserWaypoint(index)
    
     
    
#########  BLACKBIRD METHODS  ########### 
    
#sets the plane position
    def setPlanePosition(self,lat,long, heading):
        self.planeLat = lat
        self.planeLong = long
        self.planeHeading = heading 
    
#returns the plane's position to whoever calls it
    def getPlanePositionLat(self):       
        return self.planeLat
           
    def getPlanePositionLong(self):
        return self.planeLong
        
    def getPlaneHeading(self):
        return self.planeHeading
        

#BLACKBIRD add Waypoints and Obstacles 
    def BBaddWaypoint(self,waypoint):
        print "BB has added a waypoint"
        self.addWaypoint(waypoint) 
        
    def BBaddLineObstacle(self,lat,long,lat2,long2):
        print "BB has added a LINE obstacle"
        #!!!self.navigator.obstacleManager.addLine(lat, long, lat2, long2)
        
    def BBaddCircleObstacle(self,lat,long, radiusLong, radiusLat):
        print "BB has added a CIRCLE obstacle"
        #!!!self.navigator.obstacleManager.addCircle(lat, long, radiusLat, radiusLong)        
    
    def getStatus(self):
        return self.status
        
    def setPreflight(self,type,errorRate=100):
        
        self.comm.setPreFlight(type,errorRate)
        self.error = self.comm.checkErrorRate()
        self.errorType = type
        print "ERROR IS: " 
        print self.error
        if(self.error):
            if(self.errorType=="HALT"):
                self.setHaltMode()
            elif(self.errorType=="IGNORE"):
                pass
            elif(self.errorType=="RETURN"):               
                #self.HOME = Waypoint(self.groundPacket2['latitude'], self.groundPacket2['longitude'],1,0)       
                self.HOME = self.wayList[0]    
                self.clearWaylist()
                self.addWaypoint(self.HOME)
    
    #Similiar to Preflight, but for GPS ERROR
    #Error Types: HALT, IGNORE
    def setGPSError(self, type):
        self.GPSErrorType = type
        print "GPS Error Type Set: " + str(self.GPSErrorType)
        
    #Acknowledges that there was a GPS error and takes correct action
    #Action is determined by GUI
    def AckGPSError(self):        
        if(self.GPSErrorType == "HALT"):
            self.setHaltMode()
        elif(self.GPSErrorType=="IGNORE"):
            pass        
        
  
    #set by other layers for the status lights
    def setNavError(self,error):        
        self.navStat = not error  
    def setCOMMStatus(self,status):
        self.commStat = status   
    def setGPSStatus(self,status):
        self.gpsStat = status  
        if(status):
           # print "----GPS ERROR is---- "
           # print self.gpsStat     
           pass        
#methods for GUI status lights
    def checkNavStatus(self):
        #method by navigator team to check status        
        return self.navStat
       
    def checkGPSStatus(self):
        #method by comm to check gps status
        return self.gpsStat
    def checkCOMMStatus(self):
        #method by comm to check COMM status
        return self.commStat 
        
    def checkWaypointModeStatus(self):
        if(self.comm.getCurrentTruckMode() == "%1"):
            return True
        else:
            return False    
        
    def guiUnsubscribe(self, key):
        #!!!self.navigator.obstacleManager.unsubscribe(key) 
        pass
Ejemplo n.º 8
0
class ObjectGen(Pyro.core.ObjBase):
    
    def __init__ (self, name = "Object", port = 0):
        Pyro.core.ObjBase.__init__(self)
                                   
        #instatiates an instace of communication and starts it        
        self.comm = Communications()
        self.serverName = "ObjectGen"
        self.PORT = port
        
        #if invalid returns 0
        self.status = self.comm.initialize(self, self.PORT)            
        self.comm.start()       
        #instantiate an empty waypoint list
                                        
        #instantiate empty packets
        self.vehiclePacket = []
        self.groundPacket1 = []
        self.groundPacket2 = []
        self.wayListForValidating = []
        
        #instantiate variables to 0 so errors do not occur when GUI calls them
        self.curWaypoint = None
        self.isHandshaken = None
        self.targetLat = 0
        self.targetLong = 0
        self.planeLat = 0
        self.planeLong = 0
        self.planeHeading = 99
        self.mode = "waypoint"
        self.navStat = True
        self.gpsStat = True
        self.commStat = True
        self.GPSErrorType = ""

    navigator = None
    wayList = []
    #sends the handshake to comm
    #sets the flags to true     
    def setHandshake(self):
        self.comm.handshake()      
        self.isHandshaken = True       
        if self.navigator == None:
            self.navigator = Navigator(self)
            self.wayList = self.navigator.waylist 
        return self.navigator.obstacleManager.subscribe() 
           
    def completeHandShake(self):
        self.shakeFlag = False
            
    def getHandshake(self):
        return self.isHandshaken
    
    #returns the lost packet information/status
    def getLostPacketStats(self):
        return self.comm.getLostPacketStats()
    

    def getPacketB(self):
        self.comm.getPacketB()
        
    def getPacketA(self):
        self.comm.getPacketA()   

    def setTelError(self,error):
        self.packetError = error;

    def getTelError(self):
        return self.packetError
        
    #Method called by comm to push a packet to the object 
    #packetNum determines which packet it is
    #Then it copys that packet list to be stored by the object   
    def pushPacket(self, packetNum, dataList):
        if(packetNum == 1):
            self.groundPacket1 = dataList 
            #print "packet A stuff:" + str(dataList['battery_voltage'])                      
        if(packetNum == 2):
            self.groundPacket2 = dataList            
            
        if(packetNum == 3):            
            self.vehiclePacket = dataList
            #print "packet B stuff: " + str(dataList['latitude'])
        
        if(packetNum == 4):    #waylist for validating
            self.wayListForValidating = dataList
        #pushes information to navigator every time a packet is pushed
        try:
            self.navigator.obstacleManager.interpretTruckSensors(self.vehiclePacket['latitude'], self.vehiclePacket['longitude'], self.vehiclePacket['heading'], self.vehiclePacket['range'])
        except Exception, e:
            print e