Skip to content

pancx/node-kobuki

Repository files navigation

Node-kobuki

Kobuki is a lowcost mobile research robot. Kobuki has highly reliable odometry and long battery hours and provides power for an external sensor and actuator. This project aims to implement the control of kobuki by using node.js and offer apis for javascript developers.  

Installation:

Install the following basic dependencies refer to their official pages.

  1. Node.js
    Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Recommend that download the source of stable version, compile and install.
  2. node-gyp
    node-gyp is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js.
    You can install with npm:
    $ npm install -g node-gyp 
    
  3. Kobuki linux driver
    Install the kobuki driver for Linux.
    (You may need to install some dependencies like libftdi-dev and libusb-dev.)
  4. widl-nan
    This toolchain transcompiles W3C Web IDL and Version 2 to the NAN C++ code. This tool improve efficiency of Node.js Addon developing, allows developers focus on spec definition and actual implementation codes.
    Clone this project to your workspace and install widl-nan. Notice the step Compile your Web IDL, repalce it by:
    $ ./node_modules/.bin/widl-nan kobuki.widl 
    
    And do not init helper files.

Kobuki APIs

You can find its native apis on its official page kobuki_driver: Getting Started.
This project provides javascript apis and try best to ensure their names, args and return values seem as the native apis.

Raw Data

The kobuki driver runs a background thread which continually retrieves packets from the kobuki, saving the raw data, and additionally doing some processing before updating the current state of the robot.

Raw data can be accessed at any time by one of the following getXXX commands:

getCoreSensorData
getDockIRData
getCliffData
getCurrentData
getGpInputData
getInertiaData
getRawInertiaData
getControllerInfoData
The gyro provides both filtered yaw angle as well as unfiltered 3-axis inertial data hence the two calls above.

Processed Data and Status

The following are convenience methods for accessing the current state of the robot

batteryStatus
getHeading
getAngularVelocity
versionInfo : hardware, firmware and software version strings.
getWheelJointStates
isAlive : true if a kobuki is detected and streaming data.
isEnabled : true if the motor power is enabled
isShutdown : true if the worker threads for this driver have been shut down.

Soft Commands

resetOdometry

Hard Commands

setBaseControl
setLed
setDigitalOutput
setExternalPower
playSoundSequence
setControllerGain
getControllerGain

The Differential Drive Module

The final function of importance is the updateOdometry method. This updates the current odometry state of the robot, fusing encoder and gyro heading data with the previous known state. For deterministic odometry, it is important this method is called each time a new data packet from the kobuki arrives. Refer to the simple control loop example for more information and working code to illustrate.

Events

Sigslots are the primary way of kobuki driver to handle events emitted by the kobuki driver (c.f. with the usual function callbacks with void function pointers as arguments). You can go straight to the official documentation Sigslots and ecl_sigslots to find more information. It provided an asynchronous way to control the robot indeed. This project implements Sigslots by inheriting EventEmitter(learn more in its page EventEmitter) and overriding addListener and removeListener.

The following represent the available events

  • streamdata : informs when a new data packet has arrived from the kobuki
  • rosdebug : relay debug messages
  • rosinfo : relay info messages
  • roswarn : relay warning messages
  • roserror : relay error messages
  • buttonevent : receive an event when a button state changes
  • bumperevent : receive an event when the bumper state changes
  • cliffevent : receive an event when a cliff sensor state changes
  • wheelevent : receive an event when the wheel state (in/out) changes
  • powerevent : receive an event when the power/charging state changes
  • inputevent : receive an event when the gpio state changes
  • robotevent : receive an event when the robot state changes
  • versioninfo : receive version info strings on this signal

Test & usage cases

Refer to the cases in the test folder to learn more usage of the javascript apis.

$ node test.js

About

JavaScript API for Yujin Kobuki/TurtleBot

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published