Microb Technology/2008/Main code/Protocols

De Wikidroids

Sommaire

Communication protocols between main AVR and camera

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 balls"


CAM -> AVR : the response frame


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

struct hole { 
  uint8_t flags;
  uint8_t distance;   /* cm */
  int8_t  angle;      /* degrees: 0° -> 0x80 */
} __attribute__((packed))

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

CAM_COLOR_BLUE              1 /* set if the ball color is blue */
CAM_COLOR_RED               2 /* set if the ball color is red */
CAM_WHITE_BALL              4 /* set if the ball color is white */
CAM_END_FRAME             128 /* set if there is no more ball in the frame */ 

The position of the ball is relative to the robot. The holes should be ordered by distance (and angle ?) in the frame, starting from the closer one, or the most accessible.


Example :

0x00,     0x01, 0x10, 0x85,       0x02, 0x23, 0x93,           0x04, 0x25, 0x7E,      0x80

start     a blue ball             a red ball                  a white                last item
          at (16cm, 5°)           at (35cm, 18°)              at (37cm, -2°)
                                                              end of frame

We don't want to have any 0x00 bytes in the frame (except the start byte). This means that:

  • flags are always != 0 (the ball needs a color, or it is the end flag)
  • distance is != 0 and <= 255 cm
  • -127° <= angle <= 127°

Communication protocols between main AVR and extension AVR

The protocol is a bit deprecated here, refer to the i2c_commands.h file to get the last version.

Summary

We want to have the following commands/status:

  • Harvest balls from area
  • Pick up balls from dispensers
  • Prepare a shoot for a specified color
  • Prepare a drop for a specified color
  • Get white ball count
  • Get red/blue ball count
  • Get status

Status details

Only one status is needed that can report all informations. It will be implemented as a request/answer as defined in our i2c documentation.

struct i2c_req_extension_status {
	struct i2c_cmd_hdr hdr;
};
#define I2C_EXTENSION_STATUS_HARVESTING             0 /* harvesting from area */
#define I2C_EXTENSION_STATUS_PICKING_UP             1 /* picking up from dispenser */
#define I2C_EXTENSION_STATUS_DROP_READY             2 /* ready to drop a ball */
#define I2C_EXTENSION_STATUS_BUSY                   3 /* system is busy */
struct i2c_ans_extension_status {
	struct i2c_cmd_hdr hdr;
	uint8_t state;
	uint8_t white_ball_count;
	uint8_t colored_ball_count;
};

The state field value is one of the above defined macros. The white_ball_count and colored_ball_count contains the number of balls in the robot.

Commands details

One command is needed. The cmd field can take one of the values below. The roller_speed and roller_angle arguments are ignored the cmd field is not I2C_EXTENSION_COMMAND_PREPARE_*.

#define I2C_EXTENSION_COMMAND_HARVEST         0 /* harvest from area */
#define I2C_EXTENSION_COMMAND_PICKUP          1 /* pick up from dispenser */
#define I2C_EXTENSION_COMMAND_PREPARE_WHITE   2 /* prepare a white ball drop and set roller */
#define I2C_EXTENSION_COMMAND_PREPARE_COLORED 3 /* prepare a colored ball drop and set roller */
#define I2C_EXTENSION_COMMAND_DROP            4 /* drop ball */
struct i2c_cmd_extension {
	struct i2c_cmd_hdr hdr;
	uint8_t cmd;
	uint8_t roller_speed;
	uint8_t roller_angle;
};

Example

  • Tell to harvest (I2C_EXTENSION_COMMAND_HARVEST)
  • When we get a ball, we know it because the status is polled periodically
  • If we got a bad ball, it is automatically dropped, the main board is notified (I2C_EXTENSION_STATUS_BUSY) but we can ignore it.
  • If we got a correct colored ball, we can tell to prepare to shot, using I2C_EXTENSION_COMMAND_PREPARE_COLORED. This will also set the parameters for the roller.
  • When the robot is placed to shot, it has to wait I2C_EXTENSION_STATUS_DROP_READY. This mean that the ball is correctly placed in the system and that the roller configuration is fine.
  • Then we send I2C_EXTENSION_COMMAND_DROP. This will stop the roller automatically and go back in I2C_EXTENSION_STATUS_HARVESTING.
Boîte à outils
LANGUAGES