DMX, Gunnebo Business Solutions, Protocols, Technical

Prolight node for Node-RED

In the previous article on Node-RED, I talked about Art-Net node for communicating with DMX devices. In this article, I will build on that, and look into a specific device implementation.

During planning of Euroshop 2017 one requirement from the product owner was to simulate sunrise and sunset with a Prolights PixieWash. Sounds quite easy, but when you start looking into the details we found that we needed to create mathematical calculations to build arc transitioning algorithm.

Creating this algorithm and Node-RED implementation, we turned to Trembit, Node-RED specialists and finalists of IBM Global Mobile Tournament 2016 to get us on the right track.

To create the arc of the sun, we would need to calculate the light path from point A to point B along the arc. Whereas light can be rotated by 360 degrees vertically and horizontally, anyway we should use the spherical coordinate system for points forming the arc.

To start with, let’s try to recall spherical coordinates formulas

Where r > 0, 0 ≤ θ ≤ 2π , 0 ≤ φ ≤ π
Pic.1. Spherical coordinate system

In our case, there are three points in spherical coordinates: starting point A, target point and center point C. All these points belong to the sphere. We don’t care about sphere radius and can use unit sphere for calculation purposes because ray of light does not have physical distance.

The first step is converting all points into Cartesian coordinate system. We’ll use formula 1 for this purpose. JavaScript implementation for Cartesian conversion is the following:

Next, we would need to find a normal vector for a plane, where points and B belong. On this stage normal vector will be the equal unit vector vn, which will cross circle center point C. We can calculate normal vector the following way:

Also we need to find the real center point Cc’, which will be a cross point of normal vector vn and the plane where points Ac and Bc belong.

Finally, there are three points describing the plane. We’ll save Cc’ to movement_point  variable and will subtract point Cc’ from every point we have to simplify calculation. We need movement_point point for reverse transformation. After such transformations the point  Cc’ will be positioned in coordinate system center O(0,0,0). And the most interesting point – rotating coordinate system to make AcBcCc’ plane equal Oxy plane. We will use the following formulas (2) for that purpose:

Please, find JavaScript implementation below:

At this stage we can ignore coordinate and use 2D formulas because point Сс’ is in the coordinate system center and points AcBc belong to Oxy plane. coordinate equals zero. Also we calculated backVector. It’s necessary for coordinate system reverse rotation.

As a next step we would need to calculate t-parameter value for points Ac and Bc:

Now, as both sector angle created by points AcrBcrCcr and angle step are defined, we could easily calculate circle points coordinates. We’ll find sector angle and iteration step.

The final step is to find point coordinates for each iteration and to make reverse transformation.

The algorithm, described above, is used by node-red-cotrib-artnet node to perform moving on arc transitions. Please find links below.

source code npm package

Also we created a separate Node-RED node that composes input for node-red-contrib-artnet to control Prolights lights via simple UI.

source code npm package

To conclude I would like to thank Trembit and Maksym Gerasymchuk for their incredible effort with this library and their contribution to this article. We have released the code, open source, so please use it and help us make it better 🙂

Leave a Reply