import numpy as np import math import matplotlib.pyplot as plt import tkinter as tk import tkinter.messagebox import pandas as pd from openpyxl import load_workbook from warnings import simplefilter engine_torque = 10 i0 = 2.088 i1 = 2.928 ig = 2.929 efficiency = 0.96 Wheel_radius = 0.3059 slope = 0 #坡度单位弧度 slope_cos = math.cos(slope) slope_sin = math.sin(slope) rolling_resistance_coefficient = 0.01 air_coefficient = 0.28 face_area = 0.4 air_density = 1.2258 vehicle_speed = 0 weight = 268 step_size = 0.01 flag = 0 time = 0 vehicle_speed_plot = [] time_plot = [] def drive_force(engine_torque,i0,i1,ig,efficiency,Wheel_radius): drive_force = engine_torque*i0*ig*i1*efficiency/Wheel_radius return drive_force def rolling_resistance(weight,rolling_resistance_coefficient,slope_cos): rolling_resistance = weight*rolling_resistance_coefficient*slope_cos return rolling_resistance def air_resistance(air_coefficient,face_area,air_density,relative_speed): air_resistance = 0.5*air_coefficient*face_area*air_density*relative_speed*relative_speed return air_resistance def grade_resistance(weight,slope_sin): grade_resistance = weight*slope_sin return grade_resistance while flag==0: relative_speed = vehicle_speed vehicle_acclerate = (drive_force(engine_torque,i0,i1,ig,efficiency,Wheel_radius)-rolling_resistance(weight,rolling_resistance_coefficient,slope_cos)-air_resistance(air_coefficient,face_area,air_density,relative_speed))/weight vehicle_speed = vehicle_acclerate*step_size+vehicle_speed running_distance = relative_speed*step_size+0.5*vehicle_acclerate*step_size*step_size time = time+step_size if time == 10: flag = 1 vehicle_speed_plot.append(vehicle_speed) time_plot.append(time)
时间: 2024-04-23 13:26:56 浏览: 193
这段代码使用了多个变量和函数来计算车辆在直线道路上的行驶情况。具体来说,代码的主要功能是根据车辆的动力、阻力和坡度等因素来计算车辆在直线道路上的运动状态,并将结果存储在列表中以便后续使用。
代码中的变量和函数的含义如下:
- engine_torque:发动机扭矩
- i0、i1、ig:传动系数
- efficiency:传动效率
- Wheel_radius:车轮半径
- slope:坡度
- slope_cos、slope_sin:坡度的余弦值和正弦值
- rolling_resistance_coefficient:滚动阻力系数
- air_coefficient:空气阻力系数
- face_area:车辆正面面积
- air_density:空气密度
- vehicle_speed:车辆速度
- weight:车辆重量
- step_size:时间步长
- flag:循环标志,初始值为 0
- time:当前时间,初始值为 0
- vehicle_speed_plot:车辆速度列表
- time_plot:时间列表
代码中的函数包括:
- drive_force:计算车辆的驱动力
- rolling_resistance:计算车辆的滚动阻力
- air_resistance:计算车辆的空气阻力
- grade_resistance:计算车辆的坡度阻力
代码的主体部分是一个 while 循环,当 flag 等于 0 时,会一直循环下去。每次循环时,根据车辆的动力、阻力和坡度等因素来计算车辆的速度和加速度,并更新列表中的数据。当时间达到 10 秒时,循环停止。
最后,代码中使用了 numpy、math、matplotlib.pyplot、tkinter、pandas 和 openpyxl 等模块来实现各种功能。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)