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

Click For Summary

Discussion Overview

The discussion focuses on controlling a NEMA17 stepper motor in a closed-loop PID configuration using an Arduino. Participants explore the feasibility and methods of implementing feedback control, particularly in the context of robotic arms and precise positioning.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant describes their setup and expresses a desire to learn how to implement closed-loop control for precise positioning of a stepper motor using a potentiometer for feedback.
  • Another participant argues that stepper motors can be controlled effectively by counting steps and do not require feedback, suggesting that absolute stop detection is sufficient.
  • A different viewpoint emphasizes that while stepper motors can operate without feedback, feedback is necessary to compensate for missed steps if external forces intervene during operation.
  • Some participants note that a properly sized stepper motor typically does not need closed-loop control, and feedback is more useful for error detection rather than for standard operation.
  • One participant suggests that if PID control is necessary, it may indicate that the motor is undersized for the application, and they propose using position error as the process variable and step rate as the control variable in a PID loop.
  • Another participant discusses the importance of acceleration and deceleration in controlling stepper motors to avoid missing steps and suggests that open-loop control is often sufficient for stepper motors.
  • There is mention of the potential for using feedback control with stepper motors by treating them similarly to brushless DC motors, which may offer better performance in certain applications.

Areas of Agreement / Disagreement

Participants express differing views on the necessity and implementation of closed-loop control for stepper motors. Some believe feedback is essential for precise control, while others argue that stepper motors can function effectively in an open-loop configuration without feedback.

Contextual Notes

Participants highlight various assumptions regarding motor sizing, operational conditions, and the design of robotic systems, which may influence the effectiveness of feedback control. There are also discussions about the limitations of stepper motors in high-speed applications and the need for careful speed management to prevent missed steps.

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   Reactions: berkeman and Dullard

Similar threads

Replies
6
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
Replies
9
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 14 ·
Replies
14
Views
1K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 11 ·
Replies
11
Views
2K