C ONSENSUS OF M ULTI - AGENT S YSTEMS IN P RESENCE C OMMUNICATION L OSS
3.7 Implementation on Hardware
3.7.3 Robot motion
Motion control of Patrolbot is done using C++ script with ARIA library functions, installed on a laptop. The user has to define the velocity, heading etc., with the help of ARIA classes in the script. All the low-level functions like speed control, heading control etc., are taken care of by the µARCS microcontroller, which communicates with laptop through serial port.
Patrolbot is equipped with high resolution quadrature encoders for the accurate measurement of position,µARCS and ARIA calculate the precise value of velocity. Localization is achieved
using dead-reckoning principle with initial conditions provided.
The other two robots are controlled using Beaglebone Black (BBB) loaded with Ubuntu- 14.04. The BBB is equipped with main processor (1GHz ARM cortex A-8) and two axillary microcontrollers (Programmable real time units). Sending motion control signals to the drivers and communication with other robots are performed by using a C script, which runs in the OS on ARM processor. General Purpose Input Output (GPIO) pins, PWM are enabled using Device-trees during run time since, standard linux kernel doesn’t define all the input-output pins. Device-trees can be very useful if we want to deploy pins for different purposes at different occasions. For example some pins on BBB can be defined as GPIOs or PWM outputs or PRU IOs based on mode definition given in system reference manual.
A Device-tree is defined as per pin configuration given in Table 3.3. Few pins can be used without explicitly defining in the Device-tree. The Device-tree files corresponding to those pins are provided with Ubuntu OS image tailored for Beaglebone Black. Some of them are given in Table 3.4.
Table. 3.3: Device tree pin description
Pin Mode Pin usage
P9 11 GPIO fast output pulldown Right motor control signal B1 P9 12 GPIO fast output pulldown Right motor control signal B2 P9 17 GPIO fast output pulldown Left motor control signal A1 P9 18 GPIO fast output pulldown Left motor control signal A2 P9 24 PRU0 input Left wheel encoder sensor signal P9 25 PRU0 input Right wheel encoder sensor signal
Table. 3.4: Pins used but not defined in device tree
Pin Name Pin usage
P8 19 EHRPWM2A Left motor pwm signal
P9 1 GND Ground terminal
P9 3 DC 3.3V 3.3V Reference voltage for level shifters
P9 21 EHRPWM0B Right motor pwm signal
Based on motor driver data sheet, appropriate frequency (5KHz) and duty ratio are assigned from host C-script to both the PWM pins. Direction of motor shaft rotation is controlled using control signals A1, A2, B1 and B2 from host C-script which follow the logic given in Tables 3.5
and 3.6.
Table. 3.5: Motor driver logic pins description for left motor Right motor control signal A1 Right motor control signal A2 Function
0 0 Soft brake
0 1 Reverse rotation
1 0 Forward rotation
1 1 Hard brake
Table. 3.6: Motor driver logic pins description for right motor Right motor control signal B1 Right motor control signal B2 Function
0 0 Soft brake
0 1 Reverse rotation
1 0 Forward rotation
1 1 Hard brake
Wheel encoder sensor signals can be read with polling from host C-script. In polling, a signal is checked at regular intervals of time. Pulse count is updated when there is a change in the signal,hightoloworlowtohigh. Sometimes, the pulses can be miscounted if some process is blocking the processor for longer duration. Missing ahighbetween two lowsor vice versa may happen. In practice, counter misses pulses during packet data transfer and file read-write operations. Moreover, velocity measurement from polling though main processor is erroneous owing to the fact that it is not real-time. To overcome these drawbacks, Programmable real time units are used for pulse counting and motor shaft angular velocity measurement. The measure- ments can be further used to estimate position (using dead-reckoning with initial conditions) and velocity of the robot. The main processor can become almost real-time (with few excep- tions) by applyingrt patchto the OS kernel, but PRUs are preferred due to their high accuracy and to distribute the load of computation.
The Programmable real time units PRU0 and PRU1 on BBB are independent of main pro- cessor as well as of each other. The clocks of the PRUs are set at 200MHz, which implies each clock cycle takes 5ns. Normal arithmetic instructions take typical one clock cycle, data operations on data memory takes 2 clock cycles for reading and 3 clock cycles for writing. For data operations on external memory, it takes more clock cycles depending on bus congestion,
typically 10 to 15 cycles. The PRUs can be programmed using assembly level coding or C- script compiled on TI-CGT compiler provided by Texas Instruments. Assembly level coding is used in this work to have more control over number of instructions. Communication among main processor and PRUs can be done usingremoteprocarchitecture or shared memory access.
Shared memory access is chosen due to its simplicity in implementation and lack of proper documentation forremoteprocat the time of implementation.
A loop is defined in assembly script in such a manner that PRU0 polls each wheel sensors at every 80ns for pulse count. A loop counter stores the number of loop iterations executed between the pulses. The pulse count and loop counter values are stored in predefined memory location in the data memory of PRU0. The host C-script reads those memory locations to get pulse count and time gap between the pulses. The linear velocity of left and right wheels, sep- arated by distance d, is calculated using number of pulses in a given interval of time. Using left and right wheel velocities (viL, viR), linear velocity of the robot can be calculated using Eqn. (3.7) and angular velocity is calculated using Eqn. (3.8). The pulse count is used to calcu- late position of robot with dead-reckoning principle. The calculated position, linear and angular velocities of the robot are used in Eqn. (3.1).
vi=viL+viR
2 (3.7)
ωi= viL+viR
d (3.8)
The host C-script will also take care of motor velocity control using PID control. Robot heading is set at the start and corrected at regular intervals. The back-tracking algorithm is implemented wherever the need arises. In case of history following algorithm, robots use the values stored in memory.