# Probot

> ESP32 Arduino library for educational robotics competitions (Turkish
> Ministry of Education / MEB). The robot hosts a WiFi access point and a
> browser-based driver station; joystick input streams to the robot over a
> binary WebSocket at 50 Hz. Library name in the Arduino Library Manager:
> "probot". Repository: https://github.com/probot-studio/probot-core

Rules that generated code MUST follow:

- Never define `setup()` or `loop()` — the library defines them.
- The sketch must define all six hooks: `robotInit`, `robotEnd`,
  `teleopInit`, `teleopLoop`, `autonomousInit`, `autonomousLoop`
  (empty bodies are fine).
- Define `PROBOT_WIFI_AP_SSID`, `PROBOT_WIFI_AP_PASSWORD` (min 8 chars)
  and `PROBOT_WIFI_AP_CHANNEL` (1-13) BEFORE `#include <probot.h>`. For
  a fleet, give each robot a distinct fixed channel by hand. Boot-time
  auto channel select is opt-in via `PROBOT_WIFI_AUTO_CHANNEL 1`
  (default off; single-robot use, not recommended for a fleet).
- Joystick access: `auto js = probot::io::joystick_api::makeDefault();`
  then `js.getLeftY()`, `js.getA()`, `js.getPOV()` etc. Axis range is
  -1..+1, Y is positive up. `probot::io::gamepad()` is the low-level
  service and has NO getLeftX/getA-style methods.
- Servos: the library provides NO servo class — drive raw LEDC. In
  `robotInit` call `ledcAttachChannel(pin, 50, 14, 7)` (a HIGH channel, so it
  never shares a timer with `analogWrite` motor PWM → no jitter); in the loop
  `ledcWrite(pin, us * 16383 / 20000)` for a 500-2500 us pulse. Not ESP32Servo,
  not analogWrite (1 kHz can't make a 50 Hz servo frame).
- `teleopLoop`/`autonomousLoop` are called repeatedly (~50 Hz); do not
  write infinite loops or block longer than 2 s inside them.
- Telemetry to the driver station panel: `probot::printf("v=%.2f\n", v);`
- Inputs auto-zero 500 ms after the link drops — driving motors directly
  from axis values is safe.

## Docs

- [API reference](https://raw.githubusercontent.com/probot-studio/probot-core/stable/API.md): complete API, lifecycle, HTTP/WS protocol
- [README](https://raw.githubusercontent.com/probot-studio/probot-core/stable/README.md): install, configuration macros, competition channel planning, servo jitter guide

## Examples

- [JoystickTest](https://raw.githubusercontent.com/probot-studio/probot-core/stable/examples/JoystickTest/JoystickTest.ino): read axes/buttons, print telemetry
- [TankDrive](https://raw.githubusercontent.com/probot-studio/probot-core/stable/examples/TankDrive/TankDrive.ino): two-motor drive with an H-bridge (BTS7960-style)
- [ServoTest](https://raw.githubusercontent.com/probot-studio/probot-core/stable/examples/ServoTest/ServoTest.ino): jitter-free servo control from the joystick
