Ejemplo n.º 1
0
def encodedata():
    sd = sensor_data_pb2.SensorData()

    sd.unix_time = drone.navdata['header']

    sd.battery = drone.navdata['demo']['battery']
    sd.altitude = drone.navdata['demo']['altitude']
    sd.pitch = drone.navdata['demo']['theta']
    sd.roll = drone.navdata['demo']['phi']
    sd.yaw = drone.navdata['demo']['psi']
    sd.vx = drone.navdata['demo']['vx']
    sd.vy = drone.navdata['demo']['vy']
    sd.vz = drone.navdata['demo']['vz']

    sd.fly = drone.navdata['state']['fly']

    image = sd.images.add()
    tempImage = drone.image
    image.width, image.height = tempImage.size
    image.image_data = tempImage.tobytes()

    # Encode Data Via Protocol Buffer
    encodedsd = sd.SerializeToString()
    #print(sensor_data_pb2.SensorData().FromString(encodedsd))
    #Image.frombytes('RGB', (image.width, image.height), image.image_data).show()
    return encodedsd
Ejemplo n.º 2
0
def image_recognition(input):
    data = ''
    # Convert Encoded Input To Image
    encodedsd = input['sensors']
    decodedsd = sensor_data_pb2.SensorData().FromString(encodedsd)

    img = Image.frombytes(
        'RGB', (decodedsd.images[0].width, decodedsd.images[0].height),
        decodedsd.images[0].image_data)

    # Compile Valid Objects Detected List
    temp_objects = vision(img)
    valid_objects = []
    for i in temp_objects:
        if (float(i.split(":")[1].strip(' \t\n\r%')) > min_confidence):
            valid_objects.append(i.split(":")[0])

    valid_objects = list(set(valid_objects))
    print("Valid Objects: ", valid_objects)

    # Search For Desired Object
    if ("bottle" in valid_objects):
        print("Bottle")
        if decodedsd.fly == 0:
            return {
                'has_command': True,
                'meta_id': 'takeoff',
                'data': data,
            }
        else:
            return {
                'has_command': True,
                'meta_id': 'hover',
                'data': data,
            }
    elif ("person" in valid_objects):
        print("Person")
        if decodedsd.fly == 0:
            return {
                'has_command': True,
                'meta_id': 'takeoff',
                'data': data,
            }
        else:
            return {
                'has_command': True,
                'meta_id': 'spin',
                'data': data,
            }
    else:
        return {
            'has_command': False,
        }
Ejemplo n.º 3
0
    def __init__(self, name_=None, uid_=None, type_=None, index_=None):
        self.sensor_msg = sensor_data_pb2.SensorData()

        if name_:
            self.sensor_msg.name = name_
        if uid_:
            self.sensor_msg.uid = uid_
        if type_:
            self.sensor_msg.type = sensor_data_pb2.SensorData.SensorType.Value(
                type_)
        if index_:
            self.sensor_msg.index = index_

        self.update_formatter()
def vertical_flight(input):
    data = ''

    encodedsd = input['sensors']
    decodedsd = sensor_data_pb2.SensorData().FromString(encodedsd)

    # Change Directions If Drone Is Too High Or Too Low
    if (decodedsd.fly == 0):
        print("TakeOff Scheduled")
        return {
            'has_command': True,
            'meta_id': 'takeoff',
            'data': data,
        }
    else:
        if (decodedsd.altitude < 900):
            print("UP"),
            print(decodedsd.altitude)
            return {
                'has_command': True,
                'meta_id': 'up',
                'data': data,
            }
        elif (decodedsd.altitude > 1500):
            print("DOWN"),
            print(decodedsd.altitude)
            return {
                'has_command': True,
                'meta_id': 'down',
                'data': data,
            }
        else:
            return {
                'has_command': True,
                'meta_id': 'nothing',
                'data': data,
            }
def take_picture(input):
    meta_id = 'take_pic'
    data = ''

    # Global Variables
    global next_time
    global interval

    # If Timer
    cur_time = time.time()
    if cur_time > next_time:
        encodedsd = input['sensors']
        decodedsd = sensor_data_pb2.SensorData().FromString(encodedsd)

        # Get Image Constraints
        #Image.frombytes('RGB', (decodedsd.images[0].width, decodedsd.images[0].height), decodedsd.images[0].image_data).show()
        print("Picture Scheduled")
        data = {
            'width': decodedsd.images[0].width,
            'height': decodedsd.images[0].height,
            'bytes': decodedsd.images[0].image_data,
        }

        # Update next_time
        next_time = cur_time + interval

        return {
            'has_command': True,
            'meta_id': meta_id,
            'data': data,
        }
    # Else
    else:
        return {
            'has_command': False,
        }