def loaddata(file, delimeter): #加载文件,以delimeter进行分割成行和列 data = np.loadtxt(file, delimiter=delimeter) #输出处理后数据的行和列 #print('Dimensions: ',data.shape) #输出第2行到第6行 #print(data[1:6,:]) return (data)
def main(argv): letters = ["gen/"+x+"-0" for x in process_args(argv)] to_plot = [] plot = plt.subplot(3,1,1) for letter in letters: data = np.loadtxt(letter,delimiter=" "); print data plot.plot(data, label=letter[4:-2]) plot.legend(shadow=True,fancybox=True) plt.draw() plt.show()
def evaluate_design(self, x_denorm): with open('_eval/ACMConfig.h', 'r') as f: new_line = [] for line in f.readlines(): if '#define CURRENT_LOOP_BANDWIDTH' in line: new_line.append( f'#define CURRENT_LOOP_BANDWIDTH (2*M_PI*{x_denorm[0]:g})\n' ) # 15 elif '#define DELTA_THE_DAMPING_FACTOR' in line: new_line.append( f'#define DELTA_THE_DAMPING_FACTOR ({x_denorm[1]:g})\n' ) # 0.08 else: new_line.append(line) with open('_eval/ACMConfig.h', 'w') as f: f.writelines(new_line) if os.path.exists(self.work_dir + '/_eval/main.exe'): os.remove(self.work_dir + '/_eval/main.exe') subprocess.run([ "gcc", "_eval/main.c", "_eval/controller.c", "_eval/observer.c", "-o", "_eval/main" ]) while not os.path.exists(self.work_dir + '/_eval/main.exe'): time.sleep(0.1) print('sleep for main.exe') # subprocess.run( [self.work_dir+'/_eval/main.exe'] ) os.system('cd _eval && main') while not os.path.exists(self.work_dir + '/_eval/pi_opti.dat'): time.sleep(0.1) print('sleep for .dat') speed_profile = np.loadtxt('_eval/pi_opti.dat', skiprows=1) os.remove(self.work_dir + '/_eval/pi_opti.dat') TS = 0.000025 # ACMConfig.h print(max(speed_profile), 'rpm') print(min(speed_profile, key=lambda x: abs(x - 90)), 'rpm') # [rpm] print(np.abs(speed_profile - 90).argmin() * TS * 1000, 'ms') # [ms] rise_time = np.abs(speed_profile - 90).argmin() * TS * 1000 over_shoot = max(speed_profile) if over_shoot <= 100: over_shoot = 100 # modify this function to call matlab and eMach to evaluate the design with free variables as in x_denorm return over_shoot, rise_time
def main(argv): args = process_args(argv) #letters = ["train/sharad-new/"+x for x in args] letters = [""+x for x in args] #letters = ["data_train/"+x for x in args] #letters = ["train/lei-1354774953143/"+x for x in args] to_plot = [] plot = plt.subplot(1,1,1) for i in range(len(letters)): data = np.loadtxt(letters[i],delimiter=" "); x = [point[0] for point in data] y = [point[1] for point in data] plot.plot(x,y, label=args[i],linewidth=8) #plot.legend(shadow=True,fancybox=True,loc='upper center',bbox_to_anchor=(0.5,-0.1),ncol=4) plot.set_aspect('1.0') #subplots_adjust(bottom=0.25) # <-- plt.draw() plt.show()