Thumbnail

Servo Script

How To Add This Control To Your Project

  1. Make sure you have the latest version of EZ-Builder installed.
  2. Select the Install button below to download the archive file.
  3. Double click the downloaded archive file to execute installer.
  4. The installer will add this control to EZ-Builder.
  5. Load EZ-Builder and press the Project -> Add Control button from the menu.
  6. Choose the Scripting category tab.
  7. Press the Servo Script icon to add the control to your project.

Bind a script to servo position movements. This allows you to create scripts that run each time a servo is moved. A good use-case for this is to control a Serial Bus style servo as a real servo by binding to a specific servo port. Meaning, if you had a servo that worked via Serial UART and wanted it to operate like a regular ARC servo, you could write code here to bind to it. 

The alternative method to this would be creating your own behavior control that binds to the servo movement event. This is covered in the Getting Started guide for Technology Creators. However, since creating a plugin control isn't viable for a quick hack to get something working, you may use this plugin control.

Get Started With servo Script
1) Identify the command structure or protocol for your custom servo

2) Press the GEAR configuration icon on this control

3) Specify what Board # it will be (0 is default)

4) Specify what servos to monitor for position (i.e. v1, v2, v3, v4, etc)

5) Edit the script that will run for every servo position that matches the selected ports you have binded to. The example code contains fake data of Position, Port & speed. You will want to use that fake data for testing within the editor. However, you will want to comment out the "test" variables before using your scripts with real data.

The test data merely simulates what would be expected when the program runs on each servo movement. For example, the test data includes...

Code:


var positions = [90, 90, 90];
var ports = [v1, v2, v3];
var speeds = [0, 0, 0];


In the real data, these variables would contain matching array lengths relevant to the requested servo movement. A servo on V1 may be requested to move, and you have binded to V1, so ports would contain v1. etc...


The Example Script
When you create a new row for binding to a servo movement, a default script is created. Here is a preview of what you have to work with.

Code:


// These variables are created for testing only.
// Comment these variables out when you're ready to test with real data.
// The real data will be dynamically created based on the servos, positions and speed.
// If you keep these uncommented during real data tests, the real data will never be
// used.
//
// For testing, you will want to add your ports and some fake values.


// Fake values here. Comment these out after editing...
var positions = [90, 90, 90];
var ports = [v1, v2, v3];
var speeds = [0, 0, 0];


// Loop through the ports, positions and their speeds
for (var i = 0; i < ports.length; i++) {

var position = positions;
var port = ports;
var speed = speeds;

// Do something with the position, port and speed

// This is for debugging. Comment out when everything is working
print("servo: " + port + " to " + position);

}