Example #1
0
File: UAV.py Project: RManuM/UAV-RC
 def connectSerial(self, comport, autopublish):
     self.drone = AscTec(self)
     try:
         result = self.drone.connectDrone(comport, autopublish=autopublish)
     except Exception, e:
         print UAV_Logger.log_error("Comport not opened: " + str(e))
         sys.exit(1)
Example #2
0
 def setCamAngle(self, pitch, roll, request):
     LOG.log_app_info("Setting angle to (pitch/roll): (" + str(pitch) + "/" + str(roll) + ")")
     key = "CAM"
     if not self.__pending_acks.has_key(key):
         self.__pending_acks[key] = request
         self.writeData(Command.getCmd_setCam(pitch, roll))
     else:
         self.abstractUAV.ack_error(request, 1, "already pending action")
Example #3
0
 def _sendRequest(self, signal, request):
     ''' Sending a request under a certain signal
     
     Args:
         signal (str): stringrepresentation of the signal about to be emitted
         request (dict):  dictionary that will be transmitted as a JSON-string'''
     UAV_Logger.log_debug("-->  SIGNAL: " + signal + " | REQUEST: " + str(request))
     self.socketIO.emit(signal, request)
Example #4
0
 def comeHome(self, request):
     """flies to the current home-position"""
     command = Command.getCmd_comeHome()
     self.writeData(command)
     key = "COMEHOME"
     if not self.__pending_acks.has_key(key):
         self.__pending_acks[key] = request
     self.__onMission = True ## FIXME: curway checking?
     LOG.log_app_info(key)
Example #5
0
 def endFlight(self, request):
     """ ends a flight"""
     command = Command.getCmd_endFlight()
     self.writeData(command)
     key = "ENDFLIGHT"
     if not self.__pending_acks.has_key(key):
         self.__pending_acks[key] = request
     self.__onMission = True ## FIXME: curway checking?
     LOG.log_app_info(key)
Example #6
0
 def launch(self, target, request):
     """ Setting the current home-position"""
     command = Command.getCmd_launch()
     self.writeData(command)
     key = "LAUNCH"
     if not self.__pending_acks.has_key(key):
         self.__pending_acks[key] = request
     self.__onMission = True ## FIXME: curway checking?
     LOG.log_app_info(key)
Example #7
0
 def _sendRequest_requireCallback(self, signal, request, callbackFkt):
     ''' Sending a request under a certain signal
     
     Args:
         signal (str): the signal to emit
         request (dict): dictionary that will be transmitted as a JSON-string
         callbackFkt (type): the callbackfunktion executed on positive response
         '''
     UAV_Logger.log_debug("--> SIGNAL: " + signal + " | REQUEST: " + str(request))
     self.socketIO.emit(signal, request, callbackFkt)
Example #8
0
 def checkWaypointReached(self, data):
     """ Checks, whether a waypoint is reached and executed till the end"""
     wptReached = data["wptReached"]
     if wptReached:
         LOG.log_app_info("Waypoint reached")
         self.abstractUAV.em_UAV_SI_TARGET_REACHED()
         self.__onMission = False
         self._target = None
     else:
         LOG.log_app_info("Distance to waypoint: " + str(data["distance"]))
Example #9
0
 def goto(self, target, request):
     """keeping the target but moving to a different point for resuming"""
     maxSpeed= 10 ## in m/s
     timeToStay=1 ## in s
     acc=2 ## in m
     lng=float(target["lon"])
     lat=float(target["lat"])
     heading=float(target["heading"])
     height=float(target["alt"])
     command = Command.getCmd_goto(maxSpeed,timeToStay,acc,lng,lat,heading,height)
     self.writeData(command)
     key = "GOTO"
     if not self.__pending_acks.has_key(key):
         self.__pending_acks[key] = request
     self.__onMission = True ## FIXME: curway checking?
     LOG.log_app_info(key)
Example #10
0
    def __init__(self, host="localhost", port=8080, moduleID="Dummy", slots=[], signals=[]):
        """
        Args:
            host (str, optional): IP-Address of the server hosting the socket.io-Server (default is localhost)
            port (int, optional): Port on which the server is listening (default is 8080)
            name (str, optional): ModuleID of the connecting module (default is Dummy)
            slots (list, optional): list of all slots on which the socket is receiving messages (default is an empty list)
            signals (list, optional): a list of all signals the socket can send (default is an empty list)
        """
        Thread.__init__(self)
        UAV_Logger.log("registring to host")
        self.host = host
        self.port = port
        self.name = moduleID
        self.socketIO = SocketIO(host, port)
        self.slots = slots
#         self.signals = signals
        UAV_Logger.log("initialising listening")
        self.socketIO.on('connect', self.onConnect)
        self.polling_frequenze = 1 # new poll every second
        self.listening = False
        self.__initListening__()
Example #11
0
def startupWithRequest():
    LOG.log_console("started...")

    client = startup()  # @UnusedVariable

    LOG.log_console("waiting till bootup")
    time.sleep(5)
    LOG.log_console("proceed")
Example #12
0
 def setTarget(self, target, request):
     self._target = target
     ## setting cam
     pitch = float(request.get("body","cam", "pitch"))
     roll = float(request.get("body","cam", "roll"))
     self.setCamAngle(pitch, roll, request)
     
     ## setting waypoint FIXME: setting some values not statically
     LOG.log_app_info("Setting target.")
     maxSpeed= 10 ## in m/s
     timeToStay=1 ## in s
     acc=2 ## in m
     lng=float(target["lon"])
     lat=float(target["lat"])
     heading=float(target["heading"])
     height=float(target["alt"])
     flags = str(request.get("body", "cam", "trigger")).lower() == "true"
     command = Command.getCmd_uploadTarget(maxSpeed, timeToStay, acc, lng, lat, heading, height, flags)
     self.writeData(command)
     key = "WPT"
     if not self.__pending_acks.has_key(key):
         self.__pending_acks[key] = request
     self.__onMission = True
Example #13
0
 def connectDrone(self, port, autopublish=None, sending_intervall=None, poll_intervall=None):
     ''' Trys to connect a drone to the serial port specified by this class'''
     
     if autopublish is not None:
         self.__autopublish = autopublish
     if sending_intervall is not None:
         self.__sendingIntervall =  sending_intervall
     if poll_intervall is not None:
         self.__pollIntervall =  poll_intervall
         
     error, message = 0, ""
     self.__comport = port
     if not self.connected:
         try:
             ## connect serial
             AscTec.serial = serial.Serial(port=self.__comport,
                                      baudrate=self.__baud,
                                      parity=self.__parity,
                                      stopbits=self.__stopbits,
                                      bytesize=self.__databits)
         except Exception, e:
             LOG.log_error(str(e))
             error = 1
             message = str(e)
Example #14
0
def log_sent(command):
    LOG.log_serial_communication("SENT: " + str(command[3:].encode("hex")))
Example #15
0
 def kill(self):
     """Killing the socket"""
     self.listening = False
     while(self.isAlive()):
         time.sleep(1)
     UAV_Logger.log("Socket killed")
Example #16
0
 def __del__(self):
     UAV_Logger.log("deleting socket...")
     self.kill()
Example #17
0
 def trigger(self, request):
     message = Command.getCmd_triggerCam()
     LOG.log_app_info("Triggering CAM")
     self.writeData(message, request)
Example #18
0
 def on_dummyPYSlot(self, *args):
     LOG.log_console("Recieved remote package")
     request = self._receive(args[0], self._acknowledgeSignal)  # @UnusedVariable
Example #19
0
 def onPySignal_acknowledged(self, *args):
     LOG.log_debug("received callback" + str(args[0]))
Example #20
0
def log_received(data, typeName):
    LOG.log_serial_communication("RECEIVED (" + str(typeName) + ")  :" + str(data.encode("hex")))
Example #21
0
 def onConnect(self, *args):
     """Slot for handling a connect-event"""
     UAV_Logger.log("connect signal recieved")
     self.socketIO.emit('CORE_SL_SLOTS_SET', Request(self.getModuleName()).newData({"slots":self.slots}).toDictionary())
Example #22
0
 def _receive(self, args):
     ''' First handling a received request, by parsing it'''
     request = Request(self.getModuleName()).parse(args)
     UAV_Logger.log_debug("<-- DATA: " + str(request))
     return request
Example #23
0
def log_ack(ack_type):
    LOG.log_serial_communication("ACK:           " + ack_type + " --")
Example #24
0
File: UAV.py Project: RManuM/UAV-RC
    parser.add_option("--port", help="the port of the socket.io-server", default=8081)
    parser.add_option("--host", help="the socket.io-servers IP", default="localhost")
    parser.add_option("--logging_level", help="Specify logging level: DEBUG,INFO", default="INFO")
#     parser.add_option("--logfile", help="specify a file for logging", default=None)
    return parser
   
if __name__ == "__main__":
    parser = init_parser()
    options, args = parser.parse_args()
    host, port = options.host, options.port
    comport = options.comport
    autopublish = options.autopublish.lower() == "true"
    
    if options.logging_level == "DEBUG":
        logging.basicConfig(level=UAV_Logger.APP_DEBUG)
    else:
        logging.basicConfig(level=UAV_Logger.INFO)
    logging.log(logging.INFO, "---------------Starting new LOG------------------")
    UAV_Logger.serialLogger_enable(True)
    UAV_Logger.socketIoLogger_enable(False)
    UAV_Logger.appLogger_enable(True)
    
    uav = startup_UAV(host, port)
    if comport is not None:
        try:
            comport = int(comport)
            startup_serial(uav, comport, autopublish)
        except SerialException, e:
            UAV_Logger.log_error("Serial not available: " + str(e))
        except Exception,e:
            UAV_Logger.log_error("Unexspected Error: "+ str(e))
Example #25
0
 def __handleAck(self, ackType):
     if ackType is not None:
         if self.__pending_acks.has_key(ackType):
             pending_ack = self.__pending_acks.pop(ackType)
             self.abstractUAV.ack_positive(pending_ack)
             LOG.log_app_info("ACK: " + ackType)