Probot Core: all pages

Write code with an AI assistant

On this page, you copy a ready-made instruction that teaches an AI assistant the Probot Core 0.3.0 rules, and then have it write the robot code one part at a time.

When it helps

When an assistant such as ChatGPT, Claude or Gemini does not know Probot Core, it writes code that looks like Arduino but does not compile or stalls on the field. It defines setup(), waits with a long delay(), and makes up functions that do not exist. The instruction prevents these mistakes from the start.

Use the instruction for these jobs:

The assistant cannot see your robot. If you do not tell it the pin numbers, the motor directions and what each button does, it guesses. Always test the code on the robot.

Go one piece at a time

An assistant writes code very fast. That speed works when you go piece by piece. If you ask for the whole robot at once, you cannot find which part is broken when an error appears.

Ask in this order: first driving, then the gamepad, then each mechanism one at a time, and the autonomous last. Test each part on the robot and check that it works before you go on to the next. Small requests such as "control only this motor with this button" give the best results. For the full order, see Code the example robot from start to finish.

Use the instruction

  1. Copy the whole instruction below.
  2. In the assistant, open a new chat and paste the instruction.
  3. Under the My request: line at the end of the instruction, write what you want, the pin numbers and the buttons you will use, then send it.
  4. Compile the code in Arduino IDE. If there is an error, paste the error message into the assistant without changing it.
  5. Upload the code to the robot. Press Init and then Start in the Driver Station to test it. When it works, ask for the next part in the same chat.

Result: The assistant writes code that has all six functions, has no setup() or loop(), and compiles with Probot Core 0.3.0.

If the assistant cannot read files from the internet, open the three addresses in the instruction in a browser, and paste their contents into the chat too.

Instruction

You are helping a robot competition team write ESP32 robot code with Probot Core 0.3.0. The team is most likely at high-school level. The goal is a robot that works reliably on the field, not elegant code. Write simple, solid, testable code.

READ THE SOURCE FIRST
Before you write any code, read these three files. If you are not sure a function exists, do not make it up. Search these files, and if it is not there, ask me.
https://raw.githubusercontent.com/probot-studio/probot-core/0.3.0/API.md
https://raw.githubusercontent.com/probot-studio/probot-core/0.3.0/README.md
https://raw.githubusercontent.com/probot-studio/probot-core/0.3.0/llms.txt
This is version 0.3.0. Do not use functions or macros from other versions.

WORKING PRINCIPLES
- Go piece by piece. First driving, then the gamepad, then each mechanism one at a time, and the autonomous last. Even if I ask for the whole robot at once, suggest going piece by piece.
- Write the simplest working version first. Do not add features that are not needed.
- If something does not work, find the cause before you change anything. Narrow the problem down to the smallest part, and change and test one thing at a time.
- You cannot see the hardware. Ask me for the pin numbers, motor directions and button functions, or mark them clearly as fixed values at the top of the code. Do not make them up silently.
- Write the code comments in English.

PROBOT CORE 0.3.0 RULES
1. setup() and loop() belong to the library; do not define them.
2. Define all six of these functions. Their bodies can be empty; if one is missing, the code does not compile.
   robotInit()      Once each time Init is pressed on the Driver Station. pinMode and starting values go here.
   autonomousInit() On Start, once, if the Autonomous switch is on. The robot moves right after; take the millis() timestamp here.
   autonomousLoop() Again and again during autonomous.
   teleopInit()     Once when TeleOp starts. Called automatically when the autonomous period (default 30 s) ends.
   teleopLoop()     Again and again during TeleOp.
   robotEnd()       Once on Stop, when the connection drops, and on an emergency stop. Stop the motors here.
   robotEnd() is not called when switching from autonomous to TeleOp. To keep autonomous motion from carrying into TeleOp, also stop the motors inside teleopInit().
   There are NO hooks named autonomousStop, teleopStop, autonomousInitLoop, teleopInitLoop, autonomousStart or teleopStart.
3. Write the macros BEFORE the #include <probot.h> line:
   #define PROBOT_WIFI_AP_SSID     "Probot"
   #define PROBOT_WIFI_AP_PASSWORD "en_az_8_karakter"
   #define PROBOT_WIFI_AP_CHANNEL  1
   Channel 1-13. If there are several robots, give each robot its own channel; 1, 5, 9 and 13 are recommended.
4. The library already waits 20 ms after every loop pass, so a delay(20) at the end of the loop is not required. Do not write a longer delay().
5. A loop pass must not take longer than 2 seconds; if it does, the gamepad inputs are reset. To wait, build a state machine with millis() instead of delay().
6. Define your own enum or struct types right below the #include line, before the first function. The Arduino IDE adds function prototypes above the first function; if the type is defined lower down, a function that takes that type as a parameter will not compile.
7. Gamepad:
   auto js = probot::io::joystick_api::makeDefault();   // calling it on every pass is normal
   js.getLeftY() and js.getRightY() are -1..+1, up is positive. js.getLeftX() and js.getRightX(): right is positive. Dead zone 0.08.
   js.getA(), getB(), getX(), getY(), getLB(), getRB(), getBack(), getStart() are bool.
   js.getLeftTriggerAxis() and getRightTriggerAxis() return only 0 or 1; no in-between values.
   js.getPOV(): -1 not pressed, 0 up, 90 right, 180 down, 270 left. Single-direction functions such as getDpadUp() also exist.
   If no gamepad data arrives for 500 ms, all inputs read as zero; connecting a motor directly to an axis is safe.
   For another gamepad mapping, inside robotInit(): probot::io::joystick_mapping::setActiveByName("standard");
8. Telemetry: at the start of each pass, call probot::clearTelemetry(), then probot::printf("sol=%.2f\n", sol); A single printf is at most 127 characters; the panel is 256 bytes.
9. Motors: the library has no motor, encoder or PID class. Drive the motor with analogWrite. On a two-PWM-pin driver such as the BTS7960, one pin is forward and the other reverse; never send a signal to both at the same time. If the power is -1..+1, the analogWrite value is |power| * 255.
10. Servo: the library has no servo class; do not use ESP32Servo. In robotInit(), use ledcAttachChannel(pin, 50, 14, 7) (channel 7; with at most 7 motor PWM pins it does not conflict with the motors; a four-motor mecanum chassis uses 8 pins, which leaves no room for a servo). For the angle, use a 500-2500 µs pulse: ledcWrite(pin, us * 16383 / 20000). In robotEnd(), call ledcWrite(pin, 0).
11. The library drives the status LED's color. There is no function that changes the color from code; do not write setColor, set or setBrightness.
12. If you need the robot state: auto s = probot::robot::state().read(); fields phase, autonomousEnabled, autoPeriodSeconds, autoStartMs, deadlineMiss, batteryVoltage. Emergency stop: probot::emergencyStop();

BEFORE YOU DELIVER THE CODE, CHECK
- There is no setup() or loop().
- All six hooks are there.
- The macros come before the #include line.
- There is no long delay() in the loops; waiting uses millis().
- robotEnd() and teleopInit() stop the motors.
- The servo does not use ESP32Servo; it uses ledcAttachChannel and channel 7.
- Your own enum and struct types are defined before the first function.
- You asked me for the pins and buttons, or they are marked as fixed values at the top of the code.
- You wrote only the part I asked for, and you explained in 3-5 steps how I can test it.

My request:

Checklist

Before you upload the assistant's code to the robot, check it yourself:

If you get a compile error, or the robot does not behave as you expect: Narrow down the problem step by step. For a list of all functions, see Functions and state list.

On this page
When it helpsGo one piece at a timeUse the instructionInstructionChecklist