Electronics How to control a stepper motor in closed loop (PID) in arduino?

AI Thread Summary
Controlling a NEMA17 stepper motor in a PID closed loop involves integrating feedback mechanisms, such as a multiturn potentiometer, to ensure precise positioning. While stepper motors typically operate in open loop mode by counting steps, feedback can enhance performance, especially in applications like robotic arms where external forces may cause missed steps. To implement closed loop control, one can use position error as the process variable (PV) and step rate as the control variable (CV) in a PID loop. It is crucial to manage step rates to prevent missing steps, particularly during acceleration and deceleration phases. Although stepper motors can be effectively controlled without feedback, adding it can improve fault tolerance in demanding environments. However, if high precision and speed are required, a properly sized stepper motor or a brushless DC (BLDC) motor may be more suitable. For further learning, resources such as example sketches and tutorials on PID control for stepper motors are available online.
mastermechanic
Messages
107
Reaction score
15
Hello,

What I have
I have a NEMA17 stepper motor driven by a DRV8825 driver module, an arduino uno, a multiturn potentiometer.

What I want to do
I want to control the stepper motors in a PID closed loop. The motor shaft will be connected to the potentiometer and I will be sure that the motor goes to the exact position.

What I have done
All necessary physical connections (arduino,driver,pot,motor etc.) done correctly. I can spin the motor at different speeds, directions and send it to different step positions without using a library. So I am sure that there is no physical problem remaining. However, I dont exactly know how I can control it in a closed loop feedback. It is a bit different then driving a DC motor with PWM in a closed loop PID sketch therefore I am confused.

I am not constraining you,

You can explain how it's done without using a library
You can explain how it's done with using a library (i.e. accelstepper.h)
You can link some pages or videos showing an example sketch

I just want to learn how to control the position of stepper motor in closed loop as it is implemented in robotic arms.
 
Physics news on Phys.org
mastermechanic said:
I want to control the stepper motors in a PID closed loop. The motor shaft will be connected to the potentiometer and I will be sure that the motor goes to the exact position.
You control stepper motor by driving in steps and counting the steps. The only other thing you need is some absolute "stop" detection, so you can know when the stepper motor is at position "zero" or similar. You don't need feedback to control a stepper motor...
 
berkeman said:
You control stepper motor by driving in steps and counting the steps. The only other thing you need is some absolute "stop" detection, so you can know when the stepper motor is at position "zero" or similar. You don't need feedback to control a stepper motor...

Think about a robotic arm, I sent the arm to a specific position and it went, so far there is no problem. But if I force the arm to move or intervene the arm while it is moving it will miss some steps. The controller must know it is missed and it should compansate it by sending the necessary step commands (i.e. direction and # of step). This is why I need feedback.
 
mastermechanic said:
But if I force the arm to move or intervene the arm while it is moving it will miss some steps.
In general, that should be disallowed by the overall design. I guess if you're designing fighting robots or something, you might miss some steps. But in normal operation a stepper motor should not be missing steps. If you detect an overcurrent condition from a partially stuck rotor, you can back up to a reset position where you use the "stop" switch to recalibrate your zero point.

I suppose if you really want a lot of extra fault tolerance for a harsh setup, you can add feedback, but normally with a stepper motor assembly you do not add that extra cost and processing.
 
A properly sized (and operated) stepper doesn't really need closed-loop control. Feedback is useful for error detection and homing, but if you need PID for your position moves, your motor may be too small for your speed/inertia. You can position a stepper more precisely with blind steps than with potentiometer feedback.

Having said that: You can operate a PID loop with Position error as PV (input) and Step rate as CV (output). Make sure to limit the step rate to something that will work for your load - step too fast and nothing will happen.
 
Yes, if you are moving fast you can't stop immediately without missing steps. You will also need to accelerate up to high speed in control also or you will miss count. That is why open loop (dead reckoning) algorithms need for you to characterize the error free start and stop speeds for your application and then use a trapezoidal velocity profile (acceleration and deceleration). For any high performance high speed motor, you must predict where you will stop and slow down in preparation. Even purely analog controllers do this in response to a decreasing position error.

Step motors are nearly always used open loop since otherwise you would choose a BLDC motor. BLDC motors are nearly the same thing but they work better for analog control. Steps are great if you need steps, but they are an unnecessarily expensive difficulty if you aren't using them. The step motors are used because you can count discrete positions and/or they will park better if you want to turn the drive off. If you did want to use analog control or feedback control with a step motor, you can basically just pretend it's a BLDC motor, they are driven essentially the same way. There's lots of stuff on the web about this sort of application.
 
  • Like
Likes berkeman and Dullard
Three rabbits will be wintering in a 2m x 2m x 2m wooden hut. Outside temperature does not go below -30c (-22f) Planning to put a 50cm by 50cm 1mm thick stainless steel sheet on the floor of the hut (inside off course) My plan is to heat the sheet with a 50w PTC heater element https://fi.rsdelivers.com/product/dbk-enclosures/fg135600/dbk-enclosures-heating-element-75mm-50-w-100-240-v/dc/2995922?backToResults=1 Is this heater (50W) enough to keep the pad warm enough to sustain liquid...
Hey all. I'm looking to buy a zero-turn mower and I need to build/purchase a ramp to get it into my shed for storage. Exact model is this one. I need to figure out how long of a ramp I need to make sure the mower doesn't bottom out when driving up and down the ramp. Mower stats: Wheelbase: approximately 76 inches. Height: 4.5 inches (based off the highest setting on the deck height adjustment) Shed entrance is 12 inches off the ground. The manufacturer says that the mower can handle...
Back
Top