Rotate the motor with the specified PWM duty cycle.
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,
);
GPIO_NUM_4,
GPIO_NUM_2,
GPIO_NUM_5,
GPIO_NUM_23,
kPPR,
kReductionRation,
);
GPIO_NUM_17,
GPIO_NUM_12,
GPIO_NUM_35,
GPIO_NUM_36,
kPPR,
kReductionRation,
);
GPIO_NUM_15,
GPIO_NUM_14,
GPIO_NUM_34,
GPIO_NUM_39,
kPPR,
kReductionRation,
);
#else
GPIO_NUM_27,
0,
GPIO_NUM_13,
1,
GPIO_NUM_18,
GPIO_NUM_19,
kPPR,
kReductionRation,
);
GPIO_NUM_4,
2,
GPIO_NUM_2,
3,
GPIO_NUM_5,
GPIO_NUM_23,
kPPR,
kReductionRation,
);
GPIO_NUM_17,
4,
GPIO_NUM_12,
5,
GPIO_NUM_35,
GPIO_NUM_36,
kPPR,
kReductionRation,
);
GPIO_NUM_15,
6,
GPIO_NUM_14,
7,
GPIO_NUM_34,
GPIO_NUM_39,
kPPR,
kReductionRation,
);
#endif
}
void setup() {
Serial.begin(115200);
printf("setting up\n");
g_encoder_motor_0.Init();
g_encoder_motor_1.Init();
g_encoder_motor_2.Init();
g_encoder_motor_3.Init();
printf("setup completed\n");
}
void loop() {
const int16_t pwm_duty = 1023;
g_encoder_motor_0.RunPwmDuty(pwm_duty);
g_encoder_motor_1.RunPwmDuty(pwm_duty);
g_encoder_motor_2.RunPwmDuty(pwm_duty);
g_encoder_motor_3.RunPwmDuty(pwm_duty);
printf("target pwm duty: %5" PRIi16 ", current speed rpm:[%4" PRId32 ", %4" PRId32 ", %4" PRId32 ", %4" PRId32
"], pwm duties:[%5 " PRIi16 ", %5" PRIi16 ", %5" PRIi16 ", %5" PRIi16 "], pulse counts:[%" PRId64 ", %" PRId64
", %" PRId64 ", %" PRId64 "]\n",
pwm_duty,
g_encoder_motor_0.SpeedRpm(),
g_encoder_motor_1.SpeedRpm(),
g_encoder_motor_2.SpeedRpm(),
g_encoder_motor_3.SpeedRpm(),
g_encoder_motor_0.PwmDuty(),
g_encoder_motor_1.PwmDuty(),
g_encoder_motor_2.PwmDuty(),
g_encoder_motor_3.PwmDuty(),
g_encoder_motor_0.EncoderPulseCount(),
g_encoder_motor_1.EncoderPulseCount(),
g_encoder_motor_2.EncoderPulseCount(),
g_encoder_motor_3.EncoderPulseCount());
delay(100);
}
@ kAPhaseLeads
Represents the situation where phase A leads phase B when the motor is rotating forward.
String Version()
Get the version number string.