matthieuvigne / STS_servos

Arduino library for Feetech's STS smart servo
MIT License
11 stars 6 forks source link

Negative velocity results in different speed. #2

Closed kyleliamwalker closed 6 months ago

kyleliamwalker commented 1 year ago

Hi,

I've been using this library for experimenting with the STS3215 servos and found it really useful, but what I've noticed when putting the servo into wheel mode is that using negative speed values as an input results in a totally different speed of rotation.

Is this just a bug in the code or is there a specific way to command the servos to rotate anti-clockwise? Essentially, if I send the command (where servos is my initialised object from the library) :

servos.setTargetVelocity(ID1, 500)

I get a clockwise rotation at the correct speed. But if I send the command:

servos.setTargetVelocity(ID1, -500)

The servo does rotate anti-clockwise but at a much faster rate. Any help is appreciated, thanks.

matthieuvigne commented 6 months ago

Sorry for not replying, I hadn't seen the issue :(

This is definitely a bug in the library. Feetech servo handle sign in a specific way, using bit 15 as a sign byte instead of the standard 2s complement approach used in standard C++. Thus when sending negative value, the servo interprets them badly. This has been fixed and tested in the new release (V1.1.0) which features an example on using velocity mode.