Open MelvinWarnet opened 6 months ago
Can you share your code for COMM_GET_MCCONF and then how to change the value of above parameter
In the repository that I use github.com/MXMP/PyVESC-FW3.33 there is a COMM_GET_MCCONF message in getters.py so the librairy parse it. For the moment, I didn't send any COMM_GET_MCCONF message. The one that I get is send by vesc after receive the COMM_DETECT_APPLY_ALL_FOC. The COMM_GET_MCCONF is parse by pyvesc but I think fields type aren't the good one so it explained that my values are no consistent. I will try to change those types following what I can observe in vesctool and I will share the message if parsing the message is a succes. For the moment what I have for you is :
define the message class (already define in the repository I share) :
id = 14 # COMM_GET_MCCONF
can_id = None
fields = [
('pwm_mode', 'B', 1),
('comm_mode', 'B', 1),
('motor_type', 'B', 1),
('sensor_mode', 'B', 1),
('l_current_max', 'f', 1),
('l_current_min', 'f', 1),
('l_in_current_max', 'f', 1),
('l_in_current_min', 'f', 1),
('l_abs_current_max', 'f', 1),
('l_min_erpm', 'f', 1),
('l_max_erpm', 'f', 1),
('l_erpm_start', 'f', 1),
('l_max_erpm_fbrake', 'f', 1),
('l_max_erpm_fbrake_cc', 'f', 1),
('l_min_vin', 'f', 1),
('l_max_vin', 'f', 1),
('l_battery_cut_start', 'f', 1),
('l_battery_cut_end', 'f', 1),
('l_slow_abs_current', 'B', 1),
('l_temp_fet_start', 'f', 1),
('l_temp_fet_end', 'f', 1),
('l_temp_motor_start', 'f', 1),
('l_temp_motor_end', 'f', 1),
('l_temp_accel_dec', 'f', 1),
('l_min_duty', 'f', 1),
('l_max_duty', 'f', 1),
('l_watt_max', 'f', 1),
('l_watt_min', 'f', 1),
('sl_min_erpm', 'f', 1),
('sl_min_erpm_cycle_int_limit', 'f', 1),
('sl_max_fullbreak_current_dir_change', 'f', 1),
('sl_cycle_int_limit', 'f', 1),
('sl_phase_advance_at_br', 'f', 1),
('sl_cycle_int_rpm_br', 'f', 1),
('sl_bemf_coupling_k', 'f', 1),
('hall_table_0', 'b', 1),
('hall_table_1', 'b', 1),
('hall_table_2', 'b', 1),
('hall_table_3', 'b', 1),
('hall_table_4', 'b', 1),
('hall_table_5', 'b', 1),
('hall_table_6', 'b', 1),
('hall_table_7', 'b', 1),
('hall_sl_erpm', 'f', 1),
('foc_current_kp', 'f', 1),
('foc_current_ki', 'f', 1),
('foc_f_sw', 'f', 1),
('foc_dt_us', 'f', 1),
('foc_encoder_inverted', 'B', 1),
('foc_encoder_offset', 'f', 1),
('foc_encoder_ratio', 'f', 1),
('foc_sensor_mode', 'B', 1),
('foc_pll_kp', 'f', 1),
('foc_pll_ki', 'f', 1),
('foc_motor_l', 'f', 1),
('foc_motor_r', 'f', 1),
('foc_motor_flux_linkage', 'f', 1),
('foc_observer_gain', 'f', 1),
('foc_observer_gain_slow', 'f', 1),
('foc_duty_dowmramp_kp', 'f', 1),
('foc_duty_dowmramp_ki', 'f', 1),
('foc_openloop_rpm', 'f', 1),
('foc_sl_openloop_hyst', 'f', 1),
('foc_sl_openloop_time', 'f', 1),
('foc_sl_d_current_duty', 'f', 1),
('foc_sl_d_current_factor', 'f', 1),
('foc_hall_table_0', 'B', 1),
('foc_hall_table_1', 'B', 1),
('foc_hall_table_2', 'B', 1),
('foc_hall_table_3', 'B', 1),
('foc_hall_table_4', 'B', 1),
('foc_hall_table_5', 'B', 1),
('foc_hall_table_6', 'B', 1),
('foc_hall_table_7', 'B', 1),
('foc_sl_erpm', 'f', 1),
('foc_sample_v0_v7', 'B', 1),
('foc_sample_high_current', 'B', 1),
('foc_sat_comp', 'f', 1),
('foc_temp_comp', 'B', 1),
('foc_temp_comp_base_temp', 'f', 1),
('s_pid_kp', 'f', 1),
('s_pid_ki', 'f', 1),
('s_pid_kd', 'f', 1),
('s_pid_min_erpm', 'f', 1),
('s_pid_allow_braking', 'B', 1),
('p_pid_kp', 'f', 1),
('p_pid_ki', 'f', 1),
('p_pid_kd', 'f', 1),
('p_pid_ang_div', 'f', 1),
('cc_startup_boost_duty', 'f', 1),
('cc_min_current', 'f', 1),
('cc_gain', 'f', 1),
('cc_ramp_step_max', 'f', 1),
('m_fault_stop_time_ms', 'i', 1),
('m_duty_ramp_step', 'f', 1),
('m_current_backoff_gain', 'f', 1),
('m_encoder_counts', 'I', 1),
('m_sensor_port_mode', 'B', 1),
('m_invert_direction', 'B', 1),
('m_drv8301_oc_mode', 'B', 1),
('m_drv8301_oc_adj', 'B', 1),
('m_bldc_f_sw_min', 'f', 1),
('m_bldc_f_sw_max', 'f', 1),
('m_dc_f_sw', 'f', 1),
('m_ntc_motor_beta', 'f', 1)
]
Send the message :
my_msg = GetConfig(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
my_msg = pyvesc.encode(my_msg)
serial.write(my_msg)
Read the answer :
if serial.in_waiting > 0:
data = serial.read(serial.in_waiting)
msg, consummed = pyvesc.decode(data)
for field_name, _, _ in msg.fields:
print(f"{field_name}: {getattr(msg, field_name)}")
My goal is to create a Python script with the same functionality as the VESCTOOL setupwizardfoc. I am using the Pyvesc library to encode and decode messages for the VESC. I send the COMM_DETECT_APPLY_ALL_FOC message, the motor runs correctly, and I receive a response corresponding to the COMM_GET_MCCONF message. So far, I am following the same logic that I observed in the VESCTOOL source code.
What I do not understand is the logic VESCTOOL uses to analyze the mcconf of the VESC and deduce the foc_sensor_mode. In the COMM_GET_MCCONF message that I receive, there are many parameters, as you can see in the text below. However, the only parameter whose value changes depending on the Sensor mode in the FOC tab of VESCTOOL is the following:
Message sent by the VESC in response to COMM_DETECT_APPLY_ALL_FOC: