skills/picar-x-behavior/SKILL.md
Build composable robot behaviors for SunFounder Picar-X. Use when creating autonomous driving behaviors, sensor-reactive patterns, and behavior trees for the Picar-X robot platform. Do NOT use when the platform is not a SunFounder Picar-X without first adapting the API references; Do NOT use when the goal is general robotics outside the Picar-X hardware profile.
npx skillsauth add michaelalber/ai-toolkit picar-x-behaviorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
"The world is its own best model. The trick is to sense it appropriately and often enough." -- Rodney Brooks, Intelligence Without Representation
This skill builds composable, safe robot behaviors for the SunFounder Picar-X platform. Behaviors are small, testable units of reactive control that combine into complex autonomous systems through well-defined composition patterns.
Non-Negotiable Constraints:
| Principle | Description | Priority | |-----------|-------------|----------| | Safety Constraints | Hard limits on speed, servo range, and runtime; emergency stop always accessible | Critical | | Behavior Isolation | Each behavior reads sensors and produces actuator commands independently; no hidden shared state | Critical | | Composability | Behaviors combine through priority, sequence, and parallel patterns with predictable results | Critical | | Reactive Control | Sense-act loops run at fixed frequency; behaviors respond to current sensor state, not stale data | High | | Graceful Degradation | If a sensor fails, the robot reduces capability rather than crashing or acting on garbage data | High | | Deterministic Startup | Robot always starts in a known safe state: speed zero, servos centered, sensors polled | High | | Timeout Watchdogs | Every motor command expires after a bounded interval; no "set and forget" drive commands | High | | Testability | Every behavior can be tested with mocked hardware; real-hardware tests are optional second pass | High | | Observability | Behaviors log decisions, sensor readings, and actuator commands for post-run analysis | Medium | | Resource Awareness | Respect Raspberry Pi CPU/memory limits; camera processing and control loops share resources | Medium |
┌──────────────────────────────────────────────────────────────────┐
│ │
│ ┌────────┐ ┌───────────┐ ┌─────────────┐ ┌───────────┐ │
│ ─>│ DEFINE │──>│ IMPLEMENT │──>│ TEST_STATIC │──>│TEST_DYNAMIC│ │
│ └────────┘ └───────────┘ └─────────────┘ └───────────┘ │
│ │ │
│ ┌─────────┐ ┌────────┐ │ │
│ │ DEPLOY │<─────│COMPOSE │<────────────────────┘ │
│ └─────────┘ └────────┘ │
│ │ ▲ │
│ └────────────────┘ (add more behaviors) │
│ │
└──────────────────────────────────────────────────────────────────┘
Before ANY dynamic test or deployment, verify:
┌─────────────────────────────────────────────────┐
│ Pre-Flight Hardware Safety Check │
├─────────────────────────────────────────────────┤
│ [ ] Battery charged and securely connected │
│ [ ] Wheels off ground OR in bounded test area │
│ [ ] Emergency stop mechanism verified working │
│ [ ] Servo range calibration confirmed │
│ [ ] Ultrasonic sensor returning valid readings │
│ [ ] Camera stream active (if vision behavior) │
│ [ ] Max speed set to TEST level (<=30) │
│ [ ] Watchdog timeout configured (<2 seconds) │
│ [ ] Clear path / no obstacles in test zone │
│ [ ] Operator within physical reach of robot │
└─────────────────────────────────────────────────┘
Behavior base classsetup(), update(), and teardown() methodsupdate()teardown() always stops motors and centers servosupdate() produces correct actuator commands for given sensor inputsteardown() issues stop commandspytest -- all tests must pass before proceedingMaintain state across conversation turns using this block:
<picar-behavior-state>
step: [DEFINE | IMPLEMENT | TEST_STATIC | TEST_DYNAMIC | COMPOSE | DEPLOY]
behavior_name: [e.g., "obstacle_avoidance", "line_following", "object_tracking"]
safety_constraints: [e.g., "max_speed=30, emergency_stop=enabled"]
control_loop_hz: [number, e.g., 20]
last_action: [what was just done]
next_action: [what should happen next]
blockers: [any issues]
</picar-behavior-state>
Example:
<picar-behavior-state>
step: TEST_STATIC
behavior_name: obstacle_avoidance
safety_constraints: max_speed=30, emergency_stop=enabled, min_distance=25cm
control_loop_hz: 20
last_action: Implemented ObstacleAvoidance.update() with ultrasonic threshold logic
next_action: Write pytest tests with mocked ultrasonic sensor
blockers: none
</picar-behavior-state>
## Behavior: [Name]
**Goal**: [One sentence description]
**Inputs**:
| Sensor | Read Method | Expected Range |
|--------|------------|----------------|
| [sensor] | [method] | [range] |
**Outputs**:
| Actuator | Write Method | Bounded Range |
|----------|-------------|---------------|
| [actuator] | [method] | [range] |
**Safety Constraints**:
- Max speed: [value]
- Servo bounds: [min, max]
- Timeout: [seconds]
- Emergency stop: [trigger condition]
**Control Loop**:
1. Read [sensors]
2. Compute [decision]
3. Write [actuators]
4. Repeat at [Hz]
<picar-behavior-state>
step: DEFINE
behavior_name: [name]
safety_constraints: [constraints]
control_loop_hz: [hz]
last_action: Behavior defined
next_action: Implement behavior class
blockers: none
</picar-behavior-state>
## Test Results: [Behavior Name]
**Test Type**: [Static | Dynamic]
**Date**: [date]
### Static Tests
| Test | Description | Result |
|------|-------------|--------|
| [test_name] | [what it checks] | PASS/FAIL |
### Dynamic Tests (if applicable)
| Test | Environment | Speed | Duration | Result | Notes |
|------|-------------|-------|----------|--------|-------|
| [test_name] | [description] | [value] | [seconds] | PASS/FAIL | [observations] |
**Safety Verification**:
- [ ] Emergency stop triggered correctly
- [ ] Speed limits respected
- [ ] Servo bounds enforced
- [ ] Timeout watchdog fired on stall
<picar-behavior-state>
step: [TEST_STATIC | TEST_DYNAMIC]
behavior_name: [name]
safety_constraints: [constraints]
control_loop_hz: [hz]
last_action: [tests completed]
next_action: [proceed to next step or fix failures]
blockers: [any test failures]
</picar-behavior-state>
Before writing ANY behavior logic:
EmergencyStop behavior exists and is testedNo robot behavior is safe without a verified emergency stop.
Before sending ANY command to real motors or servos:
If static tests do not cover the command, DO NOT run it on hardware.
When moving from static to dynamic testing:
Untested speed levels are forbidden in production.
Before using ANY sensor reading to make a control decision:
Garbage-in-garbage-out kills robots. Validate first.
| Anti-Pattern | Why It's Dangerous | Correct Approach | |--------------|--------------------|------------------| | Monolithic control loop | Untestable, fragile, cannot compose | Break into isolated behaviors with single responsibility | | Set-and-forget motor commands | Robot runs away if control loop crashes | Use watchdog timeouts; motors stop if not refreshed | | Raw sensor values in decisions | Noise causes erratic behavior | Apply filtering (moving average, median) before thresholds | | Testing only on hardware | Slow iteration, risk of damage | Static tests with mocks first; hardware tests second | | Shared mutable state between behaviors | Race conditions, unpredictable priority | Each behavior gets immutable sensor snapshot, produces commands | | No speed ramp on startup | Sudden motion, wheel slip, mechanical stress | Ramp speed gradually over 0.5-1 second | | Hardcoded calibration values | Different robots have different offsets | Load calibration from config file; provide calibration routine | | Camera processing in control loop | Blocks the sense-act loop, drops control Hz | Run vision in separate thread/process; read latest result |
Problem: Motor current draw spikes or robot is not moving despite speed > 0
Actions:
1. Immediately set speed to 0
2. Wait 1 second
3. Check ultrasonic for obstacle at contact distance (<5cm)
4. If obstacle: back up slowly, then re-plan
5. If no obstacle: possible mechanical jam -- stop and alert operator
6. Log the stall event with sensor snapshot
Problem: Ultrasonic returns -1 or out-of-range, grayscale returns all zeros
Actions:
1. Mark sensor as unreliable in behavior state
2. Reduce speed to minimum (10)
3. If ultrasonic failed: stop forward motion, rely on other sensors or stop
4. If grayscale failed: abandon line following, switch to obstacle avoidance or stop
5. Log the failure with timestamp and last known good reading
6. Do NOT continue at full speed with degraded sensing
Problem: Two behaviors issue contradictory commands (e.g., turn left vs turn right)
Actions:
1. Priority system resolves: highest priority behavior wins
2. If same priority: stop and log the conflict
3. Review behavior conditions -- they should be mutually exclusive at same priority
4. Add guard conditions to prevent simultaneous activation
5. Re-test the composed system with the conflict scenario
Problem: Robot moving unexpectedly or not responding to stop commands
Actions:
1. Physical intervention: pick up the robot or block its path
2. Kill the Python process (Ctrl+C or kill signal)
3. If software stop fails: disconnect battery
4. Post-mortem: check watchdog configuration, verify emergency stop wiring
5. Add the failure scenario to test suite before re-running
6. Never re-run without understanding why the runaway occurred
Problem: Lost connection to Raspberry Pi during dynamic test
Actions:
1. Watchdog timeout MUST trigger automatic stop (this is why watchdogs exist)
2. If watchdog was not configured: physically stop the robot
3. Reconnect and check logs for what happened after disconnect
4. Verify watchdog timeout is set to <= 2 seconds for all future runs
5. Consider running critical behaviors locally on the Pi, not over network
sensor-integration -- Use for building and calibrating sensor pipelines (ultrasonic filtering, grayscale normalization, camera capture). Feed processed sensor data into Picar-X behaviors.edge-cv-pipeline -- Use for building computer vision pipelines (object detection, lane detection, sign recognition) that run on the Raspberry Pi. Vision behaviors consume CV pipeline outputs.tdd-cycle / tdd-agent -- Apply TDD discipline when implementing behavior classes. Write failing tests for sensor-to-actuator logic before implementing the behavior. Especially valuable for static tests with mocked hardware.jetson-deploy -- If offloading heavy CV inference to a Jetson device, use this skill for deployment. The Picar-X communicates with the Jetson over the network for inference results.development
Federal / government security overlay applied ON TOP OF a base language security review (dotnet/python/php/rust/react). Language-agnostic: adds NIST SP 800-53 control mapping, FIPS 140-2/3 cryptographic compliance (with a per-language crypto table), CUI handling, EO 14028 supply-chain requirements, and DOE Order 205.1B, and emits POA&M-ready findings with FIPS 199 impact levels. Use for federal/DOE/DOD/national-laboratory systems. Triggers on "federal security review", "NIST compliance", "NIST 800-53", "FISMA", "CUI", "FIPS audit", "DOE security", "POA&M", "ATO review". Do NOT use alone — run the matching <lang>-security-review FIRST; this overlay maps and extends it.
tools
OWASP-based security review of React / TypeScript front-end applications. Detects the framework (Vite/CRA/Next), entry points, and data flows, scans against the OWASP Top 10 (2025) mapped to React client-side patterns (XSS via raw HTML, URL/protocol injection, secrets in the bundle, insecure token storage, dependency CVEs, missing CSP, open redirects), and produces a manager-friendly executive summary plus a graded technical findings table. Use to audit React code for vulnerabilities. Triggers on "react security review", "frontend security audit", "audit react for vulnerabilities", "owasp react", "react xss", "react security posture", "npm audit review". For federal / gov / DOE / NIST / FIPS / CUI context, run security-review-federal after this base review. Do NOT use to grade architecture/structure — use react-architecture-checklist.
tools
Analyzes legacy React codebases and produces actionable modernization plans. Primary migration paths include class components to function components + hooks, Create React App to Vite, React 16/17 to 18 to 19, JavaScript to TypeScript, Enzyme to React Testing Library, legacy Redux to Redux Toolkit / Zustand / Context, and deprecated lifecycle/API removal. Does NOT perform the migration — assesses, quantifies risk, and plans. Triggers on phrases like "modernize react", "class to hooks", "upgrade react", "migrate CRA to vite", "react legacy migration", "react 17 to 18", "react js to typescript", "react technical debt", "enzyme to RTL".
development
Scaffolds feature-based React / TypeScript architecture using feature folders, presentational + container components, custom hooks, a typed data layer, and structural CQRS (query hooks vs mutation hooks). React analog of dotnet-vertical-slice and python-feature-slice — no DI framework; uses props/context for dependency injection and a query cache for server state. Use when creating feature-based React projects, adding React features, organizing components by feature rather than by technical type, or scaffolding a feature's data layer. Triggers on phrases like "scaffold react feature", "create react slice", "react feature folder", "react vertical slice", "add react feature", "react feature architecture", "organize react by feature".