text Coursera Week4编程作业2
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text Coursera Week4编程作业2相关的知识,希望对你有一定的参考价值。
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"In this notebook, you will implement the forward longitudinal vehicle model. The model accepts throttle inputs and steps through the longitudinal dynamic equations. Once implemented, you will be given a set of inputs that drives over a small road slope to test your model.\n",
"\n",
"The input to the model is a throttle percentage $x_\\theta \\in [0,1]$ which provides torque to the engine and subsequently accelerates the vehicle for forward motion. \n",
"\n",
"The dynamic equations consist of many stages to convert throttle inputs to wheel speed (engine -> torque converter -> transmission -> wheel). These stages are bundled together in a single inertia term $J_e$ which is used in the following combined engine dynamic equations.\n",
"\n",
"\\begin{align}\n",
" J_e \\dot{\\omega}_e &= T_e - (GR)(r_{eff} F_{load}) \\\\ m\\ddot{x} &= F_x - F_{load}\n",
"\\end{align}\n",
"\n",
"Where $T_e$ is the engine torque, $GR$ is the gear ratio, $r_{eff}$ is the effective radius, $m$ is the vehicle mass, $x$ is the vehicle position, $F_x$ is the tire force, and $F_{load}$ is the total load force. \n",
"\n",
"The engine torque is computed from the throttle input and the engine angular velocity $\\omega_e$ using a simplified quadratic model. \n",
"\n",
"\\begin{align}\n",
" T_e = x_{\\theta}(a_0 + a_1 \\omega_e + a_2 \\omega_e^2)\n",
"\\end{align}\n",
"\n",
"The load forces consist of aerodynamic drag $F_{aero}$, rolling friction $R_x$, and gravitational force $F_g$ from an incline at angle $\\alpha$. The aerodynamic drag is a quadratic model and the friction is a linear model.\n",
"\n",
"\\begin{align}\n",
" F_{load} &= F_{aero} + R_x + F_g \\\\\n",
" F_{aero} &= \\frac{1}{2} C_a \\rho A \\dot{x}^2 = c_a \\dot{x}^2\\\\\n",
" R_x &= N(\\hat{c}_{r,0} + \\hat{c}_{r,1}|\\dot{x}| + \\hat{c}_{r,2}\\dot{x}^2) \\approx c_{r,1} \\dot{x}\\\\\n",
" F_g &= mg\\sin{\\alpha}\n",
"\\end{align}\n",
"\n",
"Note that the absolute value is ignored for friction since the model is used for only forward motion ($\\dot{x} \\ge 0$). \n",
" \n",
"The tire force is computed using the engine speed and wheel slip equations.\n",
"\n",
"\\begin{align}\n",
" \\omega_w &= (GR)\\omega_e \\\\\n",
" s &= \\frac{\\omega_w r_e - \\dot{x}}{\\dot{x}}\\\\\n",
" F_x &= \\left\\{\\begin{array}{lr}\n",
" cs, & |s| < 1\\\\\n",
" F_{max}, & \\text{otherwise}\n",
" \\end{array}\\right\\} \n",
"\\end{align}\n",
"\n",
"Where $\\omega_w$ is the wheel angular velocity and $s$ is the slip ratio. \n",
"\n",
"We setup the longitudinal model inside a Python class below. The vehicle begins with an initial velocity of 5 m/s and engine speed of 100 rad/s. All the relevant parameters are defined and like the bicycle model, a sampling time of 10ms is used for numerical integration."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import sys\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib.image as mpimg\n",
"\n",
"class Vehicle():\n",
" def __init__(self):\n",
" \n",
" # ==================================\n",
" # Parameters\n",
" # ==================================\n",
" \n",
" #Throttle to engine torque\n",
" self.a_0 = 400\n",
" self.a_1 = 0.1\n",
" self.a_2 = -0.0002\n",
" \n",
" # Gear ratio, effective radius, mass + inertia\n",
" self.GR = 0.35\n",
" self.r_e = 0.3\n",
" self.J_e = 10\n",
" self.m = 2000\n",
" self.g = 9.81\n",
" \n",
" # Aerodynamic and friction coefficients\n",
" self.c_a = 1.36\n",
" self.c_r1 = 0.01\n",
" \n",
" # Tire force \n",
" self.c = 10000\n",
" self.F_max = 10000\n",
" \n",
" # State variables\n",
" self.x = 0\n",
" self.v = 5\n",
" self.a = 0\n",
" self.w_e = 100\n",
" self.w_e_dot = 0\n",
" \n",
" self.sample_time = 0.01\n",
" \n",
" def reset(self):\n",
" # reset state variables\n",
" self.x = 0\n",
" self.v = 5\n",
" self.a = 0\n",
" self.w_e = 100\n",
" self.w_e_dot = 0"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Implement the combined engine dynamic equations along with the force equations in the cell below. The function $\\textit{step}$ takes the throttle $x_\\theta$ and incline angle $\\alpha$ as inputs and performs numerical integration over one timestep to update the state variables. Hint: Integrate to find the current position, velocity, and engine speed first, then propagate those values into the set of equations."
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"class Vehicle(Vehicle):\n",
" def step(self, throttle, alpha):\n",
" # ==================================\n",
" # Implement vehicle model here\n",
" # ==================================\n",
" F_aero \t\t= self.c_a * self.v * self.v\n",
" R_x \t\t= self.c_r1 * self.v\n",
" F_g\t\t\t= self.m * self.g * np.sin(alpha)\n",
" F_load \t\t= F_aero + R_x + F_g\n",
" T_e\t\t\t= throttle * (self.a_0 + self.a_1 * self.w_e + self.a_2 * self.w_e * self.w_e)\n",
" W_w\t\t\t= self.GR * self.w_e\n",
" r_eff = self.v / W_w\n",
" s = (W_w * self.r_e - self.v) / self.v\n",
" cs\t\t\t= self.c * s\n",
" \n",
" if abs(s) < 1 :\n",
" F_x = cs\n",
" else:\n",
" F_x = self.F_max\n",
" \n",
" self.x \t\t= self.x + self.v * self.sample_time\n",
" self.v \t\t= self.v + self.a * self.sample_time\n",
" self.a \t\t= (F_x - F_load) / self.m\n",
" self.w_e \t= self.w_e + self.w_e_dot * self.sample_time\n",
" self.w_e_dot = (T_e - self.GR * self.r_e * F_load) / self.J_e\n",
" \n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using the model, you can send constant throttle inputs to the vehicle in the cell below. You will observe that the velocity converges to a fixed value based on the throttle input due to the aerodynamic drag and tire force limit. A similar velocity profile can be seen by setting a negative incline angle $\\alpha$. In this case, gravity accelerates the vehicle to a terminal velocity where it is balanced by the drag force."
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KG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9cEn8BDAmG\nBCB6+7sMKHP3t4L535P4RRDl/Xw+sNHdq9y9GXgaOJ1o7+f92tqvPZZrUQn+d4CjgjMAskh8KTQv\n5Jq6XTC2/SCw2t3vbrVoHnBDMH0D8Mferq2nuPvX3X2Mu48nsV//6u6fAV4Grgq6RW2btwNbzGxS\n0HQesIoI72cSQzynmllu8N/5/m2O7H5upa39Og+4Pji751Rgz/4hoS5z90j8kHig+zqgFPhm2PX0\n0DaeSeJPvXeBpcHPTBJj3i8B64PXgrBr7aHtPxt4Npg+EngbeA94EsgOu75u3tZpwMJgX/8BGBr1\n/Qz8J7AGWAH8BsiO2n4GHiPxHUYziSP6m9varySGeu4LMm05iTOeuqUOXbkrIpJiojLUIyIiHaTg\nFxFJMQp+EZEUo+AXEUkxCn4RkRSj4BcRSTEKfhGRFKPgFxFJMf8fr7SxMg907PEAAAAASUVORK5C\nYII=\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"sample_time = 0.01\n",
"time_end = 100\n",
"model = Vehicle()\n",
"\n",
"t_data = np.arange(0,time_end,sample_time)\n",
"v_data = np.zeros_like(t_data)\n",
"x_data = np.zeros_like(t_data)\n",
"\n",
"# throttle percentage between 0 and 1\n",
"throttle = 0.2\n",
"\n",
"# incline angle (in radians)\n",
"alpha = 0\n",
"\n",
"for i in range(t_data.shape[0]):\n",
" x_data[i] = model.x\n",
" v_data[i] = model.v\n",
" model.step(throttle, alpha)\n",
" \n",
"plt.plot(t_data, v_data)\n",
"# plt.plot(x_data)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We will now drive the vehicle over a slope as shown in the diagram below.\n",
"\n",
"![ramp](ramp.png)\n",
"\n",
"To climb the slope, a trapezoidal throttle input is provided for the next 20 seconds as shown in the figure below. \n",
"\n",
"![throttle](throttle.png)\n",
"\n",
"The vehicle begins at 20% throttle and gradually increases to 50% throttle. This is maintained for 10 seconds as the vehicle climbs the steeper slope. Afterwards, the vehicle reduces the throttle to 0.\n",
"\n",
"In the cell below, implement the ramp angle profile $\\alpha (x)$ and throttle profile $x_\\theta (t)$ and step them through the vehicle dynamics. The vehicle position $x(t)$ is saved in the array $\\textit{x_data}$. This will be used to grade your solution.\n"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3Xl4FeWhx/Hvm42QkASykZAQEhaB\nBEQwIO7eai1at2q1+GirVsXWtrdWa9Fubu2trbVVu7jc64KWqohaLa0K0gqVojZAAiQsIWELZAey\nELKe9/6RQwxICElOzpzl93mePJxMTjI/5iS/TN55Z8ZYaxEREf8X4nQAERHxDBW6iEiAUKGLiAQI\nFbqISIBQoYuIBAgVuohIgFChi4gECBW6iEiAUKGLiASIMG+uLDEx0WZmZnpzlSIifm/NmjU11tqk\n3p7n1ULPzMwkLy/Pm6sUEfF7xpidJ/I8DbmIiAQIFbqISIBQoYuIBAivjqEfS1tbG2VlZTQ3Nzsd\npUeRkZGkp6cTHh7udBQRkR45XuhlZWXExMSQmZmJMcbpOJ9hraW2tpaysjKysrKcjiMi0iPHh1ya\nm5tJSEjwyTIHMMaQkJDg039BiIiADxQ64LNlfpiv5xMRAR8pdBGRQFXb2MIDfy2kvrlt0Nfl+Bi6\niEggcrksCz/ZxSPvbqaptYMzxyVyQfbIQV2nCl1ExMN21BzkB4vX88mOfZw5PoEHLsthfHLMoK83\n6At9/vz5jBkzhttvvx2A+++/n5iYGO666y6Hk4mIv+lwWV749w4eeW8z4aEh/PrqaVw1I81rx+F8\nqtAf+GshRXvrPfo1s0fFct+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ZvR9+3gtn/tg2CXAde5hAdxD\nGrXux2voHJ8+yZ2r+7DMoOTqx+vmze0VBlwJvNotr1e317H6AQe/x/yh0P8DTDDGZLn3+uYCb3tj\nxe7xuWeBTdba33Rb3n3s+UvA4aPvbwNzjTFDjDFZwAQ6D8QMRrZoY0zM4cd0HlTb6M5w+Cj5DcBb\n3bJ9zX2kfTZQd/jPwkFyxJ6TL2yzbuvry/Z5D7jQGDPCPdxwoXuZRxlj5gDzgcustU3dlicZY0Ld\nj8fSuX1K3dkajDGz3d+nX+v2f/Fkrr6+bt78eb0A2Gyt7RpK8eb26qkfcPJ7bCBHeb31RufR4a10\n/rb9kRfXexadf/qsB/LdbxcDLwEb3MvfBlK7fc6P3Dm3MMCj6L1kG0vnDIICoPDwdgESgOVAsfvf\nePdyA/zBnW0DkDuI2aKAWiCu2zKvbzM6f6GUA2107gXd3J/tQ+eY9jb3202DlGsbneOoh7/PnnI/\n9yr361sArAUu7fZ1cuks2BLg97hPFPRwrj6/bp7+eT1WLvfyF4BvHPVcb26vnvrBse8xnSkqIhIg\n/GHIRUREToAKXUQkQKjQRUQChApdRCRAqNBFRAKECl1EJECo0EVEAoQKXUQkQPw//L7D6Cgz674A\nAAAASUVORK5CYII=\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"time_end = 20\n",
"t_data = np.arange(0,time_end,sample_time)\n",
"x_data = np.zeros_like(t_data)\n",
"v_data = np.zeros_like(t_data)\n",
"throttle_data = np.zeros_like(t_data)\n",
"alpha_data = np.zeros_like(t_data)\n",
"\n",
"# reset the states\n",
"model.reset()\n",
"\n",
"# ==================================\n",
"# Learner solution begins here\n",
"# ==================================\n",
"for i in range(t_data.shape[0]):\n",
" if i >=0 and i < 500:\n",
" throttle = 0.2 + 0.0006 * i\n",
" elif i >= 500 and i < 1500:\n",
" throttle = 0.5\n",
" elif i >= 1500 and i < 2000:\n",
" throttle = 2 - 0.001 * i\n",
"\n",
" if model.x < 60:\n",
" alpha = 0.05\n",
" elif model.x >= 60 and model.x <= 150:\n",
" alpha = 0.1\n",
" elif model.x > 150:\n",
" alpha = 0\n",
" \n",
" alpha_data[i] = alpha\n",
" throttle_data[i] = throttle\n",
" x_data[i] = model.x\n",
" v_data[i] = model.v\n",
" model.step(throttle,alpha)\n",
" \n",
"# print(\"i = \",i)\n",
"# print(\"throttle = \",throttle)\n",
"\n",
"# ==================================\n",
"# Learner solution ends here\n",
"# ==================================\n",
"\n",
"# Plot x vs t for visualization\n",
"# plt.plot(t_data, x_data,label = 'x')\n",
"plt.plot(v_data,label = 'v')\n",
"# plt.plot(throttle_data,label = 'throttle')\n",
"# plt.plot(alpha_data,label = 'alpha')\n",
"plt.legend()\n",
"plt.show()\n",
"# plt.plot(throttle)\n",
"# plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you have implemented the vehicle model and inputs correctly, you should see that the vehicle crosses the ramp at ~15s where the throttle input begins to decrease.\n",
"\n",
"The cell below will save the time and vehicle inputs as text file named $\\textit{xdata.txt}$. To locate the file, change the end of your web directory to $\\textit{/notebooks/Course_1_Module_4/xdata.txt}$\n",
"\n",
"Once you are there, you can download the file and submit to the Coursera grader to complete this assessment."
]
},
{
"cell_type": "code",
"execution_count": 96,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"data = np.vstack([t_data, x_data]).T\n",
"np.savetxt('xdata.txt', data, delimiter=', ')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Congratulations! You have now completed the assessment! Feel free to test the vehicle model with different inputs in the cell below, and see what trajectories they form. In the next module, you will see the longitudinal model being used for speed control. See you there!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"sample_time = 0.01\n",
"time_end = 30\n",
"model.reset()\n",
"\n",
"t_data = np.arange(0,time_end,sample_time)\n",
"x_data = np.zeros_like(t_data)\n",
"\n",
"# ==================================\n",
"# Test various inputs here\n",
"# ==================================\n",
"for i in range(t_data.shape[0]):\n",
"\n",
" model.step(0,0)\n",
" \n",
"plt.axis('equal')\n",
"plt.plot(x_data, y_data)\n",
"plt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
以上是关于text Coursera Week4编程作业2的主要内容,如果未能解决你的问题,请参考以下文章
机器学习- 吴恩达Andrew Ng 编程作业技巧 for Week4 Neural Networks
Coursera TensorFlow 基础课程-week4
Coursera TensorFlow 基础课程-week4