Add in motor stall question#229
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a new technical interview question about DC motor stall detection to the document. The question asks how to detect a stalled-rotor condition when a DC motor is connected to a load, with two scenarios: using only a current sensor or only an encoder.
Key Changes:
- Added a new question section for motor stall detection
- Introduced data structures for motor stall detection in a header file
- Integrated the new section into the main document structure
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/motor_stall.tex | New question section asking about stalled-rotor detection methods for DC motors |
| src/main.tex | Integration of the motor_stall.tex file into the document structure |
| src/code/motor_stall/motor_stall_header.h | Header file defining data structures and function prototype for motor stall detection |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
|
|
There was a problem hiding this comment.
This section is missing the answer content after the spoilerline. All other question sections in this document (like pid.tex, buck_vs_ldo.tex, current_sense.tex, interrupts.tex) include substantial answer content after the spoilerline command, such as explanations, implementations, and follow-up discussions. The question references a header file and asks for discussion of implementation approaches, but no answer is provided. Consider adding subsections that discuss the implementation approaches for both the current sensor and encoder-based detection methods.
| In a stalled-rotor condition, the motor is being driven electrically (voltage or PWM duty applied), but the shaft does not rotate or rotates much more slowly than commanded. For most DC motors, this leads to a large increase in current (approaching the stall current) and to a mismatch between expected and measured speed/position. The implementation strategy depends on which feedback is available. | |
| \subsection*{Stall detection with only a current sensor} | |
| With only a current sensor, stall detection is based on the relationship between applied voltage (or PWM duty) and the expected current. At a given supply voltage and load, a free-running motor draws a characteristic current. When the rotor stalls, the back-EMF drops to zero and the current rises toward the motor's stall current, which is typically a multiple of the nominal running current. | |
| A basic algorithm is: | |
| \begin{itemize} | |
| \item Measure the motor current periodically using the current sensor. | |
| \item Maintain an estimate of the motor operating point, e.g.\ commanded duty cycle and direction. | |
| \item Define a current threshold $I_\text{stall}$ that is safely above the normal operating current for the maximum intended load but below the continuous stall current rating. | |
| \item If the commanded duty (or voltage) is above some minimum value for a certain amount of time and the measured current persistently exceeds $I_\text{stall}$ for longer than a debounce interval $t_\text{debounce}$, declare a stalled-rotor condition. | |
| \end{itemize} | |
| Practical implementation details: | |
| \begin{itemize} | |
| \item \textbf{Filtering:} Low-pass filter the current measurement (e.g.\ moving average) to avoid false triggers caused by PWM switching ripple or short transients during start-up. | |
| \item \textbf{State awareness:} Only evaluate stall when the motor is commanded to move (non-zero duty or voltage). If the motor is commanded off, high current should instead be treated as a fault in the driver. | |
| \item \textbf{Startup vs.\ steady state:} During acceleration from standstill, high current is expected for a short time. Use a separate, longer timeout during startup, or require that a certain minimum time has elapsed since the start command before stall detection becomes active. | |
| \item \textbf{Hysteresis:} Use different thresholds for entering and leaving the stall state to prevent chattering if the current hovers around $I_\text{stall}$. | |
| \item \textbf{Action on stall:} Once stalled, the implementation should limit or cut the motor drive (e.g.\ reduce duty to zero) and report the stall via the API defined in the header file. | |
| \end{itemize} | |
| Typically, the header file would expose functions such as: | |
| \begin{itemize} | |
| \item an initialization function that configures the current measurement and thresholds, | |
| \item a periodic update function that is called from a timer interrupt or main loop, which reads the current and updates the internal stall state, and | |
| \item query or callback mechanisms for higher-level code to react when a stall is detected. | |
| \end{itemize} | |
| \subsection*{Stall detection with only an encoder} | |
| With only an encoder, we cannot directly observe current, but we can compare the commanded motion to the measured motion from the encoder. A stall manifests as the encoder position failing to change (or changing far too slowly) despite the controller commanding motion. | |
| A basic position/speed-based algorithm is: | |
| \begin{itemize} | |
| \item On each control cycle, record the current encoder count (or computed angle) and the current time. | |
| \item Compute the encoder increment $\Delta\theta$ and elapsed time $\Delta t$ since the last sample to estimate actual speed. | |
| \item From the command (desired speed or duty cycle), derive an expected minimum speed $\omega_\text{min}$ under normal operating conditions. | |
| \item If the motor is commanded to move (speed or duty above a threshold) and the measured speed remains below $\omega_\text{min}$ (or the encoder count does not change at all) for longer than a detection timeout $t_\text{stall}$, declare a stalled-rotor condition. | |
| \end{itemize} | |
| Additional considerations: | |
| \begin{itemize} | |
| \item \textbf{Quantization and low speed:} At low speeds, encoder counts change infrequently. Instead of instant speed, use a position window: if the accumulated position change over a longer window is less than a minimum $\Delta\theta_\text{min}$, treat it as stalled. | |
| \item \textbf{Direction:} Check that the sign of the encoder motion matches the commanded direction; a mismatch may indicate mechanical blockage or reversed wiring. | |
| \item \textbf{Acceleration phase:} As with current-based detection, allow a grace period for the motor to accelerate; do not flag a stall immediately when the command changes from zero to non-zero. | |
| \item \textbf{Backlash and compliance:} In systems with gearboxes or compliant couplings, small encoder motion may occur even when the load is effectively stalled. Choose thresholds and timeouts to account for this. | |
| \item \textbf{Action on stall:} As with current-based detection, the implementation should remove or reduce drive and notify higher-level software when a stall is detected. | |
| \end{itemize} | |
| In code, the header would typically define an encoder-based stall detector interface with: | |
| \begin{itemize} | |
| \item an initialization function specifying encoder resolution and timing, | |
| \item an update function that is called periodically with the latest encoder count and command information, and | |
| \item functions or callbacks to query the current stall state and to reset the detector when conditions change (e.g.\ after clearing a mechanical blockage). | |
| \end{itemize} | |
| By combining these mechanisms with suitable thresholds and timing parameters, both current-sensor-only and encoder-only systems can reliably detect stalled-rotor conditions and take protective action. |
|
|
||
| typedef struct { | ||
| motor_input_data_t input_data; | ||
| bool is_stalled; // True if the motor is stalled, false otherwise |
There was a problem hiding this comment.
The header file uses the bool type on line 9 but does not include stdbool.h. This will cause a compilation error unless stdbool.h is included before this header. Other header files in the project that use bool (such as bitstream_parity.h and packet_parsing_header.h) properly include stdbool.h. Add the include directive at the top of the file.
561b983 to
78839dd
Compare
No description provided.