Central Pattern Generator — Innate Rhythmic Locomotion
The Central Pattern Generator (CPG) produces the baseline rhythmic pattern for quadruped locomotion. It is the “innate gait” — the creature can walk before the SNN has learned anything. The SNN then learns to modulate and eventually partially replace the CPG through the competence gate.
Biological Basis
CPGs are neural circuits in the spinal cord that generate rhythmic motor patterns without sensory feedback or descending commands. In vertebrates, CPGs produce locomotion patterns that can be modulated by brainstem signals (speed, direction) and sensory feedback (terrain adaptation). Grillner (2003) demonstrated this in lamprey, where isolated spinal cord segments produce swimming patterns.
Phase-Coupled Oscillators
Each leg has an independent oscillator with phase coupling to produce quadruped gaits:
phase_i(t+1) = phase_i(t) + 2π × frequency × dt Joint commands from phase: hip_cmd = sin(phase) × hip_amplitude knee_cmd = sin(phase + knee_offset) × knee_amplitude abd_cmd = sin(phase × 0.5) × abd_amplitude Phase offsets for trot gait: FL: 0° FR: 180° (diagonal pair) RL: 180° RR: 0° (diagonal pair)
Competence Gate
The CPG fades as the SNN demonstrates competence. This prevents the SNN from fighting the CPG pattern:
motor = CPG × cpg_weight + SNN × (1 − cpg_weight) cpg_weight starts at 90%, decreases as actor_competence rises. Actor competence is measured by sustained forward velocity without falls.
In the 150k ball run, CPG weight dropped from 90% to 43% while actor competence rose to 0.939 — the SNN successfully took over most motor control.
Proximity Brake (Issue #79c)
When the creature approaches a ball (distance < 1.0m), CPG amplitude is reduced linearly:
proximity_amp_scale = max(0.1, 0.3 + 0.7 × (ball_dist / 1.0)) At 1.0m: full amplitude (1.0) At 0.3m: 30% amplitude (0.3) At 0.0m: minimum (0.1)
This prevents the creature from overshooting the ball. Biology: animals decelerate when approaching a target (optic flow regulation).
Steering
Steering is implemented inside the CPG via asymmetric per-leg amplitude modulation — not as a post-hoc motor offset. This follows the reticulospinal model (Grillner 2003): brainstem neurons modulate left/right CPG half-centers to produce turning.
References
- Grillner, S. (2003). The motor infrastructure: from ion channels to neuronal networks. Nature Reviews Neuroscience
- Ijspeert, A.J. (2008). Central pattern generators for locomotion control in animals and robots. Neural Networks
API Reference
SpinalCPG(n_actuators, joints_per_leg=4, config=None)
Phase-coupled oscillator CPG for quadruped gait.
compute(dt, arousal, freq_scale, amp_scale, steering) → np.ndarray
One step of CPG commands for direct-joint robots (Go2). Per-joint: [abd, hip, knee, ankle] × 4 legs. Steering via asymmetric abduction.
freq_scale— BehaviorPlanner multiplier (1.0=walk, 1.4=trot)amp_scale— amplitude (1.0=normal, 0.1=proximity brake)steering— -1..+1, reticulospinal turning model
compute_tendon(dt, arousal, freq_scale, amp_scale) → np.ndarray
CPG for tendon-actuated robots (Bommel). Output: [yaw, lift, extend] × 4 legs.
get_cpg_weight() → float
Current CPG weight in motor blend. Fades from 0.8 → 0.2 over cpg_weight_fade_steps.
from_evolved(path, n_actuators, jpleg) → SpinalCPG
Load evolved CPG parameters from cpg_config.json.
SpinalCPGConfig (key parameters)
frequency: 1.0 Hz (slow walk) phase_offsets: [0.0, 0.5, 0.75, 0.25] (walk gait) hip_amplitude: 0.35 knee_amplitude: 0.25 base_amplitude: 0.30 max_amplitude: 0.70 cpg_weight_start: 0.8 cpg_weight_end: 0.2