TJBot

TJBot

Class representing a TJBot

Constructor

new TJBot(configuration, credentialsFileopt) → {TJBot}

TJBot constructor. After constructing a TJBot instance, call initialize() to configure its hardware.

Parameters:
Name Type Attributes Description
configuration object

Configuration for the TJBot. See TJBot.DEFAULT_CONFIG for all configuration options.

credentialsFile string <optional>

(optional) Path to the 'ibm-credentials.env' file containing authentication credentials for IBM Watson services.

Source:

Members

(readonly) VERSION

TJBot library version

Source:

(readonly) CAPABILITIES :string

TJBot capabilities

Source:

(readonly) HARDWARE :string

TJBot hardware

Source:

(readonly) SERVICES :string

TJBot Watson services

Source:

(readonly) LANGUAGES :string

TJBot languages for listening, speaking, and seeing

Source:

(readonly) GENDERS :string

TJBot genders, used to pick a voice when speaking

Source:

(readonly) SERVO :int

TJBot servo motor stop positions

Source:

(readonly) DEFAULT_CONFIG

TJBot default configuration

Source:

Methods

(async) initialize(hardware)

Parameters:
Name Type Description
hardware array

List of hardware peripherals attached to TJBot.

Source:
See:
  • #TJBot+HARDWARE for a list of supported hardware.

(private) _setupCamera()

Configure the camera hardware.

Source:

(private) _setupLEDNeopixel(gpioPin)

Configure the Neopixel LED hardware.

Parameters:
Name Type Description
gpioPin int

The GPIO pin number to which the LED is connected.

Source:

(private) _setupLEDCommonAnode(redPin, greenPin, bluePin)

Configure the common anode RGB LED hardware.

Parameters:
Name Type Description
redPin int

The pin number to which the led red pin is connected.

greenPin int

The pin number to which the led green pin is connected.

bluePin int

The pin number to which the led blue pin is connected.

Source:

(private) _setupMicrophone()

Configure the microphone for speech recognition.

Source:

(private) _setupServo(pin)

Configure the servo module for the given pin number.

Parameters:
Name Type Description
pin int

The pin number to which the servo is connected.

Source:

(private) _setupSpeaker()

Configure the speaker.

Source:

(private) _createServiceAPI(service, version)

Instantiate the specified Watson service.

Parameters:
Name Type Description
service string

The name of the service. Valid names are defined in TJBot.services.

version string

The version of the service (e.g. "2018-09-20"). If null, the default version will be used.

Source:

(private) _assertCapability(capability)

Assert that TJBot is able to perform a specified capability. Instantiates Watson services as needed.

Parameters:
Name Type Description
capability string

The capability assert (see TJBot.prototype.capabilities).

Source:

(static) sleep(msec)

Put TJBot to sleep.

Parameters:
Name Type Description
msec int

Number of milliseconds to sleep for (1000 msec == 1 sec).

Source:

(async) analyzeTone(text) → {object}

Analyze the tone of the given text.

Parameters:
Name Type Description
text string

The text to analyze.

Source:
See:
  • Tone Analyzer documentation provides details on the response object.
Example
response = {
    "document_tone": {
        "tones": [{
                "score": 0.6165,
                "tone_id": "sadness",
                "tone_name": "Sadness"
            },
            {
                "score": 0.829888,
                "tone_id": "analytical",
                "tone_name": "Analytical"
            }
        ]
    },
    "sentences_tone": [{
            "sentence_id": 0,
            "text": "Team, I know that times are tough!",
            "tones": [{
                "score": 0.801827,
                "tone_id": "analytical",
                "tone_name": "Analytical"
            }]
        },
        {
            "sentence_id": 1,
            "text": "Product sales have been disappointing for the past three quarters.",
            "tones": [{
                    "score": 0.771241,
                    "tone_id": "sadness",
                    "tone_name": "Sadness"
                },
                {
                    "score": 0.687768,
                    "tone_id": "analytical",
                    "tone_name": "Analytical"
                }
            ]
        },
        {
            "sentence_id": 2,
            "text": "We have a competitive product, but we need to do a better job of selling it!",
            "tones": [{
                "score": 0.506763,
                "tone_id": "analytical",
                "tone_name": "Analytical"
            }]
        }
    ]
}

(async) converse(message) → {object}

Take a conversational turn in the conversation.

Parameters:
Name Type Description
message string

The message to send to the Assistant service.

Source:
See:
  • Assistant documentation provides details on the response object.
Example
response = {
    "object": {conversation response object},
    "description": "hello, how are you"
}

(async) listen()

Listen for a spoken utterance.

Source:

(private) _pauseListening()

Internal method for pausing listening, used when we want to play a sound but we don't want to assert the 'listen' capability.

Source:

(private) _resumeListening()

Internal method for resuming listening, used when we want to play a sound but we don't want to assert the 'listen' capability.

Source:

(async) see(classifierIdsopt) → {object}

Take a picture and identify the objects present.

Parameters:
Name Type Attributes Description
classifierIds array <optional>

(optional) List of classifier IDs to use in the Visual Recognition service.

Source:
See:
  • Visual Recognition documentation provides details on the response object. The response object returned by see() corresponds to response.images[0].classifiers[0].classes from Visual Recognition.

Example
response = {
    "images": [{
        "classifiers": [{
            "classifier_id": "roundPlusBanana_1758279329",
            "name": "roundPlusBanana",
            "classes": [{
                    "class": "fruit",
                    "score": 0.788
                },
                {
                    "class": "olive color",
                    "score": 0.973
                },
                {
                    "class": "lemon yellow color",
                    "score": 0.789
                }
            ]
        }],
        "image": "fruitbowl.jpg"
    }],
    "images_processed": 1,
    "custom_classes": 6
}

(async) recognizeObjectsInPhoto(filePath, classifierIdsopt) → {object}

Recognize objects in a given photo.

Parameters:
Name Type Attributes Description
filePath string

Path to the photo file.

classifierIds array <optional>

(optional) List of classifier IDs to use in the Visual Recognition service.

Source:
See:
  • Visual Recognition documentation provides details on the response object. The response object returned by see() corresponds to response.images[0].classifiers[0].classes from Visual Recognition.

(async) takePhoto(filePathopt) → {string}

Capture an image and save it in the given path.

Parameters:
Name Type Attributes Description
filePath string <optional>

(optional) Path at which to save the photo file. If not specified, photo will be saved in a temp location.

Source:

(async, private) _takePhoto(filePathopt) → {string}

Internal method to capture an image at the given path. Used to avoid triggering the check for an apikey for Watson Visual Recognition in _assertCapability() during testing.

Parameters:
Name Type Attributes Description
filePath string <optional>

(optional) Path at which to save the photo file. If not specified, photo will be saved in a temp location.

Source:

shine(color)

Change the color of the LED.

Parameters:
Name Type Description
color string

The color to shine the LED. May be specified in a number of formats, including: hexadecimal, (e.g. "0xF12AC4", "11FF22", "#AABB24"), "on", "off", "random", or may be a named color in the colornames package. Hexadecimal colors follow an #RRGGBB format.

Source:
See:

(async) pulse(color, durationopt)

Pulse the LED a single time.

Parameters:
Name Type Attributes Default Description
color string

The color to shine the LED. May be specified in a number of formats, including: hexadecimal, (e.g. "0xF12AC4", "11FF22", "#AABB24"), "on", "off", "random", or may be a named color in the colornames package. Hexadecimal colors follow an #RRGGBB format.

duration float <optional>
1

The duration the pulse should last. The duration should be in the range [0.5, 2.0] seconds.

Source:
See:

shineColors() → {array}

Get the list of all colors recognized by TJBot.

Source:

randomColor() → {string}

Get a random color.

Source:

(private) _normalizeColor(color) → {string}

Normalize the given color to #RRGGBB.

Parameters:
Name Type Description
color string

The color to shine the LED. May be specified in a number of formats, including: hexadecimal, (e.g. "0xF12AC4", "11FF22", "#AABB24"), "on", "off", "random", or may be a named color in the colornames package. Hexadecimal colors follow an #RRGGBB format.

Source:

(private) _convertHexToRgbColor(hexColor) → {array}

Convert hex color code to RGB value.

Parameters:
Name Type Description
hexColor string

Hex color code

Source:

(private) _renderCommonAnodeLed(hexColor)

Render the given rgb color for the common anode led.

Parameters:
Name Type Description
hexColor string

Color in hex format

Source:

(async) speak(message)

Speak a message.

Parameters:
Name Type Description
message string

The message to speak.

Source:

(async) play(soundFile)

Play a sound at the specified path.

Parameters:
Name Type Description
soundFile string

The path to the sound file to be played.

Source:

(async) translate(text, sourceLanguage, targetLanguage) → {object}

Translates the given text from the source language to the target language.

Parameters:
Name Type Description
text string

The text to translate.

sourceLanguage string

The source language (e.g. "en" for English).

targetLanguage string

The target language (e.g. "es" for Spanish).

Source:
See:
  • Use #TJBot+isTranslatable to determine whether lanuage can be translated from the `sourceLanguage` to `targetLanguage`.
  • Language Translator documentation provides details on the response object.
Example
response = {
    "object": {
        "translations": [{
            "translation": "Hola, mi nombre es TJBot!"
        }],
        "word_count": 7,
        "character_count": 25
     },
    "description": "Hola, mi nombre es TJBot!"
}

(async) identifyLanguage(text) → {object}

Identifies the language of the given text.

Parameters:
Name Type Description
text string

The text to identify.

Source:
See:
Example
response = {
    "languages": [{
            "language": "en",
            "confidence": 0.9804833843796723
        },
        {
            "language": "nn",
            "confidence": 0.005988721319786277
        },
        {
            "language": "sq",
            "confidence": 0.0036927759389060203
        },
        {
            "language": "nb",
            "confidence": 0.0035802051870239037
        }
    ]
}

(async) isTranslatable(sourceLanguage, targetLanguage) → {bool}

Determines if TJBot can translate from the source language to the target language.

Parameters:
Name Type Description
sourceLanguage string

The source language (e.g. "en" for English).

targetLanguage string

The target language (e.g. "es" for Spanish).

Source:

(async) translatableLanguages(sourceLanguage) → {array}

Returns a list of languages that can TJBot can translate to from the given language.

Parameters:
Name Type Description
sourceLanguage string

The source language (e.g. "en" for English)

Source:

languageForCode(languageCode) → {string}

Returns the name of the given language code.

Parameters:
Name Type Description
languageCode string

Two-character language code (e.g. "en")

Source:

codeForLanguage(language) → {string}

Returns the two-letter code for the given language.

Parameters:
Name Type Description
language string

Name of the language (e.g. "English")

Source:

(async, private) _loadLanguageTranslationModels()

Loads the list of language models that can be used for translation.

Source:

armBack()

Moves TJBot's arm all the way back. If this method doesn't move the arm all the way back, the servo motor stop point defined in TJBot.SERVO.ARM_BACK may need to be overridden. Valid servo values are in the range [500, 2300].

Source:
Example
tj.armBack()

raiseArm()

Raises TJBot's arm. If this method doesn't move the arm all the way back, the servo motor stop point defined in TJBot.SERVO.ARM_UP may need to be overridden. Valid servo values are in the range [500, 2300].

Source:
Example
tj.raiseArm()

lowerArm()

Lowers TJBot's arm. If this method doesn't move the arm all the way back, the servo motor stop point defined in TJBot.SERVO.ARM_DOWN may need to be overridden. Valid servo values are in the range [500, 2300].

Source:
Example
tj.lowerArm()

(async) wave()

Waves TJBots's arm once.

Source: