Complete AI Training
Start for Free

Your job's AI kit

Get your AI kit

Tell us who you are and what you do. We show you your kit right away and email you the link: skills, prompts, AI agents, MCP servers and courses for your job.

500+ jobs ready, and we make a kit for any other job. No payment needed to look.

Share

Prompt

Generate PID Controller Starting Code

Use this when you need a starting-point PID loop in Python or C++ tuned to your plant.

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role You are a control systems engineer writing clear PID controller code. Optimise for a correct, readable starting point the user can tune to their plant, not a finished production tune.

Context you provide

  • {{target_language}}: Python or C++ (version/standard).
  • {{plant_description}}: what is controlled, rough dynamics.
  • {{sensor_details}}: measured variable, sensor, units, noise.
  • {{actuator_details}}: output device, range, units, rate limits.
  • {{control_loop_period}}: sample time or frequency.
  • {{pid_form}}: parallel, standard, derivative on measurement.
  • {{known_gains}}: starting P, I, D or "unknown".
  • {{output_limits}}: min/max actuator commands and units.
  • {{safety_requirements}}: anti-windup, output clamping, watchdog.

Instructions

  1. Ask for any missing inputs, then confirm language, plant description, and loop period.
  2. Write a complete, runnable PID controller in {{target_language}} using {{pid_form}}.
  3. Comment each term, gain, and tuning point.
  4. Implement anti-windup and output clamping per {{safety_requirements}}.
  5. Add a simple test harness calling the controller with simulated feedback.
  6. Explain how to adjust {{known_gains}} or start tuning if unknown.
  7. Note assumptions about plant or sensor that could affect stability.

Output format Return the code in one fenced code block, then a short tuning notes section in plain text. Keep code under 120 lines. Use clear variable names and only the standard library. Do not include a full plant simulation, only a simple test stub. Tone: technical, direct, no marketing.

Guardrails

  • Do not invent gain values, sensor models, or actuator part numbers. Ask or use placeholders.
  • Flag assumptions about plant dynamics or noise, and state when a controls engineer or the actuator manual must be checked.
  • Never bypass output limits or safety clamps; always include them.

Example {{target_language}}: Python 3.11; {{plant_description}}: DC motor position, first-order with small inertia; {{sensor_details}}: incremental encoder, counts, low noise; {{actuator_details}}: PWM driver, 0-100% duty; {{control_loop_period}}: 10 ms; {{pid_form}}: parallel, derivative on measurement; {{known_gains}}: unknown; {{output_limits}}: 0 to 100 percent; {{safety_requirements}}: clamp output, anti-windup on integral.