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

Bug fix where each stepper motor references the same info list #76

Merged
merged 1 commit into from
Mar 20, 2024

Conversation

AaronYoung5
Copy link
Contributor

Hi, thanks for making this package, I've found it very useful! (I think) I've run into a bug with the stepper_info_list. TL;DR the stepper_info_list is not copied between motor instances, so when you call a method that requires a callback, it will always overwrite all other instances. As in, all stepper motor instances share the same info list.

This code snippet reproduces the issue that I see:

from telemetrix import telemetrix
import time

board = telemetrix.Telemetrix()

def create_motor(pin1, pin2, enable):
    motor = board.set_pin_mode_stepper(pin1=pin1, pin2=pin2)
    board.stepper_set_enable_pin(motor, enable)
    board.stepper_set_3_pins_inverted(motor, enable=True)
    return motor

motorX = create_motor(2, 3, 8)
motorY = create_motor(4, 5, 8)

def current_position_callback_X(_):
    print('X')

def current_position_callback_Y(_):
    print('Y')

board.stepper_get_current_position(motorX, current_position_callback_X)
board.stepper_get_current_position(motorY, current_position_callback_Y)

time.sleep(1)

Which outputs:

Y
Y

Where the indented output (which is the result you get with the changes in this PR) is:

X
Y

I've created this PR assuming this is a bug, but maybe I'm using the library wrong. Please let me know if that's the case. Thanks again!

@AaronYoung5 AaronYoung5 changed the title Fixed bug with stepper_info_list which references the same object for… Bug fix where each stepper motor references the same info list Mar 19, 2024
@MrYsLab MrYsLab merged commit c44910b into MrYsLab:master Mar 20, 2024
@MrYsLab
Copy link
Owner

MrYsLab commented Mar 20, 2024

Great catch! Thanks for the pull request. I think no one found this before because they use a single callback for all motors and then key off the motor ID.

I am going to release it to PyPi. I will add a comment here when it is available.

MrYsLab added a commit that referenced this pull request Mar 20, 2024
@MrYsLab
Copy link
Owner

MrYsLab commented Mar 20, 2024

Thanks once again. The release is available in PyPi.

MrYsLab added a commit that referenced this pull request Mar 21, 2024
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

Successfully merging this pull request may close these issues.

2 participants