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

read() does not return last write() accurately #39

Open
bigedian opened this issue Oct 8, 2023 · 0 comments
Open

read() does not return last write() accurately #39

bigedian opened this issue Oct 8, 2023 · 0 comments

Comments

@bigedian
Copy link

bigedian commented Oct 8, 2023

There is a loss of precision when reading back the angle that was last written to the servo. This prevents doing something like this: servo.write(servo.read()+1); to increment a servo by 1 degree from it's current position.

Possible cause is the value being mangled by the (integer) map() macros in the read() & write() functions.

Example test code:

for (int16_t i = 0; i <= 30; i++) {
x_axis.write(i);
Serial.printf("Wrote: %u Read: %u\n", i, x_axis.read());
}

Output:
Wrote: 0 Read: 0
Wrote: 1 Read: 0
Wrote: 2 Read: 1
Wrote: 3 Read: 1
Wrote: 4 Read: 3
Wrote: 5 Read: 3
Wrote: 6 Read: 5
Wrote: 7 Read: 5
Wrote: 8 Read: 7
Wrote: 9 Read: 7
Wrote: 10 Read: 9
Wrote: 11 Read: 10
Wrote: 12 Read: 10
Wrote: 13 Read: 12
Wrote: 14 Read: 12
Wrote: 15 Read: 14
Wrote: 16 Read: 14
Wrote: 17 Read: 16
Wrote: 18 Read: 16
Wrote: 19 Read: 18
Wrote: 20 Read: 18
Wrote: 21 Read: 20
Wrote: 22 Read: 20
Wrote: 23 Read: 22
Wrote: 24 Read: 22
Wrote: 25 Read: 24
Wrote: 26 Read: 24
Wrote: 27 Read: 26
Wrote: 28 Read: 26
Wrote: 29 Read: 28
Wrote: 30 Read: 29

Clearly this is not very useful

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

1 participant