Hello. I am current using 34:1 Metal Gearmotor 25Dx67L mm MP 12V with 48 CPR Encoder. My goal is to have the motor oscillate 15 degrees for essentially an unlimited amount of time (several hours to days). I am using Raspberry Pi Four and LN298 motor driver. I have generated code to have the motor oscillate a specific number of repetitions; however, I notice after plotting encoder position data there is a 7 count drift with each cycle. This difference happens when the motor switches from clockwise to counterclockwise. I tried using PID control, but then I am losing smooth motion because it is a small angle and 30% speed. I wanted to see if encoder position is being tracked accurately by manually moving the motor and measuring the angle, with live encoder position on python monitor. However, the motor is not movable by hand (locked). Is it possible to do this test on this motor?
Hello.
If you temporarily remove the black plastic end cap from the motor to expose the encoder, it should be easier to rotate the motor by turning the encoder disc since you circumvent the gearbox that way.
By the way, I noticed a couple shortcomings with the setup you described:
- It is not entirely clear how you are reading the encoder, but Raspberry Pi computers are typically not well suited for timing sensitive tasks, like reading encoder signals. Using a separate microcontroller with interrupts (e.g. a Raspberry Pi Pico or Arduino) is usually a better strategy.
- The L298 is an ancient and inefficient driver that have no place in modern designs. For better alternatives, you might consider one of our brushed DC motor drivers.
Also, I am not sure what your operating lifetime requirements are, but if you are expecting that your setup might be running for continuously for several days at a time, then a brushed DC motor might not be ideal. When it eventually stops working (probably the motor brushes will be the first part to wear out), you might consider revising your setup to use a stepper motor. Another reason to switch to using a stepper motor for this type of application is they are inherently position controlled, so you might not need to use an encoder with it.
- Patrick
