Edbot

Support Template

Introduction

JavaScript is a cross-platform scripting language created by Brendan Eich in 1995. It is an interpreted programming language with object-oriented capabilities. Alongside HTML and CSS, JavaScript is one of the three core technologies of Web content. The code is usually embedded in a Web page to add interactivity and highly responsive interfaces.

It is important to note that JavaScript is distinct from Java. The two languages are completely different although some aspects look similar.

The Edbot JavaScript API is implemented as a JavaScript object. It allows a JavaScript program to control your Edbots.

This guide assumes you are familiar with writing HTML Web pages containing JavaScript code. The API uses jQuery to simplify coding and you should have some familiarity with it: jQuery is a fast and concise JavaScript library created by John Resig in 2006 with the motto, "write less, do more".

Getting started

IDE setup

Download and install the JavaScript IDE (Integrated Development Environment) of your choice. For Windows choose from a fully integrated package such as Visual Studio or use an advanced text editor like Komodo or Notepad++. Linux (including Raspbian) also has a variety of IDEs available such as Bluefish and Geany.

Edbot Software

Make sure you have installed the latest version of the Edbot Software from the download page. For the purposes of this guide we'll assume you've set up your Edbot server and you're running it locally.

The Edbot Software will only run in server mode if you’ve set up at least one Edbot.

Folder structure

The JavaScript folder is part of the Edbot Software installation. In Windows the folder is located in the user's 'Documents' folder:

Documents\Edbot\javascript

Similarly for Linux:

Documents/Edbot/javascript

The folder should initially contain the following files:

base.css
edbot.js
jquery.js
leds.html
monitor.html
motions.html

The file edbot.js contains the EdbotClient class which implements the API. Several examples using the API are included:

  • leds.html selects the first Edbot and enables you to toggle the servo LEDs.

  • monitor.html displays the Edbot server status in real time.

  • motions.html queries the server for Edbots and available motions and enables you to run a motion.

The style sheet base.css gives the examples a coherent look and feel and jquery.js unsurprisingly contains the jQuery library.

You can save your own code in this folder to make it easy to develop and test.

The API makes use of AJAX to send requests to the Edbot server. As a result you must load the Web page using http. The local file protocol (file:///) will not work due to basic browser security.

For this purpose the Edbot Software runs a Web server locally. You can run the examples using the following link:

If you've changed the server port in the Edbot server setup, substitute your port in the link above.

Coding

The EdbotClient class implements the Edbot API in JavaScript. Make the class available using a <script> tag in the <head> section of your Web page. You’ll need to reference jQuery first:

<script src="jquery.js"></script>
<script src="edbot.js"></script>

Still in the <head> section, add your code in a <script> tag:

<script>
... your code ...
</script>

Firstly create an instance of the EdbotClient class. Specify the Edbot server running locally on the default port of 8080. The user parameter can be any string to identify your program to the server.

var ec = new EdbotClient("localhost", 8080, { user: "MyJavaScriptApp" });

Next connect to the Edbot server both to send commands and receive data updates. The data updates can occur at any time after connecting - they are asynchronous. However, JavaScript code runs in a single execution thread, unlike other languages like Java or Python. This problem is solved with the use of event callbacks: In essence you register a function to be called when a specific event occurs at which point program execution jumps to the function you registered. It then returns to the code before the event occurred. The Edbot JavaScript API uses this technique to handle data updates from the Edbot server.

Register your callbacks as part of the connect function. For more details consult the reference section.

ec.connect(
  {
    onopen: function(event) {
      // Not a great deal of use.
    },
    onmessage: function(event) {
      //
      // At this point we can be sure a connection has been made
      // to the Edbot server and data for each configured Edbot
      // has been received.
      //
      var data = ec.getData();

      // Do something.
    },
    onclose: function(event) {
      // The connection has been closed.
    }
  }
);

Commands

When you have successfully connected to the Edbot server you can send commands to your Edbot. For example to run a "bow 1" motion (with id of 5) on an Edbot called "Anna", use:

ec.runMotion("Anna", 5);

You can run built-in motions, control the speed and position of individual servos and much more using the API methods detailed in the reference section.

Queries

The call to getData() in the connect method above returns real time data as a JSON object. The JSON object gives access to lots of useful information you can use in your code. You can run the monitor example below to examine the current values, but note the colours and motions properties are not displayed to remove screen clutter. Here's what the values mean:

{
  "edbots": {                    // list of Edbots
    "Anna": {                    // name of the Edbot
      "type": "ERM161",          // the Edbot model
      "enabled": true,           // enabled?
      "connected": true,         // connected?
      "activeUser": "MyApp...",  // currently active user
      "reporters": {             (1)
         ...
      },
      "colours": {               // servo LED colours and their indices
        "red": 1,
        "green": 2,
        ...
      },
      "motions": {               // list of motion groups - first is "All"
        "All" : [                // array of motion names and their indices
          {
            "id": 5,
            "name": "bow 1"
          },
          ...
        ],
        ...
      }
    }
  },
  "auth": "...",                 // private session token
  "user": "MyApp...",            // session user (me!)
  "users": [                     // array of connected users
    "Scratch...",
    "MyApp..."
  ]
}
1 The reporter object or null if not connected.

Reporters

The reporter properties provide real time data from the Edbot microcontroller. If a motion is running, the motion_running property is set to true. Similarly if the Edbot is speaking, the speaking property is set to true. For example:

"reporters": {
  "motion-running": true,
  "speaking": false,
  ...
}

Data is available from the IR distance sensor property sensor-01. The distance sensor is mounted on the Edbot's head and measures the distance in centimetres to an object in front of the Edbot up to approximately 45cm away. The sensor was calibrated using the distance between the front edge of the feet and a vertical white A4 card. Note the sensor may give different measurements for different coloured objects placed the same distance away. The reading should be interpreted as an approximate distance. The value is constantly updated to 1 decimal place, but is NOT updated whilst a built-in motion is running. For example,

"reporters": {
  "sensor-01": 23.5,
  ...
}

The sensor data may have been disabled with a call to setOptions, for example during motion capture. In this mode, the value returned will be null.

Each servo has a property name beginning with servo- followed by a zero-padded 2 digit servo id. In default mode the servo data consists of the following properties:

  • The current position property in degrees to 1 decimal place.

  • The aligning property is true if the servo is in the process of moving after a call to setPosition.

  • The torque property is set to true if the servo is on.

  • The extended property is set to null. Servo data is NOT updated whilst a built-in motion is running.

For example:

"reporters": {
  "servo-01": {
    "position": 150.0,
    "aligning": false,
    "torque": false,
    "extended": null
  },
  "servo-02": {
    "position": 150.0,
    "aligning": false,
    "torque": false,
    "extended": null
  },
  ...
}

In extended servo mode, extra information is returned in the extended property:

  • The servo speed and load properties as a percentage to 1 decimal place. For both properties, a positive value means CCW rotation and a negative value means CW rotation.

  • The servo voltage property is returned to 1 decimal place. This value can be used to detect low batteries.

  • The pid property reports the PID gain values as a colon separated list in the format P:I:D.

Here's an example:

"reporters": {
  "servo-01": {
    "position": 150.0,
    "aligning": false,
    "torque": false,
    "extended": {
      "speed": 10.0,
      "load": 5.0,
      "voltage": 7.4,
      "pid": "32:0:0"
    }
  },
  "servo-02": {
    "position": 150.0,
    "aligning": false,
    "torque": false,
    "extended": {
      "speed": 10.0,
      "load": 8.0,
      "voltage": 7.3,
      "pid": "32:0:0"
    }
  },
  ...
}

Examples

Read through the following examples to gain an understanding of how to use the API. The reference section details the API methods with their parameters and return values.

Monitor

We'll begin by stepping through the monitor example.

<html lang="en">
<head>
<meta charset="utf-8">
<title>Edbot Monitor</title>
<link rel="stylesheet" href="base.css">
<script src="jquery.js"></script> (1)
<script src="edbot.js"></script> (2)
<script>
var ec = null;
$(document).ready(
  function() {
    // Make sure we are loading the page with http.
    if(!location.protocol.startsWith("http")) {
      $(".nohttp").show();
      return;
    } else {
      $(".container").show();
    }

    // Grab the port from the URL, defaulting to 8080.
    var port = location.port || 8080;

    // Create a new EdbotClient instance and connect.
    ec = new EdbotClient("localhost", port, { user: "Monitor" }); (3)
    connect();
  }
);
function connect() {
  ec.connect( (4)
    {
      onmessage: function(event) { (5)
        //
        // At this point we can be sure a connection has been made
        // to the Edbot server and data for each configured Edbot
        // has been received.
        //
        var data = ec.getData();
        var edbots = data.edbots;
        for(var name in edbots) {
          // Remove the motion & colour data - it clogs the screen!
          delete edbots[name].motions; (6)
          delete edbots[name].colours;

          // Sort reporters by key.
          if(edbots[name].reporters) {
            var reporters = {};
            Object.keys(edbots[name].reporters).sort().forEach(
              function(key) {
                reporters[key] = edbots[name].reporters[key];
              }
            );
            edbots[name].reporters = reporters;
          }
        }

        // Update the textarea.
        $("#reporter").val(JSON.stringify(data, null, 4));
      },
      onclose: function(event) { (7)
        // Server connection has gone away - clean up.
        $("#reporter").val("");
        connect();      // attempt to reconnect
      }
    }
  );
}
</script>
</head>

<body>
<div class="nohttp">
  <p>You must load this Web page using HTTP.
  Run the Edbot Software and use the following link:
  <p><a href="http://localhost:8080/coding/javascript/monitor.html">
  http://localhost:8080/coding/javascript/monitor.html
  </a>
  <p>If you've changed the server port in the Edbot server setup,
  substitute your port in the link above.
</div>
<div class="container">
  <textarea id="reporter" readonly="true"></textarea>
</div>
</body>
</html>
1 The Edbot JavaScript API uses jQuery. This should be included first.
2 The EdbotClient class implements the Edbot API.
3 Create a new EdbotClient instance.
4 Call the EdbotClient connect method to connect to the Edbot server.
5 At this point we can be sure data for each configured Edbot has been received.
6 Remove motion and colour data so as not to clutter the screen. Comment out if required.
7 Register an onclose callback to handle a closed connection.

You can try this example by clicking on the link below:

If you've changed the server port in the Edbot server setup, substitute your port in the link above.

LED toggler

The next example demonstrates how to control the servo LEDs. Here's the basic HTML markup:

<html lang="en">
<head>
<meta charset="utf-8">
<title>Edbot LED Toggler</title>
<link rel="stylesheet" href="base.css">
<script src="jquery.js"></script> (1)
<script src="edbot.js"></script> (2)
<script>
... (3)
</script>
</head>

<body>
<div class="nohttp">
  <p>You must load this Web page using HTTP.
  Run the Edbot Software and use the following link:
  <p><a href="http://localhost:8080/coding/javascript/leds.html">
  http://localhost:8080/coding/javascript/leds.html
  </a>
  <p>If you've changed the server port in the Edbot server setup,
  substitute your port in the link above.
</div>
<div class="container">
  <img id="ris" src="/images/ris.png">
  <hr>
  <div class="info">
    <p>Switch the servo LEDs on or off. This script uses the Edbot
    JavaScript API to connect to an Edbot server running locally
    and selects the first Edbot.
    <p>To try this example, first use the Edbot Software to set the
    "LED Toggler" script as the active user.
    <p>Toggle LEDs:
    <button id="on">on</button> <button id="off">off</button>
  </div>
  <textarea id="log" readonly="readonly" placeholder="Log messages..."></textarea>
</div>
</body>
</html>
1 The jQuery library needs to be included first.
2 Include the Edbot JavaScript API.
3 We'll add JavaScript code here to turn the Edbot servo lights on and off.

The code is listed below with annotations:

var ec = null;
var initialised = false;
$(document).ready(
  function() {
    // Make sure we are loading the page with http.
    if(!location.protocol.startsWith("http")) {
      $(".nohttp").show();
      return;
    } else {
      $(".container").show();
    }

    // Grab the port from the URL, defaulting to 8080.
    var port = location.port || 8080;

    // Create a new EdbotClient instance and connect.
    ec = new EdbotClient("localhost", port, { user: "LED Toggler" }); (1)
    connect();
  }
);
function connect() {
  ec.connect(
    {
      onopen: function(event) {
        log("Connected to Edbot server " + ec.getServer() + ":" + ec.getPort());
      },
      onmessage: function(event) { (2)
        //
        // At this point we can be sure a connection has been made
        // to the Edbot server and data for each configured Edbot
        // has been received.
        //
        if(!initialised) {
          var names = ec.getEdbotNames().sort(); (3)
          name = names[0];
          log("Using first Edbot: " + name);
          $("#on").click(
            function() {
              ec.setServoLED(name, "0/3", onsent, { cmd: "on"}); (4)
            }
          );
          $("#off").click(
            function() {
              ec.setServoLED(name, "0/0", onsent, { cmd: "off"}); (5)
            }
          );
          initialised = true;
        }
      },
      onclose: function(event) { (6)
        initialised = false;
        connect();      // attempt to reconnect
      },
      onerror: function(event) {
        log("Failed to connect to Edbot server");
      }
    }
  );
}
function onsent(response, osd) { (7)
  if(!response.status.success) {
    log(response.status.message);
  } else {
    log("Turning LEDs " + osd.cmd);
  }
}
function log(str){ (8)
  var now = new Date();
  var date = now.toLocaleDateString();
  var time = now.toLocaleTimeString();
  $("#log").append(date + " " + time + ": " + str + "\n");
  $("#log").scrollTop($("#log")[0].scrollHeight);
}
1 Create a new EdbotClient instance and call the connect method.
2 At this point we can be sure data for each configured Edbot has been received.
3 Retrieve the available Edbot names, sort them and choose the first one.
4 When the "on" button is pressed, set all LEDs to colour index 3.
5 When the "off" button is pressed, turn the LEDs off.
6 Handle closed connections gracefully.
7 This callback is triggered when the request has been sent to the Edbot server.
8 We'll log messages to a textarea on the page.

You can try this example by clicking on the link below:

If you've changed the server port in the Edbot server setup, substitute your port in the link above.

Motions

The final example queries the server and presents the Edbots and motions in dropdown menus. Select a motion and run it! The status of each Edbot is displayed in real time. Here's the basic HTML markup:

<html lang="en">
<head>
<meta charset="utf-8">
<title>Edbot Motions</title>
<link rel="stylesheet" href="base.css">
<script src="jquery.js"></script> (1)
<script src="edbot.js"></script> (2)
<script>
... (3)
</script>
</head>

<body>
<div class="nohttp">
  <p>You must load this Web page using HTTP.
  Run the Edbot Software and use the following link:
  <p><a href="http://localhost:8080/coding/javascript/motions.html">
  http://localhost:8080/coding/javascript/motions.html
  </a>
  <p>If you've changed the server port in the Edbot server setup,
  substitute your port in the link above.
</div>
<div class="container">
  <img id="ris" src="/images/ris.png">
  <hr>
  <div class="info">
    <p>Run a motion! This script uses the Edbot JavaScript API to connect to
    an Edbot server running locally. It retrieves the Edbots, displays them in
    a menu and then dynamically builds a second menu to display the motions
    for the selected Edbot.
    <p>To try this example, first use the Edbot Software to set the "Motions"
    script as the active user. Then choose a motion and press Run...
  </div>
  <table class="motion">
    <tr>
      <td class="label">Edbot:</td>
      <td><select id="edbots_menu"></select></td> (4)
    </tr>
    <tr>
      <td class="label">Motion:</td>
      <td><select id="motions_menu"></select></td> (5)
    </tr>
    <tr>
      <td></td>
      <td><button id="run_button">Run</button></td>
    </tr>
  </table>
  <hr>
  <div class="info">
    <p>Here we use the Edbot JavaScript API to display the current status of
    each Edbot in real time.
    <table id="status_table"> (6)
      <tr class="status_header">
        <td class="status_name">Edbot</td>
        <td class="status_active_user">Active User</td>
        <td class="status_enabled">Enabled</td>
        <td class="status_connected">Connected</td>
      </tr>
    </table>
  </div>
  <textarea id="log" readonly="readonly" placeholder="Log messages..."></textarea>
</div>
</body>
</html>
1 The Edbot JavaScript API uses jQuery. This should be included first.
2 The EdbotClient class implements the Edbot API.
3 We'll add the JavaScript code here.
4 The edbot menu populated using JavaScript.
5 The motion menu populated using JavaScript.
6 This table will display the status of each Edbot.

The code is listed below with annotations:

var ec = null;
var initialised = false;
$(document).ready(
  function() {
    // Make sure we are loading the page with http.
    if(!location.protocol.startsWith("http")) {
      $(".nohttp").show();
      return;
    } else {
      $(".container").show();
    }

    // Grab the port from the URL, defaulting to 8080.
    var port = location.port || 8080;

    // Create a new EdbotClient instance and connect.
    ec = new EdbotClient("localhost", port, { user: "Motions" }); (1)
    connect();
  }
);
function connect() {
  ec.connect(
    {
      onopen: function(event) {
        log("Connected to Edbot server " + ec.getServer() + ":" + ec.getPort());
      },
      onmessage: function(event) { (2)
        //
        // At this point we can be sure a connection has been made
        // to the Edbot server and data for each configured Edbot
        // has been received.
        //
        if(!initialised) {
          var edbotsMenu = $("#edbots_menu");
          var motionsMenu = $("#motions_menu");
          var runButton = $("#run_button");

          // Populate the Edbots menu and select the first Edbot.
          $.each(ec.getEdbotNames().sort(), (3)
            function(index, name) {
              edbotsMenu.append($("<option/>").val(name).text(name));
            }
          );
          edbotsMenu.prop("selectedIndex", 0);

          //
          // Populate the motions menu based on the selected Edbot
          // and select "initial position (1)" as default.
          //
          edbotsMenu.change( (4)
            function() {
              motionsMenu.empty();
              var edbot = ec.getData().edbots[edbotsMenu.val()];
              if(edbot.motions == null) {
                // No motion support!
                motionsMenu.append(
                  $("<option/>").val(0).text("Motions not supported")
                );
                motionsMenu.prop("disabled", true);
                runButton.prop("disabled", true);
                return;
              }
              $.each(edbot.motions.All,
                function(index, motion) {
                  motionsMenu.append(
                    $("<option/>").val(motion.id).text(motion.name)
                  ).data(motion.id.toString(), motion.name);
                }
              );
              motionsMenu.prop("disabled", false).val(1);
              runButton.prop("disabled", false);
            }
          ).change();

          // Bind the run button.
          runButton.click( (5)
            function() {
              var name = edbotsMenu.val();
              var edbot = ec.getData().edbots[name];
              var motionId = motionsMenu.val()
              ec.say(name, $("#motions_menu").data(motionId.toString())); (6)
              ec.runMotion(name, motionId, onsent); (7)
            }
          );
          initialised = true;
        }

        // Update the status table.
        var names = Object.keys(ec.getData().edbots).sort(); (8)
        for(var i = 0; i < names.length; i++) {
          var name = names[i];
          var edbot = ec.getData().edbots[name];
          var statusTable = $("#status_table");

          // Do we have an existing table row for this Edbot?
          var row = $("#status_table td").filter(
            function() {
              return $(this).text() == name;
            }
          ).closest("tr");
          if(row.length == 0) {
            // Add a new row.
            row = $(".status_header").clone().attr("class", "status_row");
            row.find(".status_name").text(name);
            statusTable.append(row);
          }
          row.find(".status_active_user").text(edbot.activeUser);
          row.find(".status_enabled").text(edbot.enabled ? "True" : "False");
          row.find(".status_connected").text(edbot.connected ? "True" : "False");
        }
      },
      onclose: function(event) {
        $("#edbots_menu").find("option").remove();
        $("#motions_menu").find("option").remove();
        $("#status_table").find("tr:gt(0)").remove();
        initialised = false;
        connect();      // attempt to reconnect
      },
      onerror: function(event) {
        log("Failed to connect to Edbot server");
      }
    }
  );
}
function onsent(response) {
  if(!response.status.success) {
    // Warn if there is a problem with the Edbot API call.
    log(response.status.message);
  } else {
    log(
      $("#edbots_menu option:selected").text() + " is running motion " +
      $("#motions_menu option:selected").text()
    );
  }
}
function log(str){
  var now = new Date();
  var date = now.toLocaleDateString();
  var time = now.toLocaleTimeString();
  $("#log").append(date + " " + time + ": " + str + "\n");
  $("#log").scrollTop($("#log")[0].scrollHeight);
}
1 Create a new EdbotClient instance and call the connect method.
2 At this point we can be sure data for each configured Edbot has been received.
3 Build the edbots menu.
4 Build the motions menu for the selected edbot.
5 Bind the run button.
6 Say the motion name, if speech is configured.
7 Run that motion!
8 Display the status of the Edbots in real time.

You can try this example by clicking on the link below:

If you've changed the server port in the Edbot server setup, substitute your port in the link above.

Reference

EdbotClient

The EdbotClient class encapsulates the Edbot JavaScript API.

Constructor

Create a new instance by calling the constructor and assigning it to a variable.

new EdbotClient(server, port[, options])

Returns: A new EdbotClient instance.
Parameters:

server

string

The ip address or hostname of the Edbot server.

port

integer

The port number on which the server is running.

options

object

Optional properties:

user

string

User name on the Edbot server, default: "User".

client

string

Client type on the Edbot server, default: "JavaScript".

Methods

getServer

Get the server name or ip address.

getServer()

Returns: A string representing the server name or ip address.
Parameters: None.


getPort

Get the server port number.

getPort()

Returns: The server port number.
Parameters: None.


connect

Open a connection to the Edbot server. This method establishes a Web Socket and registers event listeners to receive server messages in real time. The server will send status data and information about the configured Edbots. In addition an auth token is sent to your program. The subsequent API calls you make send this auth token behind the scenes as part of an HTTP request to identify your client to the server.

The Edbot Software will only run in server mode if you've set up at least one Edbot.

connect([options])

Returns: Void.
Parameters:

options

object

Optional properties:

onopen(event)

function

Callback fired after opening a connection to the Edbot server. Event is of type Event.

onmessage(event)

function

Callback fired when a message is received from the Edbot server. Event is of type MessageEvent. The message data is available in the event's data property.

onclose(event)

function

Callback fired when the connection is closed. Event is of type CloseEvent.

onerror(event)

function

Callback fired when an error occurs. Event is of type Event.


close

Close the connection to the Edbot server.

close()

Returns: Void.
Parameters: None.


getEdbotNames

Get an unsorted array containing the names of the Edbots on this server.

getEdbotNames()

Returns: The Edbot names as an array of strings.
Parameters: None.


getEdbot

Get an object representing an Edbot.

getEdbot(name)

Returns: An Edbot object with the following properties:

type

string

The Edbot model type.

enabled

boolean

True if the Edbot is enabled.

connected

boolean

True if the Edbot is connected via Bluetooth.

activeUser

string

The currently active user.

reporters

object

An object containing the reporters such as sensor values.

colours

object

The available servo LED colours. Each property has the colour name as a key and the colour index as a value.

motions

object

The available Edbot motions. The motion group name is used as a property key, with the corresponding value being an array of objects. Each object in the array has an id property and a name property which represent the motion id and name.

Parameters:

name

string

The name of the Edbot.


getData

Get an object containing the Edbot server data.

getData()

Returns: An object with the following properties:

edbots

object

The Edbots configured on the server. See the Edbot object above.

auth

string

A unique token allocated by the server used to identify this session.

user

string

The current user connection.

users

array

The users connected to the server.

Parameters: None.


activeUser

Returns true if the current user is active, otherwise false. The active user is set by the Edbot server and has control of the Edbot.

activeUser(name)

Returns: A boolean value.
Parameters:

name

string

The name of the Edbot.

You can retrieve the name of the currently active user using:

getData().edbots[name].activeUser

runMotion

Run the motion referenced by the passed in motion id. Before the motion is run:

  • Servo LEDs are switched off - if the motion_leds option is set to the default on.

  • Servo speeds are set to 100%.

When the motion completes:

  • Servo LEDs are switched off - if the motion_leds option is set to the default on.

  • Servos remain switched on.

runMotion(name, motionId[, onsent][, osd])

Returns: Void.
Parameters:

name

string

The name of the Edbot.

motionId

integer

The motion number.

onsent(res, osd)

function

Callback fired when the request has been sent to the server. The res object contains a status property which is an object with properties success (boolean) and message (string).

osd

object

User data passed to the onsent callback.


setTorque

Switch servos on or off.

setTorque(name, path[, onsent][, osd])

Returns: Void.
Parameters:

name

string

The name of the Edbot.

path

string

A string formed by the servo number followed by "/" followed by 0 or 1 to turn the servo off or on respectively. Specify multiple servos by repeating the sequence, for example "1/0/2/0/3/1/4/1". Servo number 0 means all servos, so "0/0" will turn all servos off.

onsent(res, osd)

function

Callback fired when the request has been sent to the server. The res object contains a status property which is an object with properties success (boolean) and message (string).

osd

object

User data passed to the onsent callback.


setLED

Set the colours of the servo LEDs.

setLED(name, path[, onsent][, osd])

Returns: Void.
Parameters:

name

string

The name of the Edbot.

path

string

A string formed by the servo number followed by "/" followed by the servo colour index. The colour table is returned in the Edbot object. Specify multiple servos by repeating the sequence, for example "1/3/2/3/3/3/4/3". Servo number 0 means all servos, so "0/3" will set all servo LEDs to colour index 3.

onsent(res, osd)

function

Callback fired when the request has been sent to the server. The res object contains a status property which is an object with properties success (boolean) and message (string).

osd

object

User data passed to the onsent callback.


setSpeed

Set the servo speed.

setSpeed(name, path[, onsent][, osd])

Returns: Void.
Parameters:

name

string

The name of the Edbot.

path

string

A string formed by the servo number followed by "/" followed by the speed expressed as a percentage greater than zero. Specify multiple servos by repeating the sequence, for example "1/50/2/50/3/50/4/50". Servo number 0 means all servos, so "0/12.5" will set all servos to one eighth speed.

onsent(res, osd)

function

Callback fired when the request has been sent to the server. The res object contains a status property which is an object with properties success (boolean) and message (string).

osd

object

User data passed to the onsent callback.


setPosition

Set the servo position.

setPosition(name, path[, onsent][, osd])

Returns: Void.
Parameters:

name

string

The name of the Edbot.

path

string

A string formed by the servo number followed by "/" followed by the position which is an angle from 0 to 300 degrees. servo angle
Specify multiple servos by repeating the sequence, for example "1/250/2/50".

onsent(res, osd)

function

Callback fired when the request has been sent to the server. The res object contains a status property which is an object with properties success (boolean) and message (string).

osd

object

User data passed to the onsent callback.


setPID

Set the servo PID gain values. Edbot uses state-of-the-art Robotis XL-320 servos. These advanced servos feature PID controllers. A PID controller continuously calculates an error value as the difference between the goal position and the current position. It applies a correction based on proportional (P), integral (I), and derivative (D) terms which gives this type of controller its name. The proportional term is the easiest to understand: The servo applies an electrical current proportional to the error. The integral term increases in relation to the time the error has been present, as well as the size. The derivate term applies to the rate of change of error. For more information on PID controllers consult Wikipedia.

All 3 values should be between 0 and 254, the default PID is {32, 0, 0}.

setPID(name, path[, onsent][, osd])

Returns: Void.
Parameters:

name

string

The name of the Edbot.

path

string

A string formed by the servo number followed by "/", then three values each separated by "/" representing the required P gain, I gain and D gain values. Specify multiple servos by repeating the sequence, for example "1/32/0/0/2/32/0/0".

onsent(res, osd)

function

Callback fired when the request has been sent to the server. The res object contains a status property which is an object with properties success (boolean) and message (string).

osd

object

User data passed to the onsent callback.


setOptions

Set model specific options. These options are set to defaults when the Edbot is reset either by an explicit call to reset, or when the active user is changed on the Edbot server.

setOptions(name, path[, onsent][, osd])

Returns: Void.
Parameters:

name

string

The name of the Edbot.

path

string

A string formed by the option name followed by "/" followed by the option value. Specify multiple options by repeating the sequence. Edbot currently supports the following options:

motion_leds

integer

Specify 1 to turn on the motion LEDs (default) or 0 to switch them off.

sensor_data

integer

Specify 1 to enable sensor data (default) or 0 to disable.

ext_servo_data

integer

Specify 1 to enable extended servo data or 0 for standard servo data (default).

onsent(res, osd)

function

Callback fired when the request has been sent to the server. The res object contains a status property which is an object with properties success (boolean) and message (string).

osd

object

User data passed to the onsent callback.


say

Specify text for the Edbot to speak. This method assumes the Edbot has been configured with speech on the Edbot server. Unicode escapes are fully supported.

say(name, text[, onsent][, osd])

Returns: Void.
Parameters:

name

string

The name of the Edbot.

text

string

The text to speak.

onsent(res, osd)

function

Callback fired when the request has been sent to the server. The res object contains a status property which is an object with properties success (boolean) and message (string).

osd

object

User data passed to the onsent callback.


reset

Reset the Edbot. This will stop any current speech, stop any current motion, set servo defaults, reset options and empty the request queue.

The servo speed settings are not reset due to limitatons in the firmware.

reset(name[, onsent][, osd])

Returns: Void.
Parameters:

name

string

The name of the Edbot.

onsent(res, osd)

function

Callback fired when the request has been sent to the server. The res object contains a status property which is an object with properties success (boolean) and message (string).

osd

object

User data passed to the onsent callback.