Encoder position control fix

This commit is contained in:
Benjamin Vedder 2015-12-29 02:37:09 +01:00
parent 42c1b79a08
commit cc17142264
2 changed files with 8 additions and 3 deletions

View File

@ -27,7 +27,7 @@
// Firmware version
#define FW_VERSION_MAJOR 2
#define FW_VERSION_MINOR 7
#define FW_VERSION_MINOR 8
#include "datatypes.h"

View File

@ -1848,8 +1848,13 @@ static void run_pid_control_pos(float dt) {
}
// Compute error
float angle = m_conf->foc_encoder_inverted ? encoder_read_deg() : 360.0 - encoder_read_deg();
float error = utils_angle_difference(angle, m_pos_pid_set_pos);
float angle = encoder_read_deg();
float error = utils_angle_difference(m_pos_pid_set_pos, angle);
if (m_conf->foc_encoder_inverted) {
error = -error;
}
// Compute parameters
p_term = error * m_conf->p_pid_kp;