NodeJS script to control CF with BLE

Firmware/software/electronics/mechanics
phil
Beginner
Posts: 15
Joined: Sat Feb 14, 2015 12:01 pm

NodeJS script to control CF with BLE

Post by phil »

Hello all, as I was dissatisfied with my script in Python to control the CF with BLE (connecting in MacOSX is not easy, sometimes Bluetooth needs to be restarted), I decided to take a shot at writing the same functionality for Node.js.
This proved to be very easy because of some existing libs : noble and bufferpack (you know, npm install -g). It still needs a lot of work - I'm thinking of a TOC, wrapping it in a module, maybe attempt to browserify it - but the basics are there. Basic setpoints and params can be sent to the CF.
Prerequisites : XCode, Node.js, noble and bufferpack.
Anyway, you can find the result here : https://github.com/ppossemiers/BLECrazyflie_NodeJS
jordankid93
Beginner
Posts: 8
Joined: Sun Apr 19, 2015 5:55 am

Re: NodeJS script to control CF with BLE

Post by jordankid93 »

Hey, I forked your repo and would love to help contribute to this? It's exactly what I was looking for!
phil
Beginner
Posts: 15
Joined: Sat Feb 14, 2015 12:01 pm

Re: NodeJS script to control CF with BLE

Post by phil »

Great! All help will be greatly appreciated.
I think the first thing that needs to be done, is implementing the TOC. At this moment, the code uses the hardcoded param value 11 for the hover, but this should be fetched from a downloaded TOC (like in the original python client).
Other planned additions :
1/ hooking it up to a controller
2/ wrapping it in a module
3/ browserifying it so it runs in a browser
4/ writing a UI for it. Maybe we can coordinate this with the Chrome app (https://www.bitcraze.io/2015/04/crazyfl ... chrome-app), so there is one UI. I feel Ionic would be a great choice here.

Feel free to contribute to any of these points.
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: NodeJS script to control CF with BLE

Post by arnaud »

Hi,

The nodes implementation looks simple and small, that's great! Apparently it is supposed to work also on Linux but it did not for me (BLE in Linux is a mess anyway .... I will try with a mac).

There is already a nodejs lib out there that has log/param implementation but that has not been touched for 2years: https://github.com/ceejbot/aerogel, it could be reused.

I though about trying to have a Crazyflie javascript lib modular and independent of GUI so that we can have the same lib for nodejs, chrome and possibly other platform that understands javascript (eg. firefoxOS phones). What do you think?

I did not know about ionic, I'll look at it.
phil
Beginner
Posts: 15
Joined: Sat Feb 14, 2015 12:01 pm

Re: NodeJS script to control CF with BLE

Post by phil »

Hello,
The noble library requires XCode because of some specific things that are installed on mac. I think that is the reason it doesn't work on Linux. Probably there are other libraries out there, but most of them are not open-source. I suggest we build the mac version first and in the meantime keep our eyes open for other BLE libs.

Aerogel sure looks promising. I'll look into it and see if we can reuse parts of it.

Having a modular CF lib that is independent of the GUI is indeed the best way to go. That way it can operate without GUI (which was my first goal anyway) and can be ported to different platforms. I'm not sure if we can make it work in a browser, but it's worth a try. If I can find some time next week, I'll do some tests.
jordankid93
Beginner
Posts: 8
Joined: Sun Apr 19, 2015 5:55 am

Re: NodeJS script to control CF with BLE

Post by jordankid93 »

Hey, sorry if this is a silly question but what is TOC? I haven't done any development with the Crazyflie / embedded anything before so I'm afraid I might not know what all the terms /acronyms mean.

What would you recommend for getting up to speed with development of the CF specifically? I'm familiar with node and have already started making a module for this but outside of what you have as far as plugging in to the pitch, yaw, roll, and thrust I'm kind of lost.

Again, would love to help but don't know where would be the best place to start learning HOW to help ha.
phil
Beginner
Posts: 15
Joined: Sat Feb 14, 2015 12:01 pm

Re: NodeJS script to control CF with BLE

Post by phil »

A TOC is a Table of Contents. When the CF client starts up, it downloads a list of params with an identity.
At this moment, the identity of the altitude hold param is 11, but this could change in a different version of the firmware. By downloading that list, the identity of the params is always up to date.
Apparently the guy from aerogel has already implemented that TOC, so we can probably use that code. I mailed him, so maybe he'll work with us.
If you want to contribute, I suggest you either look at a way to wrap the code in a module, in the node.js way. Or test if you can browserify (http://browserify.org/) the script. This would be a very good start.
jordankid93
Beginner
Posts: 8
Joined: Sun Apr 19, 2015 5:55 am

Re: NodeJS script to control CF with BLE

Post by jordankid93 »

Oh ok. I think I understand. I'll try looking at the aerogel code and see how it does things to maybe better understand the inner workings.

I spent a few hours today making (what I feel) is a good node-module out of what you provided. I want to double check it before submitting a pull request but he's a link for anyone interested - https://github.com/jordankid93/BLECrazyflie_NodeJS.

Gave the module a slightly shorter, all lowercase name to fit with naming conventions I've seen. Not sure if it'd be best to rename the repo as well.
phil
Beginner
Posts: 15
Joined: Sat Feb 14, 2015 12:01 pm

Re: NodeJS script to control CF with BLE

Post by phil »

Well done! This is exactly what we need.
About renaming the repository, I think you are right. We do need a shorter and catchier name. Any suggestions?

One thing though : I don't think the repository should contain its dependencies. Having the node_modules dir in there is probably redundant, since you install them with npm anyway.
jordankid93
Beginner
Posts: 8
Joined: Sun Apr 19, 2015 5:55 am

Re: NodeJS script to control CF with BLE

Post by jordankid93 »

Ahh, good catch. I've gone ahead and removed the node-module folder from the repo, edited the README, and included a .gitignore to prevent anyone from adding the node-module folder back in.

About the name, I went with "crazyflie-ble" simply because it was to the point ha
Post Reply