Hello Tello Pilot!
Join our DJI Tello community & remove this banner.
Sign up

imu state/data

hello12221

New member
Joined
Aug 21, 2018
Messages
4
Reaction score
0
Do anyone knows how to get the IMU data from the Tello drone?
Im using TelloPy hanyazou/TelloPy library
Try to make get the location of drone, displacement, direction.
And make a return home function
 
IMU data is contained in the flight log files. Look at this and this for info on how to access the data.

For the positional data I would recommend using the MVO data as this is much more accurate (this is also contained in the flight logs)
 
  • Like
Reactions: hello12221
Oh MVO sounds better in knowing the movement of drone. However, not quite sure if TelloPy got this you may see it in TelloPy- internal -protocol. What is the trick in getting it? Thanks. If they are get from flight log, does it mean that I can't get them in real time?
 
I don't think this is implemented in any of the python libraries yet.

I've been using pyTello as my base library and I've expanded that to access MVO data based on Krag's C# code (linked in the second thread). Basically, the drone sends regular log messages (these are different to the flight status messages). If you acknowledge the log message, it then sends the full log message from which you can extract MVO and IMU data

I've built this functionality into the existing pyTello Command/Receive framework. I can share the code here if you want, but if you're already working with TelloPy it might be easier to set it up yourself in that library.
 
Sounds cool. The TelloPy also receiving the flight log from time to time like battery state and the height. Like you said before there are also east and north velocity. May be the different between pyTello and TelloPy.

So would appreciate if you share the code a bit so I can learn from it:giggle:
 
The height, battery, North and East speed is from the flight status messages not the flight log. Apart from the battery info, this data is pretty rubbish. You will need to implement flight log parsing and information extraction, as this hasn't been done in TelloPy yet I don't think

I won't share the whole tello.py file as it's very big, but here's the extensions I've added to telloPy

Python:
elif cmdID == self.TELLO_CMD_LOG_HEADER_WRITE:
                    print "log header"
                    p = payload.get_array()
                    iD = (struct.unpack('<H', p[0:2])[0])
                    returnpayload = bytearray([0])
                    returnpayload.extend(struct.pack('<H', iD))
                    self._sendCmd(0x50, self.TELLO_CMD_LOG_HEADER_WRITE, returnpayload)

This part listens for the "log header" from the Tello which indicates that a log file is about to be transmitted, then sends a corresponding acknowledgement command. The Tello should follow this with the log file.

Python:
elif cmdID == self.TELLO_CMD_LOG_DATA_WRITE:
                    p = bytearray(payload.get_array())
                    self._parseLogPacket(p)

This part listens for the log file and then sends the contents of the file to be parsed

Python:
def _parseLogPacket(self, data):
        pos = 1
        while pos < len(data) - 2:
            if bytearray([data[pos]]) != 'U':
                break
            length = data[pos + 1]
            if data[pos + 2] != 0:
                break
            try: ID = struct.unpack("H", data[pos + 4: pos + 6])[0]
            except error: pass
            xorBuf = bytearray(1024)
            try:
                xorVal = bytearray([data[pos + 6]])
            except IndexError:
                pass
            if ID == 0x1d: #MVO Data
                for i in range(length):
                    try:
                        xorBuf[i] = (data[pos + i] ^ xorVal[0])
                    except IndexError:
                        pass
                velX = struct.unpack("H", xorBuf[12:14])[0]
                velY = struct.unpack("H", xorBuf[14:16])[0]
                velZ = struct.unpack("H", xorBuf[16:18])[0]
                posX = struct.unpack("f", xorBuf[18:22])[0]
                posY = struct.unpack("f", xorBuf[22:26])[0]
                posZ = struct.unpack("f", xorBuf[26:30])[0]
                tempPos = [posX, posY, posZ]
                for i in range(3):
                    if tempPos[i] > 30000:
                        tempPos[i] = (65536 - tempPos[i]) * -1
                self.position = [a - b for a,b in zip(tempPos, self.position_offset)]
pos += length

This part parses the log file (it has to be decoded from xor first). The ID at the start of the file tells you which part of the data has updated. This example is for new MVO data. If the IMU data has been updated then the ID will be different. After decoding you can pull out the relevant bits of data
 
Looks pretty cool and handy , many thanks. Look like the lib we are using is the same one:unsure:
 
Also bear in mind I'm not really a programmer by profession, so a lot of my code is quite hacky and very personalised to achieve the specific goals of my project.

I think it will be more useful to read through the threads I linked and also the wiki. They will give you a much better overview of the actual command protocols. If you want to implement these things in your code I would highly recommend using either Krag's C# code or SMerrony's Go code as a basis for your work, as their libraries are far more complete than what I've done
 
The height, battery, North and East speed is from the flight status messages not the flight log. Apart from the battery info, this data is pretty rubbish. You will need to implement flight log parsing and information extraction, as this hasn't been done in TelloPy yet I don't think

I won't share the whole tello.py file as it's very big, but here's the extensions I've added to telloPy

Python:
elif cmdID == self.TELLO_CMD_LOG_HEADER_WRITE:
                    print "log header"
                    p = payload.get_array()
                    iD = (struct.unpack('<H', p[0:2])[0])
                    returnpayload = bytearray([0])
                    returnpayload.extend(struct.pack('<H', iD))
                    self._sendCmd(0x50, self.TELLO_CMD_LOG_HEADER_WRITE, returnpayload)

This part listens for the "log header" from the Tello which indicates that a log file is about to be transmitted, then sends a corresponding acknowledgement command. The Tello should follow this with the log file.

Python:
elif cmdID == self.TELLO_CMD_LOG_DATA_WRITE:
                    p = bytearray(payload.get_array())
                    self._parseLogPacket(p)

This part listens for the log file and then sends the contents of the file to be parsed

Python:
def _parseLogPacket(self, data):
        pos = 1
        while pos < len(data) - 2:
            if bytearray([data[pos]]) != 'U':
                break
            length = data[pos + 1]
            if data[pos + 2] != 0:
                break
            try: ID = struct.unpack("H", data[pos + 4: pos + 6])[0]
            except error: pass
            xorBuf = bytearray(1024)
            try:
                xorVal = bytearray([data[pos + 6]])
            except IndexError:
                pass
            if ID == 0x1d: #MVO Data
                for i in range(length):
                    try:
                        xorBuf[i] = (data[pos + i] ^ xorVal[0])
                    except IndexError:
                        pass
                velX = struct.unpack("H", xorBuf[12:14])[0]
                velY = struct.unpack("H", xorBuf[14:16])[0]
                velZ = struct.unpack("H", xorBuf[16:18])[0]
                posX = struct.unpack("f", xorBuf[18:22])[0]
                posY = struct.unpack("f", xorBuf[22:26])[0]
                posZ = struct.unpack("f", xorBuf[26:30])[0]
                tempPos = [posX, posY, posZ]
                for i in range(3):
                    if tempPos[i] > 30000:
                        tempPos[i] = (65536 - tempPos[i]) * -1
                self.position = [a - b for a,b in zip(tempPos, self.position_offset)]
pos += length

This part parses the log file (it has to be decoded from xor first). The ID at the start of the file tells you which part of the data has updated. This example is for new MVO data. If the IMU data has been updated then the ID will be different. After decoding you can pull out the relevant bits of data
Where should I add this code in the tello.py file?
 

New Posts

Members online

No members online now.

Forum statistics

Threads
5,690
Messages
39,934
Members
17,023
Latest member
Repiv

New Posts