Difference between revisions of "Cruise control"
| Line 57: | Line 57: | ||
}} | }} | ||
| − | + | {{Code block|Vehicle model| | |
| − | |||
| − | |||
def vehicle_update(t, x, u, params={}): | def vehicle_update(t, x, u, params={}): | ||
"""Vehicle dynamics for cruise control system. | """Vehicle dynamics for cruise control system. | ||
| Line 127: | Line 125: | ||
return dv | return dv | ||
| − | + | }} | |
| − | + | {{Code block|Engine model| | |
| − | |||
| − | |||
def motor_torque(omega, params={}): | def motor_torque(omega, params={}): | ||
# Set up the system parameters | # Set up the system parameters | ||
| Line 139: | Line 135: | ||
return np.clip(Tm * (1 - beta * (omega/omega_m - 1)**2), 0, None) | return np.clip(Tm * (1 - beta * (omega/omega_m - 1)**2), 0, None) | ||
| − | + | }} | |
| − | + | {{Code block|Input/output model for the vehicle system| | |
| − | |||
| − | |||
vehicle = ct.NonlinearIOSystem( | vehicle = ct.NonlinearIOSystem( | ||
vehicle_update, None, name='vehicle', | vehicle_update, None, name='vehicle', | ||
inputs = ('u', 'gear', 'theta'), outputs = ('v'), states=('v')) | inputs = ('u', 'gear', 'theta'), outputs = ('v'), states=('v')) | ||
| − | + | }} | |
| − | + | {{Code block|Input/output torque curves (plot)| | |
| − | |||
| − | |||
# Figure 4.2a - single torque curve as function of omega | # Figure 4.2a - single torque curve as function of omega | ||
omega_range = np.linspace(0, 700, 701) | omega_range = np.linspace(0, 700, 701) | ||
| Line 184: | Line 176: | ||
plt.suptitle('Torque curves for typical car engine'); | plt.suptitle('Torque curves for typical car engine'); | ||
plt.tight_layout() | plt.tight_layout() | ||
| − | + | }} | |
| − | + | {{Code block|PI controller| | |
| − | < | + | # Construct a PI controller with rolloff, as a transfer function |
| − | + | Kp = 0.5 # proportional gain | |
| + | Ki = 0.1 # integral gain | ||
| + | control_tf = ct.tf2io( | ||
| + | ct.TransferFunction([Kp, Ki], [1, 0.01*Ki/Kp]), | ||
| + | name='control', inputs='u', outputs='y') | ||
| + | |||
| + | cruise_tf = ct.InterconnectedSystem( | ||
| + | (vehicle, control_tf), name='cruise', | ||
| + | connections = [('control.u', '-vehicle.v'), ('vehicle.u', 'control.y')], | ||
| + | inplist = ('control.u', 'vehicle.gear', 'vehicle.theta'), inputs = ('vref', 'gear', 'theta'), | ||
| + | outlist = ('vehicle.v', 'vehicle.u'), outputs = ('v', 'u')) | ||
| + | }} | ||
| + | |||
| + | {{Code block|Simulated responses| | ||
| + | # Define the time and input vectors | ||
| + | T = np.linspace(0, 25, 101) | ||
| + | vref = 20 * np.ones(T.shape) | ||
| + | gear = 4 * np.ones(T.shape) | ||
| + | theta0 = np.zeros(T.shape) | ||
| + | |||
| + | # Now simulate the effect of a hill at t = 5 seconds | ||
| + | plt.figure() | ||
| + | plt.suptitle('Response to change in road slope') | ||
| + | theta_hill = np.array([ | ||
| + | 0 if t <= 5 else | ||
| + | 4./180. * pi * (t-5) if t <= 6 else | ||
| + | 4./180. * pi for t in T]) | ||
| + | |||
| + | subplots = [None, None] | ||
| + | linecolor = ['red', 'blue', 'green'] | ||
| + | handles = [] | ||
| + | for i, m in enumerate([1200, 1600, 2000]): | ||
| + | # Compute the equilibrium state for the system | ||
| + | X0, U0 = ct.find_eqpt( | ||
| + | cruise_tf, [vref[0], 0], [vref[0], gear[0], theta0[0]], | ||
| + | iu=[1, 2], y0=[vref[0], 0], iy=[0], params={'m':m}) | ||
| + | |||
| + | t, y = ct.input_output_response( | ||
| + | cruise_tf, T, [vref, gear, theta_hill], X0, params={'m':m}) | ||
| + | |||
| + | subplots = cruise_plot(cruise_tf, t, y, t_hill=5, subplots=subplots, | ||
| + | linetype=linecolor[i][0] + '-') | ||
| + | handles.append(mlines.Line2D([], [], color=linecolor[i], linestyle='-', | ||
| + | label="m = %d" % m)) | ||
| + | |||
| + | # Add labels to the plots | ||
| + | plt.sca(subplots[0]) | ||
| + | plt.ylabel('Speed [m/s]') | ||
| + | plt.legend(handles=handles, frameon=False, loc='lower right'); | ||
| + | |||
| + | plt.sca(subplots[1]) | ||
| + | plt.ylabel('Throttle') | ||
| + | plt.xlabel('Time [s]'); | ||
| + | }} | ||
== Exercises == | == Exercises == | ||
Revision as of 05:54, 29 December 2020
This page documents the cruise control system that is used as a running example throughout the text. A detailed description of the dynamics of this system are presented in Chapter 4 - Examples. This page contains a description of the system, including the models and commands used to generate some of the plots in the text.
Introduction
Cruise control is the term used to describe a control system that regulates the speed of an automobile. Cruise control was commercially introduced in 1958 as an option on the Chrysler Imperial. The basic operation of a cruise controller is to sense the speed of the vehicle, compare this speed to a desired reference, and then accelerate or decelerate the car as required. The figure to the right shows a block diagram of this feedback system.
A simple control algorithm for controlling the speed is to use a "proportional plus integral" feedback. In this algorithm, we choose the amount of gas flowing to the engine based on both the error between the current and desired speed, and the integral of that error. The plot on the right shows the results of this feedback for a step change in the desired speed and a variety of different masses for the car (which might result from having a different number of passengers or towing a trailer). Notice that independent of the mass (which varies by 25% of the total weight of the car), the steady state speed of the vehicle always approaches the desired speed and achieves that speed within approximately 10-15 seconds. Thus the performance of the system is robust with respect to this uncertainty.
Dynamic model
To develop a mathematical model we start with a force balance for the car body. Let Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle v} be the speed of the car, Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle m} the total mass (including passengers), the force generated by the contact of the wheels with the road, and the disturbance force due to gravity, friction and aerodynamic drag. The equation of motion of the car is simply
The force Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle F} is generated by the engine, whose torque is proportional to the rate of fuel injection, which is itself proportional to a control signal Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle 0 \leq u \leq 1} that controls the throttle position. The torque also depends on engine speed Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \omega} . A simple representation of the torque at full throttle is given by the torque curve
where the maximum torque Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle T_\text{m}} is obtained at engine speed Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \omega_\text{m}} . Typical parameters are Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle T_m = 190} Nm, Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \omega_m} = 420 rad/s (about 4000 RPM) and Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \beta = 0.4} .
Let Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle n} be the gear ratio and Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle r} the wheel radius. The engine speed is related to the velocity through the expression
and the driving force can be written as
Typical values of Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \alpha_n} for gears 1 through 5 are Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \alpha_1 = 40} , Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \alpha_2 = 25} , Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \alpha_3 = 16} , Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \alpha_4 = 12} and Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \alpha_5 = 10} . The inverse of Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \alpha_n} has a physical interpretation as the effective wheel radius. The figure to the right shows the torque as a function of vehicle speed. The figure shows that the effect of the gear is to "flatten" the torque curve so that an almost full torque can be obtained almost over the whole speed range.
The disturbance force Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle F_\text{d}} has three major components: Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle F_\text{g}} , the forces due to gravity; Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle F_\text{r}} , the forces due to rolling friction; and Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle F_\text{a}} , the aerodynamic drag. Letting the slope of the road be Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \theta} , gravity gives the force Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle F_\text{g} = m g \sin\theta} , where Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle g = 9.8\, \text{m}/\text{s}^2} is the gravitational constant. A simple model of rolling friction is
where Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle C_\text{r}} is the coefficient of rolling friction and sgn(Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle v} ) is the sign of Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle v} or zero if Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle v = 0} . A typical value for the coefficient of rolling friction is Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle C_\text{r} = 0.01} . Finally, the aerodynamic drag is proportional to the square of the speed:
where Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \rho} is the density of air, Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle C_d} is the shape-dependent aerodynamic drag coefficient and Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle A} is the frontal area of the car. Typical parameters are Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle \rho = } 1.3 k/mFailed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle {}^3} , Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle C_\text{d} = 0.32} and Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle A =} 2.4 mFailed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":): {\displaystyle {}^2} .
Python model
The model for the system above can be built using the Python Control Toolbox. The code blocks in this section can be used to generate the plots above.
Exercises
The following exercises make use of the cruise control model described here:
Further Reading
- How Stuff Works: cruise control
- Wikipedia: cruise control
