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
colorsound
Posts: 12
Joined: Mon Jan 06, 2014 5:46 pm

Sending Receving Serial Protocol Messages MWP

Post by colorsound »

Hello guys . Congrats for the Multiwii project ¡¡

I,m trying to find out how send receive messages using the MultiWii Serial protocol.

Could you please show me the full string i should send for asking for MSP_ATTITUDE
and for MSP_ACC_CALIBRATION and what response i should get ?

I,m a bit confused on it so any detail example explanation apreciated.

Also what sort of checksum : CRC_8,CRC_10,CRC_12,CRC_16,CRC_16CCITT,CRC_16Modbus,CRC_16Modbus,CRC_16XModem,CRC_24,CRC_32,CRC_32CCITT ?

For now i basicly want to read the angles sensors values like when you press START in the processing MultiWiiConf.pde and raw sensor values.

thanks a lot in advance. :D


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

Re: Sending Receving Serial Protocol Messages MWP

Post by colorsound »

Hello treym

thanks for google link , but before posting in the forum i already spent some days searching trying staff ;D but i could not find out.

Those are the links i see more helpfull :

viewtopic.php?f=8&t=1516
http://www.multiwii.com/wiki/index.php? ... l_Protocol

could you tell me what will be the full command string for this command ?

for instance :
MSP_ATTITUDE
according to this : $M>[data length][code][data][checksum]

thanks

User avatar
treym
Posts: 258
Joined: Sat Jul 21, 2012 12:28 am

Re: Sending Receving Serial Protocol Messages MWP

Post by treym »

the request for MSP_ATTITUE is a zero lenght payload wich is implmented like this :

https://github.com/treymarc/multiwii-ma ... /mwi.c#L48

you can find the full implementation here : http://code.google.com/p/multiwii/sourc ... otocol.cpp

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

Re: Sending Receving Serial Protocol Messages MWP

Post by colorsound »

hi treym

i have been studying your links and I,m still trying to find out, i usually program via graphical environment vvvv.org so i miss some staff from your code.

i have tried sending :

$M<.mm with ascii CR and some other combinations

The only message that i got a response is by sending :

$M< with ascii CR which response : $M!$$

i also did some serial analysis from processing to arduino to see if i could pick some full messages and debug from there.

i see that it sends a list like : $M<.dd$M<.tt$M<.oo$M<.pp$M<.ss$M<.qq$M<.rr$M<.ee$M<.ff$M<.gg$M<.hh$M<.ii$M<.þþ

but when i send from my side nothing happend. also i dont see if there is any checksum in it.

is it posible to send a command from the arduino monitor ? what will be a full string message to it , ? this will help me.

cheers

User avatar
treym
Posts: 258
Joined: Sat Jul 21, 2012 12:28 am

Re: Sending Receving Serial Protocol Messages MWP

Post by treym »

i did not look at the arduino serial code lately, but as far as i remember it is just string based (with all the charset issue when using toByte)

anyway ... here are the hex value that you want to send

cmd: 24 4d 3c 00 6c 6c
cmd: 24 4d 3c 00 65 65
cmd: 24 4d 3c 00 68 68
cmd: 24 4d 3c 00 66 66
cmd: 24 4d 3c 00 fe fe
cmd: 24 4d 3c 00 69 69

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

Re: Sending Receving Serial Protocol Messages MWP

Post by colorsound »

Hi it worked ;D , somehow i was missing some characters in the conversion to ascii

right now i send cmd:

24 4d 3c 00 6c 6c 0d $M<.ll.

and i receive :

24 4d 3e 06 6c ff ff 03 00 70 00 19 $M>.lÿÿ..p..

now i need to convert to values i presume the values are $M>.lÿÿ..p.. wihtout $M> so
.lÿÿ..p.. 06 6c ff ff 03 00 70 00 19 ? or there are other characters there that do not represent the value.
not sure what is the right conversion i need to do now ?

User avatar
treym
Posts: 258
Joined: Sat Jul 21, 2012 12:28 am

Re: Sending Receving Serial Protocol Messages MWP

Post by treym »

$M> [paylaodlenght] [cmd] [payload] [checksum]

24 4d 3e 06 6c ff ff 03 00 70 00 19

$M> [6] [6c] [ff ff 03 00 70 00] [19]

so values are [ff ff 03 00 70 00]

you can now decode those value (ie ,are they int8 , int16, int32) using the protocole as described here : http://www.multiwii.com/wiki/index.php? ... l_Protocol or with the previous links.
Last edited by treym on Wed Jan 08, 2014 6:17 pm, edited 1 time in total.

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

Re: Sending Receving Serial Protocol Messages MWP

Post by colorsound »

hi treym thank you for your help

so that means that values of [FF FF 05 00 61 00] will be :
FFFF --> -1
0500 --> 5
6100 --> 97

right ?

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

Re: Sending Receving Serial Protocol Messages MWP

Post by colorsound »

Hello there :D

getting somewhere ;D ,I found now how to parse and decode values at least for testing, I,m using a freeimu 4.3 i get diferent range than specified here just as curiosity : http://www.multiwii.com/wiki/index.php? ... l_Protocol
so instead of (-180,180),(-90,90),(-180,180) i get (-1800,1800),(-900,900),(-180,180) apart from that values seem fine. Altimeter also fine.

--- I still dont know how to get the checksum value.

$M> [paylaodlenght] [cmd] [payload] [checksum]

24 4d 3e 06 6c ff ff 03 00 70 00 19
$M> [6] [6c] [ff ff 03 00 70 00] [19]

$M> [6] [6c] [ff ff 03 00 70 00]= [19] ?
[6] [6c] [ff ff 03 00 70 00] = [19] ?
[ff ff 03 00 70 00]= [19] ?

is the [19] achieve by checking this $M> [6] [6c] [ff ff 03 00 70 00] or only this [ff ff 03 00 70 00]
and what is the algorithm used ej: md5,sha1,CRC_8,CRC_10,CRC_12,CRC_16,CRC_16CCITT,CRC_16Modbus,CRC_16Modbus,CRC_16XModem,CRC_24,C custom one combination of them ?

---also could you give me some example string of a request command with parameters i only have the imu to try for now.

---is there a command to reset imu to relative value to its positions so all values start from 0 from this moment on 0 angles 0 alttitude etc .. i checked MSP_SET_HEAD but either i did not send right or it did not react.

cheers thanks a lot.

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