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

enlarge range for angle from 0 to 359 #70

Open
dsyleixa opened this issue Jan 24, 2021 · 8 comments
Open

enlarge range for angle from 0 to 359 #70

dsyleixa opened this issue Jan 24, 2021 · 8 comments
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement

Comments

@dsyleixa
Copy link

hello,
will it be possible to enlarge the range for angle e.g. from 0 to 359 or at least from 0 to 270?
The default servo max angle= 180 should be possible to be changed arbitrarily for that purpose.

@per1234 per1234 added the type: enhancement Proposed improvement label Jan 24, 2021
@hugoinfante83
Copy link

hugoinfante83 commented Mar 24, 2021

I think is the same issue that i have...

int Servo::read() // return the value as degrees
{
  return map(readMicroseconds()+1, SERVO_MIN(), SERVO_MAX(), 0, 180);
}

@uhertlein
Copy link

@dsyleixa, @hugoinfante83 You are aware that this won't actually change the travel range of the servo, right?
It would merely make it easier to match your code to your hardware - i.e. if you have a servo with a 270 degree travel range and then you can use that value in your code.

IMHO the mentioning of angle and in degrees in this library is a bit unfortunate, as value represents neither in the write or read methods.

Picking 180 for the maximum position can lead people to assume that it is in degrees, but 1000, 255, or 100 (like percent, but poorer resolution) might have been better choices.

@dsyleixa
Copy link
Author

IMO the servo position to write or read should always match to its actual angle in degrees and nothing else, for either servo with either travel range.

@uhertlein
Copy link

That would be ideal, and that's why I was asking about your expectations/use-case.

Unfortunately, the library has no way to find out what the physical travel range of an attached servo is.
So the programmer would need to know the travel range of the servo and could then configure that in the Servo class.

That would be an easy change (e.g. adding the max 'angle' to the constructor) and could also be done in a backwards-compatible manner by using 180 as the default.

@dsyleixa
Copy link
Author

dsyleixa commented Nov 22, 2021

yes, I know the servo's max travel range (e.g., 180° or 270° or 360°), the lib is just to handle the angles as they are programmed.
e.g., when passing 180 then it's supposed to be 180° movement at either servo, and passing 270 then 270° at servos with 270° or even larger ranges.
Of course an inappropriate programmed value would cause malfunctions, but that's up to the programmer and the builder.

@uhertlein
Copy link

I'd suggest adding an additional attach override like so:

uint8_t Servo::attach(int pin, int min_value, int min, int max_value, int max);

  • min_value is the corresponding value when the servo is at the min pulse length
  • max_value is the corresponding value when the servo is at the max pulse length

The default attach call would then call
this->attach(pin, 0, MIN_PULSE_WIDTH, 180, MAX_PULSE_WIDTH);
for backwards compatibility.

The programmer could adjust this to fit the problem, like having a range from 0..270 or even -45..45.

@dsyleixa
Copy link
Author

IMO that's a bad idea, the lib should provide the correct handsome features out of the box for either servo range.

@uhertlein
Copy link

What sort of an API do you have in mind?

You could always provide convenience functions on top of that, like Servo::attach(int pin, RangeType rangeType) that calls the attach override with [0,90], [0,180], [0,270], or [0, 360].

But for my use-case having [-45, 45] would be ideal and IMO there's no reason that the API should prohibit that.

@per1234 per1234 added the topic: code Related to content of the project itself label Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

No branches or pull requests

4 participants