Skip to content

nodriver-ai/MAVJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MAVJS

Build Status

Node.js wrapper for mavlink/MAVSDK C++ library using node-addon-api.

MAVJS is a Node.js addon, written in C++, that can be loaded into Node.js using the require() function, and used just as if they were an ordinary Node.js module.

The aim of the project is to provide an interface between JavaScript running in Node.js and MAVSDK C/C++ library.

The library also provides types definition to use Typescript.

documentation: https://nodriver-ai.github.io/MAVJS/

Prerequisites

Before starting to use MAVJS you need to assure you have the following prerequisites:

Cmake needs because we use CMake.js to build the addon

MAVJS requires MAVSDK System-wide Install.

Installation

This is a Node.js module available through the npm registry.

installation is done using the npm install command:

$ npm i @nodriverai/mavjs

Getting started

import { Mavsdk, System, Telemetry, Action } from "@nodriverai/mavjs";

//Create a Mavsdk instance
let mavsdk = new Mavsdk();

//Add connection
const connection_result = mavsdk.add_any_connection("udp://14540");

if (connection_result != Mavsdk.ConnectionResult.SUCCESS) {
    console.log(`Connection failed: ${connection_result.toString()}`);
    process.exit()
}

//Get the first system discovered
let system = mavsdk.system();

//Initialize telemtery and action objects
let telemetry = system.telemetry();
let action = system.action();

//Monitor altitude while the vehicle is in flight
telemetry.position_async((position) => {
    console.log(`Altitude: ${position.relative_altitude_m} m`)
})

// Arm vehicle
let arm_result: Action.Result = action.arm();

if (arm_result != Action.Result.SUCCESS) {
    console.log(`Arming failed: ${arm_result}`)
    process.exit();
}

// Take off
let takeoff_result: Action.Result = action.takeoff();
if (takeoff_result != Action.Result.SUCCESS) {
    console.log(`Takeoff failed: ${takeoff_result}`)
    process.exit();
}

//close all connections
mavsdk.close();

Examples

To view the examples, clone the Express repo and install the dependencies:

$ git clone https://github.com/nodriver-ai/MAVJS.git
$ cd MAVJS
$ npm install

Then run whichever example you want:

$ node examples/takeoff_and_land.js udp:://14540

Project Status

Plugins implementation:

  • Action
  • Info
  • Telemetry
  • Mission
  • MissionItem
  • Offboard
  • Geofence
  • Gimbal
  • Camera
  • LogFiles
  • MavlinkPasstrough
  • MavlinkFTP
  • MissionRaw
  • Mocap
  • Param
  • Shell
  • Tune

Tests

To run the test suite, first install the dependencies, then run npm test:

$ npm install
$ npm test

You need also a PX4 SITL running and accessible via UDP in localhost. You can use docker to run a gazebo PX4 SITL simulator.

$ docker run -d -it --net=host jonasvautherin/px4-gazebo-headless:v1.9.2

License

This project is licensed under the permissive BSD 3-clause, see LICENSE.md.