How to program OpenServo with the OSIF Interface

We need people to help document their processes here. The SPI First Time Firmware updating section needs documentation.

Summary

There are two ways to use the OSIF interface to upload firmware into a OSV3 based servo. There is one way that is required for uploading firmware to a blank OSV3, and there is a method for uploading updated firmware when the servo is in normal operation. The initial firmware installs a boot loader, that allows you to bootstrap the OSV3. Once this boot loader is installed, you can tell the OSV3 to enter a different mode which allows for features not found in the normal operation mode, like flashing the firmware.

If you purchased your OSV3 from Robotfuzz, he has already installed the initial firmware, and you can do any future updates with a normal I2C harness. However if you built your own OSV3 and need to get the boot loader installed, you will need to make a programming cable.

Bootstrapping is the action of flashing the AVR on the OpenServo board with it's initial bootloader firmware. This allows a small program to run before the servo enterer's into normal operation. This small program, will allow you to do some special tasks like uploading new firmware to the servo and updating it via I2C bus.

First Time Firmware Installation

If you purchased an OpenServo from Robotfuzz, it already has it's initial bootloader installed and this section has no importance. All further updates can be done from the next section, Updating Firmware via I2C and Boot Strap. If you assembled your own board, or are certain that it did not come with it's own firmware installed (talked to the person you bought it from), then use the steps below.

"Detail SPI firmware process here"

The SPI programming wiring harness pin out is listed below.

OSIF --> OpenServo

  1. SDA/RESET --to-- 3 Reset

  2. +V --to-- 1,2 VBatt +6V

  3. GND --to-- 5,7,9,10 GND

  4. SCL/SCK --to-- 6 SCK (SCL)

  5. +5V --to-- Not connected

  6. RESET --to-- Not connected

  7. MISO --to-- 4 MISO

  8. MOSI --to-- 8 SDA (MOSI)

Updating Firmware via I2C and Boot Strap

From the openservointerface Linux/Windows application, you can flash the OSV3 easily. From the GUI, click the picture of the three dots (next to the flash button), and then browse your computer for the desired firmware (.hex file). When you have selected the firmware, click the "Flash" button. When the upgrade is complete, you will see confirmation that the upgrade went successfully.

For instructions on compiling the firmware, visit the Firmware Installation Guide

When the "Flash" button is pressed, it triggers a reset of the OSV3 board and then waits .5 seconds before sending the file through the I2C bus to the board.

Make sure to keep power supply constant to the motor during a firmware update and do not unplug and cable during this or your device will go into "7f" mode (see below). If you do go into 7f mode, follow the instructions below to get out.

See the layout below for making a normal connector between the OSIF and the Openservo. Unless you have an unused, blank board, this harness will work for everything you need to do including "7f" firmware flashing.

OSIF --> OpenServo

  1. SDA/RESET --to-- 3, 8 SDA (MOSI)

  2. +V --to-- 1,2 VBatt +6V min +7.5 max (typical motor max)

  3. GND --to-- 5, 7, 9,10 GND

  4. SCL/SCK --to-- 6 SCK (SCL)

  5. +5V --to-- Not connected

  6. RESET --to-- Not connected

  7. MISO --to-- Not connected

  8. MOSI --to-- Not connected

Using openservointerface Application with Ubuntu 10.04 (Lucid Lynx)

After setting up the connector cable, you can now connect the OSIF to the OSV3 and the computer. A good way to test the two of them is by using the openservointerface application included in the CVS repository. To install the application, follow the commands below for assembling the software in Ubuntu. This method has been tested in Ubuntu 10.04, but probably works with other versions of Linux. Please try this method and add other versions below if they work. Installing Supporting Packages (Note version numbers may change, and as such, using Synaptic Package Manager is preferred.)

$ sudo apt-get install libusb-1.0-0 libusb-dev libusb 0.1-4 libusb-1.0-0-dev

$ sudo apt-get install libqt3-compat-headers libqt3-headers libqt3-mt-dev qt3-dev-tools qt3-qtconfig

Note that the above version of QT is version 3. The GUI was designed in QT three and compatability has not been tested by compiling with QT 4, however, with the libqt4-qt3support package, you should be able to build the file with your existing QT 4 installation.

$ sudo apt-get install gcc gcc-avr avrdude gdb-avr usbprog usbprog-gui

You will note that there are a lot of packages, however, I ran into problems from having too few packages installed, and as such, I advocate just installing all of these.

Now it is time to get a copy of the OpenServo CVS repository.

$ cvs -d:pserver: anonymous@openservo.com :/openservo login blank password
$ cvs -d:pserver: anonymous@openservo.com :/openservo login co OpenServo

If you have problems with the cvs, see http://www.openservo.com/Software for more information

Now install the shared library.

$ cd OpenServo/Interfaces/OpenServo_Interface/driver/Version_2/dll
$ gedit osif.c

Make changes detailed in the patch attached to this page. http://www.openservo.com/Forums/viewtopic.php?t=989

$ make
$ cp libOSIFlib.so.* /usr/lib/view

Now build the GUI. You might have to change the directory depending on your QT installation.

$ cd ../../../Applications/OpenServo_Control
$ /usr/bin/qmake-qt3
$ nano Makefile

Add "/usr/bin/qmake-qt3" to the qmake line and then save.

$ make

Now we build the kernel module for I2C Communications.

$ cd ../../driver/Version_2/kernel
$ make
$ sudo insmod osif.ko

Now, its time to run the application.

$ cd ../../../Applications/OpenServo_Control/bin
$ sudo ./openservointerface

You must use sudo when running the application or else libusb will not work.

Once you are running the application, you can must first tune your PID settings. By default, they are set to zero and thus, the motor will not move until the P+D (I if you are using V3-experimental branch of the firmware) have been set. For more information on setting the P(I)D, visit, http://openservo.com/ConfigPID.

Using openservointerface Application with CentOS 5

So now you have the it physically setup with a harness. Now how do you click the "flash" button in the openservointerface? Here's how I did it with CentOS 5.

To install the openservointerface for use with the OSIF device, I first install these packages with this command as root.

I then changed to the directory where I want to install. Now get a copy of the OpenServo files

Then make and install the shared libary

If the object file does not compile and you are using a new linux kernel (newer than 2.6.31), you might have to patch the osif.c file. The patch is attached to the page. http://www.openservo.com/Forums/viewtopic.php?t=989

Note CentOS doesn't correct the path when you install qt, so you have to use the full path. Also use nano or your favorite text editor to add the path to the make file. It's called for a couple lines down from the top of the file. Add the path before qmake.

Now it's time to build the a kernel module for the I2C comms.

I didn't see it under /dev, I also didn't get any error messages. Hhhmmm, well lets try it out and hope for the best.

Hmmm, seems to work, so I guess I'm good. I plugged in the OSIF, then a 9V battery, and connected the OSIF and OSV3 with a 4 wire harness. I flashed the memory and got a verified note. So I guess it's working well.

Re-Flashing from 7f Mode in Windows (XP SP2)

When you see address 7f it means you are in bootloader, and you should be able to upload some new firmware. If you download the OSIF windows drivers, there is a testapp.exe included in the Version 1 driver folder that can be used to re-flash the OpenServo using the following command.

testapp flash 0x7f file_to_flash.hex

When flashing through testapp.exe, use the "Normal Operation" 4 wire harness.

See these threads for more help: http://www.openservo.com/Forums/viewtopic.php?t=1038 http://www.openservo.com/Forums/viewtopic.php?t=1039