Kalman Filter for Dummies

I found a simple 1-dimensional Kalman filter online.  It doesn't really look much better than an IIR filter, to be honest - no control input, no way of factoring in the "ideal" value into the estimate.  But as the math of Kalman filters eludes me, this will have to do for now.

I've ported it to Processing.  Should be easy to convert to Arduino or similar.

// simple Kalman filter
// adapted from C code by Adrian Boeing, www.adrianboeing.com
class KalmanFilter
{
  // initial values for the kalman filter
  float x_est_last = 0;
  float P_last = 0;
  // the noise in the system
  float Q;
  float R;
  float K;    // Kalman gain
  float P;
  float P_temp;
  float x_temp_est;
  float x_est;
  // constructor - initialize with first estimate
  KalmanFilter(float estimate)
  {
    Q = 0.022;
    R = 0.617;
    // initialize with a measurement
    x_est_last = estimate;
  }
  KalmanFilter(float estimate, float initQ, float initR)
  {
    Q = initQ;
    R = initR;
    // initialize with a measurement
    x_est_last = estimate;
  }
  // add a new measurement, return the Kalman-filtered value
  public float step(float z_measured)
  {
    // do a prediction
    x_temp_est = x_est_last;
    P_temp = P_last + R*Q;
    // calculate the Kalman gain
    K = P_temp * (1.0/(P_temp + R));
    // correct
    x_est = x_temp_est + K * (z_measured - x_temp_est);
    P = (1- K) * P_temp;
    // update our last's
    P_last = P;
    x_est_last = x_est;
    return (x_est);
  }
}
And to use it..

  // initial estimate, measurement noise, process noise
  KalmanFilter kf = new KalmanFilter(0, 0.05, 1);
  // update with a new measurement
  float data = kf.step(measurement);

Womarts 320x240 TFT LCD Shield with Touch Screen

I bought one of these Womarts 320x240 TFT LCD Touch Screen boards on ebay because they are cheaper than the Sainsmart equivalents, and have both the TFT and carrier board in a single package, unlike the separate TFT board and carrier board that Sainsmart has. Heck, these are even cheaper than the 128x64 I2C LCD boards being sold out there.  The downside of the Womarts board is that it consumes a heck of a lot of pins. You'll be hard pressed to do anything else with one of these boards riding your Arduino.

There is a version of the Womarts board for Mega-type Arduino, and another for the Uno form factor. This post is about the Mega version. There has been some discussion on the Arduino forums about how good (or bad) these $25 Womarts boards are, so I had rather low expectations.

The main problem is that one set of pins on the board doesn't match up with my (also off-brand) China Arduino Mega. But the problem is with the board, not the Mega.

Here we see that the board consumes all of the extra pins on the bottom of the Mega. Oops.. there go the SPI pins.. I'm not sure if the SPI pins are actually used (I hope not!)
On the top side of the Arduino (with the USB port on the right):

The bummer: the bottom set of pins don't fit:


The solution is to bend the pins inward. Not the best reliability, but a necessary evil.



And the best part.. the Henning Karlsen UTFT library works out of the box (just uncomment the line near the top of the example program for the Mega).



Poor Man's On-Axis Guider


Everyone who doesn't own an Astro-Physics or Software Bisque mount, and everyone who needs to take >5 minute sub-exposures, needs to guide. And sooner or later, everyone discovers the joys of differential flexure in their guide scope setup. The cure for differential flexure, mirror flop, and a host of other ills is off-axis guiding. The main challenge with off-axis guiding is that the pick-off prism is getting light from the edges of the image circle, where there are aberrations galore. It is also pretty difficult to find guide stars using the tiny pick-off prism.

A company  called Innovations Foresight has developed a product called the On-Axis Guider.  This product uses a cold mirror (a first-surface mirror which is engineered to reflect visible light, and pass-through infrared light). In effect a cold mirror is a beam splitter that lets infrared light through.  This allows the guide camera to get light from the center of the image circle, where stars are not heavily aberrated.

There are several other similar projects:

One distinct downside of the ONAG is its rather high cost - over $800.  Having used two different off-axis guiders with limited success, I decided to try my hand at building my own On-Axis Guider. As suggested on the atm_free Yahoo group, I started with the $100 Vixen Flip-Mirror Diagonal (model 2680).



This is a very well-built cast-aluminum unit with very little plastic in it.  To take it apart only requires two tools - a Philips screwdriver, and a 2mm Allen wrench.

The first step is to remove the 2" nosepiece, by removing the four screws.


The next step is to remove the knob and the little wheel inside which moves the mirror up and down. To do this, you will need to loosen the grub screw that holds the knob.


Once the knob and internal wheel are removed, the mirror can flip up and down unconstrained. To remove the mirror holder and mirror, you will need to loosen the two 2mm screws on opposite sides of the diagonal.


The stock Vixen mirror is 30mm x 35mm in size. This is large enough so you can use an APS-C (crop sensor DSLR) imaging chip with manageable vignetting. Obviously a smaller sensor like the 4/3-format SBIG 8300 and its competitors (e.g. QSI 583) will work even better.



There may be several methods of getting the mirror off the aluminum mirror holder, but I chose to boil it in a pot.


The mirror was pretty easy to pry off once the strange Chinese glue underneath had gotten soft from the boiling. Next step is to remove the strange Chinese glue. I used a sanding drum on a Dremel to do this. Don't get too enthusiastic. I used sandpaper to clean the raised portion of the mirror holder. Our overly-large cold mirror will sit on this raised portion, and we don't want to gouge it with the Dremel.


Afterwards, it is necessary to drill a hole through the mirror holder. I used a succession of bits (starting with a 2mm and ending with a 13mm) to make the hole. The aluminum is quite thick and you need to put the mirror holder in a vise of some sort so it doesn't grab the bit, spin around, and bloody your fingers.


I then used a step bit to enlarge the hole to 20mm.


The cold mirror I used is the Edmund Optical part number 64449, "High Performance Cold Mirror 45 Degree AOI, 35.0mm Square." Note that this is slightly larger than the original 30mm x 35mm mirror, so won't fit in the mirror holder.


The mirror has protective vinyl on both sides, and you need to remove the vinyl on the back side before adhering it to the aluminum. Make sure the aluminum is clean! also make sure you know which side of the mirror is the aluminized side! do not glue the aluminized side to the mirror holder!

An easy way to check which side is aluminized is to hold a pencil to the surface of the vinyl. If the pencil point touches its reflection, that is the aluminized side. If the pencil doesn't quite touch its reflection, you've got the correct side.

I attached the mirror to the mirror holder with ordinary silicone caulk. Same thing we use to attach Newtonians to secondary holders, so should sufficiently robust. A little too much caulking (which might stress the mirror and cause astigmatism). So less caulking is better.


Here we can see that the silicone glob was just a bit too large.


After letting the silicone dry for 12-24 hours, it's time to put everything back together again. Assembly is the reverse of disassembly.  I did not remove the protective vinyl on the cold mirror's front surface until after everything was re-assembled. This helps avoid nasty mishaps to the coating while screws and screwdrivers are in the general area. Make sure to tighten the two screws that form the hinge of the flip mirror, if they aren't tight enough, the mirror will jiggle back and forth.

I initially thought of drilling a hole in the side of the flip mirror housing, then tapping it with an M4 screw. This would allow the M4 screw to bear on the mirror holder and lock it down. But with the two side-screws tightened, the mirror doesn't budge. So it's good enough for now.



And after everything is put back together. Note that my focal reducer is behind the ONAG - this particular reducer (a William-Optics 0.8X model II) only has 55mm of back focus, so cannot be used in front of the ONAG. As a result, a large amount of in-focus is required. Note that the focuser is only racked out about 40mm - and this is on an Orion 100ED with a tube that was shortened by 4 inches. The net result is that the guide camera (here a Meade DSI) needs a 1.25" diagonal to reach focus.


Also note that the Vixen Flip-Mirror Diagonal has male T-threads on both the top and rear ports. As my reducer has a 2" nosepiece, I had to use a T-thread to 2" adapter from Blue Fireball. I had this around for my Vixen OAG anyway. Otherwise, the camera can thread directly to the Vixen Flip-Mirror Diagonal, at the expense of having no reduction.

It may also be possible to put a 0.63X SCT reducer on the front port (using an SCT thread to 2" adapter) and the camera on the top port. The SCT reducers have about 105mm to 110mm of back focus. I don't know if the Diagonal would provide enough back focus.


So does it work? here is Vega at 400% on the main camera (a QHY8). The out-of-focus stellar images looked like skateboards (!) so I was quite worried that maybe the cold mirror was pinched by too much silicone. But the in-focus image is nice and round. I think the skateboard-shaped out-of-focus stars are due to the strange shape of the aperture. I took several 10-minute exposures with the main camera, and stars looked pretty round to the corners. I do not have a flat to show yet, but the vignetting is manageable.


And here's what the guide camera (a Meade DSI Pro) was seeing at the same time (1-second exposure). The stellar image is definitely astigmatic (which is why we use a cold mirror, so that the reflected image is what goes to our main imager).


Is this DIY ONAG any better than an OAG?  I can't tell for sure right now, because I haven't tried it in dark skies.  With the terrible light pollution and clouds right now in Singapore, I needed 4-second exposures on the guide camera to pull in magnitude 5 stars. Pretty bad.  It does seem easier to get guide stars with this compared to my Vixen OAG - the OAG only illuminated about half of the DSI Pro chip, so I could only see half the stars.

I'm also planning to put a 0.5X 1.25" reducer on the DSI Pro.  This will improve brightness and probably reduce the out-focus distance required on the rear port. That would allow me to get rid of the 1.25" diagonal. Another interesting refinement is to add an X-Y guide star positioner to the rear port. Orion used to sell this, but apparently they have discontinued it.