User ObjectIndex

Overview

NOTE:

This is a new feature in Build 23.

The User Object provides a method for implementing custom IO operations within the structure of the Garcia API.  A user may set various fields in the User Object to define a command that will be sent to one of the BrainStem processors in the robot or another I2C device.  Additional fields specify how a reply will be handled.

Accessing the User Object

The User Object has the following name:

If the Garcia API object is named garcia then placing the following line of code in an application will retrieve a pointer to the user object:

Example 1, Reading from a BrainStem

The following program fragment will issue a cmdPAD_IO command to read scratch pad byte 29 from module 2, the GP 2.0 processor in the Garcia robot.  The expected reply begins with the cmdPAD_IO code.  A timeout of 1000ms is specified for the reply.

Example 2, Transmitting to an I2C Device

The following program fragment will issue a command to send two bytes to an I2C device with an address of 0xC0.  No reply is expected.  Such an operation could be used to send characters to an LCD screen with an I2C interface.

Example 3, Reading from an I2C Device

The following program fragment will read the version info from an SRF08 ranger with an address of 0xE0.  First, a value of 0 is written to the device to set the read address register.  This is the address for reading the version info.  Then a cmdIIC_RD command is sent to read one byte.  The reply is a cmdDEV_VAL packet.  A timeout value of 500ms is sufficient.  If the robot receives a reply, the reply will be stored in the data buffer.

Example 4, IO with Serial Relay Stream

Another new feature in Build 23 is support for serial relay streams.  When the Moto processor is configured as a serial relay, its free serial port can be connected to a device with a serial interface.  That serial device can receive data from the API and send data back to the API.  The following program fragment will transmit the character 'A' to a device connected to the Moto processor's serial port and wait for 12 characters in response.  The cmdVAL_SET command can configure the Moto processor to act as a serial relay.  Data transmitted by the API to the serial device must be wrapped in cmdSER_RELAY commands.  This command can only transmit 7 bytes at a time so multiple commands must be used to transmit more bytes.

Property Inheritance

User Object inherits Object properties.

Properties
module
size
filter-byte
timeout
data-ptr
result

module (int)

Address of the BrainStem module or I2C device that will receive a command.  Can be even numbers in the range from 0x02 to 0xFE.


size (int)

The number of command data bytes to send.  Can range from 1 to 8.  This is the size limit for commands used by the BrainStem processors in the Garcia robot.  A command packet sent across the serial link includes an address byte and data size byte.  The size property of the User Object should not include those two additional bytes.


filter-byte (int)

The value of the first data byte in an expected reply.  A value of 0 indicates that no reply is expected.


timeout (int)

The time limit in milliseconds for a reply to be received.  A timeout of 0 will make the program wait indefinitely for a reply.  A reply timeout is only applied when the filter-byte is non-zero.


data-ptr (voidptr)

Pointer to a data buffer that contains the command bytes that will be transmitted.  Reply bytes will also be stored in this buffer and overwrite any command bytes that had been stored there previously.  When sending another command after receiving a reply, it will be necessary to reinitialize the data buffer.


result (int)

Result of the IO operation.  Reading the result property initiates transmission of the command in the data buffer and reception of a reply if one is expected.  The value will be the result of the IO operation.  Result and error codes are listed in the aErr.h file in the aInclude folder in the Garcia software distribution.


version: 1.0, build 81007
© Copyright 1994-2008 Acroname, Inc., Boulder, Colorado.  All rights reserved.