DC Motor PI Controller - Page 1
Forum section: electronics / projects

author: maurosmartins
author_rank: Regular Contributor
timestamp: December 29, 2018, 06:32:35 pm
content: Hello all,I'm interested in implementing a PI speed controller for a small vehicle, so far I've collected the data for a step response and figured out a first order transfer function approximation for the system:with that information I've calculated the Kp and Ki gains using Ziegler Nichols method. I've simulated it in scilab xcos:with the following results:Now my doubts start (assuming the previous is ok) I'm using a STM32 microcontroller to implement the PI controller, I've set PWM in such a way that it accepts a value of 0 to 1000 units, the control signal of my controller looks nothing to itDo I have to adapt this control signal to my PWM range? can someone clarify what I'm doing wrong and what I should be doing?thanks in advanced,Best regards, Mauro.

author: XaviPacheco
author_rank: Regular Contributor
timestamp: December 30, 2018, 01:15:39 am
content: Quote from: maurosmartins on December 29, 2018, 06:32:35 pmYes.As you're using a STM32, can you upload your embedded PI controller? I implemented one recently and it worked well. What are you using for feedback?

author: IanB
author_rank: Super Contributor
timestamp: December 30, 2018, 02:07:59 am
content: Quote from: maurosmartins on December 29, 2018, 06:32:35 pmIt's conventional when creating feedback control loops to normalize variables. So you would take your speed measurement between zero and the maximum expected speed and scale this to a value between 0 and 1. Then you would take the PWM control range of the motor between no power and full power and scale this also between 0 and 1. Now your controller will operate on dimensionless variables, which will be much more convenient during simulation exercises and also during implementation.A secondary thing to keep in mind when doing speed control of motor vehicles is the concept of "jerk". Sudden changes in power input to the motor can be unpleasant for passengers, so you may wish to modify the control algorithm to smooth out such changes. Of course, if the vehicle has no passengers you don't need to worry so much, but there is still a possibility of excessive wear and tear on the drivetrain.

author: rstofer
author_rank: Super Contributor
timestamp: December 30, 2018, 02:50:07 am
content: Not withstanding the excellent advice above, I don't think you are very far off. If Figure 4 is supposed to represent voltage to the motor, sure, I expect it to throttle back when the error decreases as it does when the RPM approaches the setpoint. The integral part of the equation doesn't really kick in until some long time relative to the motor spinning up to speed. Note t=0.2 on your various graphs. In fact, draw a vertical at 0.2 on all the graphs. You are starting to get close to the setpoint and the voltage is throttling back.

author: max_torque
author_rank: Super Contributor
timestamp: December 31, 2018, 01:22:40 pm
content: Speed control in the real world for a vehicle becomes a compromise!In the real world, things like gradients, head and tail winds, corners, varying battery voltages, requirements for min/max accel rates etc all play a part. The basic "stready state" gains to get to a set speed are really not the issue! You also need to consider how accurately you want your vehicle to follow the requested speed target? ie +- 1mph, or +- 0.001mph etc. That makes a huge difference!

author: maurosmartins
author_rank: Regular Contributor
timestamp: December 31, 2018, 03:55:49 pm
content: Hello all, thank you replying!Quote from: XaviPacheco on December 30, 2018, 01:15:39 amOk I'll upload my code as soon as I have something working, it may take a whilefor feedback I'm using an "AS5035" magnetic encoder with quadrature output (currently discontinued) and TIMER4 in encoder mode. I've designed a custom board with the IC and glued the magnet on the motor shaft.@IanB,Quote from: IanB on December 30, 2018, 02:07:59 amI'll try your sugestion and let you know as soon as possible, thank you very much for helping.Best regards, Mauro.