API Reference

Complete reference for all public functions in the Autobot Library.


Arduino API

AutOBot.begin()

Initializes the robot with a specific drive type and motor configuration.

#include "AutOBot.h"

AutOBot myBot;
myBot.begin(type, deviation);

Parameters

ParameterTypeDescription
typeDriveTypeThe drive configuration. One of: DRIVE_DIFFERENTIAL, DRIVE_OMNI_3W, DRIVE_MECANUM
deviationintCorrection for straight-line drift. Range: -100 to 100

Motor Pin Arrays by Drive Type

Drive TypePin Array Format
Differential (2W)motor1(a = 18, b = 19), motor2(a = 22, b = 23)
Differential (4W) / Mecanummotor1(a = 18, b = 19), motor2(a = 22, b = 23), motor3(a = 25, b = 26), motor4(a = 27, b = 14)
Omni (3W)motor1(a = 18, b = 19), motor2(a = 22, b = 23), motor3(a = 25, b = 26)

Deviation Guide

ValueEffect
-100 to -1Reduces right motor speed — use if the robot drifts left
0No correction
1 to 100Reduces left motor speed — use if the robot drifts right

robot.drive()

Commands the robot to move in a given direction at a given speed, with optional rotation.

robot.drive(speed, direction, angular);

Parameters

ParameterTypeRangeDescription
speedint0 – 100Movement speed (0 = stopped)
directionint0 – 360Heading in degrees. 0 = forward, 180 = backward
angularint-100 – 100Rotational speed. -100 = full left, 100 = full right

Pi Communication Setup

Initialize the UART connection between the ESP32 and Raspberry Pi.

// In setup()
AutOBot myBot;
AutOBotAI myAI;
myBot.begin(type, deviation);
myAI.begin(Serial, myBot);
Serial2.begin(baudRate, SERIAL_8N1, myAI.rx, myAI.tx);
ParameterTypeDefaultDescription
baudRateint115200Serial baud rate (must match the Pi-side configuration)
PI_RX_PINint16ESP32 GPIO pin connected to the Pi's TX
PI_TX_PINint17ESP32 GPIO pin connected to the Pi's RX
// In loop() — required to process incoming drive commands
AutOBotAI.handle();

AutOBotAI.requestHuman()

Requests the Raspberry Pi to start Human Tracking mode.

AutOBotAI.requestHuman(baseSpeed, turnGain, boxSize, deadzone);
ParameterTypeDefaultDescription
baseSpeedint0Forward speed while tracking. 0 = rotate only, 100 = always move forward
turnGainfloat0.5Turning sensitivity. Higher values increase responsiveness (risk of overshoot)
boxSizeint30000Target bounding box area. Larger values make the robot approach closer
deadzoneint5000Angular deadzone — the robot will not turn if the target is within this threshold

AutOBotAI.requestLine()

Requests the Raspberry Pi to start Line Tracking mode.

AutOBotAI.requestLine(baseSpeed, turnGain, thresh, color, defS, defD, defA);
ParameterTypeDefaultDescription
baseSpeedint0Forward speed while tracking. 0 = rotate only
turnGainfloat0.5Turning sensitivity
threshint100Threshold for the image mask used in line detection
colorString"black"Color of the line to follow
defSint0Fallback speed when no line is detected
defDint0Fallback direction (degrees) when no line is detected
defAint0Fallback angular speed when no line is detected

AutOBotAI.requestStop()

Stops all active AI processing on the Raspberry Pi.

AutOBotAI.requestStop();

Raspberry Pi Serial Protocol

The ESP32 communicates with the Raspberry Pi using a simple text-based serial protocol.

Message Format

:M|parameter=value|parameter=value|...

Example:

:M|spd=50|sen=0.8|LN=1

This sets the speed to 50, sensitivity to 0.8, and starts Line Tracking mode.

Parameter Reference

ParameterTypeDescription
LNintLine Tracking mode: 0 = stop, 1 = start
HMintHuman Tracking mode: 0 = stop, 1 = start
spdintMovement speed (0–100). Applies to both modes
senfloatTurning sensitivity. Applies to both modes
thrintImage threshold (0–100). Line Tracking only
typeStringDrive type: "diff", "omni", or "mac"
boxintTarget bounding box size. Human Tracking only
dzoneintAngular deadzone. Applies to both modes
colStringLine color (e.g., "black"). Line Tracking only
defStringFallback values as speed,direction,angular (e.g., "50,180,0"). Line Tracking only

More Info