You might remember this blog post by Marko Klein Berkenbusch on using a hacked mouse sensor for position control of a quad. With some help from Marko himself, I've mostly repeated his results on a branch of ArduCopterNG and thought I should share how I did it as it's slightly different. Please note that this is not official ArduCopterNG code, there's no support or anything for it.
The Hardware:
ADNS2620 Mouse Evaluation board from sparkfun.
4.3mm lens and lens mount from peau productions
STK500 compatible programmer to change the firmware on the Eval board
ftdi cable from diydrones
The software:
- modified firmware for the Evaluation board to add some extra features like:
- downloading the 18x18 image from the mouse sensor
- sending simple binary packets of the x and y change
- menu to show some simple info like surface quality (good for focusing lens)
- modified ArduCopterNG code with Mouse.h and Mouse.pde code to parse the output from the eval board
- modified boards.txt which describes the sparkfun eval board to arduino
- excel sheet which can be used to view the image from the evalboard and check you've got the focus ok
How to put it together:
- solder on the 6 pin headers on the eval board so you can connect the stk500 programmer and ftdi cable
- glue the lens mount to the bottom of the eval board. make sure it's perfectly centered over the pinhole of the mouse sensor
- screw the lens into the lens mount (don't screw it in all the way)
- upload the modified firmware to the sparkfun evaluation board using the stk500 programmer
Focussing the lens:
- connect connect your arduino ide to the eval board using the ftdi programmer and it should immediately start outputting x,y coordinates and surface quality number.
- If it just appears garbled it's probably outputting in binary press <space> to view the menu and press 'm' to switch it to ascii mode..
- the third number displayed is the surface quality, try screwing in/out the lens to get a better (i.e. higher) surface quality. note: if it's dark you might need to point the lens at a light.
- download an image by pressing 'p' and copy/paste the values into the excel sheet. adjust the lens, taking shots until it seems like a reasonable image
Playing with ArduCopter - all of the interesting code is in the Mouse.pde and Mouse.h.
- I attached the mouse's ftdi pins to the arducopter Oilpan's telemetry port (on the front of the oilpan). The mouse sends serial commands (in binary) and a parser in the arduCopterNG code picks these up at 20hz.
- In particular the mouse_calculate function does the compensation for pitch and roll. 20x per second it compares it's roll/pitch to the previous iteration and estimates what x/y it should receive from the mouse:
The expected x/y = the change in roll * pixel resolution of the camera / field of view of lens * magic number
(this magic number seems to be 5 for my set-up)
- it then subtracts this estimate from the real x/y it received leaving only the horizontal movement.
- the mouse_position_control shows the PID contorller to correct for the x/y movements from the mouse (this is a pretty normal PID controller).
Some good reference material on other people using mouse sensors for altitude hold, obstacle avoidance.
http://www.araa.asn.au/acra/acra2007/papers/paper181final.pdf
Some pictures of the camera attached to the eval board and an image captured from the camera:
Comments
Sorry, Randy!
I have translated your message is not very accurate. I realized that in the files for Arducopter there is a library for the use of your sensor. I ask you to give a link to them, because for me it is very difficult to find these files yourself. Thank you!
ATTN : Randy
Thanks for the quick reply. I know PX4Flow sensor, but I am interested in is your mouse sensor. So I want to ask you to give me a link to your Projects (even with modifications) where either. A website http://www.arducopter.co.uk. I could only find the same PX4Flow sensor. Thank you
@Gennady,
I did this post about 2.5years ago so I'm afraid things have moved on since then. ArduCopter still has some code in it to support the mouse-sensor based optical flow sensor but I'm not sure if it works or not. The plan is really to move to the PX4Flow sensor and use the Pixhawk flight controller (still running arducopter). That should be released with AC3.3 I think.
Dear Randy!
I want to repeat your Project, but could not find the Arduino and Exel file on these links to you. Please inform me where I can find these files or please send these files by e-mail me ooo.concord@gmail.com
Thanks!
i am using the mouse sensor evaluation board from sparkfun. You mentioned in ur your blog that you programmed atmega328 using sparkfun stk500 programmer. i am not using the same programmer but it uses the same stk500v2 protocol am using sina prog for downloading the code. For some reason i am not able upload the code into chip. its not being recognized by the software. just wanted to know if there are any fuse settings that need to be changed before we can download our own code onto the chip? did you face any of this problem while doing the same for your project?
Downloaded, thank you.
Juan,
In the move to GIT it became invisible. It's actually still there in svn but I've put it into my public drop box as well so you should fine it at this link. Please PM me if you have any problems.
http://dl.dropbox.com/u/3852647/ArduCopterMouseForPosHold/mouse_for...
Could you reupload the linked files to another place?
@sebastian,
sorry, that blog post got out slightly prematurely actually. I've updated it above with links to the code.
@jonathan,
As Marko says, the problem with buying the sensor without the eval board is that the sensor doesn't use a pure I2C. It's I2C without the slave address meaning that it can't be put on an I2C bus with other slaves.
As a next step, I'm looking at trying the ADNS3080 which has higher resolution (30x30 instead of 18x18) and uses a 3.3V SPI interface which should play better with other sensors.
@marko,
Thanks a lot for your help! Like you say - way points without a GPS (or values merged in with a GPS when available) and precision landing is where this is going. In the linked research reports they also use it for altitude measuring and object avoidance (in planes).
Is the code available?
I've got already a mouse sensor for my arducopter, just didn't hat the time to implement yet