Neu: Die KI-Firewall überwacht die gesamte Plattform und erklärt jeden Vorfall in einfachen Worten. So funktioniert es

Balancing robot demo: tilt angle drifts or jitters, and streaming tuning data gets me rate_limit disconnects

Balancing robot demo: tilt angle drifts or jitters, and streaming tuning data gets me rate_limit disconnects

Gelöst 6 5

Side project for our booth at a trade show: a two-wheeled balancing robot that shows its own live data on a Hermetry dashboard. ESP32, MPU6050 over I2C, two 12 V gear motors with encoders on a TB6612FNG driver. Balancing loop and telemetry in the same sketch.

Two problems, possibly related.

The angle. From the accelerometer alone (atan2(ax, az)) the tilt jitters a lot when the motors run. From the gyro alone (integrating gy) it’s smooth but drifts a few degrees per minute. With a PID on the accelerometer angle the robot oscillates harder and harder and falls within 3 seconds.

The data. To tune I wanted charts of angle, PID output and motor speed, so I publish every loop at 200 Hz to v1/telemetry. Within seconds the device is disconnected, and the Log tab shows rate_limit as the reason.

♥ 0

Could you use the DMP on the MPU6050? I thought it does the angle maths for you.

Ask me about 4–20 mA.
♥ 1

On the data side: a device profile allows 10 telemetry messages a second by default. At 200 a second you blow through it and a device that keeps doing that gets its session closed.

Measure twice, poll once.
♥ 0

That explains the disconnects. So how do people get fast data for tuning, without getting kicked?

♥ 1

Built one of these with my kid a couple of years ago and made both mistakes.

Angle: combine the two sensors with a complementary filter. The gyro is good short-term, the accelerometer long-term:

// fixed 200 Hz loop from a hardware timer, dt = 0.005
float accAngle = atan2f(ax, az) * RAD_TO_DEG;
angle = 0.98f * (angle + gy * dt) + 0.02f * accAngle;

Use a fixed loop rate from a timer, not millis() differences in a busy loop, and keep MQTT out of that loop entirely. Wilson’s DMP route works too, it just ties you to that chip’s library.

PID: start with P only and raise it until the robot oscillates around upright, then add D until the oscillation dies down, then a small I for drift. And add the motors‘ deadband to the output, gear motors don’t move below a few percent duty.

Data: collect samples in the fast loop, decimate to 20 Hz, and send one message per second as an array of records with their own timestamps:

[
  {"ts": 1767600000000, "values": {"bal.angle": 0.42, "bal.out": 12.5, "bal.speed": 3.1}},
  {"ts": 1767600000050, "values": {"bal.angle": 0.38, "bal.out": 11.9, "bal.speed": 3.0}},
  ...
]

That is 1 message a second with 20 x 3 = 60 data points, inside the per-device defaults (10 messages a second, 200 points a second and 6,000 a minute). Your plan has an organisation-wide data points per minute limit too, so check Usage if other devices are busy. The ESP32 needs NTP time for ts, otherwise leave ts out. A chart over the last 24 hours shows every raw point, so the tuning curves stay sharp. Payload forms: MQTT topics and payload reference.

If it isn't logged, it didn't happen.
Akzeptierte Lösung♥ 8

For the really fine tuning I’d also log the full 200 Hz to an SD card and keep Hermetry for the booth dashboard. Two different jobs.

♥ 0

Complementary filter at 0.98 and a timer-driven loop, and it stands. Tuned it with P=18, D=0.6, a tiny I, plus a 6 % deadband. The 1 message per second batches at 20 Hz work, no more rate_limit, and the angle chart on the booth board looks great. My mistake was publishing from inside the control loop, every publish stretched the loop and made the oscillation worse too.

♥ 1
Ansicht von 7 Beiträgen – 1 bis 7 (von insgesamt 7)
  • Du musst angemeldet sein, um auf dieses Thema antworten zu können.

Mitdiskutieren

Melde dich an, um Fragen zu stellen und zu beantworten, hilfreiche Beiträge mit „Gefällt mir“ zu markieren und die Antwort zu kennzeichnen, die dein Problem gelöst hat. Jeder Beitrag bringt Punkte und Stufen.

Teilen