Replies: 2 comments 1 reply
-
Good question. The wr_servo function returns a normalized float value that represents the servo position. If the new servo degrees entered is greater than the inital degrees, then the returned value (ye) will increase from 0.0 to 1.0. If its lower, then the returned value will decrease from 1.0 to 0.0. For example, if the initial degrees is 30 and new degrees is 60, the servo position in degrees is initial deg + deg difference * ye. When the returned value is 0.5, the servo position = 30 + 30 * 0.5 = 45 deg. If wr_servo is then called with a new value of 20 deg, then the servo When the returned value is 0.5, the servo position = 60 - 40 * (1 - 0.5) = 40 deg. Line #426 would only be true when easing isn't enabled (ke = 1.0 default). In this case, the pwm duty value is returned. When easing is enabled (ke < 1.0), having a normalized return value allows for easy plotting of servo position that's auto scaled (0-1) for any range of movement. I'll look into adding a feature to allow returning the servo position in degrees for the next release. Also, the next release will use an isr and callback function to provide smooth servo response even if there's blocking delays in the user's sketch. |
Beta Was this translation helpful? Give feedback.
-
Hi, But for easing calculations, you have already the intermediate value in line #424 ; I think it should be representative of the real position.
? Thanks |
Beta Was this translation helpful? Give feedback.
-
Hi,
I would like to notify about several intermediate positions on low speed and easing control.
I thought I could use
float read(int pin);
but it seems to give the target position but not every intermediate position.
If I read
void Pwm::wr_servo(int pin, float value, double speed, double ke) {
I guess in
https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/src/pwmWrite.cpp#L410
that easeDuty is calculated according to millis(), then written to the channel there :
https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/src/pwmWrite.cpp#L424
but lost here
https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite/blob/main/src/pwmWrite.cpp#L426
bacause it stores only the final duty, the target.
So how can I read the intermediate positions in degrees when moving ?
Thanks
Best regards
Beta Was this translation helpful? Give feedback.
All reactions