EDUCATIONAL ROBOTICS

Introduction

Java is an object-oriented programming language developed by James Gosling and colleagues at Sun Microsystems in the early 1990s. The language syntax borrows heavily from C++ but has a simpler object model. Unlike conventional languages which are generally designed either to be compiled for a specific platform or interpreted from source code at runtime, Java is compiled to bytecode, which is then run by a platform-specific Java Virtual Machine (JVM). This promises write once, run anywhere code. The JVM provides a rich set of APIs to access the device’s hardware and services. For those areas not fully covered, such as Bluetooth, Java can be extended using the Java Native Interface (JNI). This framework enables Java to call native C++ code, although this will be at the expense of the 'write once, run anywhere' mantra.

It is important to note that Java is distinct from JavaScript. The two languages are completely different although parts of the syntax look similar.

The Edbot Mini Java API enables a Java program to control your Edbot Minis. It is implemented as a set of thread-safe Java classes in the com.robotsinschools.edbot.client package.

This guide assumes you are familiar with writing Java code.

Getting started

Java Development Kit

Unsurprisingly you’ll need to install the Java Development Kit (JDK). We recommend you use a free implementation of the OpenJDK such as Liberica JDK or AdoptOpenJDK. The java compiler is called javac and we’ll be running this from the command line to keep things simple. You can, of course, choose to use an integrated development environment (IDE).

Edbot Software

Make sure you are running the latest version of the Edbot Software available 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. If the Edbot Software is running remotely, you'll need to change the localhost references to the name of the remote server.

Folder structure

The Java examples folder is part of the Edbot Software installation. In Windows the folder is located in your 'Documents' folder:

Documents\Edbot\java

Similarly for macOS and Linux:

Documents/Edbot/java

The folder should initially include the following files and folders:

jar/
  commons-io.jar
  commons-lang3.jar
  edbot-client.jar
  websocket.jar
MiniExample1.java
MiniExample2.java

The jar folder contains the JAR files which implement the API. The main JAR is called edbot-client.jar and the other JAR files are dependencies. Several examples using the API are included:

  • MiniExample1.java demonstrates simple blocking calls to the API.

  • MiniExample2.java shows a non-blocking example, useful for GUI programs.

We'll compile and run these programs later. The next section steps through the API basics, so read on.

Time to code

Write your Java program using your preferred IDE or text editor.

Importing the package

First you'll need to import the edbot package into your program.

import com.robotsinschools.edbot.client.*;

Connecting

Next create an instance of the EdbotClient class. Without arguments, this will specify the Edbot server is running locally on the default port of 8080. You can use the API to connect to a remote Edbot server too, see the Reference section, but we'll stick to a server running locally for this guide.

EdbotClient ec = new EdbotClient("localhost", 8080);

Your program should only create one instance of the EdbotClient class.

Next connect to the Edbot server to send commands.

ec.connect();

To receive data updates from the Edbot server, you'll need to create a class which implements the EdbotClientHandler interface. You then pass an instance of this class to the connect method. The example code below does this using an anonymous class. For more details consult the Reference section.

ec.connect(
  new EdbotClientHandler() {
    public void handle(Json message) {
      // Called when a message is received from the Edbot server.
    }
  }
);

The Json object

The API makes heavy use of the Json class written by Borislav Iordanov. This is a lightweight Java JSON library with a very concise API. See mJson for more info. The mJson API documentation is an essential resource when coding.

Waiting until active

After connecting to the Edbot server, your program will need control of the robot. Grant control using the active user menu in the Edbot Software. See below.

edbotsw java

If you're developing solo, the Edbot Software provides a convenient per-robot option "Open access" in the Server → Setup → Configure window. This will allow any connection to control the robot. Check this option while developing so that you don't need to give control each time you test your program. To stop other network users inadvertently accessing the robot, uncheck the "Available on network" option.

Commands

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

ec.runMotion("Bob", 5);

You can run built-in motions, control the speed and position of individual servos and even get your Edbot Mini to speak using the API methods detailed in the Reference section.

Queries

A call to getData() will return 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 examine these values in real time using the Server → Monitor option in the Edbot Software. Here's what the values mean:

{
  "server": {                          # server information
      "version": "6.0.0.1661",
      "platform": "Windows 10, 10.0.17134.523, amd64"
  },
  "auth": "9TBvXvf9",                  # private session token
  "initComplete": true,                # true after connect() returns
  "robots": {
    "Bob": {                           # name of the robot
      "enabled": true,                 # enabled?
      "connected": true,               # Bluetooth connected?
      "reporters": {                   (1)
        ...
      },
      "activeUser": "Java...",         # currently active user
      "model": {                       # the robot model
          "name": "Edbot Mini",
          "type": "ERM162",
          "key": "mini"
      }
    }
  },
  "user": "Java <Clive@[192.168.1.24]:51144>",
  "users": [
    "Java <Clive@[192.168.1.24]:51144>",
    "Scratch 2.0 <Clive@[192.168.1.24]:0>",
  ]
}
1 The reporter object or null if not connected.

Reporters

The reporter properties provide real time data from the robot microcontroller.

Internal sensors

The Edbot Mini has 4 sensor ports and the supplied IRSS-10 distance sensor mounted on the head is plugged into port1. Some Minis have been customised with a DMS-80 distance sensor mounted on the chest connected to port2. You can obtain the raw value for a particular port from the following reporter properties:

"reporters": {
  "port1": 10,
  "port2": 350,
  "port3": 580,
  "port4": 22,
  ...
}

Use the rawToIRSS10Dist method to convert the raw value of the IRSS-10 to a distance in centimetres and the rawToDMS80Dist function to convert the raw value of the DMS-80.

The sensor data is enabled by default. To receive servo data, you'll need to disable sensor data with a call to setOptions(robot, "sensor_data/0"). In this mode, the sensor reporters will be null. Sensor data is NOT returned whilst a built-in motion is running.

Servo data

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 setServoPosition.

  • The torque property is set to true if the servo is on. A positive value means CCW rotation and a negative value means CW rotation.

  • The load property as a percentage to 1 decimal place.

  • The extended property is set to null.

For example:

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

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

  • The speed property as a percentage to 1 decimal place. A positive value means CCW rotation and a negative value means CW rotation.

  • The 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,
      "voltage": 7.4,
      "pid": "32:0:0"
    }
  },
  "servo-02": {
    "position": 150.0,
    "aligning": false,
    "torque": false,
    "extended": {
      "speed": 10.0,
      "voltage": 7.3,
      "pid": "32:0:0"
    }
  },
  ...
}

The servo data is disabled by default. In this mode, the servo reporters will be null. To receive servo data, you'll need to disable sensor data with a call to setOptions(robot, "sensor_data/0"). Sensor data is NOT updated whilst a built-in motion is running.

Current word

The speechCurrentWord reporter gives the current word as it is being spoken. The reporter is set to null when not speaking. It can be used to add visual emphasis during speech, such as flashing the servo lights on and off.

"reporters": {
  "speechCurrentWord": "Hello",
  ...
}

The current word reporter is only available on Windows and Mac platforms.

Examples

To build the examples, make sure you are in the Java examples folder and enter this command:

javac -cp "jar/*" *.java

After compilation you should see some class files in the folder. If you're on Windows, run the example by typing the appropriate line:

java -cp "jar/*;." MiniExample1
java -cp "jar/*;." MiniExample2

Similarly for macOS and Linux:

java -cp "jar/*:." MiniExample1
java -cp "jar/*:." MiniExample2

MiniExample1

Read through the first example. This program uses basic blocking calls to demonstrate simple use of the API.

Many of the API methods return a Json object which includes a return status and message. See the Reference section for the details.

import java.util.*;

import com.robotsinschools.edbot.client.*;

public class MiniExample1 {
  public static void main(String[] args) throws Exception {
    // Create an EdbotClient object.
    EdbotClient ec = new EdbotClient("localhost", 8080); (1)
    try {
      // Connect to the server.
      ec.connect(); (2)

      // Grab an unsorted list of available Edbot Minis.
      String[] names = ec.getRobotNames("mini"); (3)
      if(names.length > 0) {
        // Display info for each Edbot Mini.
        for(String name : names) {
          System.out.println(name + ": " + ec.getRobot(name) + "\n");
        }

        // Wait for control of the first Edbot Mini in the list.
        String name = names[0]; (4)
        System.out.println("Waiting for control of " + name);
        ec.waitUntilActive(name); (5)

        // Say "Hello world". Block until finished.
        System.out.println("Testing speech: " + ec.say(name, "Hello world")); (6)

        // Run motion 6 (bow 2) and block until complete.
        System.out.println("Running motion: " + ec.runMotion(name, 6)); (7)
      } else {
        System.out.println("No Edbot Minis configured");
      }
    } finally {
      // Disconnect from the server.
      ec.disconnect(); (8)
    }
  }
}
1 Create a new EdbotClient instance.
2 Call the connect method. Return when connection initialised.
3 Build a list of configured Edbot Minis.
4 Select the first Edbot Mini.
5 Wait for control of the Edbot Mini.
6 Say "Hello world" and block until complete.
7 Run motion 6 (Bow 2) and block until complete.
8 Disconnect.

MiniExample2

A more advanced example. We call a non-blocking version of the say() method after registering an event handler to flash the servo LEDs when the speech has completed.

import java.util.*;

import com.robotsinschools.util.*;
import com.robotsinschools.edbot.client.*;

public class MiniExample2 {
  private static final int SEQUENCE = 1001;

  public static void main(String[] args) throws Exception {
    // Create an EdbotClient object.
    EdbotClient ec = new EdbotClient("localhost", 8080); (1)
    try {
      // Connect to the server.
      ec.connect( (2)
        new EdbotClientHandler() {
          public void handle(Json message) {
            // Called when a message is received from the Edbot server.
            try {
              Map<String, Json> robotMap = message.at("robots").asJsonMap();
              for(String name : robotMap.keySet()) {
                Json robot = robotMap.get(name);
                String token = robot
                  .at("reporters")
                  .at("speechComplete")
                  .asString()
                ;
                if(token.endsWith(String.valueOf(SEQUENCE))) {
                  // Finished speaking.
                  System.out.println(name + " has finished speaking");

                  // Flash the servo LEDs.
                  ec.setServoLED(name, "0/4"); (7)
                  Thread.sleep(500);
                  ec.setServoLED(name, "0/0");
                }
              }
            } catch(Exception ignore) {}
          }
        }
      );

      // Grab an unsorted list of configured Edbot Minis.
      String[] names = ec.getRobotNames("mini"); (3)
      if(names.length > 0) {
        // Display info for each Edbot Mini.
        for(String name : names) {
          System.out.println(name + ": " + ec.getRobot(name) + "\n");
        }

        // Wait for control of the first Edbot Mini in the list.
        String name = names[0]; (4)
        System.out.println("Waiting for control of " + name);
        ec.waitUntilActive(name); (5)

        // Say "Hello world". Pass in a sequence number so we don't block.
        System.out.println(name + " is speaking");
        Json json = ec.say(name, "Hello world", SEQUENCE); (6)
        if(json.at("success").asBoolean()) {
          for(int i = 0; i < 5; i++) {
            System.out.println("Waiting... " + i);
            Thread.sleep(1000);
          }
        } else {
          System.out.println(json);
        }
      } else {
        System.out.println("No Edbot Minis configured");
      }
    } finally {
      // Disconnect from the server.
      ec.disconnect(); (8)
    }
  }
}
1 Create a new EdbotClient instance.
2 Call the connect() method. Return when connection initialised.
3 Build a list of configured Edbot Minis.
4 Select the first Edbot Mini.
5 Wait for control of the Edbot Mini.
6 The call to say() returns immediately.
7 Flash the servo LEDs when the speech has completed.
8 Disconnect.

Reference

The following classes are contained in the com.robotsinschools.edbot.client package.

EdbotClient

The EdbotClient class contains methods to obtain sensor values and control the robot’s servos and microcontroller.

Constructor

Create a new EdbotClient instance.

public EdbotClient()
public EdbotClient(String server)
public EdbotClient(String server, int port)
public EdbotClient(String server, int port, String client)

Parameters:

server

The ip address or hostname of the Edbot server (default="localhost").

port

The port number on which the server is running (default=8080).

client

Client description (default="Java").

Returns:

A new EdbotClient instance.


connect

Open a connection to the Edbot server.

public void connect()
public void connect(EdbotClientHandler handler)

Parameters:

handler

An instance of a class implementing the EdbotClientHandler interface.

Throws:

EdbotClientException

If already connected to the server.


getConnected

Check if this client instance is connected to the Edbot server.

public boolean getConnected()

Returns:

true if connected, otherwise false.


disconnect

Close the connection to the Edbot server. This method will initiate an orderly disconnection.

public void disconnect()

Throws:

EdbotClientException

If not connected to the server.


getRobotNames

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

public String[] getRobotNames()
public String[] getRobotNames(String model)

Parameters:

model

The model key to filter a specific type of robot. Currently defined keys are "mini", "dream" and "play".

Returns:

An array of robot names.

Throws:

EdbotClientException

If not connected to the server.


getRobot

Return the named robot as a Json object.

public Json getRobot(String name)

Parameters:

name

The name of the robot.

Returns:

A Json object with the following properties:

model

A Json object containing the robot model name, type and key.

enabled

true if the robot is enabled.

connected

true if the robot is connected via Bluetooth.

activeUser

The currently active user. null means open access.

reporters

A Json reporters object or null if not connected via Bluetooth.

Throws:

EdbotClientException

If not connected to the server.


getData

Return a Json object containing the Edbot server data.

public Json getData()

Returns:

A Json object with the following properties:

robots

A Json object representing the robots configured on the server. Each robot is keyed on name and its value is a Json robot object.

initComplete

If true the connection has finished initialising.

server

A Json object containing the server version and platform.

auth

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

user

The current user connection.

users

An Array of users connected to the server.

Throws:

EdbotClientException

If not connected to the server.


isActive

Does this connection have control of the robot?

public boolean isActive(String name)

Parameters:

name

The name of the robot.

Returns:

Returns true if the current user is active, otherwise false.

Throws:

EdbotClientException

If not connected to the server.

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

getRobot(name).at("activeUser").asString()

waitUntilActive

Wait for control of the robot. This will block the current thread. See Waiting until active.

public void waitUntilActive(String name)

Parameters:

name

The name of the robot.

Throws:

EdbotClientException

If not connected to the server.


getMotions

Get the motions for the given robot.

public Json getMotions(String name)

Parameters:

name

The name of the robot.

Returns:

A Json object with the following properties:

status

A Json object containing the boolean property success and string property message.

data

A Json object representing the available motions.

Throws:

EdbotClientException

If not connected to the server.

Motions are categorised and a specific motion can appear in more than one category. The motion category "All" will always be returned first. This example shows the first two categories to illustrate the returned data structure.

{
  "All": [
    { "id": 24, "name": "backward roll" },
    { "id": 5,  "name": "bow 1" },
    { "id": 6,  "name": "bow 2" },
    { "id": 40, "name": "break dance" },
    { "id": 41, "name": "break dance flip" },
    { "id": 3,  "name": "crouch" },
    { "id": 21, "name": "forward roll" },
    { "id": 42, "name": "gangnam" },
    { "id": 2,  "name": "get up" },
    { "id": 34, "name": "goalie block" },
    { "id": 35, "name": "goalie left" },
    { "id": 36, "name": "goalie right" },
    { "id": 37, "name": "goalie spread" },
    { "id": 38, "name": "head stand" },
    { "id": 1,  "name": "initial position" },
    { "id": 25, "name": "karate left 1" },
    { "id": 27, "name": "karate left 2" },
    { "id": 26, "name": "karate right 1" },
    { "id": 28, "name": "karate right 2" },
    { "id": 11, "name": "left hook" },
    { "id": 10, "name": "left jab" },
    { "id": 30, "name": "left kick" },
    { "id": 32, "name": "left side kick" },
    { "id": 12, "name": "left uppercut" },
    { "id": 14, "name": "left wave" },
    { "id": 29, "name": "push" },
    { "id": 23, "name": "push up" },
    { "id": 8,  "name": "right hook" },
    { "id": 7,  "name": "right jab" },
    { "id": 31, "name": "right kick" },
    { "id": 33, "name": "right side kick" },
    { "id": 9,  "name": "right uppercut" },
    { "id": 13, "name": "right wave" },
    { "id": 39, "name": "run forwards" },
    { "id": 18, "name": "sidestep left" },
    { "id": 17, "name": "sidestep right" },
    { "id": 22, "name": "sit up" },
    { "id": 4,  "name": "stand" },
    { "id": 16, "name": "turn left" },
    { "id": 15, "name": "turn right" },
    { "id": 20, "name": "walk backwards" },
    { "id": 19, "name": "walk forwards" }
  ],
  "Gym": [
    { "id": 24, "name": "backward roll" },
    { "id": 21, "name": "forward roll" },
    { "id": 38, "name": "head stand" },
    { "id": 23, "name": "push up" },
    { "id": 22, "name": "sit up" }
  ],
  ...
}

getDefaultMotions

Get the default motions for the given robot model.

public Json getDefaultMotions(String model)

Parameters:

model

Model key. Currently defined keys are "mini", "dream" and "play".

Returns:

A Json object with the following properties:

status

A Json object containing the boolean property success and string property message.

data

A Json object representing the available motions.

Throws:

EdbotClientException

If not connected to the server.


setServoTorque

Switch servos on or off.

public Json setServoTorque(String name, String path)

Parameters

name

The name of the robot.

path

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.

Returns:

A Json object with boolean property success and string property message.

Throws:

EdbotClientException

If not connected to the server.


setServoSpeed

Set the servo speed.

This function simultaneously sets the servo torque on to work around a firmware bug.

public Json setServoSpeed(String name, String path)

Parameters

name

The name of the robot.

path

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.

Returns:

A Json object with boolean property success and string property message.

Throws:

EdbotClientException

If not connected to the server.


setServoPosition

Set the servo position.

public Json setServoPosition(String name, String path)

Parameters:

name

The name of the robot.

path

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

Returns:

A Json object with boolean property success and string property message.

Throws:

EdbotClientException

If not connected to the server.


setServoLED

Set the colours of the servo LEDs.

public Json setServoLED(String name, String path)

Parameters:

name

The name of the robot.

path

A string formed by the servo number followed by "/" followed by the servo colour index. 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.

Returns:

A Json object with boolean property success and string property message.

Throws:

EdbotClientException

If not connected to the server.

The colour index value maps to a colour according to the following table:

0

Off

-

1

Red

2

Green

3

Yellow

4

Blue

5

Magenta

6

Cyan

7

White


setServoPID

Set the servo PID gain values. Edbot Mini 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}.

public Json setServoPID(String name, String path)

Parameters:

name

The name of the robot.

path

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".

Returns:

A Json object with boolean property success and string property message.

Throws:

EdbotClientException

If not connected to the server.


setCustom

This advanced method allows you to set a value in the microcontroller's control table.

public Json setCustom(String name, String path)

A description of the control table can be found at the following link:

As an example you can use this method to turn on the green LED on the controller using a path of "79/1/1".

Parameters:

name

The name of the robot.

path

A string formed by the control table address (0 - 65535) followed by a "/" followed by the size in bytes (1 or 2) followed by "/" followed by the option value to write (0 - 255 if 1 byte : 0 - 65535 if 2 bytes).

Returns:

A Json object with boolean property success and string property message.

Throws:

EdbotClientException

If not connected to the server.


setOptions

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

public Json setOptions(String name, String path)

Parameters:

name

The name of the robot.

path

A string formed by the option name followed by "/" followed by the option value. Specify multiple options by repeating the sequence. Edbot Mini 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) and disable servo data or 0 to disable sensor data and enable servo data.

ext_servo_data

integer

Specify 1 to enable extended servo data or 0 for standard servo data (default). This has no effect if servo data is disabled (see sensor_data above).

Returns:

A Json object with boolean property success and string property message.

Throws:

EdbotClientException

If not connected to the server.


runMotion

Run the motion referenced by the passed in motion id, starting from 1.

You can also use this method to issue special commands whilst a motion is running. Running motion 0 will stop the currently executing motion in its tracks. Motion -1 will instruct the current motion to run its exit unit, then stop. For more information on this advanced usage, see Motion index numbers.

The first method will block the current thread until the motion has completed. The second will return immediately and append the passed in sequence number to the "motionComplete" reporter when the motion has completed. See MiniExample2.

public Json runMotion(String name, int motion)
public Json runMotion(String name, int motion, int seq)

Parameters:

name

The name of the robot.

motion

The motion number.

seq

A sequence number.

Returns:

A Json object with boolean property success and string property message.

Throws:

EdbotClientException

If not connected to the server.

Before the motion is run:

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

  • Servo speeds are reset to 100%.

When the motion completes:

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

  • Servo PID controller values are reset to {32, 0, 0}.

  • Servos remain switched on.


say

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

The first method will block the current thread until the speech has completed. The second will return immediately and append the passed in sequence number to the "speechComplete" reporter when the speech has completed. See MiniExample2.

public Json say(String name, String text)
public Json say(String name, String text, int seq)

Parameters:

name

The name of the robot.

text

The text to speak.

Returns:

A Json object with boolean property success and string property message.

Throws:

EdbotClientException

If not connected to the server.


reset

Reset the Edbot Mini. This will stop any current speech, stop any current motion, switch off the servo LEDs, set defaults and empty the request queue.

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

public Json reset(String name)

Parameters:

name

The name of the robot.

Returns:

A Json object with boolean property success and string property message.

Throws:

EdbotClientException

If not connected to the server.


EdbotClientHandler

The EdbotClientHandler interface defines a single handle method. You can implement this interface in your own class and pass an instance to the connect method of the EdbotClient class. The handle method will then be called each time a message is received by the client. It will be passed a Json object representing the message.

public void handle(Json message)

Parameters:

message

The message received from the server.


EdbotClientException

The EdbotClientException class represents a chainable exception thrown by a number of the Edbot Mini Java API methods.

public EdbotClientException(String msg)
public EdbotClientException(Throwable t)
public EdbotClientException(String msg, Throwable t)

Parameters:

msg

The detail message.

t

The cause.


SensorUtils

The SensorUtils class contains static utility methods to convert raw sensor values to the approriate units.

rawToIRSS10Dist

Convert the raw value from the IRSS-10 IR sensor to centimetres. The measuring range is 3cm to 30cm.

public static double rawToIRSS10Dist(int raw)

Parameters:

raw

The raw sensor reading in the range 0 - 1023.

Returns:

Distance in centimetres rounded to 1 decimal place.

The method returns 100.0 if the raw value is 0 (out of range).

The sensor was calibrated using the distance between the front edge of the feet and a vertical white A4 card. The card was held a known distance from the sensor and the raw sensor value was noted. This was repeated for different distances. A non-linear power curve was then used to fit the data points. Note the sensor readings will differ for different coloured objects placed the same distance away.


rawToDMS80Dist

Convert the raw value from the DMS-80 IR sensor to centimetres. The measuring range is 8cm to 80cm.

edbot.rawToDMS80Dist(raw)

Parameters:

raw

integer

The raw sensor reading in the range 0 - 1023.

Returns:

Distance in centimetres rounded to 1 decimal place.

The function returns 100.0 if the raw value is 0 (out of range).

The sensor was calibrated using the distance between the front edge of the feet and a vertical white A4 card. The card was held a known distance from the sensor and the raw sensor value was noted. This was repeated for different distances. A non-linear power curve was then used to fit the data points.