Friday, May 6, 2011

Arduino helicopter infrared controller

Hello!

Some time ago I got the S107 helicopter as a birthday present, and as I found myself with some free time, I got an Arduino board with the intent of flying it with my computer.


Helicopter being tracked with webcam and speed adjusted
My experience has always been on the software side, so this is my first try  utilizing hardware and micro controllers.

While waiting for the Uno, I started reading the basics and found this amazing tutorial on how Infrared works, and code samples on reading and emitting infrared signals.

The code in that tutorial was extremely helpful in getting me started, and understanding the basics of Infrared communications.



Arduino Uno and IR emitter and receiver circuit
Delivery day and I get my arduino, (for some reason I ordered two usb cables instead of two IR leds, guess I didn't double check the order)

Following the arduino.cc first steps, I installed the software, and then tested out the board with the begginer examples it provides.
Later on, I built the ladyala emitter and receiver circuit, and its ready for work!

The schematics are identical to the ones here, but on an Uno board instead of the duemilanove version, but it shouldn't be a problem.

Before getting into the helicopter remote, I tried it with  my audio remote control, which has only 3 buttons and seems simpler.
After decoding the pulse, I played around to make a program that graphics the pulses.

As the Arduino runs in the board, the communication is done through the serial port.
To communicate with it while it’s running, it’s done through the same serial port used to upload data to it.

Utilizing Processing language (www.processing.org) the program to graphic the pulse is quite simple.

Here’s a picture of the three button’s pulses (on, vol up, vol down), done with the Processing language.









On to the helicopter!
This is a little bit trickier, because once you’re flying the helicopter it’s a continuos stream of data from the remote to the helicopter, instead of a single burst of data.
We’ll need to figure out how it transmits the data to the helicopter, that is, which protocol it uses.

Reading a bit more into IR protocols, I found a thread that depicted usual protocol pulses here.

There is a Header followed by “bits”. Each bit is a pair of on/off IR pulse. The 0 is a short on, short off, and the 1 is a short on, longer off.

With the decoding program loaded into the board, the output for the helicopter is the following:

(off / on)
-10072 – 1930
1880 - 330
250 - 370
230 - 350
590 - 320
640 - 330
640 - 370
210 – 370
….

So, the header is a 2000 ms on, 2000ms off, the 0 a 300/300 pair and the 1 a 300/600 pair pulse.

The separation between headers is between 32 pairs, so I assume the helicopter uses a 32bit pulse.
Modifying the receiver program to adapt to this format, and make it easier to figure out the protocol, the output now shows H for header, 0 and 1, in a 32 bit string:

HH00111011001111111111111100101111   

The next step is the most tedious:
Detecting the changes when only one movement is done, to figure out which bits do what.
I recorded hundreds of combinations, and did a little program to eliminate the repeated ones.

The outcome:

Byte 1: Yaw
Byte 2: Pitch
Byte 3: Throttle
Byte 4: Yaw correction from Remote.

They all use the last 7 bits of the byte.
Throttle goes from 0 to 126, while pitch and yaw start centered in 63.

With all this info, it’s time to create a processing program to test this, a program to transmit pulses with the decoded format.
Then some buttons to handle the increases and decreases, and off it goes!

The emitter program in the arduino to keep sending the same pulse, and the processing program to just notify the changes in the bits, instead of always telling the board what pulse to send, for timing purposes
(It uses a simple way of just sending one ascii character, and both programs know which bit it’s referring to)

It works! But the IR Led seems to be quite underpowered compared to the one in the remote control, so the range is about one meter, then the helicopter drops dead.

One final test is to have the computer do some flying on its own.
As a proof of concept, with the jMyron library for Processing to handle video input, I want to make the program have the helicopter hover at a steady position.

Utilizing the input from the webcam, it adjusts the speed until the helicopter is in the middle of the screen.
If it goes too high, it lowers the speed. If it gets too low or is stopped, it slowly increases the upwards speed.
It works!

Any ideas on what to move on to next?




Arduino Source Code:



26 comments:

  1. I love it! i just ordered my arduino Uno, i never played with hardware...
    ill try something like that!

    Very good Post!

    ReplyDelete
  2. "Any ideas on what to move on to next?"

    Make it dance to the beat of whatever music track you have playing. :)

    ReplyDelete
  3. This is great. Thanks for posting. I was just about to start trying to decode this myself. My idea is to add a lightweight Arduino compatible board to the s107 and make it fly autonomously. I will probably remove the IR detector and hard wire my chip to it.

    ReplyDelete
  4. Hi, thanks for sharing the code ! I adapted it to fly a cheap 3ch heli with a Wii nunchuk. You can find the complete step-by-step guide here : http://www.instructables.com/id/Nunchuk-controlled-Helicopter/

    Thanks again !
    John

    ReplyDelete
  5. Nice! I was hoping someone would do something like this, was curious what sort of IR protocol it was using.

    ReplyDelete
  6. Hi, you say that the hearder is a 2000 ms pulse?? but 2000 ms is 2 seconds, did you mean 2ms?? thanks

    ReplyDelete
  7. Yes I do have an idea for what to do next. There is already excellent software @ http://www.ez-robot.com/EZ-Builder/. It should easily be adaptable to maintaining a hover with feature recognition.

    ReplyDelete
  8. Hey man, totally awesome. Your library worked perfectly. My (non-technical) friends and I just bought five of these and it's going to blow their minds when I show them how to control it with their comps/arduino!

    ReplyDelete
  9. Hey, thanks for the excellent write-up! I'm curious, how did you figure out the type of resistor you had to use? My background is mostly in software and I barely remember any of the electrical networks stuff I learned in college! The LED that I'm going to be using is the TSAL6400: http://www.vishay.com/docs/81011/tsal6400.pdf

    Thanks!

    ReplyDelete
  10. Hi, just used your's and Aqualungs tutorial to get it at least flying. I've got the perfect idea for what to do next.
    Hook it up to a Kinect. As Kinect can detect humans and also has depth vision, maybe you can get it to follow someone around the room. You can even control it with hand signals. It will also allow you to acurately set a predefined course an get it to follow it.
    Any way thanks for the great tutorial.

    ReplyDelete
  11. Man how can you control the helicopter with just the processing program with the camera. I just want to control the helicopter from the computer for now. Also what do I edit in the arduino code for my particular helicopter. I already got my bit info from my controller.

    ReplyDelete
  12. Thanks for the great write up! I'm learning a bit about the whole electrical engineering/arduino aspect. I'm with Paul K on this one, what would be the best way to try and control this via command line? Can values be piped to the device? It appears that JMyron library has been broken recently, unsure if it's due to a processing upgrade or not. http://sourceforge.net/tracker/?atid=555932&group_id=79235&func=browse I've been getting the unsatisfied link errors as well with a Fedora 18 x64 system. Thanks again!

    ReplyDelete
  13. Hi, Im currently using your code to help me with my final year project. I have the code working, well to an extent. The yaw works fine, however the throttle is unresponsive. Any ideas?
    Thanks!

    ReplyDelete
    Replies
    1. I have the same problem, did you get an answer for it?

      Delete
  14. The circuit at http://2.bp.blogspot.com/-1QIf47Kvy9o/TcOlnEqaeOI/AAAAAAAABus/h_wP4k4aah0/s1600/P1030063.JPG
    is very obscure/unclear. It's better you take some other pictures.
    Please ..

    ReplyDelete
  15. Thanks for sharing.

    We hope to show a demo of decoding the RC IR helicopter at the upcoming Maker faire in Dublin, Ireland on July 27th.

    We plan to add support for this IR protocol to the existing 17 IR protocols already supported by AnalysIR.

    For anyone interested in IR protocols - we have just launched a project on IndieGoGo for AnalysIR - IR Decoder & Analyzer GUI (Arduino & Raspberry Pi). Currently we support 17 IR protocols and are looking for more to add as part of the AnalysIR project. Suggestions Welcome!

    Find out more about our project on http://bit.ly/1b7oZXH or Screenshot via www.AnalysIR.com or Meet us at DublinMakerFaire on Jul 27th

    ReplyDelete
  16. Hello my name is Diego, I have a problem with processing, if I use the 32-bit version I get the following error: alibrary relese on native code not aviable. or only works properly When the schetch is run as a 64-bit application.
    and instead using 64 bit processing. serial does not run in 64 bit mode processing.app sketchexception: serial is only compatible wit the 32-bit

    ReplyDelete
    Replies
    1. did you ever resolve this issue? I'm getting the same thing

      Delete
  17. hello. the first code is for the arduino. and the second code where I put it??

    ReplyDelete
    Replies
    1. hav u figure out the where put the second code?

      Delete
  18. Quickly this site will indisputably be famous among all blogging people, because of its fastidious articles or reviews.wwom

    ReplyDelete
  19. When the technology help to make your life easier so Arduino helicopter infrared controller tech also become wonderful item for global community.red-current

    ReplyDelete
  20. Hey thought I'd point this out - I think in the processing sketch, you meant to write getArrayValue() not arrayValue() in lines 396 and 298. Also, how might one resolve the whole 32-bit vs 64-bit issue with the JMyron library? Any ideas?

    ReplyDelete
  21. Top 9 Casino Vendors in Malaysia - JTHub
    The 춘천 출장샵 best casinos 동두천 출장샵 in Malaysia include 안산 출장안마 Jumba Casino, Kepang Besar, Jumba Casino, Jumba Casino, Jumba Casino, 대구광역 출장마사지 Jumba Casino, Jumba Casino, Jumba 충청남도 출장마사지 Casino, Jumba

    ReplyDelete