Code Monkey home page Code Monkey logo

mavlink_js_library's Introduction

MAVLink Library Wrapper

This is a small MAVLink JS library wrapper that provides a more streamlined access to it, patches the original MAVLink library to prevent certain bugs and also adds tests for some particularly touchy functions.

General Usage

For most Integrations (Broker)

var mavjs = require('mavlink-js');

// Prepare your connection stream (serial, UDP, etc.):
const systemConn = new mavjs.UdpConnection("0.0.0.0", 14550);

// Get broker object
const broker = new mavjs.MavlinkSystemBroker(systemConn);

// Access all available systems
let systems = broker.getSystems();

systems.forEach((system, index) => {
    console.log(`Got system ${system.sysId}`);
});

// OR: Get notified when a system connects
broker.on('newSystem', function(system) {
    console.log(`Got system ${system.sysId}`);
});

// OR: Get the universal system to access all data if you don't worry about multiple different systems
system = broker.getUniversalSystem();
console.log(`Got universal system ${system.sysId}`); // is ID 0

For Low Level Handling (Direct)

var mavjs = require('mavlink-js');

// Prepare your connection stream (serial, UDP, etc.):
var connection = mavjs.SerialConnection("/dev/tty.usbmodem01", 57600);

// The connection needs to define a "send" function to allow writing of data to the connection
// and emit a "data" event when receiving data.
// mavlink-js provides 2 simple implementations: mavjs.SerialConnection and mavjs.UdpConnection

// Create the Mavlink wrapper object providing at least:
// system ID, component ID, send data callback
var mavlib = new mavjs.MavlinkLib(255, 0, (buffer) => {
    connection.send(buffer);
});

// Forward data for parsing when it comes in:
connection.on('data', function(data) {
	mavlib.parseData(data);
});

// Receive successfully parsed messages:
mavlib.on('message', function(msg) {
	console.log(msg);
});

// Receive specific successfully parsed messages:
mavlib.on('HEARTBEAT', function(msg) {
	console.log(msg);
});

// Send a message:
var msg = new mavjs.messages.heartbeat(
    mavjs.mavlink.MAV_TYPE_GCS, // type
    mavjs.mavlink.MAV_AUTOPILOT_INVALID, // autopilot
    0, // base mode
    0, // custom mode
    mavjs.mavlink.MAV_STATE_ACTIVE, // system status
    mavjs.mavlink.WIRE_PROTOCOL_VERSION
);

mavlib.sendMessage(msg);

MAVLink Parameter Helpers

var mavlib = mavjs.MavlnkLib(...);

// Read parameter value from received MAVLink message
var value = mavlib.readParamValue(msg);

// Create int param_set message
var msg = mavlib.createParamSetMessage("MAV_TEST_PAR", 123, false);

// Create float param_set message
var msg = mavlib.createParamSetMessage("MAV_HUD_FREQ", 5.354, true);

Update from MAVLink Definitions

# Generate from definitions:
cd mavlink
./pymavlink/tools/mavgen.py --lang JavaScript_Stable --wire-protocol 2.0 -o ../mavlink_js_library_v2_private/src/mavlink/mavlink.js message_definitions/v1.0/standard.xml
cd ../mavlink_js_library_v2_private

# Execute patch script and run tests:
npm test

# If tests were successful commit update:
git commit -a
git push

mavlink_js_library's People

Contributors

andreasantener avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar Simon Wilks avatar  avatar  avatar

Forkers

aerialoopcorp

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.