Position Hold with Optical Flow sensor - done

alexmos
Posts: 108
Joined: Tue Aug 09, 2011 12:12 pm

Position Hold with Optical Flow sensor - done

Post by alexmos »

Just for fun, i have implemented position hold. It uses ADNS-5050 as low-cost 5v sensor with simple connection. Lense is from chinese laser pointer (about 9mm focal length).

This mode is always on, but start working only when sticks are in their neutral position - so full manual control is retained.

Sensor:
Image Image

Test video: http://www.youtube.com/watch?feature=pl ... dZnxTz1Y_g

Sorry but there are no instructions how to insert this mod into current multiwii code, because there are many dependencies with my other mods. The code is quite simple to do this by your own hands.

UPDATE:

My code based on latest MWC 2.0: http://code.google.com/p/multiwii-alexm ... akechanges

Position Hold is activated in GPS Hold mode (even if you have not GPS, use this checkbox to switch mode). Works only in LEVEL (STABLE) mode.

ADNS-5050 wiring:
Image
SCLK,SDIO,NCS may be connected to any unused arduino pins (don't forget about +5V, Ground).
Last edited by alexmos on Thu Apr 26, 2012 6:40 pm, edited 2 times in total.

sandmen
Posts: 24
Joined: Mon Feb 21, 2011 3:26 pm

Re: Position Hold with Optical Flow sensor - done

Post by sandmen »

great idea, and fantastic doing :-)

The code is quite simple to do this by your own hands.

maybe a Small snippet for MW2.0 :-)

Peter

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

Re: Position Hold with Optical Flow sensor - done

Post by copterrichie »

This is awesome and I strongly believe this is the system used in the Flymentor. By Chance, have you tested the range or altitude ?

Thank you.

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

Re: Position Hold with Optical Flow sensor - done

Post by copterrichie »

I am receiving an error message when clicking on the code link.


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

Re: Position Hold with Optical Flow sensor - done

Post by copterrichie »

Awesome, Thank you PatrikE

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

Re: Position Hold with Optical Flow sensor - done

Post by copterrichie »

I located a source for those chips if anyone is interested.

http://search.digikey.com/us/en/cat/sen ... =adns-5050

alexmos
Posts: 108
Joined: Tue Aug 09, 2011 12:12 pm

Re: Position Hold with Optical Flow sensor - done

Post by alexmos »

copterrichie wrote:This is awesome and I strongly believe this is the system used in the Flymentor. By Chance, have you tested the range or altitude ?

Thank you.


In my code, starting from 2 meters, if altitude increases - stabilization effect decreases proportionaly (because no trust for sensor data). But I have noticable effect on altitudes about 6 meters, and I think with good light conditions it should be up to 10 meters.

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: Position Hold with Optical Flow sensor - done

Post by Alexinparis »

Very interesting !
Could we find ready to use sensor for this ? (with the right lens for several meters)

alexmos
Posts: 108
Joined: Tue Aug 09, 2011 12:12 pm

Re: Position Hold with Optical Flow sensor - done

Post by alexmos »

Yes, there is full assembled sensor for sale, for example http://store.diydrones.com/ProductDetai ... BR-0016-01. ADNS-3080 is better than I have used, and lense is better - so it should works fine.

But it requires a little code modification to handle it (reading data part in OpticalFlow.pde).. If anyone will buy it - I will help to implement.

There is support for this sensor in ArduCopter, so you can steal reading code and useful utils for testing from this project :)

alexmos
Posts: 108
Joined: Tue Aug 09, 2011 12:12 pm

Re: Position Hold with Optical Flow sensor - done

Post by alexmos »

Also notice, that ADNS-3080 requires additional PIN (total 4 pins) compared to ADNS-5050 (total 3 pins) for SPI-communication, so firstly check have you free pins to connect sensor? (I am using Serial Sum PPM so has 3 extra pins in my ATMEGA 328P)

nhadrian
Posts: 421
Joined: Tue Oct 25, 2011 9:25 am

Re: Position Hold with Optical Flow sensor - done

Post by nhadrian »

Dear Alexmos,

This is quite interresting project indeed! could be really useful on field!
But I have some questions. First, did you make any tests in windy conditions? What do you think, could this code hold the position in wind too?
How copter reacts to different angles?
If ADNS-3080 would work with mwi that would be great!!!

BTW, thanks for the good job!!!!!

alexmos
Posts: 108
Joined: Tue Aug 09, 2011 12:12 pm

Re: Position Hold with Optical Flow sensor - done

Post by alexmos »

I have made only one outdoor test, there was no wind. But I think it should compensate even strong wind, due to I-term of PID regulator.

In rotation, sensor will not give any data or will give wrong data - so rotation is hard to compensate for it. But I have not tested it.

In windy condition, after rotation I-term should be re-found, so position will be lost. Theoretically it is possible to rotate I-vector to the same angle - but we can't distinguish what information is stored in it. It can hold information about wrong leveling (and compensate level drift), too. This part should not be rotated.

I have no test data now. After some field tests, I will decide is it neccesary to rotate I. Ma be compensation of strong wind is more useful than compensation of small level drift.

alexmos
Posts: 108
Joined: Tue Aug 09, 2011 12:12 pm

Re: Position Hold with Optical Flow sensor - done

Post by alexmos »

And also I want to try a potentialy useful idea: when I-term will hold informatin about wind (i.e. the angles of inclination to compensate wind), we can use it in flight, not only in position hold mode.

wilco1967
Posts: 156
Joined: Thu Aug 18, 2011 6:04 pm
Location: Winterswijk, Netherlands

Re: Position Hold with Optical Flow sensor - done

Post by wilco1967 »

Very impressive !
Thats a feature that would be very welcome in 2.1.

I also noticed how it holds altitude so well ? That is not due to the flow sensor, or is it ?

alexmos
Posts: 108
Joined: Tue Aug 09, 2011 12:12 pm

Re: Position Hold with Optical Flow sensor - done

Post by alexmos »

Altitude holding by sonar sensor. It has 0.3 cm precision by spec, so with strong PID it gives very good results on low altitudes.

I have implemented ideas I sayed above, all code on SVN. But have not tested and I am afraid can't test it on this week :(

nhadrian
Posts: 421
Joined: Tue Oct 25, 2011 9:25 am

Re: Position Hold with Optical Flow sensor - done

Post by nhadrian »

this optical flow hold looks impressive and interresting.
Can't wait for final solution (I mean find the most optimal sensor for us)....
Keep on good work guys!!!!

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

Re: Position Hold with Optical Flow sensor - done

Post by copterrichie »

because of the way a multi-rotor copters has to tilt the airframe, placing the optical lens on a gimbal may increase the altitude.

nhadrian
Posts: 421
Joined: Tue Oct 25, 2011 9:25 am

Re: Position Hold with Optical Flow sensor - done

Post by nhadrian »

There is sonar and optical sensor on the ar-drone 1 and works great even on a windy day, so this behaviour should work without gimballs, only used the calculations.
BTW, when optical flow sensor is used for compensating the relative sideway movements, it could be work great, because some dergees of frame tilt would cause only some dm mooves.

LuFa
Posts: 160
Joined: Fri Jan 27, 2012 7:56 pm

Re: Position Hold with Optical Flow sensor - done

Post by LuFa »

nice work !

is it possible to juse your code with Hexa with PPM Receiver by activate A0/A1 to get the SPI Pins free ?

have order some ADNS5050 ;)

nhadrian
Posts: 421
Joined: Tue Oct 25, 2011 9:25 am

Re: Position Hold with Optical Flow sensor - done

Post by nhadrian »

Dear Alexmos,

the same question as from LuFa.
What do you think, is it possible to use the ADNS3080 (with optical lens from DIYDRONES Store) with a 328P in a hexa, if PPM receiver is used?
The other question is that I'm using an XBee module for telemetry, so RT/TX is used. Does it cause a problem for this sensor?
My last question is that approx. how many bytes is the optical flow code in the sketch?
Thanks for your reply in advance!

BR
Adrian

msev
Posts: 186
Joined: Thu Apr 14, 2011 11:49 am

Re: Position Hold with Optical Flow sensor - done

Post by msev »

Alexmos which sonar do you use? Is there any good cheap supplier for ADNS-5050?

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

Re: Position Hold with Optical Flow sensor - done

Post by PatrikE »


alexmos
Posts: 108
Joined: Tue Aug 09, 2011 12:12 pm

Re: Position Hold with Optical Flow sensor - done

Post by alexmos »

copterrichie wrote:because of the way a multi-rotor copters has to tilt the airframe, placing the optical lens on a gimbal may increase the altitude.


That's right, it will help a little to improve altitue range. But it requires option in config to disable tilt compensation in calculations and very precise gimbal needed (because we well know angle of frame, but don't know angle of gimbal if it is not precisely holds horizon)

alexmos
Posts: 108
Joined: Tue Aug 09, 2011 12:12 pm

Re: Position Hold with Optical Flow sensor - done

Post by alexmos »

LuFa wrote:nice work !

is it possible to juse your code with Hexa with PPM Receiver by activate A0/A1 to get the SPI Pins free ?

have order some ADNS5050 ;)


You can connect sensor to any 3 DIGITAL pins, because I am using software SPI without interrupts, etc. As I know, A0-A5 may be used as DIGITAL pins. So answer is yes.

alexmos
Posts: 108
Joined: Tue Aug 09, 2011 12:12 pm

Re: Position Hold with Optical Flow sensor - done

Post by alexmos »

nhadrian wrote:Dear Alexmos,

the same question as from LuFa.
What do you think, is it possible to use the ADNS3080 (with optical lens from DIYDRONES Store) with a 328P in a hexa, if PPM receiver is used?
The other question is that I'm using an XBee module for telemetry, so RT/TX is used. Does it cause a problem for this sensor?
My last question is that approx. how many bytes is the optical flow code in the sketch?
Thanks for your reply in advance!

BR
Adrian


You can look at you device and count free pins. For ADNS3080, it's required 4 pins. It can be any pin with digital mode. My code does not use any interrupts, timers and so on.

Compiled optflow code takes 2462 bytes.

alexmos
Posts: 108
Joined: Tue Aug 09, 2011 12:12 pm

Re: Position Hold with Optical Flow sensor - done

Post by alexmos »

msev wrote:Alexmos which sonar do you use? Is there any good cheap supplier for ADNS-5050?


I have bought it on ebay under label "HC-SR04". But it is slightly differs from specifications I have found in net. I suppose any analog sonar with Echo and Trig pins will work with my code (I have added many configurable parameters in config.h)

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

Re: Position Hold with Optical Flow sensor - done

Post by copterrichie »

alexmos wrote:
copterrichie wrote:because of the way a multi-rotor copters has to tilt the airframe, placing the optical lens on a gimbal may increase the altitude.


That's right, it will help a little to improve altitue range. But it requires option in config to disable tilt compensation in calculations and very precise gimbal needed (because we well know angle of frame, but don't know angle of gimbal if it is not precisely holds horizon)


A mathematical solution would be best as long as the tilt is within the FOV of the optical lens.

This is a great Project and I think it has great potential.

LuFa
Posts: 160
Joined: Fri Jan 27, 2012 7:56 pm

Re: Position Hold with Optical Flow sensor - done

Post by LuFa »

Hi ,

Some ADNS5050 are on the way to me :)
But i have some questions :

- which Lens is the best one ?
- How to adjust the Lens ? is there any kind of video quality output in the code ?
- Can you upload the 2.0 with your optical flow ? because i use the MPU6050
- which PID Values are good for the first start ?
- works the calculation of the movement in relation of the altitute only with sonar or also with baro ?


Thanks so mutch !

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

Re: Position Hold with Optical Flow sensor - done

Post by copterrichie »

I have a question, are there some mouses/mice that also have this chip? If true, will the lens work for this project?

Waldmensch
Posts: 31
Joined: Sat Dec 31, 2011 12:10 am

Re: Position Hold with Optical Flow sensor - done

Post by Waldmensch »

Important is to know the FOV of lense. This is the distance from lense to Sensor.

alexmos
Posts: 108
Joined: Tue Aug 09, 2011 12:12 pm

Re: Position Hold with Optical Flow sensor - done

Post by alexmos »

LuFa wrote:Hi ,

Some ADNS5050 are on the way to me :)
But i have some questions :

- which Lens is the best one ?
- How to adjust the Lens ? is there any kind of video quality output in the code ?
- Can you upload the 2.0 with your optical flow ? because i use the MPU6050
- which PID Values are good for the first start ?
- works the calculation of the movement in relation of the altitute only with sonar or also with baro ?


Thanks so mutch !


- I have plastic lense about 6mm focal distance from laser pointer. If you find lense from camera with 5-8mm, it will work better.
- To view row data from sensor, download sketch and java GUI from this post attachement. It will help to fine tune focus.-
- I am going to merge with 2.0 in few weeks..
- Try to start from very low PIDS: P=3, I = 0.010, D=5. (remember tis is VEL section in GUI). I have a very little test data to say the best PIDS
- I think altitude from baro will works, too. In my test on 6 meters only baro was used.
Attachments
ADNS_5050_test.zip
(21.12 KiB) Downloaded 668 times

alexmos
Posts: 108
Joined: Tue Aug 09, 2011 12:12 pm

Re: Position Hold with Optical Flow sensor - done

Post by alexmos »

copterrichie wrote:I have a question, are there some mouses/mice that also have this chip? If true, will the lens work for this project?


No, I don't know where this sensor was used. I bought it in electronic shop. Mouse lense will not work, it has less focal distance than needed.

LuFa
Posts: 160
Joined: Fri Jan 27, 2012 7:56 pm

Re: Position Hold with Optical Flow sensor - done

Post by LuFa »

thanks :)

can you tell me how to run the Java Gui ?

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

Re: Position Hold with Optical Flow sensor - done

Post by copterrichie »

alexmos wrote:
copterrichie wrote:I have a question, are there some mouses/mice that also have this chip? If true, will the lens work for this project?


No, I don't know where this sensor was used. I bought it in electronic shop. Mouse lense will not work, it has less focal distance than needed.


Thank you, it was a wild thought. :D

nhadrian
Posts: 421
Joined: Tue Oct 25, 2011 9:25 am

Re: Position Hold with Optical Flow sensor - done

Post by nhadrian »

My ADNS3080 with lens from DIY Drones is on the way... :D

alexmos
Posts: 108
Joined: Tue Aug 09, 2011 12:12 pm

Re: Position Hold with Optical Flow sensor - done

Post by alexmos »

LuFa wrote:thanks :)

can you tell me how to run the Java Gui ?


It is quite simply - download and install Java (JRE from Sun.com). And run "mousecam/bin/run.bat" (java.exe must be in the path environment).

LuFa
Posts: 160
Joined: Fri Jan 27, 2012 7:56 pm

Re: Position Hold with Optical Flow sensor - done

Post by LuFa »

ok , i have chanche the .bat to this :

Code: Select all

set path=.;C:\Program Files (x86)\Java\jre6\bin
java mousecam/MouseCam


and if i start it i see this :

Image

is that right ? how can i see the camera picture ?

Thanks :)

alexmos
Posts: 108
Joined: Tue Aug 09, 2011 12:12 pm

Re: Position Hold with Optical Flow sensor - done

Post by alexmos »

I have downloaded mousecam from http://www.bidouille.org/hack/mousecam They says: "You can download the Arduino script and the PC program below. The program is in java and requires the RXTX library to be installed. You need to get the "RXTX 2.1 for use withOUT Sun's CommAPI (namespace gnu.io)" version. No, as of 2008 java still does not natively support the serial port. It should work with Linux, Mac OS X and Windows, but I only tested it under Windows."

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

Re: Position Hold with Optical Flow sensor - done

Post by copterrichie »

alexmos wrote:I have downloaded mousecam from http://www.bidouille.org/hack/mousecam They says: "You can download the Arduino script and the PC program below. The program is in java and requires the RXTX library to be installed. You need to get the "RXTX 2.1 for use withOUT Sun's CommAPI (namespace gnu.io)" version. No, as of 2008 java still does not natively support the serial port. It should work with Linux, Mac OS X and Windows, but I only tested it under Windows."


Would you believe I JUST disassembled one of these yesterday? It appears to be the same as the Wireless Microsoft Mouse. It has a A2030 Chip but I was unable to locate the Datasheet for it.

P1110720.JPG

LuFa
Posts: 160
Joined: Fri Jan 27, 2012 7:56 pm

Re: Position Hold with Optical Flow sensor - done

Post by LuFa »

i cant find the right download link to the txrx lib :(

is that the only way to setup the lens ?

i´m to stupid to bring the java programm to run :(

alexmos
Posts: 108
Joined: Tue Aug 09, 2011 12:12 pm

Re: Position Hold with Optical Flow sensor - done

Post by alexmos »

https://www.google.ru/search?hl=ru&q=adns+2030+pdf - the first link is what you need :) But it is much more complicated to connect this sensor to arduino (3.3V, many electronics required)

LuFa
Posts: 160
Joined: Fri Jan 27, 2012 7:56 pm

Re: Position Hold with Optical Flow sensor - done

Post by LuFa »

the hardware is allready ready :) (use BSS123 for levelconverter)
are you shure that is it the right link ? its a google search link

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

Re: Position Hold with Optical Flow sensor - done

Post by copterrichie »

alexmos wrote:https://www.google.ru/search?hl=ru&q=adns+2030+pdf - the first link is what you need :) But it is much more complicated to connect this sensor to arduino (3.3V, many electronics required)


Awe! Thank you, I have a few more mouses around here, maybe we will hit the jackpot. :)

LuFa
Posts: 160
Joined: Fri Jan 27, 2012 7:56 pm

Re: Position Hold with Optical Flow sensor - done

Post by LuFa »

have receive now my adns 5050 sensors :)

can you tell me where is the front of the sensor ? in wich direction should i mount the sensor ?

how did you connect the NRESET Pin from the adns 5050 ? High , Low or NC ? :D

thanks ;)

alexmos
Posts: 108
Joined: Tue Aug 09, 2011 12:12 pm

Re: Position Hold with Optical Flow sensor - done

Post by alexmos »

Image

Y = PITCH - Forward direction of other sensors, X = ROLL

NRESET should be HIGH. I have connected it to +5V (don't know is it safe, but works)

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

Re: Position Hold with Optical Flow sensor - done

Post by copterrichie »

I apologize for being a pain. :D

I just opened a MAC original mouse and found an ADNS-2051, any opinions?

http://www.alldatasheet.com/datasheet-p ... S2051.html


Hmmm: http://www.martijnthe.nl/2009/07/interf ... r-arduino/

alexmos
Posts: 108
Joined: Tue Aug 09, 2011 12:12 pm

Re: Position Hold with Optical Flow sensor - done

Post by alexmos »

You can connect almoust ANY mice sensor to arduino :) All you need - to add some code into OpticalFlow.pde to read delta_x and delta_y according to the datasheet, and properly convert them to mm. All other mathematics and PID control things are the same for every sensor :) I have selected ADNS-5050 only because it has the most simply connection for me.

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

Re: Position Hold with Optical Flow sensor - done

Post by copterrichie »

Awesome, I will bench test this and report back. :)

sandmen
Posts: 24
Joined: Mon Feb 21, 2011 3:26 pm

Re: Position Hold with Optical Flow sensor - done

Post by sandmen »

@alexmoos
today I assembled my diy-flow-control :D
I have a lense from a old laser pointer. I can adjust it via a screw.
The Adns-2610 has some different regs on I2C. I will use your script from here,
viewtopic.php?f=7&t=1413&start=30#p11421
and modify the address. Do you think I have to connect the LED_CNTL?
Hope this will work :-)

My question is, about your repository.
- You have integrated into your repo, sonar and flwo control , based 1.9. Is that correct?
- Is your repo working with mega (flyduino) ? or What board/mcu do you use?
- Where is your repo ? :mrgreen:
- Do you plan to merge it with 2.0

Post Reply