@@ -30,36 +30,16 @@ extern "C" void app_main(void) {
3030
3131 // make the velocity filter
3232 static constexpr float core_update_period = 0 .001f ; // seconds
33- static constexpr float filter_cutoff_hz = 4 .0f ;
34- espp::ButterworthFilter<2 , espp::BiquadFilterDf2> bwfilter ({
35- .normalized_cutoff_frequency = 2 .0f * filter_cutoff_hz * 0.01 // core_update_period
36- });
37- espp::LowpassFilter lpfilter (
38- {.normalized_cutoff_frequency = 2 .0f * filter_cutoff_hz * 0.01 , // core_update_period,
39- .q_factor = 1 .0f });
40- auto filter_fn = [&bwfilter, &lpfilter](float raw) -> float {
41- // return bwfilter.update(raw);
42- // return lpfilter.update(raw);
43-
44- // NOTE: right now there seems to be something wrong with the filter
45- // configuration, so we don't filter at all. Either 1) the filtering
46- // is not actually removing the noise we want, 2) it is adding too
47- // much delay for the PID to compensate for, or 3) there is a bug in
48- // the update function which doesn't take previous state into
49- // account?
50- return raw;
51- };
5233
5334 // now make the mt6701 which decodes the data
54- std::shared_ptr<espp::Mt6701> mt6701 = std::make_shared<espp::Mt6701>(
55- espp::Mt6701::Config{.write = std::bind (&espp::I2c::write, &i2c, std::placeholders::_1,
56- std::placeholders::_2, std::placeholders::_3),
57- .read_register = std::bind (&espp::I2c::read_at_register, &i2c,
58- std::placeholders::_1, std::placeholders::_2,
59- std::placeholders::_3, std::placeholders::_4),
60- .velocity_filter = filter_fn,
61- .update_period = std::chrono::duration<float >(core_update_period),
62- .log_level = espp::Logger::Verbosity::WARN});
35+ using Encoder = espp::Mt6701<>;
36+ std::shared_ptr<Encoder> mt6701 = std::make_shared<Encoder>(
37+ Encoder::Config{.write = std::bind (&espp::I2c::write, &i2c, std::placeholders::_1,
38+ std::placeholders::_2, std::placeholders::_3),
39+ .read = std::bind (&espp::I2c::read, &i2c, std::placeholders::_1,
40+ std::placeholders::_2, std::placeholders::_3),
41+ .update_period = std::chrono::duration<float >(core_update_period),
42+ .log_level = espp::Logger::Verbosity::WARN});
6343
6444 // now make the bldc driver
6545 std::shared_ptr<espp::BldcDriver> driver = std::make_shared<espp::BldcDriver>(
@@ -78,7 +58,7 @@ extern "C" void app_main(void) {
7858 .log_level = espp::Logger::Verbosity::WARN});
7959
8060 // now make the bldc motor
81- using BldcMotor = espp::BldcMotor<espp::BldcDriver, espp::Mt6701 >;
61+ using BldcMotor = espp::BldcMotor<espp::BldcDriver, Encoder >;
8262 auto motor = BldcMotor (BldcMotor::Config{
8363 // measured by setting it into ANGLE_OPENLOOP and then counting how many
8464 // spots you feel when rotating it.
0 commit comments