File tree 6 files changed +64
-0
lines changed
6 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -982,6 +982,27 @@ float mc_interface_get_abs_motor_current_unbalance(void) {
982
982
return ret ;
983
983
}
984
984
985
+ int mc_interface_set_tachometer_value (int steps )
986
+ {
987
+ int ret = 0 ;
988
+ switch (m_conf .motor_type )
989
+ {
990
+ case MOTOR_TYPE_BLDC :
991
+ case MOTOR_TYPE_DC :
992
+ ret = mcpwm_set_tachometer_value (DIR_MULT * steps );
993
+ break ;
994
+
995
+ case MOTOR_TYPE_FOC :
996
+ ret = mcpwm_foc_set_tachometer_value (DIR_MULT * steps );
997
+ break ;
998
+
999
+ default :
1000
+ break ;
1001
+ }
1002
+
1003
+ return DIR_MULT * ret ;
1004
+ }
1005
+
985
1006
int mc_interface_get_tachometer_value (bool reset ) {
986
1007
int ret = 0 ;
987
1008
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ void mc_interface_set_current_rel(float val);
44
44
void mc_interface_set_brake_current_rel (float val );
45
45
void mc_interface_set_handbrake (float current );
46
46
void mc_interface_set_handbrake_rel (float val );
47
+ int mc_interface_set_tachometer_value (int steps );
47
48
void mc_interface_brake_now (void );
48
49
void mc_interface_release_motor (void );
49
50
float mc_interface_get_duty_cycle_set (void );
Original file line number Diff line number Diff line change @@ -832,6 +832,26 @@ float mcpwm_get_tot_current_in_filtered(void) {
832
832
return mcpwm_get_tot_current_filtered () * fabsf (dutycycle_now );
833
833
}
834
834
835
+ /**
836
+ * Set the number of steps the motor has rotated. This number is signed and
837
+ * becomes a negative when the motor is rotating backwards.
838
+ *
839
+ * @param steps
840
+ * New number of motor steps will be set after this call.
841
+ *
842
+ * @return
843
+ * The previous tachometer value in motor steps. The number of motor revolutions will
844
+ * be this number divided by (3 * MOTOR_POLE_NUMBER).
845
+ */
846
+ int mcpwm_set_tachometer_value (int steps )
847
+ {
848
+ int val = tachometer ;
849
+
850
+ tachometer = steps ;
851
+
852
+ return val ;
853
+ }
854
+
835
855
/**
836
856
* Read the number of steps the motor has rotated. This number is signed and
837
857
* will return a negative number when the motor is rotating backwards.
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ void mcpwm_set_pid_speed(float rpm);
34
34
void mcpwm_set_pid_pos (float pos );
35
35
void mcpwm_set_current (float current );
36
36
void mcpwm_set_brake_current (float current );
37
+ int mcpwm_set_tachometer_value (int steps );
37
38
void mcpwm_brake_now (void );
38
39
void mcpwm_release_motor (void );
39
40
int mcpwm_get_comm_step (void );
Original file line number Diff line number Diff line change @@ -958,6 +958,26 @@ float mcpwm_foc_get_tot_current_in_filtered(void) {
958
958
return m_motor_state .i_bus ; // TODO: Calculate filtered current?
959
959
}
960
960
961
+ /**
962
+ * Set the number of steps the motor has rotated. This number is signed and
963
+ * becomes a negative when the motor is rotating backwards.
964
+ *
965
+ * @param steps
966
+ * New number of steps will be set after this call.
967
+ *
968
+ * @return
969
+ * The previous tachometer value in motor steps. The number of motor revolutions will
970
+ * be this number divided by (3 * MOTOR_POLE_NUMBER).
971
+ */
972
+ int mcpwm_foc_set_tachometer_value (int steps )
973
+ {
974
+ int val = m_tachometer ;
975
+
976
+ m_tachometer = steps ;
977
+
978
+ return val ;
979
+ }
980
+
961
981
/**
962
982
* Read the number of steps the motor has rotated. This number is signed and
963
983
* will return a negative number when the motor is rotating backwards.
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ void mcpwm_foc_set_openloop(float current, float rpm);
43
43
void mcpwm_foc_set_openloop_phase (float current , float phase );
44
44
void mcpwm_foc_set_openloop_duty (float dutyCycle , float rpm );
45
45
void mcpwm_foc_set_openloop_duty_phase (float dutyCycle , float phase );
46
+ int mcpwm_foc_set_tachometer_value (int steps );
46
47
float mcpwm_foc_get_duty_cycle_set (void );
47
48
float mcpwm_foc_get_duty_cycle_now (void );
48
49
float mcpwm_foc_get_pid_pos_set (void );
You can’t perform that action at this time.
0 commit comments