Connect the encoded motor to the specified positions E0 as described in the example program. After the program runs successfully, it will print out whether kAPhaseLeads or kBPhaseLeads should be used based on the actual phase relationship between the A and B phases of the encoder during forward rotation of the motor, helping the user determine the value that should be set for the phase_relation parameter when creating an EncoderMotor object.
namespace {
constexpr uint32_t kPPR = 12;
constexpr uint32_t kReductionRation = 90;
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0)
GPIO_NUM_27,
GPIO_NUM_13,
GPIO_NUM_18,
GPIO_NUM_19,
kPPR,
kReductionRation,
);
#else
GPIO_NUM_27,
0,
GPIO_NUM_13,
1,
GPIO_NUM_18,
GPIO_NUM_19,
kPPR,
kReductionRation,
);
#endif
}
void setup() {
Serial.begin(115200);
printf("setting up\n");
g_encoder_motor_0.Init();
g_encoder_motor_0.RunPwmDuty(1023);
printf("setup completed\n");
}
void loop() {
const auto rpm = g_encoder_motor_0.SpeedRpm();
if (rpm > 0) {
printf(
"[%lu] RPM: %d . The phase of A leads B. Constructed with the em::EncoderMotor::PhaseRelation::kAPhaseLeads "
"enum.\n",
millis(),
rpm);
} else if (rpm < 0) {
printf(
"[%lu] RPM: %d . The phase of B leads A. Constructed with the em::EncoderMotor::PhaseRelation::kBPhaseLeads "
"enum.\n",
millis(),
rpm);
} else {
printf("The motor is not running currently.\n");
}
delay(200);
}
@ kAPhaseLeads
Represents the situation where phase A leads phase B when the motor is rotating forward.
String Version()
Get the version number string.