control algorithm for motor

Hey everyone!

I want to get an RC car to reach and maintain a certain speed. So far I have got a digital hall sensor to measure the current speed of the vehicle and I can give commands to the motor with the ESC via PWM.

The part I struggle with now is to figure out what command to give the ESC at a given time. I am basically looking for a function updateThrottle(currentSpeed, targetSpeed, currentThrottle).

Obviously, I must increase the throttle if currentSpeed < targetSpeed and vice versa. But how exactly?

I would be grateful for general guidance on this topic (=

Havel a nice day,
Mark

Most people use PID control.

In general every application requires a different set of Kp, Kd and Ki values (can be zero), and you have to determine the best set of values in a process called "tuning". Google "PID tuning" for tutorials.

jremington:
Most people use PID control.

In general every application requires a different set of Kp, Kd and Ki values (can be zero), and you have to determine the best set of values in a process called "tuning". Google "PID tuning" for tutorials.

Uhhh that seems to be a very interesting rabit hole to go down! Thank you for your help. I will try to understand them and implement one myself.

I posted the code for a simple motor control system I am using at the bottom of this Post. If you read through the the Thread you should get a good sense of the context. My code uses the same core calculations as the PID library.

I am working on an easier-to-understand version together with an explanation but I won't be ready to publish it for a few more days.

...R