0.1.59 • Published 7 years ago

ev3-client v0.1.59

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

ev3-client

Build status Git tag NPM version Code style

Client for rtm-api

Installation

npm install ev3-client

Usage

let {robot, move, read, sleep, motor} = require('ev3-client') //expose ev3-client methods
var run = robot('ip address of websocket server') // connect to robot

var steer = move('b', 'c') // set drive motors to ports b and c
var motor1 = motor('a') // set arm motor to port a

run(function * () {
  var devices = yield read() // read sensor data
  var dist = devices.sonic(1) // get distance reading from ultrasonic sensor in port 1

  if (dist < 10) {
    yield steer.rotations(-1, 40, 0) // move one rotation backward
  } else {
    yield steer.rotations(1, 40, 0) // move one rotation forward
  }
  yield sleep(1000) // wait for 1 second
  yield motor1.degrees(90, 40) // spin motor in port a 90 degrees
})

API

robot(str)

  • str - string containing the ip address of the ev3 server

Returns a runner for ev3 actions

move(leftPort, rightPort)

  • leftPort - port letter of the left motor. defaults to 'b'.
  • rightPort - port letter of the right motor. defaults to 'c'.

Returns: object of move functions

.forever(speed, turn)

Run both motors until they receive a stop command.

  • speed - number between 0 and 100 to control the speed at which to run the motors
  • turn - number between -100 and 100 to denote amount of turning. -100 is maximum left turn. 0 is straight. 100 is maximum right turn.

.degrees(degrees, speed, turn)

Run both motors for a number of degrees with the ability to turn.

  • degrees - number of degrees for the motor to spin
  • speed - number between 0 and 100 to control the speed at which to run the motors
  • turn - number between -100 and 100 to denote amount of turning. -100 is maximum left turn. 0 is straight. 100 is maximum right turn.

.rotations(rotations, speed, turn)

Run both motors with a number of degrees the ability to turn.

  • rotations - number of rotations for the motor to spin
  • speed - number between 0 and 100 to control the speed at which to run the motors
  • turn - number between -100 and 100 to denote amount of turning. -100 is maximum left turn. 0 is straight. 100 is maximum right turn.

.timed(time, speed, turn)

Run both motor for a specified amount of time.

  • time - time in milliseconds
  • speed - number between 0 and 100 to control the speed at which to run the motors
  • turn - number between -100 and 100 to denote amount of turning. -100 is maximum left turn. 0 is straight. 100 is maximum right turn.

.stop()

Stop both motors.

read()

Read the data from all devices connected to the robot

Returns Object to access sensor data

.touch(port)

Reads the state of the touch sensor

  • port - the port the touch sensor is plugged in to

Return Number

valuemeaning
0Not pressed
1Pressed

.sonic(port)

Reads the value of the ultrasonic sensor (defaults to inches)

  • port - the port the touch sensor is plugged in to

Returns Number

.color(port)

Reads the value of the color sensor (defaults to color)

  • port - the port the touch sensor is plugged in to

Returns Number

valuemeaning
0no color
1black
2blue
3green
4yellow
5red
6white
7brown

.ir(port)

Reads the value of the infrared sensor (defaults to seek mode)

  • port - the port the touch sensor is plugged in to

Returns Object

{
  heading1: heading towards beacon with channel 1,
  distance1: distance towards beacon with channel 1,
  heading2: heading towards beacon with channel 2,
  distance2: distance towards beacon with channel 2
}

.motor(port)

Read the state of the motor

  • port - the port the motor is plugged in to

motor(port)

  • port - port letter of the motor. defaults to 'a'.

Returns: object of move functions

These function are exactly the same as the motors function but without the turn parameter.

sleep(ms)

Pause execution for an amount of time

  • ms - Time to pause execution in milliseconds

license

MIT

0.1.59

7 years ago

0.1.58

7 years ago

0.1.57

7 years ago

0.1.56

8 years ago

0.1.55

8 years ago

0.1.54

8 years ago

0.1.53

8 years ago

0.1.52

8 years ago

0.1.51

8 years ago

0.1.50

8 years ago

0.1.49

8 years ago

0.1.48

8 years ago

0.1.46

8 years ago

0.1.45

8 years ago

0.1.44

8 years ago

0.1.43

8 years ago

0.1.42

8 years ago

0.1.41

8 years ago

0.1.40

8 years ago

0.1.39

8 years ago

0.1.38

8 years ago

0.1.37

8 years ago

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