Assistance with Power DIY servo

Hello,

I post this message in this section because I think it fits better, but if moderators think I should change it to mechanics section, please let me know.

We, at a secondary school in Spain, try to build a power servo for using in big projects. Since commercial big servos are too expensive for us, we decided to build one with a DC motor and our own means. We have been working on this project for some months, testing different components, and now we are stuck because it does not work the way we'd like.

The components we are using are:

  • 300 W DC motor
  • encoder HP QEDS-7163
  • H-bridge made by us, capable of 2000 W

In addition to these components, we have an Arduino board that controls the system and a set of reduction gears. We have added a second Arduino board that is used to control the first one from a remote point, via an I2C communication.

The picture of our system is:

We attach the program we are using. We use the PID library to control the speed and direction of the motor, and we have tuned the parameters Kp, Ki and Kd the best we could know, but the output shaft moves slowly and oscillates. If we change the parameters so that it does not oscillate, the movement is very slow. An we are working without load.
There is another slight problem: the h-bridge accepts a PWM input to select the motor speed, and another pin to select the direction, but the motor can't run at speeds lower than the minimum, so we ignore when the pid function gives an output in that range, which means that sometimes the servo output shows a small angle error.

I plan to record a video of the servo performing and upload it tomorrow.

Any ideas to improve the servo would be appreciated.

Rafael Caballos

Servo300PID.ino (9.32 KB)

Do you know how many times per second your control loop runs? I can see a big delay of 1000ms, which would mean it's only updating the motor speed once per second. This is probably too slow to approximate a PID, even with the best parameters it can't respond fast enough.

There is also serial printing code in the control loop, this has a large and variable delay, not what you want in a controller.

You should be trying to separate out which parts of the control loop are 'real time', the PID update, and which parts can be delayed (serial communication). Eventually the PID loop should go in a timer triggered interrupt.

Your H-bridge probably can't handle 2000W (though a 300W motor might be fine). Without a heatsink even the best MOSFETs can only handle a fraction of their rated capacity.

An electronics diagram may help. Include the circuit of your H bridge.

Weedpharma

Reading your code is like reading Spanish :wink: - is there a Spanish forum perhaps?

You might get more results if you translate it...

But yes, any delays will hinder accurate PID tracking - it is always there, but the idea is to reduce it to the level of other factors (chain is as strong as the weakest link).

If that delay(1000) (or any other like delay(500), delay(100) etc...) is actually in the PID loop that the first thing you need to address - PID might be theoretically 'working' but in terms of the time-ranges you're interested in, it's killing your system.

Also, is that your encoder on the end of all that gearing?

You're going to have mechanical latency there also - think of all the slop in the system, it'll take time for a change of direction to be 'seen' by the encoder - meanwhile your PID is trying to fix this, but of course your PID has those delays ! - heh heh, two wrongs almost making a right...

Have you done much control theory? Laplace? Perhaps, do you have a intuitive understanding of how P, I and D work in isolation? ... and the effects too much of either can have? Ziegler–Nichols?

You can have a standard servo control a large H-bridge for a large motor like below.