I have a Pololu geared motor - 131:1 ration. I am trying to use the PID library to drive this motor.
I recognize this post is somewhat repetitive to my other posts.
I still have a problem getting one part of my program to work correctly.
I am driving the DC geared motor, using Setpoint,Input, and Output from the PID
object. The input value comes from an encoder on the motor shaft. I use pin change
interrupt to increase (or decrease) the count ==> the Input. When I run the PID in the
DIRECT mode, the input speed is detected and adjusted more or less “close enough”, the “count” is incremented, and I.E. a Setpoint of 40, gives and input of 39 or 40, the PWM is around 39.
BUT if it reverse the direction of the motor (switching HIGH to LOW on Arduino Pin 2, and LOW to HIGH - Arduino pin 4) the motor reverses, the encoder interrupt decrements for a few counts and the motor stops, which means the encoder has no output.
I have made some changes in the code I am using, and now when I reverse the motor from the initial direction (in this case clockwise) - the PWM goes to MAX (255), the motor runs at full speed (approx 100 rpm), and the encoder decrements, but the PID object does not respond - i.e. does not try to maintain setpoint of 40,
I have tried using myPid.SetControllerDirection(REVERSE), etc to no avail.
Any guidance here? I am missing something. I will attach the code I am using.
I also have code here (commented out) that performs a manual error calculation using Kp and Kd,
and this code functions correctly - I can reverse direction of motor (using “getparam” func) and the motor
will reverse and maintain the setpoint.
My end goal for all this is to be able to use a DC motor (not a stepper), and perform a “one step” with
a combination of PID and count - I want to rotate motor 1 “click” pause for a given time, and move one more “click”, etc.
FullMotorControl.ino (16.1 KB)