Course overview
Lesson 2 of 9 · 3 promptsAI for Robotics Engineers
LESSON 02 OF 9

Draft Control System Code

3 prompts for Robotics Engineers

Prompts for Robotics Engineers: copy one, fill it in, paste it into your AI.

Track progress as a member

In this lesson

  1. 01Generate PID Controller Starting CodeUse this when you need a starting-point PID loop in Python or C++ tuned to your plant.
  2. 02Draft Robot State Machine LogicUse this when you are structuring robot behavior modes and want clean transition logic.
  3. 03Write ROS Node SkeletonsUse this when you're starting a new node and want publishers, subscribers, and parameters scaffolded.
1Copy the promptClick Copy on the prompt you need.
2Paste it into your AIChatGPT, Claude, Gemini or Copilot.
3Fill in the {{brackets}}Your own details, or let the AI ask you.
4Follow up and checkUse the follow-ups, then check the facts.
01

Generate PID Controller Starting Code

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

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.

Open as its own page

02

Draft Robot State Machine Logic

Use this when you are structuring robot behavior modes and want clean transition logic.

Prompt

Role You are a robotics control systems engineer who turns behavior requirements into clear state machine logic, optimising for safe, readable transitions and maintainable code.

Context you provide

  • {{robot_platform}} - controller, firmware, or runtime (e.g., robot controller, PLC, microcontroller)
  • {{language}} - programming language and version
  • {{behavior_modes}} - list of modes or states (e.g., idle, homing, executing, fault)
  • {{transition_rules}} - events or conditions that move between states
  • {{safety_constraints}} - interlocks, timeouts, or fault handling requirements
  • {{existing_code}} - optional snippets or interfaces to match
  • {{output_style}} - e.g., switch statement, class, pseudocode

Instructions

  1. Ask for any missing inputs, then restate the target behavior in one sentence.
  2. List every state with entry actions, exit actions, and allowed transitions.
  3. Draft the state machine logic in the requested language and style, using a clear pattern such as table-driven, enum plus switch, or state pattern.
  4. Handle invalid transitions, timeouts, and fault recovery explicitly; keep safety checks separate from normal flow.
  5. Add short comments for each transition condition and state purpose.
  6. Provide a transition table or text diagram.
  7. Note where hardware-specific calls or vendor libraries must be replaced with real APIs.

Output format Markdown code block with the draft, a state transition table, and a short assumptions list. Tone: technical, plain, no hype. Leave out full hardware drivers, lengthy prose, and untested safety claims.

Guardrails

  • Do not invent hardware APIs, register names, or safety certification claims; use placeholders where the real interface is unknown.
  • Flag every assumption about timing, sensor behavior, or failure modes.
  • Tell the user to validate the logic against the robot's risk assessment and manufacturer manuals before running on hardware.

Example Robot: 6-axis arm; modes: idle, homing, pick, place, fault; transitions: start, home_done, pick_done, fault_detected.

Open as its own page

03

Write ROS Node Skeletons

Use this when you're starting a new node and want publishers, subscribers, and parameters scaffolded.

Prompt

Role You are a robotics engineer who writes clean, minimal ROS node skeletons for control systems. Optimise for a compilable, well-commented scaffold that the user can extend.

Context you provide

  • {{ros_version}} — ROS 1 or ROS 2
  • {{ros_distribution}} — e.g., Noetic, Humble
  • {{language}} — Python or C++
  • {{node_name}} — name of the node
  • {{package_name}} — name of the ROS package
  • {{publishers}} — list of topics and message types, e.g., /cmd_vel: geometry_msgs/Twist
  • {{subscribers}} — list of topics and message types, e.g., /odom: nav_msgs/Odometry
  • {{parameters}} — list of parameter names, types, and default values, e.g., max_speed: double = 1.0
  • {{loop_rate_hz}} — frequency in Hz for the main loop timer

Instructions

  1. Ask for any missing inputs, then generate the node skeleton.
  2. Use the correct ROS client library for the given {{ros_version}} and {{language}} (e.g., rclpy for ROS 2 Python, rospy for ROS 1 Python, rclcpp for ROS 2 C++, roscpp for ROS 1 C++).
  3. Create a node class or main function that declares all {{parameters}}, creates publishers for each {{publishers}} entry, and subscribers for each {{subscribers}} entry.
  4. Add a timer using {{loop_rate_hz}} with an empty callback that contains a comment marking where to insert control logic.
  5. Include comments for each section: imports, parameter declaration, publisher setup, subscriber setup, timer callback, and main entry point.
  6. Ensure the code is syntactically correct and follows ROS naming conventions.

Output format Provide a single code block in the chosen language. Keep it under 100 lines. Use clear placeholder comments like "# TODO: implement control logic". Tone: professional and concise. Do not include any business logic or hardware-specific code.

Guardrails

  • Do not invent message types, package names, or parameter names; use only the placeholders provided.
  • Flag any assumptions about ROS version or language if not specified.
  • Tell the user to verify the skeleton against their ROS distribution documentation and hardware interface.

Example ROS 2 Humble, Python, node_name: motor_controller, package_name: my_robot, publishers: /cmd_vel: geometry_msgs/Twist, subscribers: /odom: nav_msgs/Odometry, parameters: max_speed: double = 1.0, wheel_base: double = 0.5, loop_rate_hz: 10.

Open as its own page

Skills for these tasks

Give your AI these skills and it does these tasks the expert way. Connect your AI once and it picks them up by itself.