QTrobot JavaScript API Reference
The qtrobot.js library is JavaScript SDK for QTrobot. It is a wrapper over roslibjs which facilitate stablishing connection with QTrobot rosbridge and expose simple APIs to interact with the robot's ROS interfaces such as playing gestures, configuring the text-to-speech interface, showing emotion, etc. It also offers some generic functions to call any ROS service (call_service), publish (publish) and subscribe (subscribe) to a generic topic.
Please read QTrobot Interface documentation for the details description of available ROS interfaces for QTrobot.
constructor
QTrobot constructor method this function will automatically call the connect method with the given 'url' to the constructor
Parameters:
paramsobject an object with the following fields- url: the rosbridge websocket url (e.g.
ws://127.0.0.1:9090) - reconnect_time: an optional delay (in ms) before traying to reconnect
- callback.connection: an optional callback to be called upon connection
- callback.close: an optional callback to be called on closing/disconnection
- callback.error: an optional callback to be called upon any error on connection
- url: the rosbridge websocket url (e.g.
call_service
Call a ros service
Parameters:
_namestring service name (e.g. /qt_robot/speech/say)_typestring service type (e.g. qt_robot_interface/speech_say)_paramsobject an object specifying the service’s paramscallbackfunction a callback to get the result (optional, defaultnull)
publish
Publish to a ros topic
Parameters:
_namestring topic name (e.g. /qt_robot/speech/say)_typestring topic message type (e.g. std_msgs/String)_paramsobject object specifying the message fields (e.g. {data: 'hello'})
subscribe
Subscribe to a ros topic
Parameters:
_namestring topic name (e.g. /qt_robot/joints/state)_typestring topic message type (e.g. sensor_msgs/JointState)callbackfunction a callback to receive the published message (optional, defaultnull)
show_emotion
Show a facial emotion on QTrobot display
Parameters:
emotionstring name of the emotion (e.g. QT/happy)callbackfunction a callback to be called after playing the emotion file (optional, defaultnull)
play_gesture
Play a QTrobot recorded gesture
Parameters:
gesturestring name of a gesture (e.g. QT/happy)callbackfunction a callback to be called after playing the gesture (optional, defaultnull)
set_volume
Set QTrobot speaker volume
Parameters:
volumenumber level in percentage (0-100)callbackfunction a callback to check the result (optional, defaultnull)
home_motors
Move all QTrobot motors to home position
Parameters:
callbackfunction a callback to be called after homing all motors (optional, defaultnull)
say_text
Speak a text using QTrobot TTS
Parameters:
messagestring text messagecallbackfunction a callback to be called after speaking out the message (optional, defaultnull)
configure_tts
Configure QTrobot TTS engine
Parameters:
languagestring speech language (e.g. en_US) (optional, default'default')pitchnumber speech pitch value (it may not supported for all voices) (optional, default0)speednumber speech talking speed (100 is the normal speed.) (optional, default0)callbackfunction a callback to check the result (optional, defaultnull)
play_audio
Play a mp3 or wav audio file
Parameters:
namestring the name of the audio file without extension (e.g. QT/5LittleBunnies)pathstring an optional path (leave it empty '' for QTrobot default audio path) (optional, default'')callbackfunction a callback to be called after playing the audio file (optional, defaultnull)
talk_text
Speak a text using QTrobot TTS with facial emotion (moving mouth)
Parameters:
messagestring text messagecallbackfunction a callback to be called after speaking out the message (optional, defaultnull)
talk_audio
Play a mp3 or wav audio file with facial emotion (moving mouth) This is useful when you want to play a recorded audio speech.
Parameters: