Kaynağa Gözat

加入foc()和mot_contrl()接口

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 2 yıl önce
ebeveyn
işleme
60c8295050

+ 6 - 6
Applications/app/app.c

@@ -126,26 +126,26 @@ int plot_type = 0;
 static void plot_smo_angle(void) {
 #if 1
 	float smo_angle = foc_observer_sensorless_angle();
-	float delta = smo_angle - motor.controller.foc.in.mot_angle;
+	float delta = smo_angle - foc()->in.mot_angle;
 	float s, c;
 	arm_sin_cos(delta, &s, &c);
 	delta = fast_atan2(s, c)/PI*180.0f;
-	can_plot3(motor.controller.foc.in.mot_angle, smo_angle, delta);
+	can_plot3(foc()->in.mot_angle, smo_angle, delta);
 #else
 	can_plot2((s16)(foc_observer_sensorless_diff() * 100.0f), (s16)(foc_observer_sensorless_ration() * 100.0f));
 #endif
 }
 static u32 _app_plot_task(void * args) {
 	if (plot_type == 1) {
-		can_plot2((s16)foc_observer_sensorless_speed(), (s16)mot_contrl_get_speed(&motor.controller));
+		can_plot2((s16)foc_observer_sensorless_speed(), (s16)mot_contrl_get_speed(mot_contrl()));
 	}else if (plot_type == 2) {
-		can_plot2(mot_contrl_get_final_torque(&motor.controller), motor.controller.target_torque);
+		can_plot2(mot_contrl_get_final_torque(mot_contrl()), mot_contrl()->target_torque);
 	}else if (plot_type == 3) {
 		plot_smo_angle();
 	}else if (plot_type == 4) {
-		can_plot2((s16)motor.controller.foc.out.curr_dq.d, (s16)motor.controller.foc.out.curr_dq.q);
+		can_plot2((s16)foc()->out.curr_dq.d, (s16)foc()->out.curr_dq.q);
 	}else if (plot_type == 5) {
-		can_plot2((s16)motor.controller.foc.in.target_id.interpolation , (s16)motor.controller.foc.in.target_iq.interpolation);
+		can_plot2((s16)foc()->in.target_id.interpolation , (s16)foc()->in.target_iq.interpolation);
 	}else if (plot_type == 6) {
 		//do it in other place
 	}else if (plot_type == 7) {

+ 8 - 0
Applications/foc/motor/motor.h

@@ -119,6 +119,14 @@ void mc_enable_tcs(bool enable);
 bool mc_set_target_vel(s16 vel);
 float mc_get_max_torque_with_gear_vel(s16 vel, u8 gear);
 
+static __INLINE mot_contrl_t *mot_contrl(void) {
+	return &motor.controller;
+}
+
+static __INLINE foc_t *foc(void) {
+	return &motor.controller.foc;
+}
+
 static __INLINE float motor_encoder_get_angle(void) {
 #ifdef USE_ENCODER_HALL
 	return hall_sensor_get_theta(true);

+ 3 - 3
Applications/prot/can_foc_msg.c

@@ -33,9 +33,9 @@ void can_report_power(u8 can) {
 void can_report_phase_current(u8 can) {
 	u8 data[8];
 	encoder_can_key(data, CMD_2_CAN_KEY(Foc_Report_Phase_Current));
-	encode_s16(data + 2, S16Q5(motor.controller.foc.in.curr_abc[0]));
-	encode_s16(data + 4, S16Q5(motor.controller.foc.in.curr_abc[1]));
-	encode_s16(data + 6, S16Q5(motor.controller.foc.in.curr_abc[2]));
+	encode_s16(data + 2, S16Q5(foc()->in.curr_abc[0]));
+	encode_s16(data + 4, S16Q5(foc()->in.curr_abc[1]));
+	encode_s16(data + 6, S16Q5(foc()->in.curr_abc[2]));
 	can_send_message(get_indicator_can_id(can), data, sizeof(data), 0);
 }