20constexpr uint32_t kPPR = 12;
21constexpr uint32_t kReductionRation = 90;
23#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0)
125 Serial.begin(115200);
126 printf(
"setting up\n");
128 g_encoder_motor_0.Init();
129 g_encoder_motor_1.Init();
130 g_encoder_motor_2.Init();
131 g_encoder_motor_3.Init();
132 printf(
"setup completed\n");
136 const int16_t rpm = 100;
137 static auto s_state_changed_time = millis();
138 static enum State : uint8_t {
143 } s_state = kForward;
145 if (millis() - s_state_changed_time > 2000) {
148 g_encoder_motor_0.Stop();
149 g_encoder_motor_1.Stop();
150 g_encoder_motor_2.Stop();
151 g_encoder_motor_3.Stop();
154 g_encoder_motor_0.RunSpeed(rpm);
155 g_encoder_motor_1.RunSpeed(rpm);
156 g_encoder_motor_2.RunSpeed(rpm);
157 g_encoder_motor_3.RunSpeed(rpm);
160 g_encoder_motor_0.RunSpeed(-rpm);
161 g_encoder_motor_1.RunSpeed(-rpm);
162 g_encoder_motor_2.RunSpeed(-rpm);
163 g_encoder_motor_3.RunSpeed(-rpm);
168 s_state =
static_cast<State
>((
static_cast<uint8_t
>(s_state) + 1) % kStateNum);
169 s_state_changed_time = millis();
172 printf(
"target speed rpm: %4" PRIi16
", current speed rpm:[%4" PRId32
", %4" PRId32
", %4" PRId32
", %4" PRId32
173 "], pwm duties:[%5 " PRIi16
", %5" PRIi16
", %5" PRIi16
", %5" PRIi16
"], pulse counts:[%" PRId64
", %" PRId64
174 ", %" PRId64
", %" PRId64
"]\n",
176 g_encoder_motor_0.SpeedRpm(),
177 g_encoder_motor_1.SpeedRpm(),
178 g_encoder_motor_2.SpeedRpm(),
179 g_encoder_motor_3.SpeedRpm(),
180 g_encoder_motor_0.PwmDuty(),
181 g_encoder_motor_1.PwmDuty(),
182 g_encoder_motor_2.PwmDuty(),
183 g_encoder_motor_3.PwmDuty(),
184 g_encoder_motor_0.EncoderPulseCount(),
185 g_encoder_motor_1.EncoderPulseCount(),
186 g_encoder_motor_2.EncoderPulseCount(),
187 g_encoder_motor_3.EncoderPulseCount());
@ kAPhaseLeads
Represents the situation where phase A leads phase B when the motor is rotating forward.
String Version()
Get the version number string.