AIToday
RoboticsAI Coding AssistantsQiita 機械学習Published: Nov 7, 2026, 22:01 JST

M5Stack Core2 runs tiny AI to balance robot 60秒

Send on LINE
M5Stack Core2 runs tiny AI to balance robot 60秒

3 Key Points

  1. What happened

    After logging 1,000 samples of PD control at a 5 ms cycle, the author trained a 2-4-1 MLPRegressor and ran only its output on the M5Stack Core2, achieving 60 seconds of continuous balancing with repeated finger-push disturbances.

  2. Why it matters

    The experiment shows that a very small network (four hidden neurons) can imitate an existing controller well enough for real-time robot control, suggesting imitation learning is an accessible entry point for physical AI projects.

Not sure about something? Ask the AI

Questions and answers are published on this page.

Summaries like this, every morning.

Context & Analysis

The project addresses a practical hurdle in physical AI: training directly on real hardware risks damaging the robot during trial and error. By first getting the pendulum to balance with a conventional PD controller, the author could safely collect 1,000 samples of stable behavior over about 5 seconds. Those samples then served as training data for a small neural network on a PC.

The network itself is deliberately minimal — two inputs (tilt angle and angular velocity), four hidden neurons, and one output (motor command). After training with scikit-learn's MLPRegressor, the weights and biases were transferred to the Core2, where a short MicroPython function performs inference. The author notes that this is closer to behavior cloning than to reinforcement learning; the AI reproduces the controller's input-output relationship rather than discovering a new balancing strategy.

Safety measures remained in place even during AI-only control: the PD command was computed in parallel, and the system stopped if the AI and PD commands diverged too much, if tilt exceeded 20 degrees, or if the control cycle became abnormal. The author also cautions that the disturbance magnitude was not measured, so the comparison between PD and AI disturbance rejection is not quantitative.

FAQ
What hardware was used for the experiment?
The project used an M5Stack Core2 with its built-in accelerometer and gyro, two Roller485 Lite motor drivers, wheels about 80 mm in diameter, and a LEGO frame. A Windows 11 PC handled training with scikit-learn.
Did the AI learn to balance on its own?
No. The neural network was trained to imitate the output of an existing PD controller, a method the author calls behavior cloning. It did not discover balancing through trial and error.
How well did the AI match the original controller?
The mean absolute error was about 0.34 in motor command units. During the 60-second AI-only run, the average difference between AI and PD commands was about 0.36, with a maximum of about 2.43.
Qiita 機械学習Read Original Article
Send on LINE

AI news that matters for your work, delivered every morning.

Pick your industry and the AI tools you use, and get news related to your work every day.

Free · 30 seconds with Google · unsubscribe anytimeWhat is AIToday? →

Ask AI

Ask AI anything about this article. The AI reads this article, earlier AIToday articles, and Wikipedia, and cites its sources. Q&As are published on this page for other readers too.

Questions and answers are published on this page.

Related Articles

Next articleARTEX agents stole 300 Apple certs for under $1,500