Stepper API not emitting PositionChange/Stopped if int(position) == position

Any hardware type questions or problems for all other Phidget devices.
Post Reply
Rhybot
Phidgeteer!
Posts: 52
Joined: Wed Aug 14, 2019 4:58 pm
Contact:

Stepper API not emitting PositionChange/Stopped if int(position) == position

Post by Rhybot »

I am programmatically commanding STC1000_0 from Python via the Stepper API.

My workflow for motion is:
1. Given a new target_position (float)
2. Since PositionChange and Stopped events are only emitted when motion takes place, return early if target_position == stepper_api.getPosition()
3. Call stepper_api.setTargetPosition(target_position)
4. Wait for Stopped event (I use stepper_api.setOnStoppedHandler)

Seem to make sense?

There is a subtle bug here: target_position == stepper_api.getPosition()

Even though stepper_api.getPosition() and PositionChange events are typed as a float, both actually return an integer value cast as a float. This made me realize the Stepper API's backend seems to work with int values.

So, if you are currently at position int(x1), and you command x2 in [int(x1) - 0.49, int(x1) + 0.49], a problem arises:
1. target_position == stepper_api.getPosition() will be False, so we don't return early
2. Then we wait for the Stopped event, which never arrives as the Stepper API doesn't see the target position as any different

In conclusion, I think the Stepper API should somehow print a warning, to give developers the understanding that the Stepper API will not send new PositionChange/Stopped events, if the position does not differ by at least 0.5 counts.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests