# ev3-client

> Client for rtm-api

Latest version **0.1.59** (published 2017-07-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install ev3-client
pnpm add ev3-client
yarn add ev3-client
bun add ev3-client
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.59 |
| Published | 2017-07-13 |
| First published | 2016-03-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 14 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | danleavitt0 |
| Maintainers | danleavitt0 |

## Links

- npm: https://www.npmjs.com/package/ev3-client
- Repository: https://github.com/ev3-js/ev3-client
- Homepage: https://github.com/ev3-js/ev3-client#readme
- Issues: https://github.com/ev3-js/ev3-client/issues
- npm.io page: https://npm.io/package/ev3-client

## Dependencies (14)

- [yoco](https://npm.io/package/yoco.md) 1.4.2
- [@f/sleep](https://npm.io/package/@f/sleep.md) 1.0.0
- [flo-bind](https://npm.io/package/flo-bind.md) 1.1.1
- [websocket](https://npm.io/package/websocket.md) ^1.0.22
- [@f/channel](https://npm.io/package/@f/channel.md) 1.1.0
- [@f/compose](https://npm.io/package/@f/compose.md) 1.0.1
- [@f/map-obj](https://npm.io/package/@f/map-obj.md) ^1.2.2
- [deep-equal](https://npm.io/package/deep-equal.md) 1.0.1
- [redux-flow](https://npm.io/package/redux-flow.md) 0.0.1
- [@f/defaults](https://npm.io/package/@f/defaults.md) 1.0.1
- [@f/identity](https://npm.io/package/@f/identity.md) 1.1.1
- [@f/is-object](https://npm.io/package/@f/is-object.md) ^1.1.4
- [@f/is-generator](https://npm.io/package/@f/is-generator.md) 1.3.2
- [@f/create-action](https://npm.io/package/@f/create-action.md) 1.1.1

## Recent versions

- 0.1.59 (latest) — 2017-07-13
- 0.1.58 — 2017-07-13
- 0.1.57 — 2017-06-22
- 0.1.56 — 2016-04-28
- 0.1.55 — 2016-04-11
- 0.1.54 — 2016-04-11
- 0.1.53 — 2016-04-07
- 0.1.52 — 2016-04-07
- 0.1.51 — 2016-04-06
- 0.1.50 — 2016-04-06
- 0.1.49 — 2016-04-06
- 0.1.48 — 2016-04-05
- 0.1.46 — 2016-03-31
- 0.1.45 — 2016-03-31
- 0.1.44 — 2016-03-31
- … 42 more at https://npm.io/package/ev3-client/versions

## README

# ev3-client

[![Build status][travis-image]][travis-url]
[![Git tag][git-image]][git-url]
[![NPM version][npm-image]][npm-url]
[![Code style][standard-image]][standard-url]

Client for rtm-api

## Installation
```js
npm install ev3-client
```

## Usage
```js
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](http://github.com/ev3-js/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

value | meaning
---|---
0 | Not pressed
1 | Pressed

#### .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

value | meaning
---|---
0 | no color
1 | black
2 | blue
3 | green
4 | yellow
5 | red
6 | white
7 | brown

#### .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

[travis-image]: https://img.shields.io/travis/ev3-js/ev3-client.svg?style=flat
[travis-url]: https://travis-ci.org/ev3-js/ev3-client
[git-image]: https://img.shields.io/github/tag/ev3-js/ev3-client.svg?style=flat
[git-url]: https://github.com/ev3-js/ev3-client
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat
[standard-url]: https://github.com/feross/standard
[npm-image]: https://img.shields.io/npm/v/ev3-client.svg?style=flat
[npm-url]: https://npmjs.org/package/ev3-client

---
_Source: https://npm.io/package/ev3-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
