Tuesday, August 21, 2012

What is a Kalman Filter?

What a week. I flew out to L.A. on Sunday afternoon to spend a week at the Kalman Filter Consultant Associates (KFCAs) course on Global Navigation Satellite System (GNSS) and Inertial Navigation System (INS) integration. I'll say that the course was a blur. We covered two graduate level text-books in one week, and the whole time I felt like I was just barely able to tread water. The good news, however, is that I feel like I have a fairly solid understanding of what a Kalman Filter is and how it can be used, any further epiphanies on the subject I will be sure to capture on this blog.

 Quick History

Kalman filters have a bit of a buzz about them.  They first gained fame with their use in the Apollo program landing lunar modules, but nowadays they are showing up in many different platforms.  One of the more common places is in AI and robotics (where I first saw them).

What is it?

A Kalman Filter is a state-space prediction and analysis algorithm. In lay-mans terms, it can predict the outputs and the reliability of those outputs for a given set of related equations.  Kalman Filters are closely related to Least-Squares estimators, in fact given a pre-set data set they will arrive at the same result.  The difference is that a Kalman Filter is recursive, needing only the previous output and the current output.

How does it work?

Kalman Filters require a model of the system they will be used on.  This model creates the predicted response of a system which is subtracted from the system's sensor outputs to yield an error state matrix.  It is essentially a system model coupled with an noise predictor, using normalized noise spectra in the multiplications.  Normal noise also known as Gaussian noise has the characteristic of shrinking its standard deviation when multiplied by another Normal noise profile.  That means regardless of the spread of the two noises, the combined profile will be more certain than either of the originals.  The pivotal piece is that your noise profiles must be gaussian or be compensated to be gaussian.

Monday, August 13, 2012

Using Orcad Layout with Circuit Works

One of the tasks I've taken on is to mesh our electrical documentation into our mechanical models.  Our mechanical modeling software is Dassault Systems' SolidWorks.  A handful of years back SolidWorks integrated in a piece of software called CircuitWorks that will create a solid model from an IDF file.  This is a pretty simple process, once you have everything set up correctly.  Here is what I discovered with how Orcad Layout exports its .MAX files to IDF files and how to configure both SolidWorks and Layout to bring things together nicely.

First, when exporting a .MAX file there are a couple important things to note:
  1. Parts will be exported by their footprint (geometry) name and their reference designator.  When CircuitWorks reads this in, it will create a part for each unique IDF part name.  So for example:  if you have two resistors, R1 and R2, with the same R1206 footprint, Circuitworks will create an R1206_R1 and an R1206_R2 part.  The way to circumvent this is to select the checkbox "Use Library Footprints" in the IDF export dialog in Layout.  Checking this box will remove the reference designator from the IDF part names.
  2. Exported parts will have 0 height unless you've specifically set the height of the component_outline obstacle.
Second, when importing into CircuitWorks note the following:
  1. CircuitWorks defaults to creating models on the XY-plane, meaning boards will show up vertically in any previews you have. (Probably not a big deal)
  2. CircuitWorks will use any models pre-existing in your part library.  This is a really nice feature since you can import a true 3D model as your part, instead of using the generated "block" part that CircuitWorks creates.  However, the critical thing to note is that in order to place and orient your imported part you must create an origin called CWX. The XY-plane of the origin should be parallel to the board and the +Z axis should point toward the top of the component.  Also, the origin must be centered where the board will contact your part.  None of this is documented very well in any SolidWorks documentation.  Showing Origins in Circuitworks is a good way to help you decide where your origin should be centered and how it should be oriented on the component.
I will be doing some more integration work between Layout and SolidWorks in the near future and will provide information on using a central component library, as well as how we are meshing Capture, Layout, and CircuitWorks component libraries.

Friday, August 10, 2012

AD5668 Documentation Snag

Another chip I'm using in my current project is the AD5668 8-channel 16-bit DAC.  The chip comes in a variety of suffixes that change the accuracy and power-up output states.  The wiring is simple for the chip, but the documentation contains an easy to overlook nuance.  I found myself stuck, looking at perfect signals, but an unresponsive DAC.

The nuance comes into play when sending certain commands to the AD5668.  The specific commands are Power-up / down channel, Set-up Internal Ref, Load Clear Code Register, and Load LDAC Register.  When using these commands it is important to notice that DB0 is different from D0. The DB bits are the bits for the entire 32-bit message.  The D0 bits only apply when the start and end bits of the message are Don't Cares.  It is never specifically mentioned in words, only in the command diagrams, which I overlooked.

Thursday, August 9, 2012

Powering an LTC1857/LTC1858/LTC1859

I ran into a problem this week with these little A2D converters. I am using the LTC1859, the 16-bit version. I worked through my Microprocessor setup just fine, all of the MC's signals were transmitting correctly, but the output of the LTC was continually zero (0x8000).

The problem turned out to be in how I was powering the chip. My circuit is the following:
LTC1859 Circuit Diagram
LTC1859 Circuit
 With VDD = +3.3V.  Upon closer inspection of the documentation for this guy, it turns out that the DVdd pin must be connected to +5V. A simple correction but an easy to overlook requirement.

I'll post the snag I found on the AD5668 16-bit D2A tomorrow.

Friday, July 27, 2012

PIC32MX575F512L SPI Macro Bugs

I'm using two of Microchip's PIC32MX575F512L processors in a project I'm working on at work.  On one microprocessor I am interfacing to three Fiber Optic Gyros (FOGs) as an SPI slave.  In setting up the PIC for communication I was acting the part of a good programmer using macros to make my code more dynamic and easier to read, macros provided by Microchip.  However, I discovered that two of those macros were at least partway broken.
//The following macros do not function as expected in the C32 v2.02 compiler from Microchip

void INTSetVectorPriority(INT_VECTOR vector, INT_PRIORITY priority);
// The function fails for the following inputs:
// INT_SPI_3_VECTOR or INT_VECTOR_SPI(SPI_CHANNEL3)
// I haven't tested channel 4 yet

#define INT_VECTOR_SPI(chn)             ((INT_SPI_1_VECTOR - 1) + (chn))
// The following inputs do not work
// SPI_CHANNEL2 and SPI_CHANNEL3 (SPI_CHANNEL4 is untested)
To correct the code I've converted everything to hard coded configurations. I have a ticket in to Microchip here, if they release a new version of the library I will revert to my macro based code.

Saturday, June 23, 2012

The Power of Ctrl-Z

When working in the Linux shell I have often erroneously hit the ctrl-z "panic" button in a feeble attempt to undo a mistake I've made.  However, this habit comes from years of using GUI applications and in Linux takes on an entirely different meaning.  Instead of happily seeing my mistake fixed, I usually end up back at the prompt with some text as follows:
[1]+ Stopped                 vi back-end/upload.php
Most times I would utter a curse under my breath, and reopen whatever application I was working in (often VIM).
Today, I learned that in pressing Ctrl-Z, I have backgrounded the application I was using.  This would be equivalent dropping back to the desktop in the GUI world.  Essentially, the prompt is your desktop, after pressing Ctrl-Z you are sent back to the prompt and you are given the job number of the application you were working in (the number inside the square brackets).  To reopen an application, you call the foregrounding program, fg, with the job number as a parameter.  This site is where I learned this info.

Super useful!

Friday, June 22, 2012

Configuring a text editor for GIT on Windows

This one is pretty simple, but the syntax is maybe not so helpful.  Here's the story:

I am getting ready to lead a walkthrough for my company on how to use GIT (we make instruments, so software management is not at the forefront of most people's minds).  In thinking about how to deploy this walkthrough I realized that my affinity for VIM is probably not shared throughout the company.  The solution can be found in the command:
git config --global core.editor <editor_path>
The trick comes in setting the editor path.  When I set the editor path to the location on the file system using:
"c:/Program Files (x86)/Notepad++/Notepad++.exe"
I received the following errors:
$ git commit c:/Program Files (x86)/Notepad++/notepad++.exe: -c: line 0: syntax error near unexpected token `(' c:/Program Files (x86)/Notepad++/notepad++.exe: -c: line 0: `c:/Program Files (x86)/Notepad++/notepad++.exe \$@\' error: There was a problem with the editor 'c:/Program Files (x86)/Notepad++/notepad++.exe'. Please supply the message using either -m or -F option.
I think the trouble is due to how git is parsing the path of the editor, namely that it is seeing the spaces as argument separators. The problem can be fixed by placing an extra set of quotes around the editor path like so:
'"c:/Program Files (x86)/Notepad++/Notepad++.exe"'
Git will now see the editor path as one parameter.

One extra note, Notepad++ has lots of extra features that are nice when working on a project, but these can be a nuisance when editing your commit messages. The biggest offender is that by default Notepad++ will restore your session and open the commit message in a new tab. To prevent this default behavior some extra command line parameters are required. My final statement to configure the git editor is:
$ git config --global core.editor '"c:/Program Files (x86)/Notepad++/notepad++.exe" -multiInst -notabbar -nosession -noPlugin "$*"'
Note: the "$*" argument tells bash where to place the arguments from GIT. More on special bash arguments here.

Happy GITing!

Motivate!

This blog has been on my list of things to tackle for a while.  In essence, I am thinking that this blog will be half notebook half informational walk-throughs.  As I venture down the road of new (to me) technologies, I'm sure I will encounter a number of obstacles along the way.  My plan is to record these obstacles here, as well as the solutions to surmount those obstacles.  Perhaps others will find this information useful, but if not I will certainly be happy to have it to look back on.  Off to my first post!