Downloadable .pdf version is available on the Downloads page
This document describes how to use the robot controller circuit board. The description covers two aspects:
It is strongly recommended to read the following chapters in the Technical Design Document:
Board overview and connectors
The board includes two Atmel ATmega 168 microcontrollers (MCUs). The top MCU is the Robot Controller, which contains all the robot control software. This MCU generates the timer values for the servo motor control pulses (see Tech doc section), and transfers these values over an SPI interface to the other MCU, the Pulse Controller AVR, whose task is to receive and process these timer values and generate the physical pulses at the servo motor connectors.
Figur 1 shows an overview of the board and its connectors.
How to configure and program the Robot Controller
The implementation of robot functions is done on the Robot Controller AVR, the upper AVR in Figur 1, with the standard Atmel toolchain and an ISP programmer. Connect the programmer to the upper AVR SPI connector. The other AVR (Pulse Controller) needs normally not be programmed.
Project and folder structure
The software consists of two separate Atmel Studio projects. The #include statements in the source files require the projects to be under the same main projects folder, and named as shown in Figur 2.
Under each project folder, the files are organized as Atmel Studio projects.
Installing the AVR software
Install the software on each of the AVRs using a programmer connected to the AVR ISP connector (the two AVR ISP connectors are aligned with its corresponding AVR).
Make sure that the software is installed as follows:
The clock speed should be set to 20MHz, by clearing the CKDIV8 fuse, and setting the SUT_CHKSEL fuse as shown in Figur 3.
Programming the Robot Controller
This section describes how to program the Robot Controller AVR. It is strongly recommended to read the following chapters in the Technical Design Document:
Writing robot functions
Programming the Robot Controller is based on writing functions that generate or update the timer values in microseconds, that correspond to the duration of the servo control pulses. These, in turn, correspond to the angular positions of each servo.
The robot functions are called in a timer based ISR every 20ms, to correspond to the period of the servo control pulses. To achieve this, the robot functions must be called directly from within the ISR. Suggested placement for calling robot functions is indicated by comments in the ISR(SPI_STC_vect) ISR, which is called every 20ms.
The programming interface is described in detail in the Technical Design document, but in summary, the main steps for programming the Robot Controller AVR is as follows:
An array of type struct, is defined, containing the following parameters for each servo:
The struct is defined as shown in Figur 5.
The user-written robot functions will generally be updating the position and step (if used), and then writing the updated values to the array input_register . Once the updated timer values are written to this array, they will be automatically transmitted to the Pulse Controller AVR on the next invocation of the ISR(SPI_STC_vect) ISR.
Initializing the position of the servo motors
The initial position of each servo can be defined in the function init_servo_values(). For each servo there is a section where the parameters can be in initialized, see Figur 6. Note that the max and min values can be defined by #define in the Robot.h header file. The scale parameter is automatically calculated, and needs normally not be changed by the robot programmer.
Note that when powering up the circuit, the servos are initialized, one by one, to their physical positions, to avoid large current surges. This is done by the function init_servo_position() called from the ISR(SPI_STC_vect) ISR.
Controlling servo position or speed using external potentiometers
ADC channels 0 – 5 are initialized in init_r(), and three functions are provided for setting the position or speed (using the .step parameter described above). The functions are:
Enabling or disabling individual servo motors
Individual servo motors can be enabled or disabled using the uint8_t servo_mask array. This array contains bit masks, one for each shift register. A ‘1’ in the bit pattern means that the corresponding servo is enabled, while a ‘0’ means that it is disabled. The values in the servo_mask array is transmitted to the Pulse Controller AVR in the input_register array along with all the timer values.