24 Feb 2013

Example using getopt from C


// $Id$

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>

struct opt_t {
 char* opt;
 char* arg;
};

int opt_parse(int argc, char *argv[], const char * optstring) {

 //Specifying the expected options
 //The two options l and b expect numbers as argument
 while ((option = getopt(argc, argv, optstring /*"apl:b:"*/)) != -1) {
  switch (option) {
   case 'd':
    printf("Database: %s\n", optarg);
    break;
   default: 
     printf("Huh?"); 
    return EXIT_FAILURE;
  }
 }
 
 return 0;
}

int main(int argc, char** argv) {
 const char* opts = "d:";
 
 int r = opt_parse(argc, argv, opts);
 
 return r;
}

13 Feb 2013

Problems programming ATtiny85 from Arduino IDE

After several successful firmware uploads from the Arduino IDE via Arduino Uno as ISP programmer to an ATtiny85 it suddenly stopped to work.

I have not figured out why this happens, a friend of mine has the same problem and couldn't find what caused it neither.

Long story short, the work around is to use Arduino IDE to compile the sketch and avrdude directly to do the uploading.

Compiling

Compiling code for ATtiny85/45 in Arduino IDE requires that the hardware definitions of these chips are installed in Arduino IDE:

Once the code is compiled it can be found in /tmp/build[0-9]*.tmp/*.hex on a *nix platform (C:\Windows\temp\... probably on windows, check the Arduino IDE manual).

Once the location of the hex file is known, I copy it to a safe place (data in the temp folder are purged occasionally).

Arduino as ISP

I am using Arduino Uno as programmer. For this wot work the arduino must be flashed with an already available sketch called: ArduinoISP (found under Examples).

Once this sketch is uploaded, the Arduino Uno works as In System Programmer and can be hooked up to your ATtiny device. The Arduino Uno is the used as "bridge" between your USB port on the computer and the tiny, as well as power supply.


Uploading

Using avrdude with the following parameters worked out of the box for me on a virgin ATTiny85 from linux:
$ avrdude -P /dev/ttyACM0 -p t85 -c avrisp -b 19200 \
          -v -F -U flash:w:pulse_in.cpp.hex



4 Feb 2013

nag-o-meter



This is our new status display of the Service Monitoring System I have built up during the last years. My cow-orkers keep forgetting to act upon warnings. I thought I could add some extra motivation for fixing errors in a timely manner (note the nice sound it makes :) ).

A little bit of python, a little bit of *nix voodoo glued together with a bash script - done.



APM log analysis



I personally prefer to use mavproxy and it's example utilities (such as mavgraph.py). It should be ported to windows by now. More info about mavproxy on diydrones.com.

Randy Mackay made some nice instructional videos on analyzing APM log files with Mission Planner and Microsoft Excel (basically any spreadsheet tool will do as long as it understands delimited text files).

First, the onboard logs are always available except if the APM is destroyed, for example, in a crash. This video shows how to analyse the onboard logs of an ArduPilot Mega board:


For those new to APM, Randy explains in more detail how to obtain the onboard logs of an APM 2.5. Make sure to connect your APM board via USB to the computer and you might use APM Mission planner to download the onboard logs:


Telemetry log files (*.tlog) provide much more information than onboard logs. The telemetry logs can be analysed in Mission Planner as well. Here a short overview on ho to work with tlogs in mission planner: