Hi Mattia,
I tested this on a controller here with exactly your program shape (6 commands, alternating addMoveJ/addMoveL, one waypoint each) and currentCommandId does step through every id, 1..6:
t= 0.121 current=1 previous=0 state=RUN
t= 0.140 current=2 previous=1
t= 1.271 current=3 previous=2
t= 2.791 current=4 previous=3
t= 4.271 current=5 previous=4
t= 6.751 current=6 previous=5
t= 7.971 current=0 previous=6 state=DONE
So the counter is fine — what you are hitting is a sampling problem, and play() is the main cause:
RobotCommand.play() sleeps wait_time (default 1.0 s) before it returns. That whole program above finished in 8 s, so by the time play() hands control back you are already on command 2 or 3. Call robot.play(0.0) and start observing before/immediately after it.
The first transition took 20 ms. If the robot is already at your first waypoint (which it is, after moveToStart), command 1 is a zero-length move and completes in a single cycle. No polling loop will catch that — only previousCommandId will show it happened.
Polling on the request connection is too coarse. Subscribe instead, so you get a sample every control cycle:
sub_ids = sub.subscribe([
"root/MotionInterpreter/currentCommandId",
"root/MotionInterpreter/previousCommandId",
"root/MotionInterpreter/actualStateOut"], "ids", 1)
sub_ids.get()
...
while True:
vals = sub_ids.read()
if vals:
cur, prev, state = [v.value[0] for v in vals]
Two more things that bit me while testing:
commandStatus[0] leads currentCommandId — it showed 2 while currentCommandId was still 1, because it reports the command being prepared, not the one executing. Use currentCommandId for "now" and previousCommandId for "just finished".
- With waypoint smoothing/blending the handover between two moves is not a sharp point, so the id flip there is approximate by nature.
For your recovery use case I would drive it off previousCommandId rather than currentCommandId: it is monotone within a program run and never drops to 0 mid-program, so "last command that definitely completed" is exactly the resume point you want.
Coen