Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different values on identical motors #38

Open
SimeonOA opened this issue May 14, 2019 · 1 comment
Open

Different values on identical motors #38

SimeonOA opened this issue May 14, 2019 · 1 comment

Comments

@SimeonOA
Copy link

Hi,

I am using DC motors controlled by a Raspberry Pi Model 3 running Stretch.

I adapted the code from rotary_worker_test.py to read from two of the wheels as below.

import time
import pigpio
import gaugette.gpio
import gaugette.rotary_encoder
from time import sleep
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

rf=16
rfr=13
lf=27
lfr=22
pwm=4
    
GPIO.setup(lf, GPIO.OUT)
GPIO.setup(lfr, GPIO.OUT)
GPIO.setup(rf, GPIO.OUT)
GPIO.setup(rfr, GPIO.OUT)
GPIO.setup(pwm, GPIO.OUT)

pulse = GPIO.PWM(pwm,100)
pulse.start(50)

A_PIN = 5 #(21 is Wpi)
B_PIN = 6 #(22 is Wpi)
C_PIN = 14
D_PIN = 15

gpio = gaugette.gpio.GPIO()
encoder = gaugette.rotary_encoder.RotaryEncoder(gpio, A_PIN, B_PIN)
encoder.start()
gpio2 = gaugette.gpio.GPIO()
encoder2 = gaugette.rotary_encoder.RotaryEncoder.Worker(gpio2, C_PIN, D_PIN)
encoder2.start()

while True:
    delta = encoder.get_steps()
    delta2 = encoder2.get_steps()
    if delta!=0 or delta2!=0:
        print ("rotate %d" % delta, delta2)
    else:
        time.sleep(0.05)


##BACK
    GPIO.output(lf, 1)
    GPIO.output(lfr, 0)
    GPIO.output(rf, 1)
    GPIO.output(rfr, 0)

    time.sleep(.3)

##TURN OFF GPIO
GPIO.cleanup()

However, when I run it, I am having the following results:

rotate 31 0
rotate 848 235
rotate 961 109
rotate 968 100
rotate 967 98
rotate 973 132
rotate 955 92
rotate 979 81
rotate 977 129
rotate 973 178
rotate 973 112
rotate 955 140
rotate 969 78
rotate 971 166
rotate 972 88
rotate 973 120
rotate 971 93
rotate 974 147
rotate 972 120
rotate 972 199
rotate 973 180
rotate 973 177
rotate 973 201

While I expected that there might be a difference between the number of steps being taken by each motor, I did not expect up to 4x given that they are identical motors.

I am wondering if there is something I am missing.

I am new to using encoders in general and do apologise if the answer to my question is already obvious

I am primarily interested in using the library to get a robot to move in a straight line or move in angles when required.

Any help I can get would be appreciated.

Thanks

@guyc
Copy link
Owner

guyc commented May 14, 2019

Yeah that's not good. I don't see anything wrong in your use of the library. I'd try slowing the PWM rate way down, and see if the issue is related to speed. You are showing nearly 1000 increments per cycle on the first motor, so about 3000 encoder steps per second, which is pretty fast. You might be running up against some interrupt rate limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants