專注在兩個非常重要卻又簡單的東西 data & function
先思考 input 與 ouput的data是什麼
dict 這個 data structure
將其收起來,還不知道的值就先給 None
,用專案中馬達設計的部分呈現如下。motor_cal_params = {
"stator": {
"OD_limit": None,
"slot": 12,
"shoes_height_front": 1,
"shoes_height_back": 1,
"slot_open": 4.5,
"slot_corner_arc": 0.5,
},
"rotor": {
"pole": 10,
"mag_emb": 0.8, # easier magetization
},
"coil": {
"conductor_OD": 1,
"y_para": 1,
"membrane_ratio": 1.075,
"slot_fill_factor": 0.43,
},
"estimate": {
"kt_ke_ratio": 0.9,
"max_J": 18,
"voltage_buffer": 0.9,
"torque_density": 25,
"teeth_mag_ang_ratio": 0.6,
"york_teeth_ratio": 0.7,
"rotor_OD_ratio": 0.6,
"bg": 1.2,
"mag_pc": 7.5, # for not easy to broke
},
"calculation": {
"est_rotor_OD": None,
"est_stator_OD": None,
"mag_thick": None,
"teeth_width": None,
"york_width": None,
"slot_height": None,
"slot_width_front": None,
"slot_width_back": None,
"para_conductor": None,
"coil_turns": None,
"real_slot_fill_factor": None,
},
"material": {
"stator": "\"35CS250_steel\"",
"rotor": "\"35CS250_steel\"",
"magnet": "\"N44SH_20deg_mag\"",
"coil": "\"copper\"",
},
"setting": {
"cycle": 1,
"split_step": 50
},
"voltage_dc": None,
"length": None,
"airgap": 0.5,
"w_factor_10p12s": 0.933,
"ke": None,
"kt": None,
"corner_speed_rpm": None,
"max_speed_rpm": None,
"max_current_rms": None,
"core_loss_factor": 1,
}
def ktke_calculation(total_cal_params):
# 計算 total_cal_params 的某個值
# 將 計算值 替算掉原本在total_cal_params中的未定值
return total_cal_params
def assign_spec_value(total_cal_params):
# 計算 total_cal_params 的某個值
# 將 計算值 替算掉原本在total_cal_params中的未定值
return total_cal_params
def expend_NBLR(total_cal_params):
# 計算 total_cal_params 的某個值
# 將 計算值 替算掉原本在total_cal_params中的未定值
return total_cal_params
def expend_stator_teeth_york(total_cal_params):
# 計算 total_cal_params 的某個值
# 將 計算值 替算掉原本在total_cal_params中的未定值
return total_cal_params
def expend_stator_slot(total_cal_params):
# 計算 total_cal_params 的某個值
# 將 計算值 替算掉原本在total_cal_params中的未定值
return total_cal_params
def expend_magnet(total_cal_params):
# 計算 total_cal_params 的某個值
# 將 計算值 替算掉原本在total_cal_params中的未定值
return total_cal_params
motor_cal_params
放在 ctx[params]
中)total_cal_params = ctx["params"]
ktke_calculation(total_cal_params) and \
assign_spec_value(total_cal_params) and \
expend_NBLR(total_cal_params) and \
expend_stator_teeth_york(total_cal_params) and \
expend_stator_slot(total_cal_params) and \
expend_magnet(total_cal_params)
print(total_cal_params)
使用上述的方法,是不是很單純,且很直觀就能看懂設計的過程,debug也非常容易,執行程式時將total_cal_params
印出來看就好。
當整個程式設計完成後,接下來就是去優化每一個 function & data 讓它們更容易被看懂,更能直觀的對應馬達設計。
更詳細可參考我的設計,未來還會持續的優化設計。
更多相關文章發表於我的網站。