0

I'm using the pigpio library to run my motor in my Raspberry Pi like below.

ESC = 18
esc_pi = pigpio.pi()
esc_pi.set_servo_pulsewidth(ESC, 2000)

I'm wondering is there any way to detect the motor is STILL rotating when I set the pulse width to mid value from max value? (no current so the motor will stop)

The reason why I ask this is because I want to input an opposite pulse value to increase the decceration for stopping the motor if detecting the motor rotation is possible like below.

# Assume 1000 is min value, 1500 is mid value and 2000 is max value
# so 1501-2000 is forward and 1000-1499 is backward
def get_current_motor_pulse():
    ...
    return current_motor_pulse

esc_pi.set_servo_pulsewidth(ESC, 2000)      // Forward
sleep(10)                                   // Keep forward
esc_pi.set_servo_pulsewidth(ESC, 1500)      // STILL forward for few seconds
while get_current_motor_pulse() > 0:
    esc_pi.set_servo_pulsewidth(ESC, 1400)  // Increase the decceration

Here is the pigpio library, but I am not sure which function is the best fit for my case.

1
  • The make encoders and Tachometer that should do what you want. With the correct encoder you can also determine shaft position.
    – Gil
    May 15, 2022 at 18:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.