Using XBee (or eg. APC 220) for control

Post Reply
Delpee
Posts: 9
Joined: Fri Oct 12, 2012 1:52 pm

Using XBee (or eg. APC 220) for control

Post by Delpee »

Hello MultiWii-forum,

This is my first post (of hopefully many to come). I do not have a lot of experience in the field of remote controlled operation of vehicles. I have only once controlled a remotely operated airplane and only a few times have I controlled a RC car. Also I have only once build a remotely operated vehicle (submarine, build for a school project, check it HERE if you're interested!), please be easy on me ;). That said, I have build up some experience in the electronics area and I'm currently studying Computer Science in the Netherlands, so programming is probably no problem. I'm also really interested! I also have experience with Arduino.

Now, to the problem at hand: I would like to build a MultiWii quadrocopter (at least try, I know it's not easy). I bought a WM+ (had the nunchuck laying around already) and set up the config file and uploaded the software to the Arduino (Uno, I also have a Duemilanove). I got telemetry over serial with the MultiWii_Conf software. I do not own a RF receiver, nor a transmitter. For multifunctionality purpose I would like to use a XBee (or even better, an APC220) for communicating with the quad. This means I do not just want to receive the orientation (etc.) data, but also send control information to the quad in order to control it via my PC (or maybe 'gamepad' --> PC --> quad).

My question is: is this possible? Can I use a XBee or APC220 to control the quad, is there software available on the PC side, and does MultiWii have an option to use such a device?

Thanks in advance!
Delpee

capt
Posts: 54
Joined: Wed Jan 19, 2011 10:54 pm

Re: Using XBee (or eg. APC 220) for control

Post by capt »

No, you will need a controller. TX/RX.

Delpee
Posts: 9
Joined: Fri Oct 12, 2012 1:52 pm

Re: Using XBee (or eg. APC 220) for control

Post by Delpee »

It is not in any way possible to rewrite some MultiWii Arduino code that takes data over the RX TX port of the arduino, but send by a PC in some way?

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: Using XBee (or eg. APC 220) for control

Post by crashlander »

MultiWii suports sending commands over serial (BT, cable, whatever) from at least version 2.0.
I personally bench tested BT (serial) with Android and MultiWii EZ-GUI.
So serial communication with XBee or APC220 should work but you have to write PC app to send proper commands.

Regards
Andrej

BTW: look for

Code: Select all

//#define RCSERIAL

in code

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: Using XBee (or eg. APC 220) for control

Post by Hamburger »

crashlander's reply is to the point.
One thing to add:
some time ago an android app was mentioned to exist which included sending of the steering commands. It was not open source GPL though.

PatrikE
Posts: 1976
Joined: Tue Apr 12, 2011 6:35 pm
Location: Sweden
Contact:

Re: Using XBee (or eg. APC 220) for control

Post by PatrikE »

I have played a little with Joystick in Processing using.
The proCONTROLL library

It works fine.....
Bot it's not Obslolete!
It shares some parameternames with controlP5 library.

Iw'e tried to recompile the procontroll library with eclips but cant get it to work.

It's possible to connect a joystick to MWii Gui if the conflicts can be solved.

Delpee
Posts: 9
Joined: Fri Oct 12, 2012 1:52 pm

Re: Using XBee (or eg. APC 220) for control

Post by Delpee »

Thanks for the replies! Got scared it wasn't possible after capt's reply there ;). Even though I was pretty sure it wouldn't be a problem :P. I think it wouldn't be too difficult for me to write the software in C# or C++. How would I found out what the commands are that have to be send? Is there a place with this information?
Maybe I have to go through the code again :P.

Delpee

KeesvR
Posts: 194
Joined: Fri May 27, 2011 6:51 pm
Location: The Netherlands

Re: Using XBee (or eg. APC 220) for control

Post by KeesvR »

There is somebody who's flying with a modified joystick.
viewtopic.php?f=9&t=510

Double
Posts: 3
Joined: Sat Oct 20, 2012 2:29 pm

Re: Using XBee (or eg. APC 220) for control

Post by Double »

This most definitely works, i fly using a laptop and a PS3 controler.

I wrote a java application that translates the PS3 input to serial commands and i transmit using a 3DRadio (xbee compatible).

It sends a command 20 times per second and works perfectly. I did buy a regular controler tough, because the PS3 sticks are to small and you have to carry a laptop with you.

I added a link to the code below, but it also uses a lot of libraries and you will need to edit some stuff to work with your controler:
http://pastie.org/5088848

copterrichie
Posts: 2261
Joined: Sat Feb 19, 2011 8:30 pm

Re: Using XBee (or eg. APC 220) for control

Post by copterrichie »

Double wrote:This most definitely works, i fly using a laptop and a PS3 controler.

I wrote a java application that translates the PS3 input to serial commands and i transmit using a 3DRadio (xbee compatible).

It sends a command 20 times per second and works perfectly. I did buy a regular controler tough, because the PS3 sticks are to small and you have to carry a laptop with you.

I added a link to the code below, but it also uses a lot of libraries and you will need to edit some stuff to work with your controler:
http://pastie.org/5088848


Double, thank you for sharing your code. I am receiving the following error code when trying to run it with Processing:

I have the proCONTROLL library installed.

Code: Select all

ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();


The function getDefaultEnvironment() does not exist, any suggestions?

Double
Posts: 3
Joined: Sat Oct 20, 2012 2:29 pm

Re: Using XBee (or eg. APC 220) for control

Post by Double »

It's java. And you'll need the RXTX and Jinput libraries.

copterrichie
Posts: 2261
Joined: Sat Feb 19, 2011 8:30 pm

Re: Using XBee (or eg. APC 220) for control

Post by copterrichie »

Double wrote:It's java. And you'll need the RXTX and Jinput libraries.


Awe and thank you.

Delpee
Posts: 9
Joined: Fri Oct 12, 2012 1:52 pm

Re: Using XBee (or eg. APC 220) for control

Post by Delpee »

I have some upcomming exams, after that I'm going to get started writing some C#/C++ code to get some simple communication going.
I'll probably need some help with that though, since I'm not completely sure how the serial-com protocol works (it's not too difficult, just need to put some reading time into it :P).

Thanks for all responses!
Delpee

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: Using XBee (or eg. APC 220) for control

Post by crashlander »

Any pointers where to find some docs, examples... how to "cook" the data/signal for sending to MWII.
I already have APC220 and old analog TX and I'm considering to transform it into LR system...
Regards Andrej

Double
Posts: 3
Joined: Sat Oct 20, 2012 2:29 pm

Re: Using XBee (or eg. APC 220) for control

Post by Double »

The easiest way to see how to format the serial data is by looking at serial.pde in the source. (or for a java implementation, look at the code I posted).
I just switched to a regular tx because i got tired of taking the laptop with me. and both approaches have their pros and cons. The regular TX is more practical, but using a game controler means everything is full digital, so your end points and trim are perfect all the time (big plus for me). telemetry is build in, and you got as much channels as you can find uses for.

BTW, i'm working on an android app using USB-host to connect to my 3DRadio. But it might take a while to be ready for prime time.

copterrichie
Posts: 2261
Joined: Sat Feb 19, 2011 8:30 pm

Re: Using XBee (or eg. APC 220) for control

Post by copterrichie »

Double wrote:The easiest way to see how to format the serial data is by looking at serial.pde in the source. (or for a java implementation, look at the code I posted).
I just switched to a regular tx because i got tired of taking the laptop with me. and both approaches have their pros and cons. The regular TX is more practical, but using a game controler means everything is full digital, so your end points and trim are perfect all the time (big plus for me). telemetry is build in, and you got as much channels as you can find uses for.

BTW, i'm working on an android app using USB-host to connect to my 3DRadio. But it might take a while to be ready for prime time.


Double, have you see this project? viewtopic.php?f=13&t=1801

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: Using XBee (or eg. APC 220) for control

Post by crashlander »

Hello,
in my attempt to create Arduino RCSERIAL sender for controling multy I came to the point that my limited programming skils are unable to pass :)
Basically I created function in which I feed 8 channels (8 uints with range 1000 to 2000), function than cooks data and write it to serial port (cable, APC220, XBee...).
The values are coming from serial port of TX and into serial port of AIO (I checked with MultiSerialMega sketch from Ardu. examples), but I can not see any response in GUI (connected to different serial port).
I based my function on Java implementation from GUI and the one posted earlier in thread but my java knowledge is even worse than C and there are some differences in data types between java and Arduino.
Please take a look into my code and help.

Code: Select all

void msp_babel(uint16_t rx_chs[8]){ 
  char msp_rx_string[18];
  char tabela[16];
  char checksum=0;
 
    uint8_t msb_pl=0;
    uint8_t lsb_pl=1;
   
    for(int i=0;i<8;i++){
      tabela[msb_pl]=rx_chs[i] & 0xff;
      msb_pl=msb_pl+2;
     
      tabela[lsb_pl]=rx_chs[i] >> 8;
      lsb_pl=lsb_pl+2;
    }
   
    msp_rx_string[0]=sizeof(tabela) & 0xff;
    checksum ^= (sizeof(tabela) & 0xFF);
   
    msp_rx_string[1]=MSP_SET_RAW_RC & 0xff;
    checksum ^= (MSP_SET_RAW_RC & 0xFF);
   
    for(int j=0;j<16;j++){
      msp_rx_string[2+j]=tabela[j] & 0xff;
      checksum ^= (tabela[j] & 0xff);
    }
   
    msp_rx_string[18]= checksum;
   
    for(int u=0;u<19;u++){
     Serial.write(msp_rx_string[u]);
    }
}


Regards Andrej

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: Using XBee (or eg. APC 220) for control

Post by crashlander »

Crackit :)
The code misses inti string before last for.....

Code: Select all

 Serial.print("$M<");


Now I'm back in game.....

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: Using XBee (or eg. APC 220) for control

Post by crashlander »

Double wrote:This most definitely works, ...
... i transmit using a 3DRadio (xbee compatible).

Hello, you are saying that you update (send) data with 20Hz (why not 50Hz)?
What bit-rate are you using?
What version of 3DRadio are you using 433MHz, 900MHz...?
Have you measured/tested safe operating distance?

Regards Andrej

Delpee
Posts: 9
Joined: Fri Oct 12, 2012 1:52 pm

Re: Using XBee (or eg. APC 220) for control

Post by Delpee »

Ordered the apc220 from dfrobots.com, looking forward to trying it out! I'll update when I got it :). Delpee

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: Using XBee (or eg. APC 220) for control

Post by crashlander »

Today I have air tested my mod of old Futaba F-14 equipped with APC220.
I'm using ordinary ProMini with 4 analog inputs for sticks and 2 digital inputs for AUX switches, I have also added status/notification led and buzzer. APC is set to 9600 baud wire connection and 19600 air.
I have cheated and just took Turnigy Plush 10A ESC for powering Arduino from 3S LiPoly (at least for start).
Currently I'm only sending TX data (MSP encoded) to multi but in the future I have plan to also read back status and maybe some telemetry data.

If anyone is interested the code (mock-up) is on Google SVN: https://code.google.com/p/mwii-msp-tx/

Happy Flying
Andrej

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: Using XBee (or eg. APC 220) for control

Post by Hamburger »

Can you feel a delay in response (compared to another tx/rx)?

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: Using XBee (or eg. APC 220) for control

Post by crashlander »

Today I was only "park flying" no aggressive moves (also with tame setup) and with that flying style I have not noticed any difference.
Currently I'm using 20Hz refresh/send rate, with 50Hz I was noticing quite observable lag of response in GUI (not the GUI itself)!?

Regards
Andrej

copterrichie
Posts: 2261
Joined: Sat Feb 19, 2011 8:30 pm

Re: Using XBee (or eg. APC 220) for control

Post by copterrichie »

Awesome Andrej, just outright awesome!

Delpee
Posts: 9
Joined: Fri Oct 12, 2012 1:52 pm

Re: Using XBee (or eg. APC 220) for control

Post by Delpee »

Sounds good Andrej!
Wanted to check out your code ons googleCode, but it didn't show me anything. Could you check that? I would love to see your code (especially the commands your sending)!

Received my APC220 the other day, will start on some programming myself next weekend (have some exams this week :/).
I'll keep you all posted on the progress :D.

Delpee

Edit: Nvr mind, found it, was looking in the wrong place! Checking it out a.w.s.!

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: Using XBee (or eg. APC 220) for control

Post by crashlander »

@Delpee:
As you can see my code changes quite often and quite often is untested (rain outside and so many ideas inside) :)
The only stable part that has not changed from the beginning is MSP_BABEL.ino (and there is all there is to it). It is not so clean as original Java since I omitted referencing by pointers (my Cfu is not too good).
The missing/not working idea is still to be able to read back some data from MWII and with that check state of connection (range).

Regards Andrej

Delpee
Posts: 9
Joined: Fri Oct 12, 2012 1:52 pm

Re: Using XBee (or eg. APC 220) for control

Post by Delpee »

Yeah, I've seen the code, and it looks very compact, that's great!
I do have some questions though. It's probably because I don't Java, but I can't really figure out how the message is build up. Say I have some integer data about Yaw, Pitch, Roll and all the other things I might send, how would I package it, and how is the checksum generated? It's not so hard to see you generate checksum out of the size and the actual data, but what does the ^= operator return in different cases (the internet says it is an assignment of a bitwise exclusie OR, but how would that return anything usefull for checksumming)? Is the checksum just parity?

I hope you can enlighten me! :D

Regards,
Yuri

Edit: Forgot to mention that I received the APC's and have started working on an application that should make this all work. The connection was really easilly set-up! Just for funzies, a quick screenshot:
Image

It's still very empty, but I have a wireless serial connection running and can exchange data. :)

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: Using XBee (or eg. APC 220) for control

Post by crashlander »

Delpee wrote: ^= operator return in different cases (the internet says it is an assignment of a bitwise exclusie OR, but how would that return anything usefull for checksumming)? Is the checksum just parity?

I hope you can enlighten me! :D


Sorry I have only copyed that from Java (GUI), or C (MWI Serial.ino) and have not really considered its meaning (or at least now I can not remembered otherwise) :)

Basically you have integers from 1000 up-to 2000 and than you pack them in 8bit integers (for one number you create two 8 bit by bit shifting and arranging magic).
Every message starts with $M< than you add size of useful data (payload), message type (RAW_RC data in our case),payload 8*2 (since you pack those bits) and append checksum.

Regards Andrej

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: Using XBee (or eg. APC 220) for control

Post by crashlander »

Hello,
today I implemented function to read/receive confirmation that is send from MWII back to TX. But the confirmation only works when TX and MWII (RX) are connected with physical cable. It seems that APC220 introduces some kind of delay big enough to bypass/skips my receiving function which checks if serial data is available.

Code: Select all

if (Serial.available()) {
    while (Serial.available()) {
      inByte[i] = Serial.read();
      if (i<6){ //read only 6 ints
        i++;
      }
      else{
        i=6;
      }
    }
  }

Are there any other options to read back that short string without introducing big delay in main process (sending RC data to MWII)?

Regards Andrej

copterrichie
Posts: 2261
Joined: Sat Feb 19, 2011 8:30 pm

Re: Using XBee (or eg. APC 220) for control

Post by copterrichie »

I think you may want to take a look at the latency issue with Bluetooth, not sure if it is the same with Xbee

http://www.free2move.se/?page_id=1058

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: Using XBee (or eg. APC 220) for control

Post by crashlander »

@copterrichie: Thank you for idea, it is probably correct.

In my current (after r18) version I'm experimenting with adaptive TX sending frequency. It means that when sticks are only slightly moved I'm sending (and quite successfully receiving) data with only 10Hz for slow FPV style flying but when sticks are moved out of deadband area TX switches into max send rate (currently 20Hz) for couple of seconds and telemetry receiving is also stopped for that duration.
I must also experiment some with higher air data rate (currently 9600) and now I also have option to test actual range with different data rates.

Regards
Andrej

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: Using XBee (or eg. APC 220) for control

Post by crashlander »

Today weather is fine so I was able to get out in the field and did some more tests with r19 of my TX code.
I have observed that for easy flying it suffice to have 10Hz refresh rate (no observable issues) even with FFF and long turns but for more aggressive (3D) setup/type of flying even 20Hz is not enough (normal TX works with 50Hz+) or at least it would take some time to adjust my reflexes to it.

Regards
Andrej

copterrichie
Posts: 2261
Joined: Sat Feb 19, 2011 8:30 pm

Re: Using XBee (or eg. APC 220) for control

Post by copterrichie »

Thanks for the information Andrej. So it is safe to assume, serial control would most likely work great for FPV flights?

copterrichie
Posts: 2261
Joined: Sat Feb 19, 2011 8:30 pm

Re: Using XBee (or eg. APC 220) for control

Post by copterrichie »

Andrej, I am very slow at getting things done (lack of financial resources) however, one thing that is on my agenda to do is to use WiFi in the same way you are using the XBee with the exception, I wanted to use the Spektrum protocol. The advantage is, the MWC already fully support the protocol on the serial port.

viewtopic.php?f=13&t=1801&start=40#p25250

copterrichie
Posts: 2261
Joined: Sat Feb 19, 2011 8:30 pm

Re: Using XBee (or eg. APC 220) for control

Post by copterrichie »

Here is an interesting read on the topic: http://diydrones.com/profiles/blogs/spektrum-dx6i

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: Using XBee (or eg. APC 220) for control

Post by crashlander »

I decided to use MSP because it enables me to get telemetry data back at the same time. Right now I'm just checking MWII's ACK to raw RC signal and using that for range test (I'm lighting a LED when signal is good). But in my pipeline there is also code to read ALT/VARIO data (+ LCD display to show those data).
My code switches automatically between 10 and 20Hz and even with 10Hz there is no observable difference for slow (FPV type) flying of multy but my next step is to test it on Flying wing.
Also I decided for APC220 (apart from already being in my drawer and otherwise being quite cheap 32$ pair) for its long-range potential and maybe not just LOS flying type (it goes/bounces thru the walls, and works out of elevators)! :)

Regards Andrej

Post Reply