JavaScript port of odrivetool

For all you JavaScripters out there, I just published a javascript port of odrivetool for node.js.
https://www.npmjs.com/package/odrivetool

1 Like

I’m working on a socket.io to usb bridge to run the FIbre protocol right out of the browser. I think a pub/sub framework could make it possible to share state with multiple endpoints.

I have a html/javascript UI on github pages. It utilizes webUSB to provide local access to your Odrive. Currently only supported by chrome. odrivetool

Very cool! Personally I know nothing about javascript and web development, but having stuff run in the browser is usually very slick.

How can I try it? I tried your last link, and it shows me a page, but I’m not sure how to give it access to my USB.

Thanks! Unfortunately access to USB devices through the browser is only supported by Chrome at this point, but I have tested on Linux, Mac and Windows successfully.

The page loads a “control” panel expanded to show “usb”, “odrive” and “fibre”. If you expand “usb”, you can change configuration parameters if need be, but the current settings work for me.

Click the “( )” next to “connect” in the “usb” panel and the browser will pop up a window of all devices matching the vendorID 0x1209 (4617 in base 10). Select the Odrive interface and click connect.

If all goes well, a new sub-window pops up called x(odrv0) showing the connection loading the JSON schema from the device. Once loaded, it samples any visible endpoint every 500ms. Currently I’m seeing around 200 to 300 msgs/sec max. If you expand the “fibre” panel there is a real-time msg queue and per second counter.

You can set endpoints and call remote functions with this html wrapper around the odrv0 JavaScript object.

The current version I’m working on has some real-time graphs and gauges as well as an IDE and terminal for the ASCII protocol.

for linux webusb access to odrive you must create a udev rule:

cat /etc/udev/rules.d/50-odrive.rules 

SUBSYSTEM=="usb", ATTR{idVendor}=="1209", MODE="0666", GROUP="plugdev"

Here is a list of platform specific settings for webusb

@PrimeEuler,
I was wondering if you might be able to help me get your code up and running. I’d like to see about controlling a pair of motors through nodejs, creating plots and doing the configuration with a web page. It looks like you’ve covered alot of ground with the fibre protocol and more. I’m getting an error about “acking” in the fibre queue though when using the odrivetool. Seems I might be missing a step… any ideas? Thanks in advance!

Nevermind!!! Needed the udev rule. Pardon the interruption! I’m playing now!!! :slight_smile:

Awesome! Are you using the WebUSB or the node.js interface? The WebUSB interface will obviously have less hops because you’re accessing the Odrive directly from the browser instead of hopping through a web socket / server. I’ve built a USB to web socket proxy but for real-time plotting, the latency makes it feel sluggish. Ultimately I think the fibre server running on the Odrive should have the ability emit multiple endpoints in one payload instead of the individual query and response that is currently implemented. Obviously the RTT of those individual transactions adds up.

Node.js. With the stuff that marshals the object back and forth. That then presents the data to a websocket interface that I can use to control things and do motor tuning dynamically on.

I was about to build all this with threads in python and that was going to be really, really annoying. This… though, with nonblocking javascript … and all is fantastic. Specifically I grabbed the “odrive” npm package.