Just fetch the cogging ratio every time we need it

This commit is contained in:
Paul Guenette
2019-05-25 17:29:25 +02:00
parent dfca556185
commit 6654b3a375
3 changed files with 9 additions and 11 deletions
+4 -3
View File
@@ -5,7 +5,8 @@
Controller::Controller(Config_t& config) :
config_(config)
{}
{
}
void Controller::reset() {
pos_setpoint_ = 0.0f;
@@ -90,7 +91,7 @@ bool Controller::anticogging_calibration(float pos_estimate, float vel_estimate)
config_.anticogging.cogging_map[std::clamp<uint32_t>(config_.anticogging.index++, 0, 3600)] = vel_integrator_current_;
}
if (config_.anticogging.index < 3600) {
set_pos_setpoint(config_.anticogging.index * config_.anticogging.cogging_ratio, 0.0f, 0.0f);
set_pos_setpoint(config_.anticogging.index * axis_->encoder_.getCoggingRatio(), 0.0f, 0.0f);
return false;
} else {
config_.anticogging.index = 0;
@@ -106,7 +107,7 @@ bool Controller::anticogging_calibration(float pos_estimate, float vel_estimate)
bool Controller::update(float pos_estimate, float vel_estimate, float* current_setpoint_output) {
// Only runs if config_.anticogging.calib_anticogging is true; non-blocking
anticogging_calibration(pos_estimate, vel_estimate);
float anticogging_pos = pos_estimate / config_.anticogging.cogging_ratio;
float anticogging_pos = pos_estimate / axis_->encoder_.getCoggingRatio();
// Trajectory control
if (config_.control_mode == CTRL_MODE_TRAJECTORY_CONTROL) {
-4
View File
@@ -99,10 +99,6 @@ void Encoder::set_linear_count(int32_t count) {
cpu_exit_critical(prim);
}
void Encoder::cpr_changed_callback(){
axis_->controller_.config_.anticogging.cogging_ratio = config_.cpr / 3600.0f;
}
// Function that sets the CPR circular tracking encoder count to a desired 32-bit value.
// Note that this will get mod'ed down to [0, cpr)
void Encoder::set_circular_count(int32_t count, bool update_offset) {
+5 -4
View File
@@ -67,9 +67,6 @@ public:
void sample_now();
bool update();
void cpr_changed_callback();
const EncoderHardwareConfig_t& hw_config_;
Config_t& config_;
Axis* axis_ = nullptr; // set by Axis constructor
@@ -94,6 +91,10 @@ public:
float sincos_sample_s_ = 0.0f;
float sincos_sample_c_ = 0.0f;
constexpr float getCoggingRatio(){
return config_.cpr / 3600.0f;
}
// Communication protocol definitions
auto make_protocol_definitions() {
return make_protocol_member_list(
@@ -120,7 +121,7 @@ public:
make_protocol_property("pre_calibrated", &config_.pre_calibrated,
[](void* ctx) { static_cast<Encoder*>(ctx)->check_pre_calibrated(); }, this),
make_protocol_property("zero_count_on_find_idx", &config_.zero_count_on_find_idx),
make_protocol_property("cpr", &config_.cpr, [](void* ctx) { static_cast<Encoder*>(ctx)->cpr_changed_callback(); }, this),
make_protocol_property("cpr", &config_.cpr),
make_protocol_property("offset", &config_.offset),
make_protocol_property("offset_float", &config_.offset_float),
make_protocol_property("enable_phase_interpolation", &config_.enable_phase_interpolation),