Page 1 of 5

Position Hold with Optical Flow sensor - done

Posted: Sun Mar 25, 2012 9:22 pm
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).

Re: Position Hold with Optical Flow sensor - done

Posted: Sun Mar 25, 2012 9:58 pm
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

Re: Position Hold with Optical Flow sensor - done

Posted: Sun Mar 25, 2012 10:39 pm
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.

Re: Position Hold with Optical Flow sensor - done

Posted: Sun Mar 25, 2012 10:43 pm
by copterrichie
I am receiving an error message when clicking on the code link.

Re: Position Hold with Optical Flow sensor - done

Posted: Sun Mar 25, 2012 11:38 pm
by PatrikE

Re: Position Hold with Optical Flow sensor - done

Posted: Sun Mar 25, 2012 11:43 pm
by copterrichie
Awesome, Thank you PatrikE

Re: Position Hold with Optical Flow sensor - done

Posted: Sun Mar 25, 2012 11:45 pm
by copterrichie
I located a source for those chips if anyone is interested.

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

Re: Position Hold with Optical Flow sensor - done

Posted: Mon Mar 26, 2012 9:25 am
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.

Re: Position Hold with Optical Flow sensor - done

Posted: Mon Mar 26, 2012 11:22 am
by Alexinparis
Very interesting !
Could we find ready to use sensor for this ? (with the right lens for several meters)

Re: Position Hold with Optical Flow sensor - done

Posted: Mon Mar 26, 2012 12:02 pm
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 :)

Re: Position Hold with Optical Flow sensor - done

Posted: Mon Mar 26, 2012 12:08 pm
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)

Re: Position Hold with Optical Flow sensor - done

Posted: Tue Mar 27, 2012 5:15 am
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!!!!!

Re: Position Hold with Optical Flow sensor - done

Posted: Tue Mar 27, 2012 7:55 am
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.

Re: Position Hold with Optical Flow sensor - done

Posted: Tue Mar 27, 2012 8:04 am
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.

Re: Position Hold with Optical Flow sensor - done

Posted: Tue Mar 27, 2012 8:52 pm
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 ?

Re: Position Hold with Optical Flow sensor - done

Posted: Tue Mar 27, 2012 9:36 pm
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 :(

Re: Position Hold with Optical Flow sensor - done

Posted: Thu Mar 29, 2012 7:59 pm
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!!!!

Re: Position Hold with Optical Flow sensor - done

Posted: Thu Mar 29, 2012 8:44 pm
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.

Re: Position Hold with Optical Flow sensor - done

Posted: Fri Mar 30, 2012 5:41 am
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.

Re: Position Hold with Optical Flow sensor - done

Posted: Fri Mar 30, 2012 7:17 am
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 ;)

Re: Position Hold with Optical Flow sensor - done

Posted: Fri Mar 30, 2012 7:33 am
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

Re: Position Hold with Optical Flow sensor - done

Posted: Fri Mar 30, 2012 8:51 am
by msev
Alexmos which sonar do you use? Is there any good cheap supplier for ADNS-5050?

Re: Position Hold with Optical Flow sensor - done

Posted: Fri Mar 30, 2012 10:43 am
by PatrikE

Re: Position Hold with Optical Flow sensor - done

Posted: Fri Mar 30, 2012 1:07 pm
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)

Re: Position Hold with Optical Flow sensor - done

Posted: Fri Mar 30, 2012 1:11 pm
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.

Re: Position Hold with Optical Flow sensor - done

Posted: Fri Mar 30, 2012 1:20 pm
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.

Re: Position Hold with Optical Flow sensor - done

Posted: Fri Mar 30, 2012 1:25 pm
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)

Re: Position Hold with Optical Flow sensor - done

Posted: Fri Mar 30, 2012 1:30 pm
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.

Re: Position Hold with Optical Flow sensor - done

Posted: Sat Mar 31, 2012 9:40 pm
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 !

Re: Position Hold with Optical Flow sensor - done

Posted: Sat Mar 31, 2012 10:39 pm
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?

Re: Position Hold with Optical Flow sensor - done

Posted: Sat Mar 31, 2012 10:51 pm
by Waldmensch
Important is to know the FOV of lense. This is the distance from lense to Sensor.

Re: Position Hold with Optical Flow sensor - done

Posted: Sat Mar 31, 2012 11:28 pm
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.

Re: Position Hold with Optical Flow sensor - done

Posted: Sat Mar 31, 2012 11:31 pm
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.

Re: Position Hold with Optical Flow sensor - done

Posted: Sat Mar 31, 2012 11:36 pm
by LuFa
thanks :)

can you tell me how to run the Java Gui ?

Re: Position Hold with Optical Flow sensor - done

Posted: Sat Mar 31, 2012 11:50 pm
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

Re: Position Hold with Optical Flow sensor - done

Posted: Sun Apr 01, 2012 6:11 am
by nhadrian
My ADNS3080 with lens from DIY Drones is on the way... :D

Re: Position Hold with Optical Flow sensor - done

Posted: Sun Apr 01, 2012 10:24 am
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).

Re: Position Hold with Optical Flow sensor - done

Posted: Sun Apr 01, 2012 3:16 pm
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 :)

Re: Position Hold with Optical Flow sensor - done

Posted: Sun Apr 01, 2012 7:50 pm
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."

Re: Position Hold with Optical Flow sensor - done

Posted: Sun Apr 01, 2012 8:31 pm
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

Re: Position Hold with Optical Flow sensor - done

Posted: Sun Apr 01, 2012 9:16 pm
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 :(

Re: Position Hold with Optical Flow sensor - done

Posted: Mon Apr 02, 2012 9:19 am
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)

Re: Position Hold with Optical Flow sensor - done

Posted: Mon Apr 02, 2012 10:38 am
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

Re: Position Hold with Optical Flow sensor - done

Posted: Mon Apr 02, 2012 12:45 pm
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. :)

Re: Position Hold with Optical Flow sensor - done

Posted: Mon Apr 02, 2012 7:04 pm
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 ;)

Re: Position Hold with Optical Flow sensor - done

Posted: Mon Apr 02, 2012 9:58 pm
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)

Re: Position Hold with Optical Flow sensor - done

Posted: Mon Apr 02, 2012 10:13 pm
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/

Re: Position Hold with Optical Flow sensor - done

Posted: Mon Apr 02, 2012 10:27 pm
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.

Re: Position Hold with Optical Flow sensor - done

Posted: Mon Apr 02, 2012 10:44 pm
by copterrichie
Awesome, I will bench test this and report back. :)

Re: Position Hold with Optical Flow sensor - done

Posted: Wed Apr 04, 2012 3:15 pm
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