moveToBlocking() for scripting

added [servo].moveToBlocking() as testing.

It is useful, to wait a finished moveTo() before to launch another. Without using a sleep(x) because sleep() didn't take care of servo speed.

leftArm.bicep.moveToBlocking(0)
leftArm.bicep.moveToBlocking(180)
leftArm.bicep.moveToBlocking(0)

For good result, you need to apply a speed to servo ( leftArm.bicep.setVelocity(42) )

With maximum speed ( leftArm.bicep.setVelocity(-1) ) , a blocking event will occur, but not related to servo real speed : There is magic but no miracle, no defined speed > no simulated position information.

I didn’t tested diy servo with it

 

any feedback welcome.

 


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
moz4r's picture

Result is not worky as I

Result is not worky as I expect. I Will find good method

moz4r's picture

method changed to used

method changed to used synchronized things between wait event and servo position+disable status.

Seem robust now. Need more test.

GroG's picture

Hi Moz4r, I think

Hi Moz4r,

I think moveToBlocking is a great idea, and I assume your using a stop event to release the blocking ?

moz4r's picture

Hi! I've tried lots of

Hi! I've tried lots of things, the published thing seems stable and do not cause interferences to moveTo thread. MoveToBlocking is conditioned by the finished event of a moveTo + autodisable delay if used.

What I have done is to use a synchronized object

Blocked event:

https://github.com/MyRobotLab/myrobotlab/blob/4f404e4dc237767817c1688d6240405ae6d83db1/src/org/myrobotlab/service/Servo.java#L515

Notify event to release the blocked event

https://github.com/MyRobotLab/myrobotlab/blob/4f404e4dc237767817c1688d6240405ae6d83db1/src/org/myrobotlab/service/Servo.java#L1197

Notify event to release the blocked event if isAutoDisabled:

https://github.com/MyRobotLab/myrobotlab/blob/4f404e4dc237767817c1688d6240405ae6d83db1/src/org/myrobotlab/service/Servo.java#L542

GroG's picture

Seems like a good

Seems like a good implementation moz4r !  Safety 30 seconds instead of infinite block is probably a good idea too. I'm going to do a little standardization & formatting.

  • formatting is best left to the machine (ctrl-shift-f) formats the whole file - but be sure you have mrl formatting standard template (window -> preferences -> Java -> Code Style -> Formatter -> mrl_java_formatter (this file is checked in the root of myrobotlab/mrl_java_formatter.xml)
  • Java's instance variable are camel cased, but always start with small case so MoveToBlocked is moveToBlocked
  • I usually do not like to use exception.printStackTrace() as it does not use the logger.  If there's an exception you want to log as an error do this
    log.error("something intelligent about the error", e);
    this is now "classified" as an error and is controlled by the logger - done this way with the exception as the second parameter we will get the stack trace in the log file.
    If interruption may be a valid use case, you might not want to log it as an error.
    Since moveTo can release the thread (non error) - I changed it to 
    log.info("servo {} moveToBlocked was interrupted", getName());
  • Comments above methods should be in JavaDoc format.  Magic key strokes of
    /** above a comment then press enter and the comment will partially write itself !
    You just need to fill in the details
  • I see now this ?

    But I see in the comments .. "TODO - moveToBlocking - blocks until servo sends "ARRIVED_TO_POSITION" response"

    Heh, it seemed like you set everything up well to have signalling done correctly .. and then didn't implement it ?   Was there an issue in the appropriate signal ?

GroG's picture

Was also curious about the

Was also curious about the method returning boolean, were you thinking it would return true if it completed the move and return false if it was interrupted ?  If so should probably return false after the catch & log statement.

moz4r's picture

Thank for the time you take

Thank for the time you take to review. I will learn best practices. It is very useful.

About boolean , if a moveToBlocking() action is initiate, it will finish, there is no reason.

Exept if there is an other move action to the same servo initiated from an other thread. So at this time , this action will break the first moveToBlocking action. Personaly, I dont have utility to read if the moveToAction was breaked or not. But may be useful later for others.

About the second conditon : if velocity==-1 :

If velocity is not set ( set to max ) , we cannot know if the servo had finished the move, because magic cannot do the job. There is defaut autoDisable thing set to 10 seconds. This is only "estimated" thing. Beter is to set a velocity. A moveToBlocking() is not accurate if velocity==-1.