Friday, May 26, 2017

Node js C++ Addon Overload Resolution - v1.2.0

Major feature implemented for namespace and class wrapping, no more SetMethod/SetPrototypeMethod and target tracking, all is done automatically. 


Since its inefficient to write so much code, while making sure SetMethod and SetPrototypeMethod is called on each overload and track the namespaces used to store the callbacks manually, an experimental namespace_wrap and class_wrap were introduced, these two classes wrap the needed calls as well as track the targets (v8::Object).
The wrappers do add overhead to function execution time but it didn't even register when I did performance analysis.
to use the wrappers you'll need to initialize an overload_resolution instance normally but also start tracking a root target:
void init(v8::Handle<v8::Object> target) {
 auto overload = std::make_shared<overload_resolution>();
 auto base_overload = overload->register_module(target);
    ...
}
NODE_MODULE(tester, init);
once you have the base_overload you can start attaching methods:
base_overload->add_overload("standalone_function_construct", {}, standalone_function_construct);
nest methods:
auto nested = base_overload->add_namespace("namespace_construct");
nested->add_overload("nc_standalone_function_construct", {}, nc_standalone_function_construct_nc);
add classes:
auto class_def = base_overload->add_class("class_constructs");
class_def->add_overload_constructor({}, New);
class_def->add_static_overload("test_static", {}, test_static);
class_def->add_overload("test_member", {}, test_member);

constructor.Reset(class_def->done<class_constructs>());
note: you must call done<T>() when you're done defining the class methods, otherwise the class won't register in both the overload_resolution and V8.
for now classes can be nested inside namespaces but not the other way around, though it should be theoretically possible.

Minor build and bug fixes:
- integration with node-addon-tracer npm package so build is simpler.
- expose node-overload-resolution as an npm module, so require("node-overload-resolution") works in parent module gyp files.
- remove support for node 0.11
- fix travis ci builds

Sunday, May 14, 2017

50V 15A Power Supply - $140

I've recently found myself in need of a more powerful power supply than my loyal 50V 3A  Circuit Specialists (CSI5003X) I had for many years.



So when I did a bit of research, I've found out that even now prices are not very low for a more powerful power supply I've decided to try and DIY it without doing any electronic work.


A while back I've seen the DPS5015, which is a 50v 15A programmable power supply which has other versions, 30v/50v, 2A/3A/5A/12A and 15A, add on top of it the possibility to DIY your own programming and it looks like a winner to me (~$37). 



You can even get an enclosure with a fan for it (~$24).




But that is just the controller, it needs a power source of some sort, I've looked around and found a 48v 16.7A switching power supply (~$73).





Throw in a couple of banana screw terminals ($1-2) - don't get the cheap ones, they fall apart.



and add a 3 Terminal Power Socket with Fuse Holder and you have a working power supply (don't forget the fuse! I've used 5A)



A few wires and a cover for the power supply and you're done.



For now, the only drawback I've seen is that this specific PSU doesn't monitor the temperature and power the fan accordingly, so the fan is always on, making a lot of noise.

I've thought about adding something like this to fix that, but I'm not sure yet, need to do a bit more reading about it and see if the power supply needs an always on cooling or not.




In the end, the time and effort to find the parts, read, design a back cover, print it and build it took a long time and I'm not really sure its efficient use of one's time, but I've had fun doing it! 



Saturday, April 29, 2017

Rover

Project Rover is officially starting!



I've selected these first few components due to their unique features:

- Rugged 4WD with 130mm wheels, I've selected it because of the large wheels and base plate since I wasn't sure how much hardware I wanted on it but at some stage I want it outside and 4 separate motors are nice to have.

- WingXine APO-L1 - works up to 30v, 10A (with current limiter), PWM 1ms - 2ms (1.5ms zero) which should work with APM controller, I've selected it because I wanted the motors to self balance but each one is 12v, so if one motor stalls, the other will push harder, a theory which I did not put to the test yet, think of it as an electronic differential.



I've wanted to power the rover with standard LIPOs so I had to boost the power to 24v or use two batteries, in the end I've selected a boost converter instead, which makes the power source more flexible.

DC-DC boost converter - 8.5-48v to 10-50v, which should get me a stable 24v out of whichever LIPO I have laying around.

For now I'm concentrating on a combination of hardware and software, I've made a USB joystick to PPM converter, which I've gotten fried due to human error, I've made a serial TFT LCD and PPM generator to be connected to a companion computer along with a mavlink connection and I'm reviewing a few npm packages for later use, you'd be surprised how many potential problems can be found before even running a single test just by converting the project to typescript and imposing a few basic types and interfaces not to mention the learning curve to the package internals and functions is reduced to minimum.

- dns-packet and multicast-dns - originally by Mathias Buus
- ip/node-ip  - originally by Fedor Indutny

and today I've checked out mavlink package, originally by Owen McAree, I've just seen the data flowing from APM, great!


message AHRS { omegaIx: 0.0003541054902598262,
  omegaIy: 0.0006027567433193326,
  omegaIz: -3.3141745348075347e-7,
  accel_weight: 0,
  renorm_val: 0,
  error_rp: 0.0018874505767598748,
  error_yaw: 1 }
message HWSTATUS { Vcc: 4349, I2Cerr: 1 }
message SYSTEM_TIME { time_unix_usec: 0, time_boot_ms: 16363 }
message ATTITUDE { time_boot_ms: 16402,
  roll: 0.018413120880723,
  pitch: 0.01433389913290739,
  yaw: -0.0002040785038843751,
  rollspeed: 0.00037805165629833937,
  pitchspeed: 0.0006373348878696561,
  yawspeed: 0.00040407307096756995 }
message VFR_HUD { airspeed: 0,
  groundspeed: 0,
  alt: 0.07000000029802322,
  climb: 0,
  heading: 0,
  throttle: 100 }
message RAW_IMU { time_usec: 16643270,
  xacc: 20,
  yacc: -10,
  zacc: -986,
  xgyro: 0,
  ygyro: 0,
  zgyro: 0,
  xmag: 0,
  ymag: 0,
  zmag: 0 }
message SYS_STATUS { onboard_control_sensors_present: 2153475,
  onboard_control_sensors_enabled: 2129923,
  onboard_control_sensors_health: 2153475,
  load: 371,
  voltage_battery: 0,
  current_battery: -1,
  drop_rate_comm: 0,
  errors_comm: 0,
  errors_count1: 0,
  errors_count2: 0,
  errors_count3: 0,
  errors_count4: 0,
  battery_remaining: -1 }
message MEMINFO { brkval: 6629, freemem: 1519 }
message MISSION_CURRENT { seq: 0 }
message ATTITUDE { time_boot_ms: 16644,
  roll: 0.01850038766860962,
  pitch: 0.014476700685918331,
  yaw: -0.00014243528130464256,
  rollspeed: -0.00006719821249134839,
  pitchspeed: 0.0005361465737223625,
  yawspeed: 0.00013777358981315047 }







Tuesday, March 28, 2017

Global Azure Bootcamp 2017 - IoT


Global Azure Bootcamp 2017

By Alon Fliess, The Internet of Things (IoT) brings together devices, sensors, cloud, data and your imagination. Join the global Azure community and take part in this Azure Boot camp hackathon event. Come, learn and create an IoT device, connect it to Azure IoT hub and form an IoT system. Whether this will be your first experience with the Internet of Things or you’re a seasoned pro, you will experience tools and technologies that get you going in Internet of Things (IoT)!


Agenda:
  • 08:30-09:00 – Gathering 
  • 09:00-09:45 – Introduction to the internet of things, IoT devices 101. 
  • 09:45-10:30 – Azure IoT – IoT Hub, Device SDK, Device Management & Communication. 
  • 10:30-10:45 – Break 
  • 10:45-11:00 – Team building, project idea definition, IoT device and tools setup 
  • 11:00-13:30 – Work on projects 
  • 13:30 – 14:00 – Projects Presentation 



Also, CodeValue Azure Bootcamp - Service Fabric, By Eran Stiller, is available at Herzlia:

Azure Service Fabric represents a revolution in the way we can host and manage our applications both on premise and in the cloud. On the one hand, with its generic hosting capabilities, Azure Service Fabric can be used to reliably host any application in the cloud. On the other hand, and using its varied programming model we can easily author, host and manage a micro-services based application with a mixture of reliable services and actors. In addition, support for reliable, scalable stateful services truly represents a breakthrough in the way we model our apps and store their data.

Saturday, March 4, 2017

OpenCV Node js Bindings - Background Subtraction Demo - on Raspberry PI !

Finally, the arm build is working, some of the problems I had to overcome, well? waiting for Raspberry PI to compile, why this computer is so popular when RK3288 is available I will never know. I've ordered a few RK3288 to accelerate my work on arm, meanwhile I think my RK3188 will be faster, I'll update as soon as I can.

Another problem is some issues I've had with file names, while working on the linux port, the typescript import file names were case insensitive and this time they were.

Lastly, different version of gcc than the linux test machine, so c++14 wasn't the default, I've added it to the build, hopefully there won't be any issues now.

In any case, this demo is for background subtraction, on arm, about 3-4 fps for two background subtraction algorithms, CPU  is about 25-30%, mostly single core, in the video its higher because ffmpeg attempts to capture and compress the screen capture in the background, the x11 took some more CPU.

Not bad but if you're planning to run OpenCV on Raspberry PI, you'll probably need to do some serious optimizations by resizing or changing algorithm parameters.




Saturday, February 25, 2017

Node js C++ Addon Overload Resolution - v1.0.0

Module compiles and all tests are passing cross platform, windows/linux/arm (raspberry pi) were tested!




Lessons learned:
- gcc is a lot less forgiving than visual c++, cryptic error messages when there are circular references between header files.
- gcc 6 is missing some minor c++17 implementations (std::size for example).
- c++ 11 (and up) - windows header includes some headers by default, in gcc you have to include them explicitly, like cmath.
- node-gyp adds c++11 compilation flag which kills gcc's ability to compile c++ 14. it can be removed but why was it even there...?

edit 2017-02-26:
- gcc multi-line comment warning makes sense when you realize the backslash at the end ( \ ) might be used to comment the line following the comment.
- gcc doesn't like extra (and useless) typename keyword
- gcc doesn't like you not using typename where it should be clear its a type definition. 
- gcc doesn't like to mix definitions from headers and code files. 

and many more... 

I guess gcc makes you write better code :-)

OpenCV Node js Bindings - HOG Demo

This is a simple demo showing that the addon is starting to work, many of the basic objects are implemented and working, including Rect, Point, Matrix, and more.

The HOG demo is actually a ported version of pedestrian detection demo from opencv_extras, since the CPU version of VideoCapture only plays mpeg files, I've modified utility.ts (which is ported from utility.h/cpp) to use my own ffmpeg bindings instead.

The porting work I've done attempts to include the GPU APIs as well, but until I'll implement cuda/GPU work in node-alvision, its only a stub, but the CPU version works as well as I could see, the code runs pretty slow since I've tested it in in debug mode while developing, but it should run faster in release and these APIs could run in node js threadloop, so in theory it could be a lot faster, but it remains to be seen if it will be.

ported typescript file is pedestrian_detection.ts