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.
ADNS2620 Mouse Evaluation board from sparkfun.
STK500 compatible programmer to change the firmware on the Eval board
ftdi cable from diydrones
- 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
- 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.
Some pictures of the camera attached to the eval board and an image captured from the camera: