hanyazou / TelloPy

DJI Tello drone controller python package
Other
689 stars 292 forks source link

'Tello' object has no attribute 'EVENT_LOG_DATA' #72

Closed GalBrandwine closed 2 years ago

GalBrandwine commented 4 years ago

Hey hanyazou!

for some reason I get an error when trying to subscribe to:

 drone.subscribe(drone.EVENT_LOG_DATA, handler)

in the handler itself:

def handler(event, sender, data, **args):
    drone = sender    
    if event is drone.EVENT_FLIGHT_DATA:
        flight_data = data
        print(flight_data)
    elif event is drone.EVENT_LOG_DATA:
        log_data = data
        print(log_data.imu)

I get the error: 'Tello' object has no attribute 'EVENT_LOG_DATA'

Any ideas why? Thanks, Gal.

P.S it's nice to go back and work with the tello again :) it reminded me how awesome the TelloPy repo is!

benjaminjacobreji commented 4 years ago

I used EVENT_LOG instead of EVENT_LOG_DATA it helped me solve issues when doing tello-openpose project

GalBrandwine commented 4 years ago

UPDATE: Tried that:

def log_data_handler(event, sender, data):
        """
            Listener to log data from the drone.
        """  
        pos_x = -data.mvo.pos_x
        pos_y = -data.mvo.pos_y
        pos_z = -data.mvo.pos_z

The data received is Bytes - hence cant access to its internals..

Any help there? How did you accessed to the internals of "data"? - I've seen youre project (quite impressive), what have i missed?

Thanks, Gal

gemSquared commented 4 years ago

Hello! I'm going to assume you use python 3? I also get a bytes string and I run python 3.6.

Imma take a peep at the _internal folder and see what gives.

gemSquared commented 4 years ago

Okay! So! Download the latest tellopy (develop-0.7.0 (default)) library from here, not pip.

Then go back and use EVENT_LOG_DATA.

The data is already parsed for you.

https://github.com/hanyazou/TelloPy/blob/a997d2909a5af3bfec61d9001be01594bd60db0a/tellopy/_internal/protocol.py#L286

lmmedino commented 4 years ago

Hi, I am still confused on how to get the position information @gemSquared, can you explain further in what part we are getting the x,y,z positions?

gemSquared commented 4 years ago

The EVENT_LOG_DATA event passes what seems to be a class. Here's what I did to get the data:

sensors = None
def logDataHandler(event, sender, data):
    global sensors
    sensors = data

drone.subscribe(drone.EVENT_LOG_DATA, logDataHandler)

Here's where I get the data out, for example yaw (you might need this btw)

def quaternion2yaw(q0,q1,q2,q3):
    siny = 2.0*(q0*q3+q1*q2)
    cosy = 1.0-2.0*(q2*q2+q3*q3)
    return math.atan2(siny,cosy)

yaw = quaternion2yaw(
                sensors.imu.q0,
                sensors.imu.q1,
                sensors.imu.q2,
                sensors.imu.q3)

The format is:

EVENT_LOG_DATA

lmmedino commented 4 years ago

What do you mean by "container"?

gemSquared commented 4 years ago

I don't know what things are called when I code. I just learn meself, haha. If you copy that handler function with the (event, sender, data) and subscribe it, just do something like

x = data.mvo.pos_x
y = data.mvo.pos_y
z = data.mvo.pos_z

inside the function.

lmmedino commented 4 years ago

Hi, thanks for the help. I ended up getting the data, but I move Tello and it seems like the data is not changing, is this normal?

gemSquared commented 4 years ago

If x,y, and z are near zero, hold your tello up about 0.5 meters over a well lit surface. Those values come up when the Tello is flying. They also may not start at zero because the values drift without mvo correction, so set the "home position" when in the air.

ALSO! When the tello loses sight of the ground (low light/flat texture) the mvo goes off and the values snap to zero again. Use the first byte of EVENT_LIGHT to get a low-light warning. If the byte equals 1, that means the mvo is about to/already cut off. Otherwise it'll be zero.

P.S. you may want to get yaw from the imu quaternions ;)

lmmedino commented 4 years ago

Hi @gemSquared,

Do you know where do we set up the frequency we get the data from tello?

xinyangt9 commented 3 years ago

Thank you! This error confused me for several days. @gemSquared Could you please update the source of pip so that people can pip install the latest version of tellopy package? @hanyazou

gemSquared commented 3 years ago

Hi @gemSquared,

Do you know where do we set up the frequency we get the data from tello?

It appears the tello just streams it in, hence why this library uses event handlers. Not 100% sure though.