Microb Technology/2006/Protocols

De Wikidroids

Communication AVR ATMega 128 <-> CAM

The dialog is bidirectionnal. Here is the sequence of a communication :

  • The AVR sends a request to the camera.
  • The camera replies


AVR -> CAM : the request frame

The frame is composed of 1 uniq character. The value of this byte is 0x00, it means "The AVR requests the position and the status of the holes"


CAM -> AVR : the response frame


The frame starts with a 0x00, then follows a list of structures like the one below :

struct hole { 
  unsigned char flags;
  unsigned char distance;   /* cm */
  char angle;               /* degrees */
} __attribute__((packed))

The camera DSP tries to set the following flags in the structure.

HOLE                    1 /* set if it is a hole (0 is it is only a ball) */
COLOR_RED               2 /* set if color is red (only for holes) */
BALL                    4 /* set if there is a ball in the hole, or if it is a ball only  *
WHITE_BALL              8 /* set if the ball is white */
LAST_ITEM              16 /* set if there is no more hole coming in the frame */ 
ALWAYS_ONE             32 /* always set to one, to avoid emitting 0x00 (start of frame) */

The position of the hole is relative to the robot. The holes should be ordered by distance in the frame, starting from the closer one.


Example :

0x00,     0x25, 0x10, 0x05,       0x23, 0x23, 0x13,           0x31, 0x25, 0xFE

start     a blue hole             a red hole                  a blue hole     
          filled with a           empty                       empty
          black ball              at (35cm, 18°)              at (37cm, -2°)
          at (16cm, 5°)                                       end of frame


Communication AVR ATMega 128 <-> PC

We can choose between two kind of communications between the robot and the PC : they don't have the same objectives.

Menu

The first type of communication (we won't detail it here) is a simple menu interface, used to configure and debug the robot from a serial terminal.

Pyroman (PYthon RObot huMAN interface

The second type of communication is a binary unidirectionnal flow of data. The goal of this interface is to send debug informations from the robot to the PC, and to display these informations on a cool interface.

For instance, the robot will send its position through the serial line to the PC, and the PC will display a 3D area, and the robot at the specified position. We will do the same for hole status, balls...

Here is a first screen shot of the area (the program is done by serpilliere) :

Pyroman1.jpg


Structure of a frame

START = 0xAA         (1 byte)     indicate the beginning of the frame
TYPE                 (1 byte)     type of information, also fixes the size
DATA                 (X bytes)    data, depending on type. Don't contain any 0xAA (see below).

If data contain a 0xAA, we cannot emit it since it means START OF FRAME.

  • To emit a 0xAA, we emit two bytes : 0x55 0xA5
  • To emit a 0x55, we emit two bytes : 0x55 0x5A

Frame types

  • Position : type=0x01, data=( s16 x_cm, s16 y_cm, s16 a_deg )
  • Totem arrangement : type=0x02, data=( u08 arrangement_num )


Communication AVR ATMega 128 <-> AVR ATMega32

This communication will be done over i2c.

ATMega32 -> ATMega 128

The role of ATMega32 will be to manage the balls in the robot. So the communication between atm128 and atm32 will be quite simple (number of balls, color, ...). The ATMega 32 tries to get the maximum number of balls, and keeps them in the robot until it gets a command from the ATMega 128.

  • Status register : tell if there is an available ball and if is black or white.
u08 status; /* status is a bit field (see values below) */
BALL_IS_READY             1  /* set if there is at least one ready ball */
BALL_IS_WHITE             2  /* set if the ready ball is white */
HAVE_SEVERAL_BALLS        4  /* set if there is more than one ball in the system */
EVACUATION_SYSTEM_IS_BUSY 8  /* set if the evacuation system if busy, so we cannot resuck a ball */
SYSTEM_BUSY               16 /* set if any action is runnning */

ATMega128 -> ATMega 32

The ATMega 128 is the "brain" of the robot. It decides the actions to do. It asks the ATMega32 if it has stored ball, and tell it to drop them in hole, or eject them from the system. The ATMega 128 can also decide to suck a ball from a hole.

u08 command; /* command is a number that defines a command */
LAYDOWN_BALL 0x01
EJECT_BALL   0x02
RESUCK_BALL  0x03
Boîte à outils
LANGUAGES