0.1.35 • Published 8 years ago

ev3-api v0.1.35

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

rtm-api

Build status Git tag NPM version Code style

A realtime API for use on ev3 robots with rtm-server and ev3-client

Installation

npm install ev3-api

Usage

var server = require('rtm-server')
var API = require('ev3-api')

server(API, 5000)

API

messages

Emitter for communication with the server.

sensor_mode(data, cb)

Set the mode of one of the sensors.

data

Type: object

Object with options for the sensor mode.

command

Type: string

The ev3dev sensor mode to set.

port

Type: string, number

The number of the port the sensor is connected to.

cb

Type: function

Callback function that is called when the sensor mode change is completed. Function should have an error argument.

sensor_subscribe(data, cb)

Subscribe to read the values from the sensors and the state of the motors. The first time this is called it begins the polling process. The messages are then emitted via messages as an object.

data

Type: object

Object that contains the socket id for the emitter to transmit on.

socketId

Type: number

reading channel ID for emitting the sensor object.

Example sensors object:

{
  'a': {
    'type': 'motor',
    'value': 'running'
  },
  '1': {
    'type': 'sonic',
    'value': 50
  }
}

cb

Type: function

Callback function that is called when the sensor polling has been started.

sensor_unsubscribe(data, cb)

Stop receiving information from the sensors. If this is the last connection to the robot, the sensor polling will be stopped.

data

Type: object

socketId

Type: number

The ID of which reading channel to close.

cb

Type: function

Callback function that is called when the sensor polling has been canceled.

motor_write(data, cb)

Start a single motor move.

data

Type: object

Object with information to start motor moves.

command

Type: string

Type of ev3dev motor command to run.

port

Type: string

Letter of the port the motor is attached to.

opts

Type: object

Options to set for the move command. Check out the ev3dev tacho-motor tutorial for more information on these options. The three most common ones are explained below.

speed_sp

Type: string

Set the speed of the motors. The tutorial above has a more in depth explanation but the number should stay below 800 for the ev3 motors.

time_sp

Type: string

Set the time the motor should run for in milliseconds. Should only be used for a run-timed command.

position_sp

Type: string

The degrees the tacho-motor should spin. This is used for the run-to-rel-pos and run-to-abs-pos commands.

motors_write(data, cb)

Moves two motors at the same time. Should be used to handle driving the robot.

data

Type: object

Object with information to start motor moves.

command

Type: string

Type of ev3dev motor command to run.

port

Type: array

Array of strings that indicate the two drive motors.

Example:

['b', 'c']
left

Type: object

motor_write opts object to use for the left motor (first in the ports array). See above for details.

right

Type: object

motor_write opts object to use in the right motor (second in the ports array). See above for details.

cb

Type: function

Callback function is called either on error or when both motors have successfully written their commands. First argument is err.

ping(data, cb)

A ping to check the connection to the client.

cb

Type: function

Function gets passed (err, true).

setPaths(paths)

Change the default paths to the motors and sensors. Useful for testing purposes.

paths

Type: object

motor

Type: string

Path to motor. Default path is '/sys/class/tacho-motor/'.

sensor

type: string

Path to sensor. Default path is '/sys/class/lego-sensor/'.

reading()

Check to see if the sensors are currently reading. Only used for testing.

Returns a boolean

0.1.35

8 years ago

0.1.34

8 years ago

0.1.33

8 years ago

0.1.32

8 years ago

0.1.31

8 years ago

0.1.30

8 years ago

0.1.29

8 years ago

0.1.28

8 years ago

0.1.27

8 years ago

0.1.26

8 years ago

0.1.25

8 years ago

0.1.24

8 years ago

0.1.23

8 years ago

0.1.22

8 years ago

0.1.21

8 years ago

0.1.20

8 years ago

0.1.19

8 years ago

0.1.18

8 years ago

0.1.17

8 years ago

0.1.16

8 years ago

0.1.15

8 years ago

0.1.14

8 years ago

0.1.13

8 years ago

0.1.12

8 years ago

0.1.11

8 years ago

0.1.10

8 years ago

0.1.9

8 years ago

0.1.8

8 years ago

0.1.7

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago