Sending Receving Serial Protocol Messages MWP

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
eagleye
Posts: 1
Joined: Tue Feb 04, 2014 4:09 am

Re: Sending Receving Serial Protocol Messages MWP

Post by eagleye »

Hey colorsound,

I have a couple of questions for you as well as the general audience.

1. How did you decode the payload of the MSP_ATTITUDE command? It's not a direct hex -> decimal conversion. Something about 2's compliment and dividing by 256?

" FFFF = -1 "
" 0500 = 5 "
" 6100 = 97 "

2. When I do a MSP_ATTITUDE command, my return message is of payload size 8, but it seems like it should only be size 6 like yours. Any ideas?

I send: 24 4d 3c 00 6c 6c
and receive: [24 4d 3e] [08] [6c] [09 00 f5 ff b1 00 00 00] [d6]

Lastly, the checksum is defined by the length field, message type, and payload. So in your case it would be the XOR of [6] [6c] [ff ff 03 00 70 00]. However, I'm shaky on the actual steps to perform that byte to byte XOR, but here is a nice PDF on that information: http://armazila.com/sites/default/files/content/download/MultiwiiSerialProtocol(draft)v04.pdf

Thanks!

colorsound
Posts: 12
Joined: Mon Jan 06, 2014 5:46 pm

Re: Sending Receving Serial Protocol Messages MWP

Post by colorsound »

Hi eagleeye
I do not have it connected right now but it was like that :
from the receive message i get rid of : $M>l and also from last checksum character then i get :
"FFFF05006100"
" FFFF = 17990 "
" 0500 = 12598 "
" 6100 = 13616 "
the other conversion was wrong , i get diferent ranges of advertised ones but they work properly. In the Multiwwii they should be from -180,180 i get them -1800,1800.

User avatar
stronnag
Posts: 114
Joined: Thu Oct 24, 2013 9:32 pm
Location: New Forest, England
Contact:

Re: Sending Receving Serial Protocol Messages MWP

Post by stronnag »

That's a documentation error. The values in the message are *10 the actual values for angx,angy.

BKLronin
Posts: 19
Joined: Sat Feb 01, 2014 2:10 pm
Location: Jena, Germany

Re: Sending Receving Serial Protocol Messages MWP

Post by BKLronin »

Hello,

I'm trying to read out the altitude via MSP. I'm using this python script as a starting point:

Code: Select all

import serial,time, struct
ser=serial.Serial()
ser.port="/dev/ttyUSB0"
BASIC="\x24\x4d\x3c\x00"
MSP_IDT=BASIC+"\x64\x64"
MSP_STATUS=BASIC+"\x63\x63"
MSP_RAW_IMU=BASIC+"\x66\x66"
MSP_SERVO=BASIC+"\x67\x67"
MSP_MOTOR=BASIC+"\x68\x68"
MSP_RC=BASIC+"\x69\x69"
MSP_RAW_GPS=BASIC+"\x70\x70"
MSP_COMP_GPS=BASIC+"\x71\x71"
MSP_ATTITUDE=BASIC+"\x72\x72"
MSP_ALTITUDE=BASIC+"\x73\x73"
MSP_BAT=BASIC+"\x76\x76"

CURRENT=MSP_ALTITUDE
ser.baudrate=115200
ser.bytesize=serial.EIGHTBITS
ser.parity=serial.PARITY_NONE
serial.stopbits=serial.STOPBITS_ONE
ser.timeout=0
ser.xonxoff=False
ser.rtscts=False
ser.dsrdtr=False
ser.writeTimeout=2
try:
    ser.open()
except Exception,e:
    print("Error open serial port: "+str(e))
    exit()

if ser.isOpen():
    time.sleep(15)
    print("Serial port is open at"+ser.portstr)
    try:
        ser.flushInput()
        ser.flushOutput()
        ser.write("\x24\x4d\x3c\x00\x73\x73")
        print("Writing to "+ser.portstr+CURRENT)
        time.sleep(0.5)
        numOfLines=0
        while True:
            response=ser.readline()
            #print(type(response))
           
            print(response.encode("hex"))
            numOfLines=numOfLines+1
            print(response)
           
           
            if(numOfLines>=1):
                break
        ser.close()
    except Exception,e1:
        print("Error communicating..."+str(e1))
else:
    print("Cannot open serial port")


I'm a total noob to python but managed to write an IK program for my biped. I searched and experimented for 2 days now and didn't came any further.

When I send "\x24\x4d\x3c\x00\x73\x73" I'm receiving 24 4d 3e 0873030506020708090a but I have no idea how to read useful data out of it, as I can't decode it.

My plan is to read out if a waypoint is reached and then let the Rasperry pi trigger the camera. Help would be appreciated as this is for science project and I'm currently stuck with the MSP.

:(

EDIT: When I send the ATTITUDE Command I'receive

Code: Select all

00000000: 24 4d 3e 16 72 00 00 7e   04 3a 07 b6 03 00 00 00 
00000010: 00 00 00 00 00 1a 00 6c   98 94 8c 60


With Serial Monitor Cutecom

User avatar
stronnag
Posts: 114
Joined: Thu Oct 24, 2013 9:32 pm
Location: New Forest, England
Contact:

Re: Sending Receving Serial Protocol Messages MWP

Post by stronnag »

The response posted belongs to the MSP_MISC command (0x72, 114 decimal), the length is consistent (0x16, 22 decimal), with the returned data structure (22 bytes) as documented on the wiki. If you map the returned bytes into the documented fields, you get the data values, in this case:

intPowerTrigger1 = 0 (0 + (0 << 8))
conf.minthrottle = 1150 (0x7e + (0x4 << 8))
MAXTHROTTLE = 1850 (0x3a + (0x7 << 8))
MINCOMMAND = 950
...
etc.

It's a trivial case of understanding how binary data is transmitted and constructed and following the MSP documentation. If is also necessary to pay attention to the message type returned in the payload, then you don't confuse MSP_MISC as being MSP_ATTITUDE.

BKLronin
Posts: 19
Joined: Sat Feb 01, 2014 2:10 pm
Location: Jena, Germany

Re: Sending Receving Serial Protocol Messages MWP

Post by BKLronin »

I tried another code that works with struct from this forums. It seems that I get the right information back now.
When I send command 118 for MSP WP I'm receiving with no sat fix or enabled functions. (Not possible next to the PC)

[244d3e] [15][76][00]000000000000000000000000000000000000000162
--------------------------^wp_no? -> unsigend integer 8 with two positions in message?

I'm working with two documents to understand the communication. That is you link and the first posts of "new multiwii serial protocol". I think I know where the searched Information is in the message, If the above assumption is correct but the calculation like you performed up there, is still a mystery. I never came across hexadecimals in my 1,5 months of python programming.

As soon as you know how to do something, it always appears trivial ;)

EDIT: If I activate pos_HOLD the string should read
[244d3e] [15][76][0f]000000000000000000000000000000000000000162
--------------------------^ for wp 15
Is that correct?

BKLronin
Posts: 19
Joined: Sat Feb 01, 2014 2:10 pm
Location: Jena, Germany

Re: Sending Receving Serial Protocol Messages MWP

Post by BKLronin »

I still don't get it, sorry.

I'm receiving 244d3e157600007ad5521eceb8ed0600000000000000000000011c

Can anyone point me to the basics of binary data communication or decode it with example like stronnag tried?

BKLronin
Posts: 19
Joined: Sat Feb 01, 2014 2:10 pm
Location: Jena, Germany

Re: Sending Receving Serial Protocol Messages MWP

Post by BKLronin »

Okay I got it.

The Hexconverter I used gave me strange values for FFFF now above example with conversion to decimal ->65535 (almost max value) and mapping it to the Value range of 0 -1800 makes total sense.

However I still find it difficult to get a wp or flag out of it. Not even the WinGUI seems to ask for those values (serial monitor), even if there are labeled fields under mission for it. The Documentation states that it is at least availabe for Home and Hold postion but im not sure why I m getting 00 at that postion right now. Should be 0f when Hold is active I thought.

BKLronin
Posts: 19
Joined: Sat Feb 01, 2014 2:10 pm
Location: Jena, Germany

Re: Sending Receving Serial Protocol Messages MWP

Post by BKLronin »

Understood MSP_WP right now. It is meant to find locations of Waypoints and is not carrying things like which WP is currently set as target. SO I found MSP_NAV_STATUS , that seems to reply with the desired Information. Could'nt test right now but will investigate further.

Feels like beeing Sherlock :D

Post Reply