import matplotlib.pyplot as plt f = open("TEST_SD.TXT") a = f.read() b = a.split("\n") c = [] time = [] force = [] I = 0 for i in b: if (i != "\n")and(i != ""): c.append(i) for i in range(len(c)): d = c[i].split(",") time.append(float(d[0])) force.append(float(d[1])) while force[0] < 3: force.pop(0) time.pop(0)#删除试车前的数据 while force[-1] < 3: force.pop(-1) time.pop(-1)#删除试车后的数据,不直接设定阈值是考虑到多推力峰 t0 = time[0] for i in range(len(time)): force[i]*=0.1#我的实验得到的数据单位是0.1N,我不知道是不是都这样,如果不是的话可以改下代码 time[i] -= t0 for i in range(len(time)-1): dt = time[i+1]-time[i] di = force[i]*dt I += di#积分算总冲 data = input('''请输入相关数据,格式如下: 发动机名称/直径(mm)/长度(mm)/开伞延时(s)/燃料质量(kg)/总质量(kg)/制造商 若要跳过请输入0,不计算比冲,不形成eng文件\n''') if data != "0": d = data.split("/") name = d[0] diameter = int(d[1]) length = int(d[2]) dertatime = int(d[3]) fuelmass = float(d[4]) mass = float(d[5]) maker = d[6] else: mass = 1 f.close() f1 = open("时间-推力表.txt", "w") f1.write("总冲(N.s):%f\n"%I) if data != "0": isp = (I/mass)/9.8#计算以秒为单位的比冲 f1.write("比冲(s):%f\n"%isp) fmax = force[0] for i in range(len(force)): if fmax < force[i]: fmax = force[i]#计算最大推力 f1.write("最大推力(N):%f\n"%fmax) f1.write("时间(s) 推力(N)\n") for i in range(len(time)): f1.write("%f %f\n"%(time[i],force[i])) f1.close() fig = plt.figure(figsize=(20, 10), dpi=100) plt.plot(time, force) plt.xlabel("F(N)") plt.ylabel("t(s)") plt.title("F - t") plt.show() fig.savefig("F - t 图")#绘制并保存推力时间曲线 if data != "0": f2 = open("导入openrocket的数据.eng","w") f2.write("%s %d %d %d %f %f %s\n"%(name, diameter, length, dertatime, fuelmass, mass, maker)) for i in range(len(time)): f2.write("%.3f %f\n"%(time[i], force[i])) f2.write(";") f2.close()#生成可以直接导入openrocket的.eng文件
唉,刚刚太着急,代码的模式搞错了
时段 | 个数 |
---|---|
{{f.startingTime}}点 - {{f.endTime}}点 | {{f.fileCount}} |