Giter Site home page Giter Site logo

rplidar's Introduction

NodeJS (and Web Serial API) driver for slamtec RPLidar

Please note: this driver tested only on A1 (but it will certainly suit advanced models without significant problems).

Yep, you can use the driver both in NodeJS and even in your browser at almost maximum design speeds (~440RPM for A1)!

Installing

// Usual module for NodeJS
import {RPLidar} from '@tsofist/rplidar';

// Usual module (for bundling) for Browser
import {RPLidarBrowser} from '@tsofist/rplidar';

// Independent module for Browser (as esm/cjs module)
import {RPLidarBrowser} from '@tsofist/rplidar/lib/rplidar-browser.esm.js';
import {RPLidarBrowser} from '@tsofist/rplidar/lib/rplidar-browser.js';

// Independent module for Browser from CDN as esm
import {RPLidarBrowser} from 'https://unpkg.com/@tsofist/rplidar/lib/rplidar-browser.esm.js';

Usage

const lidar = new RPLidar();

console.log('Opening lidar port..');

await lidar.open();
await lidar.motorStop();

console.log(`RPLidar ready on "${lidar.serialPortPath}"`);
console.log(`Lidar Info:`, await lidar.getInfo());
console.log(`Device health:`, await lidar.getHealth());
console.log(`Lidar samples rates:`, await lidar.getSamplesRate());
console.log(`Lidar scanning modes:`, await lidar.listScanModes());

lidar.on(`scan:sample`, (sample: RPLidarScanSample) => {
  console.log(`Scan sample:`, sample);
  console.log(`Actual speed: ${lidar.scanningRPM}RPM (${lidar.scanningHz}Hz)`);
});

console.log(`Start scanning..`);

await lidar.motorStart();
await lidar.scanStart();

await delay(5_000);

console.log(`Stop scanning..`);

await lidar.scanStop();
await lidar.motorStop();

await delay(3_000);

await lidar.close();

console.log(`Lidar port closed`);

rplidar's People

Contributors

tsofist avatar semantic-release-bot avatar

Stargazers

 avatar Arnaud Juracek avatar

Watchers

 avatar  avatar

rplidar's Issues

Thank you

I used your library to read sensor data from my robot, and then generate svg output. Very helpful thanks

image

I used some basic math to generate svg points and spit out a string like this:

const svgString = `<svg xmlns="http://www.w3.org/2000/svg" height="${svgHeight}" width="${svgWidth}" viewBox="0 0 ${svgWidth} ${svgHeight}">
  <polygon points="${svgPoints.map(point => `${point.x},${point.y}`).join(' ')}" style="fill:lime;stroke:purple;stroke-width:1" />
  <circle cx="${center.x}" cy="${center.y}" r="5" />
</svg>`

How to set the scanMode?

Hi. I can't find an option to set the scan mode. Is there any?
Thanks in advance. BTW: great job ;-)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.