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

Fix attach servo with initial value #8723

Closed

Conversation

om2804
Copy link

@om2804 om2804 commented Nov 22, 2022

functions

uint8_t attach(int pin);
uint8_t attach(int pin, uint16_t min, uint16_t max);

always sets 0 (zero) as the initial value. This is not obvious. It does not allow to attach servo without movement.

I changed the body of functions, so that the movement was caused only when transmitting the value to the function.
uint8_t attach(int pin, uint16_t min, uint16_t max, int value);

@dok-net
Copy link
Contributor

dok-net commented Dec 4, 2022

What is wrong with using this overload, as it is intended to serve your use case:

    // attach the given pin to the next free channel, sets pinMode, min, and max values for write(),
    // and sets the initial value, the same as write().
    // returns channel number or 0 if failure.
    uint8_t attach(int pin, uint16_t min, uint16_t max, int value);

@om2804
Copy link
Author

om2804 commented Dec 4, 2022

@dok-net In the current implementation, it is impossible attach without moving a servo drive. This is not obvious. This violates compatibility with https://github.com/arduino-libraries/servo.

@dok-net
Copy link
Contributor

dok-net commented Dec 5, 2022

[...] violates compatibility with https://github.com/arduino-libraries/servo.

I have checked the implementations for AVR and and SAMD in that lib. The Servo constructor sets a default position, attach starts the PWM on the set pin. To be sure, write does nothing more but update the position. I can't see how your claim that in that library attach would not cause the servo to move unless it is the default position to begin with already.

@om2804
Copy link
Author

om2804 commented Dec 5, 2022

Moving to zero will be at each attach after deattach without a reconstruction of a class instance.

example:
servo = new Servo();
servo .attach(9); // move to 0, first attach, it's ok
servo.write(value); // move to value
servo.detach();
servo.attach(9); // current implementation moves servo to 0, it's not ok
servo.write(value); // move to value

@dok-net
Copy link
Contributor

dok-net commented Dec 10, 2022

@om2804 No offense, but I am certain I have a simpler solution that does what you requested. Please review.

@om2804
Copy link
Author

om2804 commented Dec 13, 2022

@ dok-net ok. I close this PR.

@om2804 om2804 closed this Dec 13, 2022
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.

None yet

2 participants