Community Blog Buy Now
Blog

Misty Community Forum

2019.12.17 - JavaScript API Changes: MoveHead, MoveHeadDegrees, & MoveHeadRadians

On 2019-12-17T07:00:00Z, Misty will receive a system update that may break certain implementations of the following JavaScript API methods:

  • misty.MoveHead()
  • misty.MoveHeadDegrees()
  • misty.MoveHeadRadians()

After this change, each of the methods listed above will have a new, optional argument – Duration – that can be used instead of Velocity to specify how long a given head movement should take.

For each method, the Duration parameter will be positioned between the Velocity and PrePause arguments. After Misty’s December 17 update, the system will expect the fourth value passed into these methods to be a value for Duration, instead of a value for PrePause.

These changes will bring the JavaScript methods for moving Misty’s head to parity with the MoveHead operation in Misty’s REST API.

These changes will break your skills if you use the PrePause and PostPause arguments when you call the methods listed above in your JavaScript skills. If you do not pass in a value for the PrePause and PostPause arguments when you call the listed methods, then you can safely ignore this change.


11/27 edit:

As an addendum to this notice, the team has decided to bring the misty.MoveHead() method to full parity with the MoveHead operation in Misty’s REST API by allowing the method to accept a Units parameter. You can use this parameter to specify whether Misty should interpret the values you pass in for pitch, roll, and yaw as degrees , position , or radians . If you do not specify a value, the command defaults to degrees . After 12/17, the syntax for misty.MoveHead() will be:

misty.MoveHead(double pitch, double roll, double yaw, [double velocity], [double duration], [string units], [int prePauseMs], [int postPauseMs]);

AaaHHH!! This morning early bird gets to redo his code!!! :wink:

I am not complaining, as I have been playing with this, and am so looking forward to having the additional lever Duration in the JavaScript API!

My plan in preparation for this change is to go through and comment all the code with the new updated methods, and then when my Misty gets the Dec 17 update, to go through and uncomment out these and delete old methods. Any new code between now and then will have both lines, with the new one commented out.

However, I happily expect that this is going to happen in the future as Misty learns more and more. If I operate with the principle that I never want my Skill Code to break, is there a way to accomplish this? My thought is to create a if(version old) then (use old MoveHead) else (use new MoveHead). Presently, I cannot figure out how to do this - is there a software version check?

This change will break some of the Misty sample and tutorial code. How is the Misty Team going to update tutorials? Is this a step change, where the code will just not work right, or can the code be made to run the correct command based on system software version?

Any insight is appreciated.

1 Like

Our goal is to give the community at least 30 days notice (or roughly two release cycles) before making changes like this so everyone has a chance to update their skills or refactor for backwards compatibility :slight_smile:

You can get Misty’s software and firmware version information with a call on the misty.GetDeviceInformation() method. You’d probably want to compare against the value of robotVersion. It’s not yet confirmed what the version number will be for the Dec 17 release (though will likely be 1.8.X.X).

Our goal is to update all the official sample code and tutorials hosted in the docs and on GitHub within 24 hours of a release, and the repos hosted in MistySampleSkills shortly thereafter. Fortunately, this change is relatively minor. I believe most of the calls on MoveHead in the code samples omit the prePause and postPause arguments, so shouldn’t require updating :slight_smile:

1 Like

Hi All,

I recommend for the best practice I’ve been using as below pseudo code example to avoid future releases that break the code and require fixing the code.

Old: MoveHead(pitch,roll,yaw,velocity)
New: MoveHead(pich,roll,yaw,velocity,duration=0)

The duration is set to 0 by default.
if(duration == 0) --> old way
else --> angular velocity will be calculated based on the (target - current degree) and given duration.
with the new way, the input velocity can be any number because it will be recalculated for the safe movement of Misty head based on the requested duration.

Suggesting rules:

  • Any new parameters will always be added to the right or with key=default value pair.
  • Don’t change the working API function name and rather add a new one if needed.

I hope this suggested solution will allow us to reuse the existing demo skills at any time. Otherwise, the incompatibilities in new release will cause a setback for those who are often provide to public many skill demos in the future. This can be a big impact for any entertainment or business events.

Thanks,

Phillip

1 Like

Hi @johnathan,

I have a question regarding to the duration implementation. Once the duration specified, will the MoveHead wait until the duration to complete before returning? For supporting the parallelism programming, I prefer to have it return while running a thread to complete the MoveHead task. At the same time, an event can be registered to monitor if the MoveHead task is done to proceed to a next step. Please let me know.

Thanks,

Phillip

Great question. My understanding is that the command will not wait for the duration to elapse before returning. If you invoke two MoveHead commands sequentially without pausing between, the second will take control of the neck motors before the first can complete.

As an example, when you run this snippet, Misty will receive all three commands, but you will only see the third command execute. (Note the null values for velocity, and the fourth duration argument as “time (in seconds)”.

misty.MoveHead(0, 0, 0, null, 1);
misty.MoveHead(-26, -41, -81, null, 1);
misty.MoveHead(35, 41, 81, null, 1);

To see each of these commands execute, you could use something like this (note the one second pause – the same as our value for duration – between each command):

misty.MoveHead(0, 0, 0, null, 1);
misty.Pause(1000);
misty.MoveHead(-26, -41, -81, null, 1);
misty.Pause(1000);
misty.MoveHead(35, 41, 81, null, 1);
misty.Pause(1000);

Or, like you suggested, you could register for ActuatorPosition event messages and use that information to trigger sequential movements :slight_smile:

Hi Johnathan, using the ActuatorPosition event messages would be the best for this case. That’s great, thanks.

Phillip

1 Like

Update:

In implementing this change, the team has decided to bring the misty.MoveHead() command up to full parity with the MoveHead operation in Misty’s REST API. This means that, in addition to adding an optional Duration parameter, the misty.MoveHead() method will also accept a Units parameter. You can use this parameter to specify whether Misty should interpret the values you pass in for pitch, roll, and yaw as degrees, position, or radians. If you do not specify a value, the command defaults to degrees.

After 12/17, the syntax for misty.MoveHead() will be:

misty.MoveHead(double pitch, double roll, double yaw, [double velocity], [double duration], [string units], [int prePauseMs], [int postPauseMs]);