From 5e531c08515ffbbe931fcc1fda760b9b5b53af05 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Jan 2026 03:51:02 +0000 Subject: [PATCH 1/3] Initial plan From 8792fe7798e4e463e0c31e27177f8c96d9a1ca5c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Jan 2026 03:57:22 +0000 Subject: [PATCH 2/3] Fix line number references and document Agents/Skills in Lesson 6 Co-authored-by: thomasiverson <12767513+thomasiverson@users.noreply.github.com> --- lessons/06-debugging/demo-script.md | 22 +++---- lessons/06-debugging/hands-on-exercises.md | 30 +++++----- lessons/06-debugging/readme.md | 67 +++++++++++++++++++--- lessons/06-debugging/slides.md | 6 +- 4 files changed, 88 insertions(+), 37 deletions(-) diff --git a/lessons/06-debugging/demo-script.md b/lessons/06-debugging/demo-script.md index e23c7148..e58495b0 100644 --- a/lessons/06-debugging/demo-script.md +++ b/lessons/06-debugging/demo-script.md @@ -226,9 +226,9 @@ and the call from motor.cpp. **Step 1: Open the demo file** -Open `src-ODrive/Firmware/MotorControl/demo_buggy.cpp` and scroll to the `FaultLogger` class (around line 23). +Open `src-ODrive/Firmware/MotorControl/demo_buggy.cpp` and scroll to the `FaultLogger` class (around line 24). -**The buggy code (lines 29-37):** +**The buggy code (lines 31-38):** ```cpp // BUG: Can you spot the off-by-one error? void log_fault(uint32_t error_code) { @@ -253,7 +253,7 @@ void log_fault(uint32_t error_code) { **Step 2: Use /fix in Chat** -1. **Select lines 29-37** (the entire `log_fault` function) +1. **Select lines 31-38** (the entire `log_fault` function) 2. Open **Inline Chat** panel (`Ctrl+I`) first 3. Type: ``` @@ -314,9 +314,9 @@ Explanation: **Step 4: Show threading bug** -**In the same file (`demo_buggy.cpp`), scroll to the `Encoder` class (around line 52).** +**In the same file (`demo_buggy.cpp`), scroll to the `Encoder` class (around line 55).** -**The buggy code (lines 63-76):** +**The buggy code (lines 65-77):** ```cpp // Called from 8 kHz interrupt void update_isr() { @@ -342,7 +342,7 @@ float get_position() { **Step 5: Ask /fix for solutions** -1. **Select lines 63-80** (both `update_isr()` and `get_position()` functions) +1. **Select lines 65-81** (both `update_isr()` and `get_position()`/`get_velocity()` functions) 2. Open **Copilot Chat** panel (`Ctrl+Alt+I`) 3. Type: ``` @@ -410,7 +410,7 @@ Recommendation for 8 kHz ISR: Option 1 (interrupt disable) - only ~10 cycles. ## Demo 3: Real-World Debug Session (9 min) ### Setup -- Continue using `demo_buggy.cpp` - scroll to the `SpeedCalculator` class (around line 85) +- Continue using `demo_buggy.cpp` - scroll to the `SpeedCalculator` class (around line 92) - This demonstrates the full /explain → /fix → test workflow ### Demo Flow @@ -422,7 +422,7 @@ Recommendation for 8 kHz ISR: Option 1 (interrupt disable) - only ~10 cycles. **Step 1: Show the buggy code** -**In `demo_buggy.cpp`, scroll to the `SpeedCalculator` class (line 85). The buggy code is lines 96-106:** +**In `demo_buggy.cpp`, scroll to the `SpeedCalculator` class (line 92). The buggy code is lines 104-111:** ```cpp // BUG: Integer overflow at high speeds! @@ -446,7 +446,7 @@ float calculate_rpm() { **Step 2: Ask for explanation** -1. **Select lines 96-106** (the `calculate_rpm` function) +1. **Select lines 104-111** (the `calculate_rpm` function) 2. Open **Copilot Chat** panel (`Ctrl+Alt+I`) 3. Type: ``` @@ -523,7 +523,7 @@ First select @ODrive-QA in chat. Generate a unit test for calculate_rpm that tests high speed values to catch integer overflow ``` -> **Note:** Using `@ODrive-QA` invokes the `odrive-qa-assistant` skill which is specialized for test generation. +> **Note:** Using `@ODrive-QA` invokes the `cpp-testing` skill which is specialized for test generation. **Expected AI Response:** ```cpp @@ -559,7 +559,7 @@ TEST_CASE("Encoder RPM calculation at high speed") { ``` **Presenter Says:** -> "Excellent! `@ODrive-QA` generated a unit test that specifically checks high-speed values where overflow would occur. This ensures the bug stays fixed. The agent invoked the `odrive-qa-assistant` skill to create comprehensive tests." +> "Excellent! `@ODrive-QA` generated a unit test that specifically checks high-speed values where overflow would occur. This ensures the bug stays fixed. The agent invoked the `cpp-testing` skill to create comprehensive tests." --- diff --git a/lessons/06-debugging/hands-on-exercises.md b/lessons/06-debugging/hands-on-exercises.md index 2ce2dc49..f899ddc9 100644 --- a/lessons/06-debugging/hands-on-exercises.md +++ b/lessons/06-debugging/hands-on-exercises.md @@ -29,9 +29,9 @@ Open this file in VS Code before starting. ### Bug Locations in demo_buggy.cpp | Bug | Class | Lines | |-----|-------|-------| -| 1. Circular Buffer | `FaultLogger` | 29-37 | -| 2. Race Condition | `Encoder` | 63-80 | -| 3. Integer Overflow | `SpeedCalculator` | 96-106 | +| 1. Circular Buffer | `FaultLogger` | 31-38 | +| 2. Race Condition | `Encoder` | 65-81 | +| 3. Integer Overflow | `SpeedCalculator` | 104-111 | ### If demo_buggy.cpp Doesn't Exist @@ -197,7 +197,7 @@ The motor controller logs the last 10 faults in a circular buffer. Users report ### Buggy Code -**File:** `src-ODrive/Firmware/MotorControl/demo_buggy.cpp` — `FaultLogger` class (lines 23-48) +**File:** `src-ODrive/Firmware/MotorControl/demo_buggy.cpp` — `FaultLogger` class (lines 24-48) ```cpp #define FAULT_HISTORY_SIZE 10 @@ -225,8 +225,8 @@ public: **Step 1: Identify the Bug (2 min)** -1. Open `demo_buggy.cpp` and scroll to the `FaultLogger` class (line 23) -2. **Select lines 29-37** (the `log_fault` function) +1. Open `demo_buggy.cpp` and scroll to the `FaultLogger` class (line 24) +2. **Select lines 31-38** (the `log_fault` function) 3. Open **Copilot Chat** panel (`Ctrl+Alt+I`) 4. Type: ``` @@ -251,7 +251,7 @@ Ask Copilot to generate a test: @ODrive-QA Generate a unit test that logs 15 faults and verifies no crash ``` -> **Note:** Using `@ODrive-QA` invokes the `odrive-qa-assistant` skill for test generation. +> **Note:** Using `@ODrive-QA` invokes the `cpp-testing` skill for test generation. Run the test mentally or with a simple main(): ```cpp @@ -304,7 +304,7 @@ The encoder updates position estimates in an 8 kHz interrupt. The main control l ### Buggy Code -**File:** `src-ODrive/Firmware/MotorControl/demo_buggy.cpp` — `Encoder` class (lines 52-81) +**File:** `src-ODrive/Firmware/MotorControl/demo_buggy.cpp` — `Encoder` class (lines 55-82) ```cpp class Encoder { @@ -342,8 +342,8 @@ public: **Step 1: Identify the Race (2 min)** -1. In `demo_buggy.cpp`, scroll to the `Encoder` class (line 52) -2. **Select lines 63-80** (both `update_isr()` and `get_position()` functions) +1. In `demo_buggy.cpp`, scroll to the `Encoder` class (line 55) +2. **Select lines 65-81** (both `update_isr()` and `get_position()`/`get_velocity()` functions) 3. Open **Copilot Chat** panel (`Ctrl+Alt+I`) 4. Type: ``` @@ -463,7 +463,7 @@ The encoder calculates motor RPM from tick counts. At low speeds it works fine, ### Buggy Code -**File:** `src-ODrive/Firmware/MotorControl/demo_buggy.cpp` — `SpeedCalculator` class (lines 85-109) +**File:** `src-ODrive/Firmware/MotorControl/demo_buggy.cpp` — `SpeedCalculator` class (lines 92-112) ```cpp class SpeedCalculator { @@ -497,8 +497,8 @@ public: **Step 1: Understand the Bug (2 min)** -1. In `demo_buggy.cpp`, scroll to the `SpeedCalculator` class (line 85) -2. **Select lines 96-106** (the `calculate_rpm` function) +1. In `demo_buggy.cpp`, scroll to the `SpeedCalculator` class (line 92) +2. **Select lines 104-111** (the `calculate_rpm` function) 3. Open **Copilot Chat** panel (`Ctrl+Alt+I`) 4. Type: ``` @@ -535,7 +535,7 @@ Ask: @ODrive-QA Generate a unit test for calculate_rpm that tests speeds from 100 to 50,000 RPM ``` -> **Note:** `@ODrive-QA` will invoke the `odrive-qa-assistant` skill to create comprehensive test cases. +> **Note:** `@ODrive-QA` will invoke the `cpp-testing` skill to create comprehensive test cases. ### Success Criteria - ✅ Understand intermediate overflow concept @@ -676,7 +676,7 @@ Context: [files involved, expected vs actual behavior] @ODrive-QA Verify the fix compiles correctly ``` -> **Note:** `@ODrive-QA` invokes the `odrive-qa-assistant` skill for builds and tests. +> **Note:** `@ODrive-QA` invokes the `cpp-testing` and `odrive-toolchain` skills for builds and tests. ### Context is Key diff --git a/lessons/06-debugging/readme.md b/lessons/06-debugging/readme.md index e24362e8..9de3531f 100644 --- a/lessons/06-debugging/readme.md +++ b/lessons/06-debugging/readme.md @@ -31,6 +31,7 @@ Debugging is where developers spend 30-50% of their time. This lesson teaches yo - [Overview](#overview) - [Prerequisites](#prerequisites) +- [Available Agents and Skills](#available-agents-and-skills) - [Why Debugging with Copilot Matters](#why-debugging-with-copilot-matters) - [Learning Path](#learning-path) - [@terminal for Build Errors](#1-terminal-for-build-errors-10-min) @@ -75,6 +76,56 @@ Before starting this session, ensure you have: --- +## Available Agents and Skills + +This repository includes several custom agents and skills that enhance debugging capabilities. Understanding when to use each agent is key to efficient debugging. + +### Custom Agents + +| Agent | Invocation | Purpose | Best For | +|-------|------------|---------|----------| +| **ODrive Engineer** | `@ODrive-Engineer` | Primary orchestrator for development tasks | Multi-file bugs, firmware development, complex analysis | +| **ODrive QA** | `@ODrive-QA` | Testing & QA orchestrator | Test generation, build verification, coverage analysis | +| **ODrive Reviewer** | `@ODrive-Reviewer` | Code review specialist | Style, safety, embedded best practices | +| **ODrive Toolchain** | `@ODrive-Toolchain` | Build & test operations | Building firmware, running tests, symbol search | +| **ODrive Ops** | `@ODrive-Ops` | CI/CD workflows | Release management, GitHub Actions | +| **Ada to C++ Migrator** | `@ada-to-cpp-migrator` | Language migration specialist | Migrating Ada code to Modern C++ | + +### Available Skills + +Skills are specialized capabilities that agents can invoke: + +| Skill | Description | Status | +|-------|-------------|--------| +| **cpp-testing** | Unit test generation with doctest framework | ✅ Production | +| **odrive-toolchain** | Build firmware, run tests, symbol search | ✅ Production | +| **odrive-ops** | CI/CD workflows, releases, deployment | ✅ Production | +| **control-algorithms** | PID controllers, observers, control transformations | 🚧 Planned | +| **foc-tuning** | Automated FOC parameter tuning | 🚧 Planned | +| **sensorless-control** | Sliding mode observers, PLL, back-EMF estimation | 🚧 Planned | +| **pcb-review** | PCB schematic/layout review | 🚧 Planned | +| **signal-integrity** | Impedance calculation, EMI analysis | 🚧 Planned | +| **ada-cpp-migration** | Ada to Modern C++ migration patterns | ✅ Production | + +### When to Use Which Agent + +``` +Build/compile error? ──→ @terminal (quick fix) + └─→ @ODrive-Toolchain (complex build issues) + +Single-file logic bug? ──→ /fix (inline correction) + +Multi-file bug? ──→ @ODrive-Engineer (orchestrated analysis) + +Need tests? ──→ @ODrive-QA (test generation) + +Code review? ──→ @ODrive-Reviewer (style & safety check) + +CI/CD issue? ──→ @ODrive-Ops (workflow management) +``` + +--- + ## Why Debugging with Copilot Matters Debugging is where developers spend 30-50% of their time. AI-assisted debugging can dramatically reduce this overhead. @@ -389,7 +440,7 @@ The `/fix` command is a **code-focused debugging assistant** that: #### 1. **Off-by-One Errors** -**File:** `demo_buggy.cpp` — FaultLogger class (line 29-37) +**File:** `demo_buggy.cpp` — FaultLogger class (lines 31-38) **Buggy Code:** ```cpp @@ -452,7 +503,7 @@ Or initialize watchdog_timer_ in constructor to avoid nullptr. #### 3. **Race Conditions (Thread Safety)** -**File:** `demo_buggy.cpp` — Encoder class (lines 63-80) +**File:** `demo_buggy.cpp` — Encoder class (lines 65-81) **Buggy Code:** ```cpp @@ -537,7 +588,7 @@ If heap is required: #### 5. **Integer Overflow** -**File:** `demo_buggy.cpp` — SpeedCalculator class (lines 96-106) +**File:** `demo_buggy.cpp` — SpeedCalculator class (lines 104-111) **Buggy Code:** ```cpp @@ -762,7 +813,7 @@ while (dma1->SR & DMA_BUSY) { ### Debugging Strategy with Copilot **🎯 Copilot Modes: Chat + Agent** -> **Tip:** For complex debugging involving multiple files or domain expertise, use `@ODrive-Engineer` for firmware issues or `@ODrive-QA` for test-related debugging. The agents can invoke specialized skills like `odrive-qa-assistant` to build and verify fixes. +> **Tip:** For complex debugging involving multiple files or domain expertise, use `@ODrive-Engineer` for firmware issues or `@ODrive-QA` for test-related debugging. The agents can invoke specialized skills like `cpp-testing` to build and verify fixes. **Step 1: Reproduce the Bug** - Can you trigger it consistently? @@ -865,7 +916,7 @@ if (fault_write_idx_ >= FAULT_HISTORY_SIZE) { ### Bug 2: Race Condition in Position Estimate (5 min) -**File:** `demo_buggy.cpp` — Encoder class (lines 52-81) +**File:** `demo_buggy.cpp` — Encoder class (lines 55-82) **Buggy Code:** ```cpp @@ -937,7 +988,7 @@ void Encoder::get_estimates(float* pos, float* vel) { ### Bug 3: Integer Overflow in Speed Calculation (5 min) -**File:** `demo_buggy.cpp` — SpeedCalculator class (lines 96-106) +**File:** `demo_buggy.cpp` — SpeedCalculator class (lines 104-111) **Buggy Code:** ```cpp @@ -956,8 +1007,8 @@ float SpeedCalculator::calculate_rpm() { **Your Task:** **Step 1:** Use Copilot Chat to detect overflow -1. Open `demo_buggy.cpp`, scroll to SpeedCalculator class (line 85) -2. Select lines 96-106 (the `calculate_rpm` function) +1. Open `demo_buggy.cpp`, scroll to SpeedCalculator class (line 92) +2. Select lines 104-111 (the `calculate_rpm` function) 3. Open Chat (`Ctrl+Alt+I`) and type: ``` /explain why this gives wrong values at high speeds diff --git a/lessons/06-debugging/slides.md b/lessons/06-debugging/slides.md index 7eb607c0..995abe05 100644 --- a/lessons/06-debugging/slides.md +++ b/lessons/06-debugging/slides.md @@ -548,15 +548,15 @@ float get_position() const { // Now const-correct **Fix 3 bugs in `demo_buggy.cpp` in 15 minutes:** 1. **⭐⭐ Circular Buffer (5 min)** — FaultLogger class - - Off-by-one boundary check (lines 29-37) + - Off-by-one boundary check (lines 31-38) - Use /fix in Chat mode 2. **⭐⭐⭐ Race Condition (5 min)** — Encoder class - - ISR writes, main loop reads (lines 63-80) + - ISR writes, main loop reads (lines 65-81) - Evaluate multiple solutions 3. **⭐⭐ Integer Overflow (5 min)** — SpeedCalculator class - - RPM calculation overflow (lines 96-106) + - RPM calculation overflow (lines 104-111) - Use /explain then /fix **Files:** `demo_buggy.cpp` + `hands-on-exercises.md` From d936d751d3ef33d004878326df7187b8f5804c61 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Jan 2026 03:58:34 +0000 Subject: [PATCH 3/3] Fix additional line number references from code review feedback Co-authored-by: thomasiverson <12767513+thomasiverson@users.noreply.github.com> --- lessons/06-debugging/hands-on-exercises.md | 4 ++-- lessons/06-debugging/readme.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lessons/06-debugging/hands-on-exercises.md b/lessons/06-debugging/hands-on-exercises.md index f899ddc9..f726663c 100644 --- a/lessons/06-debugging/hands-on-exercises.md +++ b/lessons/06-debugging/hands-on-exercises.md @@ -304,7 +304,7 @@ The encoder updates position estimates in an 8 kHz interrupt. The main control l ### Buggy Code -**File:** `src-ODrive/Firmware/MotorControl/demo_buggy.cpp` — `Encoder` class (lines 55-82) +**File:** `src-ODrive/Firmware/MotorControl/demo_buggy.cpp` — `Encoder` class (lines 65-81) ```cpp class Encoder { @@ -463,7 +463,7 @@ The encoder calculates motor RPM from tick counts. At low speeds it works fine, ### Buggy Code -**File:** `src-ODrive/Firmware/MotorControl/demo_buggy.cpp` — `SpeedCalculator` class (lines 92-112) +**File:** `src-ODrive/Firmware/MotorControl/demo_buggy.cpp` — `SpeedCalculator` class (lines 104-111) ```cpp class SpeedCalculator { diff --git a/lessons/06-debugging/readme.md b/lessons/06-debugging/readme.md index 9de3531f..b042edb0 100644 --- a/lessons/06-debugging/readme.md +++ b/lessons/06-debugging/readme.md @@ -916,7 +916,7 @@ if (fault_write_idx_ >= FAULT_HISTORY_SIZE) { ### Bug 2: Race Condition in Position Estimate (5 min) -**File:** `demo_buggy.cpp` — Encoder class (lines 55-82) +**File:** `demo_buggy.cpp` — Encoder class (lines 65-81) **Buggy Code:** ```cpp