-
Notifications
You must be signed in to change notification settings - Fork 1
Add in motor stall question #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| typedef struct { | ||
| float measured_current_A; // Measured current in Amperes | ||
| float commanded_bus_voltage_V; // Commanded bus voltage in Volts | ||
| float motor_speed_rad_per_s; // Motor speed in radians per second from encoder | ||
| } motor_input_data_t; | ||
|
|
||
| typedef struct { | ||
| motor_input_data_t input_data; | ||
| bool is_stalled; // True if the motor is stalled, false otherwise | ||
| // Additional variables can be added as needed | ||
| } motor_handle_t; | ||
|
|
||
| /** | ||
| * @brief Function to be called every 1 ms for motor stall detection | ||
| * @param motor Pointer to the motor handle structure | ||
| */ | ||
| void motor_stall_detect_period_run_1ms(motor_handle_t *motor); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,16 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| \documentclass[main.tex]{subfiles} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| \begin{document} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| \section{Suppose a DC motor is connected to a load - how would you detect a stalled-rotor condition?} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Assume the header in Listing \ref{code:motor-stall-header} is provided. Discuss the implementation of stalled-rotor detection in the following circumstances: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| \begin{itemize} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| \item The DC motor features only a current sensor. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| \item The DC motor features only an encoder. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| \end{itemize} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| \lstinputlisting[caption={Motor Stall Detection Header}, label={code:motor-stall-header}]{code/motor_stall/motor_stall_header.h} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| \spoilerline | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+14
to
+15
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.