A continuous loop with a frequency of 100 Hz is executed by the standard firmware. That means, every 10 msec the following actions are achieved by the main C167 using the CAN bus:
The optional second C167 executes a loop with the same frequency, regarding the sensors that are attached to it:
Hence, a control program executed by the PC system may receive all appropriate sensor values and supply motor commands according to desired behaviors without taking care of the very low level details of microcontroller programming.
If the microcontroller eventually receives no new messages from the PC, e.g. because of a disconnected CAN bus, all motors are stopped for security reasons.
There are two types of CAN messages used within the system:
Motor control messages always have CAN Id. 1 and are discriminated by the first two bytes of the data frame defining the control-mode. Motor control messages have to be sent by the PC system which controls the robot. In contrast to former versions of this firmware, no remote frames are used for this or any other purpopse.
Sensor messages have a CAN Id. > 4. They are continuously sent by the microcontroller. CAN Id.s > 15 are used by the optional second microcontroller.
CAN Id. | Data Format | Description |
---|---|---|
0 | - | reserved (don't use) |
1 | short control_mode, byte[6] settings | motor control (depending on control-mode) |
2 | - | reserved (don't use) |
3 | - | reserved (don't use) |
4 | - | reserved (don't use) |
5 | short adc_00, adc_01, adc_02, adc_03 | analog input channels 0 - 3 (10 bit): sonar sensor 0 - 3 |
6 | short adc_04, adc_05, adc_06, adc_07 | analog input channels 4 - 7 (10 bit): sonar sensor 4 - 7 |
7 | short adc_08, adc_09, adc_10, adc_11 | analog input channels 8 - 11 (10 bit): sonar sensor 8 - 9, tilt sensor value 1 and value 2 |
8 | short adc_12, adc_13, adc_14, adc_15 | analog input channels 12 - 15 (10 bit): motor current right and left, compass curve 1 and curve 2 |
9 | short encoder_left, encoder_right | motor encoder left and right |
10 | char bumpers, rc | bumper and remote control states |
11 | - | reserved (don't use) |
12 | - | reserved (don't use) |
13 | - | reserved (don't use) |
14 | - | reserved (don't use) |
15 | - | reserved (don't use) |
16 | - | reserved (don't use) |
17 | - | reserved (don't use) |
18 | - | reserved (don't use) |
19 | - | reserved (don't use) |
20 | - | reserved (don't use) |
21 | short adc_00, adc_01, adc_02, adc_03 | analog input channels 0 - 3 (10 bit) |
22 | short adc_04, adc_05, adc_06, adc_07 | analog input channels 4 - 7 (10 bit) |
23 | short adc_08, adc_09, adc_10, adc_11 | analog input channels 8 - 11 (10 bit) |
24 | short adc_12, adc_13, adc_14, adc_15 | analog input channels 12 - 15 (10 bit) |
25 | - | reserved (don't use) |
26 | - | reserved (don't use) |
27 | - | reserved (don't use) |
28 | - | reserved (don't use) |
29 | - | reserved (don't use) |
30 | - | reserved (don't use) |
31 | - | reserved (don't use) |
The motors are controlled by a single CAN message depending on the selected control mode.
RAW control-mode: The two motors are controlled by three parameters: direction of rotation, brake (switch motor on or off), and pulse width (similar to voltage). Direction is controlled by one bit, where '0' means "forward" and '1' means "back". Brake is controlled by another bit, where '0' means "brake off" (i.e. actually drive) and '1' means "brake on". Pulse width for left and right motor may be set separately to a value between 0 and 1024, where the meaning of 0 is "full power", 256 is corresponding to a duty cycle of 75 %, 512 is corresponding to a duty cycle of 50 %, and the meaning of 1024 is "no power at all". The intermediate values are treated in an analogous manner. This definition is in direct accordance with the operation of the C167's pulse width modulation module as described in chapter 15 of [1].
SPEED control-mode: The speed for left and right motor may be set separately to a value between -100 and +100, where the meaning of -100 is maximum speed back, 0 means no speed at all, and the meaning of +100 is maximum speed forward. The intermediate values are treated in an analogous manner. The desired speed will be maintained by the microcontroller.
The current values of sonar sensors 0 - 3 (attached to channels 0 - 3 of the C167's analog/digital converter, resolution: 10 bit) are transmitted in 4 groups of 2 bytes.
The current values of sonar sensors 4 - 7 (attached to channels 4 - 7 of the C167's analog/digital converter, resolution: 10 bit) are transmitted in 4 groups of 2 bytes.
The current values of sonar sensors 8 - 9 (attached to channels 8 - 9 of the C167's analog/digital converter, resolution: 10 bit) are transmitted in 2 groups of 2 bytes, followed by the tilt sensor's value 1 and value 2.
The current values of the left and right motor's current sensors (attached to channels 12 -13 of the C167's analog/digital converter, resolution: 10 bit) are transmitted in 2 groups of 2 bytes, followed by the current values of the compass sensor's curve 1 and curve 2 [2]. The actual direction may be computed by applying a formula of the type: dir = ((pi + atan2(curve1, curve2)) * 180) / pi
The current values of the left and right motor's encoders are transmitted in 2 groups of 2 bytes, meaning number of encoder signals per 100 msec.
The current state of bumpers 0 - 5 is transmitted in a single byte, containing '0' at the corresponding bit position if the bumper is pressed and '1' otherwise, i.e. 0x3F means "no bumper is pressed". The current state of the remote control's buttons 0 - 7 is transmitted in a single byte, containing '0' at the corresponding bit position if the button is pressed and '1' otherwise, i.e. 0xFF means "no button is pressed".
The current values of the analog sensors 0 - 3 (attached to channels 0 - 3 of the optional second C167's analog/digital converter, resolution: 10 bit) are transmitted in 4 groups of 2 bytes.
The current values of the analog sensors 4 - 7 (attached to channels 4 - 7 of the optional second C167's analog/digital converter, resolution: 10 bit) are transmitted in 4 groups of 2 bytes.
The current values of the analog sensors 8 - 11 (attached to channels 8 - 11 of the optional second C167's analog/digital converter, resolution: 10 bit) are transmitted in 4 groups of 2 bytes.
The current values of the analog sensors 12 - 15 (attached to channels 12 - 15 of the optional second C167's analog/digital converter, resolution: 10 bit) are transmitted in 4 groups of 2 bytes.
[1] | Infineon: C167 Derivatives, 16-Bit Single-Chip Microcontroller. User's Manual V 3.1, 2000-03 |
[2] | PEWATRON: Analog & digital hall effect compass sensor model 6070 (data sheet) |
$Id: kurt2167.htm,v 1.2 2002/03/13 12:29:34 worst Exp $