Getting Started | Lesson 1 | Lesson 2 | Lesson 3 | Lesson 4 | Lesson 5 | Hardware

Lesson 1 - Testing and Calibrating Your Hardware

Introduction

Because hardware differs from robot to robot (specifically the RC oscillator in the ATmega8 and servo motor in the Mini-Z platform), it is necessary to do some calibration on each robot.

Programming the Fuse Bits

If we ever come up with a way to make these Motorboards for you, this step might not be necessary. For now however, it is required that you manually program the fuse bits.
	uisp -dprog=dapa --rd_fuses
	uisp -dprog=dapa --wr_fuse_h=0xd1
	uisp -dprog=dapa --wr_fuse_l=0xe2
	uisp -dprog=dapa --rd_fuses
-dprog=dapa means tht you are programming over the parallel port and you should add a -dlpt=3 if using an IBM Thinkpad. The high fuse byte command will assure that the EEPROM is preserved during reprogramming and the low byte sets the internal RC oscillator to 2MHz. Reading the fuse bits afterwards allows you to check that things have changed.

Auto Calibration

I'm currently working on a program that will automatically calibrate the clock and servo for you and will post things here when it is completed.

Setting up Communication Between the MotorBoard and Mica Mote

Currently, the two boards communicate using the UART, although I2C is also available. Unfortunately, both the current version of the motorboard and the mica motes lack pull-up resistors (about 10k or so) required on the SDA and SCL lines for I2C to work. In addition, we are using the internal RC oscillator on the ATmega8 -- not a wise choice in hindsight. The internal oscillator requires a calibration constant to become accurate enough for the UART to function properly -- this is done through loading a value in the on-chip EEPROM which is read on startup in contrib/cotsbots/tos/platform/atmega8/RealMain.nc. The calibration constant should be around 173, although this can change from chip to chip -- I haven't noticed changes more than +/- 2 on the ATmega8s I've programmed. To program this value into the EEPROM manually, do the following:
	uisp -dprog=dapa --terminal
	ss eeprom
	du 0
	wr 0 0xad
	du 0
This starts the uisp terminal program and switches to the EEPROM memory segment. The "wr 0 0xad" command is where you will set the calibration constant because RealMain.nc reads the calibration constant from address 0. "du 0" at the end allows you to view your changes.

You could also plug in the value you'd like into RealMain.nc directly, but as it changes from motorboard to motorboard, I though this was cleaner. Make sure you take care in doing this otherwise, you could screw up your processor and you won't be able to talk to it.

Adjusting the Servo

This is only critical on the Mini-Z platform for now. If you managed to drive your Mini-Z around before cannabalizing it, you probably noticed that in order to make it go straight, you had to adjust a "trim" knob on the controller. This is true for most RC cars in fact. We have to do the same thing electronically.

First, some background on how a servo works so that you understand exactly what we're doing. A servo is essentially a motor, with a potentiometer (variable resistor) on the shaft. As the motor turns, the resistance from the pot changes. We have the leads from this variable resistor in a resistor-divider network (picture at right). This voltage is read into the ADC on the ATmega8 and gives us the current position of the wheels.

We will put a value in the EEPROM for the straight value now. I've seen values ranging from 45 to 130 for "straight", but it should be pretty obvious where you lie on the spectrum. A lower value is left and a higher value moves right. The EEPROM address for "straight" is at 12.
	uisp -dprog=dapa --terminal
	ss eeprom
	du 0
	wr 12 0x30
	du 0
In order to turn, there is a PI (Proportional-Integral) control loop wrapped around this. You can modify the constants used in this control loop -- Kp (address 10) modifies the current error and Ki (address 11) modifies the integrated error.
	uisp -dprog=dapa --terminal
	ss eeprom
	du 0
	wr 10 0x50
	wr 11 0x0a
	du 0
Later, you will see how to adjust these settings using the RobotCmdGUI.

Go to Lesson 2