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:
params
object 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:
_name
string service name (e.g. /qt_robot/speech/say)_type
string service type (e.g. qt_robot_interface/speech_say)_params
object an object specifying the service’s paramscallback
function a callback to get the result (optional, defaultnull
)
publish
Publish to a ros topic
Parameters:
_name
string topic name (e.g. /qt_robot/speech/say)_type
string topic message type (e.g. std_msgs/String)_params
object object specifying the message fields (e.g. {data: 'hello'})
subscribe
Subscribe to a ros topic
Parameters:
_name
string topic name (e.g. /qt_robot/joints/state)_type
string topic message type (e.g. sensor_msgs/JointState)callback
function a callback to receive the published message (optional, defaultnull
)
show_emotion
Show a facial emotion on QTrobot display
Parameters:
emotion
string name of the emotion (e.g. QT/happy)callback
function a callback to be called after playing the emotion file (optional, defaultnull
)
play_gesture
Play a QTrobot recorded gesture
Parameters:
gesture
string name of a gesture (e.g. QT/happy)callback
function a callback to be called after playing the gesture (optional, defaultnull
)
set_volume
Set QTrobot speaker volume
Parameters:
volume
number level in percentage (0-100)callback
function a callback to check the result (optional, defaultnull
)
home_motors
Move all QTrobot motors to home position
Parameters:
callback
function a callback to be called after homing all motors (optional, defaultnull
)
say_text
Speak a text using QTrobot TTS
Parameters:
message
string text messagecallback
function a callback to be called after speaking out the message (optional, defaultnull
)
configure_tts
Configure QTrobot TTS engine
Parameters:
language
string speech language (e.g. en_US) (optional, default'default'
)pitch
number speech pitch value (it may not supported for all voices) (optional, default0
)speed
number speech talking speed (100 is the normal speed.) (optional, default0
)callback
function a callback to check the result (optional, defaultnull
)
play_audio
Play a mp3 or wav audio file
Parameters:
name
string the name of the audio file without extension (e.g. QT/5LittleBunnies)path
string an optional path (leave it empty '' for QTrobot default audio path) (optional, default''
)callback
function 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:
message
string text messagecallback
function 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: