From 6b89aaf9c24b1248953282e9c0ccefac20ac2484 Mon Sep 17 00:00:00 2001 From: Sahil Kale Date: Thu, 27 Nov 2025 10:04:09 -0800 Subject: [PATCH] more motor stall work --- src/code/motor_stall/motor_stall_header.h | 17 +++++++ src/main.tex | 2 + src/motor_stall.tex | 58 +++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 src/code/motor_stall/motor_stall_header.h create mode 100644 src/motor_stall.tex diff --git a/src/code/motor_stall/motor_stall_header.h b/src/code/motor_stall/motor_stall_header.h new file mode 100644 index 0000000..c10958d --- /dev/null +++ b/src/code/motor_stall/motor_stall_header.h @@ -0,0 +1,17 @@ +typedef struct { + float commanded_bus_voltage_V; // Commanded motor bus voltage in Volts + // float proposed_sensor_UNIT; +} motor_input_data_t; + +typedef struct { + 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 input_data Pointer to the motor input data structure + * @param motor Pointer to the static motor handle structure + */ +void motor_stall_detect_period_run_1ms(const motor_input_data_t* const input_data, motor_handle_t *motor); + diff --git a/src/main.tex b/src/main.tex index fb4bdd7..328ed24 100644 --- a/src/main.tex +++ b/src/main.tex @@ -159,6 +159,8 @@ \newpage \subfile{buck_vs_ldo.tex} % place after passives.tex, opamp.tex \newpage +\subfile{motor_stall.tex} +\newpage % Appendix \subfile{appendix_packet_parsing_tests.tex} diff --git a/src/motor_stall.tex b/src/motor_stall.tex new file mode 100644 index 0000000..6da14bb --- /dev/null +++ b/src/motor_stall.tex @@ -0,0 +1,58 @@ +\documentclass[main.tex]{subfiles} + +\begin{document} +\section{Suppose a Brushed DC motor is connected to a load - how would you detect a stalled-rotor condition?} +Discuss what sensor(s) could be used to detect a stalled-rotor condition, and provide a C code snippet that implements the algorithm with the proposed sensor. Assume a header similar to the one in listing \ref{code:motor-stall-header} is provided. + +\lstinputlisting[caption={Motor Stall Detection Sample Header}, label={code:motor-stall-header}]{code/motor_stall/motor_stall_header.h} + +\spoilerline + +\subsection{Defining a Stalled-Rotor Condition} +A stalled-rotor condiition occurs when the motor's rotor can no longer rotate, typically due to an excessive load or mechanical obstruction. If a motor is left in this condition, it may result in overheating (and damage to the motor windings), increased power consumption, and depending on the system, cause damage to other systems or people. Accordingly, implementing stall detection is a classic requirement for active control systems that use motors. + +\subsubsection{DC Motor Model} +When analyzing how to detect a stalled-rotor condition, it is useful to understand the first-principles electrical model of a DC motor, shown in Figure \ref{fig:dc-motor-model}. +\begin{figure}[H] + \centering + \begin{circuitikz}[american] + \draw + (0,0) to[short, o-] (1,0) + to[R, l=$R$] (3,0) + to[L, l=$L$] (6,0) + to[vsource, l_=$V_{emf}$] (6,-3) + to[short] (0,-3) + to[vsource, l_=$V_{in}$, invert] (0,0) + ; + \end{circuitikz} + \caption{Electrical Model of a DC Motor with Upright Voltage Sources} + \label{fig:dc-motor-model} +\end{figure} + +\newnoindentpara Where $V_{in}$ is the input voltage to the motor, $R$ is the resistance of the motor windings, $L$ is the inductance of the motor windings, and $V_{emf}$ is the back electromotive force (EMF) generated by the motor as it spins - $V_{emf} = K_e \cdot \omega$, where $K_e$ is the motor's back EMF constant and $\omega$ is the angular velocity of the motor shaft. Additionally, the torque generated by the motor is given by $T = K_t \cdot I$, where $K_t$ is the motor's torque constant and $I$ is the current flowing through the motor windings.\footnote{Note that for a given motor, $K_e$ and $K_t$ are numerically equal when using SI units.} + +\subsection{Fundamental Principle of Stalled-Rotor Detection} +As we've defined a stalled-rotor condition to be one where the motor's rotor is not rotating ($\omega = 0$), we can leverage the DC motor model to inform our detection strategy. Since $V_{emf} = K_e \cdot \omega$, when the rotor is stalled, $V_{emf}$ will be zero. By extension, the motor's current draw will be at its maximum - all of the input voltage $V_{in}$ will be dropped across the motor's resistance and inductance, leading to a high current draw according to Ohm's Law ($I = \frac{V_{in}}{R}$ for a stalled motor). A schematic of this concept is shown in Figure \ref{fig:dc-motor-stall}. + +\begin{figure}[H] + \centering + \begin{circuitikz}[american] + \draw + (0,0) to[short, o-] (1,0) + to[R, l=$R$] (3,0) + to[L, l=$L$] (6,0) + to[short] (6,-3) + to[short] (0,-3) + to[vsource, l_=$V_{in}$, invert] (0,0) + ; + \draw[->, thick] (2.5, 0.5) -- (3.5, 0.5) node[midway, above] {$I$}; + \end{circuitikz} + \caption{DC Motor Electrical Model with Shunted Back-EMF and Current Direction} + \label{fig:dc-motor-stall} +\end{figure} + +\newnoindentpara As a result, we can detect a stalled-rotor condition either by monitoring the motor's current draw (as a high current draw indicates a stall) or by monitoring the motor's angular velocity (as a zero angular velocity indicates a stall). + + + +\end{document} \ No newline at end of file