Taming a Leg With Python and CAN Bus: MIT Cheetah-Style Single-Leg Control Practice
by fulaijin007 in Circuits > Robots
23 Views, 0 Favorites, 0 Comments
Taming a Leg With Python and CAN Bus: MIT Cheetah-Style Single-Leg Control Practice

Taming a Leg with Python and CAN Bus: MIT Cheetah-Style Single-Leg Control Practice
Supplies
Taming a Leg with Python and CAN Bus: MIT Cheetah-Style Single-Leg Control Practice
Video source: MIT Cheetah One Leg Control Demo (Python & CAN Bus | Quadruped) — YouTube
Acknowledgment: Special thanks to JLCCNC for providing CNC components for this experiment.
1. Background: From Papers to the Workbench
In recent years, the MIT Mini Cheetah has become a hallmark of small-scale, high-power-density, and hackable quadruped platforms—bringing legged robotics from academic papers to real-world experiments. It can perform backflips, run fast over grass and gravel, and handle unstructured terrain with remarkable agility.
However, before you can “tame” an entire cheetah, the most pragmatic starting point is — getting one leg to behave.
This demo represents a classic “single-leg first” approach: using Python to control brushless actuators via CAN bus, implementing joint-space trajectory and impedance control, and showcasing basic motion primitives.
2. What Happens in the Demo
At its core, the demo consists of a Python-based control script communicating via a CAN-USB adapter with three joint actuators. It demonstrates mode switching, zero-point calibration, trajectory following, and small periodic motions that mimic a walking gait.
The process can be summarized in three steps:
Step 1 — Hardware Setup
The single-leg assembly is fixed on a jig, with hip pitch and knee joints each powered by a brushless motor + encoder. Each joint provides position, velocity, and current feedback, connected to the host PC via the CAN bus.
Step 2 — Power-On Initialization
The Python program:
- Scans for CAN nodes
- Sets operation modes (torque / position / impedance) and limits
- Performs zero-point calibration or soft zeroing
Step 3 — Motion Demonstration
- Joint-Space Trajectory: Sine or step trajectory tracking to verify closed-loop gain and delay.
- Virtual Spring-Damper (Impedance) Control: When the end-effector is disturbed, joint torque compensates instantly, behaving like a compliant spring.
- Basic Gait Primitives: Using simplified triangular trajectories as joint targets to simulate lifting and swinging cycles.
This “single leg → half body → full robot” progression is a common strategy in quadruped research like MIT’s Mini Cheetah program.
3. Control and Communication Highlights
3.1 CAN Communication and Command Timing
- Command Frequency: 100–500 Hz host-side control loops already provide smooth results; higher-bandwidth loops can remain on the motor driver’s internal current loop (≥10 kHz).
- Message Organization: Each joint is assigned a fixed CAN ID, with periodic transmission of position, velocity, and torque targets plus enable bits; the driver returns encoder position, current, temperature, and fault codes.
- Fault Tolerance: Implement debouncing and a safety watchdog to handle packet loss or timeouts.
3.2 Joint-Space PD and Impedance Control
- PD Tuning: Always start with small gain increments and tune one joint at a time.
- Impedance Control: Implement a “virtual spring-damper” at the joint level for compliant response to external forces. This forms the basis for advanced behaviors such as hopping or landing absorption.
- Safety and Limits: Apply three-layer limits (current, velocity, position). Use ramp-in/out during enable/disable to avoid sudden impacts.
3.3 Sensing and Calibration
- Zeroing: Use software zeroing after startup or mechanical hard stops to prevent angular drift or gear misalignment.
- Directional Consistency: Motor phase, encoder direction, and joint rotation direction must align to avoid “inverted PD” issues.
4. Why Start with a Single Leg
- Easier Parameter Tuning: A single leg reduces complexity to two joints and a clear force path, making it easier to optimize bandwidth, delay, and friction compensation.
- High Reusability: PD/impedance gains, filtering, and limit strategies tuned here can be transferred directly to multi-leg systems with minor dynamic adjustments.
- Safety and Cost: A single leg is low-energy and low-stiffness—ideal for “fail fast, fix fast” iterations.
This approach aligns perfectly with the philosophy behind the Mini Cheetah: The full robot aims for high agility (e.g., 3.9 m/s running, rough terrain adaptation) by combining learning-based control with classic templates (Impedance / SLIP models). Your fine-tuned “low-level behaviors” on a single leg are the foundation for the robot’s full-body agility.
5. Subtle Details Viewers Might Miss
1. Apparent Joint Coupling
When three joints run simultaneously, the end-effector path may appear unstable or “floating.” This often results not from poor control but from quantization, static friction, or unsynchronized sampling.
Fixes:
- Send all joint targets on a unified time base.
- Apply a first-order low-pass or Savitzky–Golay filter to velocity feedback.
- Use symmetric trajectories to eliminate geometric bias.
2. “Soft but Stable” Impedance Control
Higher stiffness doesn’t always mean more stability. Excessively high Kp amplifies encoder noise, causing torque oscillations—especially with slender links or soft footpads.
Empirical Tip: Raise Kd (damping) first until vibrations stop, then gradually increase Kp.
3. CAN Frame Rate Isn’t “The Higher, The Better”
If the Python user-space loop can’t sustain 1 kHz but you still push high frame rates, timing irregularities (“micro-lags”) appear.
Practical Strategy:
- Send targets at 200–500 Hz from the host;
- Run current control locally at ≥10 kHz;
- Use interpolation or zero-order hold to smooth trajectories and reduce step artifacts.
6. Evolving from “One Leg” to “Walking and Running”
- Foot Force Estimation Use current and joint posture to infer contact events, or add 6-axis force sensors for robust detection.
- Task-Space Control After kinematic calibration, switch to inverse-kinematics control for end-effector trajectories (circular, triangular, parabolic). This makes motion appear more natural.
- Height Loop / SLIP Control Implement a simplified Spring-Loaded Inverted Pendulum (SLIP) model to achieve vertical “bounce–absorb–rebound” dynamics.
- Dual-Leg and Full-Body Extension Map impedance parameters from single to dual legs, introduce pelvis/CoM control and inter-leg coupling, then extend to full gait phase control.
For reference, MIT’s “Rapid Locomotion via Reinforcement Learning” demonstrates how learned control policies transfer to the real Mini Cheetah—running on grass, ice, and gravel at nearly 4 m/s.
7. Further Reading
- Mini Cheetah Background (MIT News) — Emphasizing lightweight, modular, and repairable design, ideal for rapid controller testing.
- Mini Cheetah Overview (Robots Guide) — History, research positioning, and system characteristics.
8. Conclusion
Though the demo may appear simple, it solidifies the three fundamental pillars of quadruped control: Stable communication, robust low-level loops, and compliant impedance.
Mastering one leg before tackling the full body remains the most pragmatic path from lab prototype to real-world agility.
The next steps — foot force estimation → task-space trajectory → height control (SLIP) — will gradually turn this leg’s “feel” into the robot’s full-body “flow.”