Skip to main content Link Menu Expand (external link) Document Search Copy Copied

MLTK API


Kind: global class

new MLTK(TrainFunction, PlayFunction, [onConnect], [onDisconnect])

MLTK main class

Param Type Description
TrainFunction function The function used for the training
PlayFunction function The function used in play mode
[onConnect] function The function to be called after the boards connects
[onDisconnect] function The function to be called after the board disconnects

Example

let mltk;
function setup() {
 //inizialize the mltk object passing the two callback functions used fot training and play mode
 mltk = new Mltk( train, play );

 //add a button to initialize the connection
 mltk.createMLTKInterface();
};

function draw() {
}

function train() {
 //get the label of the class selected from the board
 let label = mltk.getActiveClass();
 //get some data from the board sensor and use it as training features
 let features = mltk.getMagnetometerData();
 mltk.addTrainingData( label, features );
}

function play() {
 //get the data you want to "classify"
 let features = mltk.getMagnetometerData();
 //pass the data to the function who does the classification, once done call the "gotResults" callback function
 mltk.classify( features, gotResults );
}

function gotResults( err, result ) {
 if ( err ) {
   console.log( err );
 } else {
   //take the name of the label identified and store it in the global variable activeClass
   activeClass = result.label;
   play();
 }
}

mltk.addTrainingData(label, features)

add some training data to a specific class

Kind: instance method of MLTK
Category: ML

Param Type Description
label String the label of the class to which associate training data
features Array the training data

Example

function train() {
   //get the label of the class selected from the board
   let label = mltk.getActiveClass();
   //get some data from the board sensor and use it as training features
   let features = mltk.getMagnetometerData();
   mltk.addTrainingData( label, features );
}

mltk.classify(features, callback)

Run a set of data trough the trained classifier and assess to which class the data belongs to

Kind: instance method of MLTK
Category: ML

Param Type Description
features Array the data to be classified data
callback function the function to invoke when the classification has produced some results

Example

//this function will be run in loop when you are in play mode
function play() {
   //get the data you want to "classify"
   let features = mltk.getMagnetometerData();
   //pass the data to the function who does the classification, once done call the "gotResults" callback function
   mltk.classify( features, gotResults );
 }

 function gotResults( err, result ) {
   if ( err ) {
     console.log( err );
   } else {
     //take the name of the label identified and store it in the global variable activeClass
     activeClass = result.label;
     play();
   }
 }

mltk.isConnected() ⇒ boolean

returns true if the mltk board is connected

Kind: instance method of MLTK
Returns: boolean - TRUE when MLTK board is connected
Category: MLTK BOARD API

mltk.isTrainModeActive() ⇒ boolean

returns true if the train/play switch on the mltk board is set to TRAIN

Kind: instance method of MLTK
Returns: boolean - TRUE when MLTK board is set to TRAIN
Category: MLTK BOARD API

mltk.isPlayModeActive() ⇒ boolean

returns true if the train/play switch on the mltk board is set to PLAY

Kind: instance method of MLTK
Returns: boolean - TRUE when MLTK board is set to PLAY
Category: MLTK BOARD API

mltk.isRecordButtonPressed() ⇒ boolean

returns true if the record button on the mltk board is pressed

Kind: instance method of MLTK
Returns: boolean - TRUE when train button is pressed
Category: MLTK BOARD API

mltk.getColorimeterData() ⇒ Array

Returns an array containing the colorimeter data.

Kind: instance method of MLTK
Returns: Array - [r,g,b] Array containing red green and blue value as measured from the MLTK onboard colorimeter
Category: MLTK BOARD API

mltk.getGyroscopeData() ⇒ Array

Returns an array containing the gyroscope data.

Kind: instance method of MLTK
Returns: Array - [Gx,Gy,Gz] Array containing the rotational velocity on the 3 axis as measured by the on board LSM9DS1 IMU
Category: MLTK BOARD API

mltk.getMagnetometerData() ⇒ Array

Returns an array containing the Magnetometer data.

Kind: instance method of MLTK
Returns: Array - [Gx,Gy,Gz] Array containing the measured magnetic field measured by the LSM9DS1 IMU
Category: MLTK BOARD API

mltk.getActiveClass() ⇒ Number

Returns the id of the selected class.

Kind: instance method of MLTK
Returns: Number - The number of the selected class (also shown with the on board led)
Category: MLTK BOARD API

mltk.setRGBLed(r, g, b)

Set the color of the rgb led on the Arduino BLE sense.

Kind: instance method of MLTK
Category: MLTK BOARD API

Param Type Description
r Number The value of the red component [0-255]
g Number The value of the green component [0-255]
b Number The value of the blue component [0-255]

mltk.setLedRing(index, r, g, b)

Set the color of the leds on the MLTK board.

Kind: instance method of MLTK
Category: MLTK BOARD API

Param Type Description
index Number The led we want to change color to [0-7]
r Number The value of the red component [0-255]
g Number The value of the green component [0-255]
b Number The value of the blue component [0-255]

mltk.updateStatusMsg(message)

Create the connect disconnect button and visualize the connection status

Kind: instance method of MLTK
Category: UI

Param Type Description
message String message to display in the MLTK interface return {void}

mltk.createControlInterface()

Create the connect disconnect button and visualize the connection status

Kind: instance method of MLTK
Category: UI
Example

mltk.createControlInterface();

mltk.createLiveDataView()

Visualizes the data from the sensors on the MLTK board.

Kind: instance method of MLTK
Category: UI

mltk.createTrainingDataView()

Visualize the data recorded in the 8 classes

Kind: instance method of MLTK
Category: UI