How To Setup DC Motor PID Speed Control With The EPMC
Learn how to setup PID control for your geared DC motor with the Easy PID Motor Controller (EPMC)
Last updated
Learn how to setup PID control for your geared DC motor with the Easy PID Motor Controller (EPMC)
Last updated
The Easy PID Motor Controller (EPMC) is an easy-to-use PID motor driver for precise control of the angular speed of geared DC motors with quadrature encoders. It allows you to command the motors with actual velocity commands (in rad/sec) rather than the traditional PWM commands.
It has a GUI application that allows one to easily set up the motor PID parameters and libraries for easy interfacing with your preferred project (whether ROS2, Arduino, Python, or Cpp robotics projects).
It can easily be used by hobbyists, students, learners, researchers, etc.
But before one can begin sending angular velocity commands to the DC motors (i.e using it in your preferred project), some parameter setup like the motor PID gains. needs to be done.
This tutorial aims to teach you how to setup your Geared DC Motor PID with the EPMC so you can start using it in your preferred project.
Here are the steps we would be following to setup the Motor Velocity PID with the EPMC Module:
Ensure your PC is capable of communicating with Arduino boards - specifically Arduino Nano -(both code upload and serial communication) as the EPMC Module uses a super-mini arduino nano microcontroller.
Ensure to have ready your Geared DC Motor(s), the EPMC Module, and a USB Cable for serial communication.
First things first, you need to ensure the EPMC module is properly powered - 12v (actually from 7v to around 12v) and GND - and the motor encoder is also properly powered -VCC and GND - on the MOTOR port.
Then connect the M+ and M- motor pins and the A and B encoder pulse pins (yours might be any other label).
After this, connect the EPMC Module to your PC.
First Start the application
Once you start the application and connect to the EPMC module to your PC, you will see a page that allows you to choose the USB port. Select the right port, and click connect, then wait for about 5 seconds (you should see a green-blue LED sequence on the EPMC Module during this time) and you should have a successful connect dialog appear, click ok to continue. If not, refresh and try again to ensure you select the right port.
You should now see a menu on the left-hand side. If you’re setting up for the first time, reset all parameters by selecting the RESET PARAMS menu option and clicking the RESET ALL PARAMS button to start the setup process with a clean slate. Once the reset is completed, close the application, disconnect and reconnect the EPMC Module, and start the application again.
On the module, your motor with encoder would be connected to one of the MOTOR A or MOTOR B port. On the Application menu, you should see the MOTOR A ENC menu option, select it.
You should now see options for setting Encoder Pulse Per Revolution (*PPR), Motor Default Direction for positive PWM or velocity commands (*DIR), Test Control PWM ( TEST_PWM), and Test Duration (DURATION).
You will also see the MANUAL MOTOR CONTROL arrow buttons for controlling the Actual Motor electronically instead of having to turn the motor with your hands.
Again, you will see the Motor’s angular position [POS(rad)] and angular velocity readings [VEL(rad/s)] with two buttons – one to send a PWM command to the Actual Motor (START MOTOR) and the other to reset the hand of the Display Motor (RESET HAND).
Leave the *PPR settings as is (its default value is 1000 after reset) and change the *DIR settings to forward. Set a PWM value and leave the DURATION as it is for now.
Motor (M+ and M-) Connection Check For this check, you’ll watch the Actual Motor, not the Display Motor. Ensure the *DIR is set to forward and command the Motor with a TEST_PWM value. Watch the Actual Motor begin to rotate, if rotation is counterclockwise then the motor (M+ and M-) is properly connected. If not (i.e. it’s rotating clockwise), switch the M+ and M- connection and test it again you should see it now rotating counterclockwise.
Motor Encoder Pin (A and B) Connection Check For this check, you’ll watch the Display Motor, not the Actual Motor. Ensure the *DIR is set to forward and command the Motor with a TEST_PWM value. Watch the Display Motor begin to rotate, if rotation is counterclockwise then the motor encoder (A and B) is properly connected. If not (i.e. it’s rotating clockwise), switch the A and B connections, without touching the M+ and M- connection, and test it again you should see the Display Motor now rotating counterclockwise.
Final Result: Both Actual Motor and Display Motor Should be rotating Counterclockwise.
Before you commence this step, first test-control the motor with the lowest possible PWM that can rotate. You want to make sure you can make the motor move as slowly as possible (as much as it can allow). PWM values between 70 and 100 should do depending on the motor. Once done, note this value (I will call it slow PWM).
Also, add a form of marker to your Actual Motor to track the position during the test. This can be easily done by attaching a wheel to it and marking the wheel to track its angular position.
The *PPR value is the number of encoder pulses per full rotation on the outer shaft (after the gearing). I recommend initially leaving the PPR value as the default value (1000) or you can choose to calculate the initial value from your motor’s datasheet with the formula below.:
Once you have calculated the initial PPR value, enter it and click the SET button to set it.
Now, use the MANUAL CONTROL buttons to align the Actual Motor so its marker is positioned vertically, then click the RESET HAND button to align the Display Motor marker vertically. Both the Actual Motor and Virtual Motor Markers should now be pointing vertically upward.
Command the motor with the slow PWM gotten earlier and notice the marker motion of both the Actual Motor and Display Motor till both come to a stop.
If the Display Motor marker is faster than the Actual Motor marker, increase the *PPR value and go back to aligning the Actual and Display motor markers and commanding with the slow PWM again (as done previously).
If the Display Motor marker is slower than the Actual Motor marker, decrease the *PPR value and go back to aligning the Actual and Display motor markers and commanding with the slow PWM again (as done previously).
Keep doing the above until you get a satisfactory value (i.e. both are moving at the same pace and stopping at the same angular position).
As the heading implies, we want to know the maximum possible angular speed (w_max) the motor controller can command based on the encoder PPR parameter obtained in the previous step.
On the Application menu, you should see the MOTOR A PID menu option, select it.
You should see the PID gains (*KP, *KI, and *KD). Also, you’ll see the *W_MAX(rad/s) variable which holds the maximum target command velocity that can be sent to the motor as allowed by the EPMC module.
Next, we check the actual motor’s w_max speed (in rad/sec) from the GUI.
Go back to the MOTOR A ENC page, send a high PWM value (250 or 255) to the motor, and note the VEL(rad/sec) value being printed, use this as the actual motor’s w_max speed (in rad/sec). If the actual motor’s w_max speed (in rad/sec) is less than the initial computed *W_MAX(rad/s), change it. if not leave it as it is (as you cannot change it to any value above the initial computed value).
On the Application menu, you should see the MOTOR A PID menu option, select it.
First, set the TARGET(rad/sec) value to a value close to the *W_MAX(rad/sec) value.
Set the *KP (keeping *KD = 0.0, *KI = 0, and TEST_SIGNAL is set to step) by increasing, adjusting, and testing using the START PLOT button it to see its output on the graph. Keep increasing and adjusting until the actual velocity signal begins overshooting beyond the target velocity signal.
Set the *KD (keeping *KP the same, *KI = 0.0, the TEST_SIGNAL is set to step) by increasing and adjusting it until the overshooting actual velocity signal is damped (smoothened out).
You can further use the square wave signal to continue setting the *KD gain (i.e keeping *KP the same, *KI = 0.0, the TEST_SIGNAL is set to square).
This is good for checking and removing any form of jerking (i.e. little reverse motion) during an abrupt stop (halt). Increase the *KD gain till you see no jerking in the motor when stopping abruptly (halt). This setting is very good for mobile robots.
Finally, Set *KI (keeping *KP and *KD the same, and the TEST_SIGNAL is set to square or step) by increasing it until the steady-state error is removed (i.e. till the actual velocity signals meet the target velocity signal).
Once done, test with other signal types (and even other target velocity values) to see if you are satisfied with the result. If not, you can repeat the process of the PID gain setting tweaking it to your taste and application.
Now go back to the MOTOR A ENC menu option, select it.
You can set the default positive direction (*DIR) to forward or reverse.
Set it to forward if you want to use it as a “left wheel” or if you want the positive rotational direction to be counterclockwise.
Set it to reverse if you want to use it as a “right wheel” or if you want the positive rotational direction to be clockwise.
You can also set its i2c address for communication with Arduino microcontrollers.
Select the I2C SETUP menu and set your preferred address value (between 1 – 127). The default address value is 1.
.
Download the EPMC Setup Application executable and extract it.
NOTE: if you don't find the application for your operating system, you'll need to run the epmc setup application python code via a python virtual environment. check the github repo for that (Windows, Linux [Ubuntu], and MacOS)
facing any issues,
The PID gain is set empirically. You can learn more from this video by