Closed loop brushed DC motor - constant speed algorithms

TLDR; looking for algorithms to control a motor. I have a near-random torque, a battery current that can destroy my motor driver, and I aim for a stable output speed regardless of torque. My inputs are current as reported by the motor driver, and a rotary encoder.

Google led me to PID (proportional, integral, derivative) motor control. Looking at internet examples, PID seems more suited for predictable or more tunable loads than what I'm facing. It also doesn't stop drawing too much current when the motor stalls/starts. I'm trying to avoid reinventing the wheel. Is there some algorithm/library that handles this? Should over-current be a hardware/electrical thing rather than software thing?

Background

I'm building a big mechanical walker robot for an art show. We do the arts-part and two master students are helping us with the walker. They're a bit behind and I'm helping out with the code (approved by their profs). I can code but I lack insight in the control algorithms that I can implement.

The walker has 6 segments. Each segment has 2 legs. The legs are moved with a linkage system, all tied together with a central drive to keep all legs in sync.

I have:

  • arduino nano
  • 500W 24V brushed DC motor
  • BTS7960 43A motor controller dual H-bridge
    • L- and R- current sense readout of the controller
  • Rotary encoder
  • RC transceiver with a pressure sensitive trigger
  • Li-Ion battery packs that can supply 60A
  • A 6 meter (20ft) 12-legged walker with variable torque between -3 and 10Nm
    • As the legs go round, there is a function (from simulation and measurements) to get the expected torque for a certain leg position on a flat surface. As soon as we hit a bump in the road, the balance shifts and we have no idea. I guess I should consider torque to be random.
  • Walking speed that is +-1000rpm (30:1 gear reduction in drive shaft to legs)
  • circuit diagram (my first ever, be gentle)

My goals:

  • more or less constant speed, regardless of torque
  • don't burn the controller/motor
    • current protection for startup/stall ?

Current status:

  • motor spins depending on RC trigger (no load)
  • rotary encoder signal is coming in
  • current sense is still troublesome, but I found a video. Hope to have that working soon
  • copy-pasted implementation of PID, but without load this doesn't do much

Any advice is appreciated, especially if I'm doing something stupid. It's a broad topic to quickly wrap my head around.

I have a project somewhere that does constant speed brushed DC motor control based on an Adafruit Metro M0 Express (I had an extra one sitting around, sue me) and an encoder. It does not do current control and it would be completely unsupported because I haven't run it in a couple years and don't remember anything about it. However, the code is really basic and shouldn't be hard to follow.

If you think that it might be useful, I'll look for the project source (may already be on github...), but remember: there's no support.

That would definitely help! I can handle the 'no support' part. Just curious about the control flow.
Thanks!

PID is usually used for brushed DC speed control, and you have all the parts you need (motor, encoder and controller). There are plenty of tutorials on line, which can be found with a search phrase like "arduino pid motor speed control".

Yes, true indeed. PID seems to be ideal for tuning a motor attached to a certain load. For example a sign you spin, a pully you want to use to lift something, a machine you set in motion. Most, if not all examples I can find have a very "steady load". Speed up the motor and you can almost exactly calculate what the required change in torque will be. For these scenarios and in ideal conditions torque over time is a flat line.

Our walker varies tremendously in required torque, based on random events it encounters (speedbumps, sidewalk). In ideal frictionless conditions our torque looks like this and I have no idea if that matters. I can image that it doesn't as cruise control encounters wind, hills, bumps, ... I can also grasp that what makes PID work (integral and derivative terms) can work against me.

Am I overthinking this? The robot is currently being refactored by the students till Friday and I have to wait till I can test it out. Hence me trying to find the best algorithm.

The best algorithm is the one that performs well in your particular application, and better than any other algorithm you have tested. The field is covered in Control Theory courses for advanced, graduate level engineering students.

An interesting algorithm is this phase-locking of the encoder pulses with a reference frequency by varying the power to the motor:

Your process doesn't so much look like "Constant speed" as looking for controlled position changes in time--If you spin too fast against a low torque resistance, or too slow against a high torque resistance, I think you might want to correct for the phase offset, rather than seek constant rpm.

Hey, sorry to report but I can't find the source code for that project.
Which is really bothering me: I still have the hardware and I thought it
was on my github but apparently not.

And of course right afterwards, I found it. Not on github, I'll see if I can PM you the file.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.