Skip to content

Different values on identical motors #38

@SimeonOA

Description

@SimeonOA

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions