Skip to content

Commit

Permalink
Add support for ColorSensor, MotionSensor, FisheyeSensor in C#, node-JS
Browse files Browse the repository at this point in the history
  • Loading branch information
doronhi committed Dec 26, 2019
1 parent 9227baf commit 936a22b
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 7 deletions.
6 changes: 6 additions & 0 deletions wrappers/csharp/Intel.RealSense/Types/Enums/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,11 @@ public enum Extension
GlobalTimer = 36,
Updatable = 37,
UpdateDevice = 38,
L500DepthSensor = 39,
TM2Sensor = 40,
AutoCalibratedDevice = 41,
ColorSensor = 42,
MotionSensor = 43,
FisheyeSensor = 44
}
}
56 changes: 54 additions & 2 deletions wrappers/nodejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,19 @@ class Device {

const array = [];
sensors.forEach((s) => {
if (s.isDepthSensor()) {
if (s.is(RS2.RS2_EXTENSION_DEPTH_SENSOR)) {
array.push(new DepthSensor(s));
} else {
}
else if (s.is(RS2.RS2_EXTENSION_COLOR_SENSOR)) {
array.push(new ColorSensor(s));
}
else if (s.is(RS2.RS2_EXTENSION_MOTION_SENSOR)) {
array.push(new MotionSensor(s));
}
else if (s.is(RS2.RS2_EXTENSION_FISHEYE_SENSOR)) {
array.push(new FisheyeSensor(s));
}
else {
array.push(new Sensor(s));
}
});
Expand Down Expand Up @@ -1088,6 +1098,45 @@ class DepthSensor extends Sensor {
}
}

/**
* Color sensor
*/
class ColorSensor extends Sensor {
/**
* Construct a device object, representing a RealSense camera
*/
constructor(sensor) {
super(sensor);
}
}


/**
* Motion sensor
*/
class MotionSensor extends Sensor {
/**
* Construct a device object, representing a RealSense camera
*/
constructor(sensor) {
super(sensor);
}
}


/**
* Fisheye sensor
*/
class FisheyeSensor extends Sensor {
/**
* Construct a device object, representing a RealSense camera
*/
constructor(sensor) {
super(sensor);
}
}


const internal = {
ctx: [],
objs: [],
Expand Down Expand Up @@ -6418,6 +6467,9 @@ module.exports = {
Sensor: Sensor,
DepthSensor: DepthSensor,
ROISensor: ROISensor,
ColorSensor: ColorSensor,
MotionSensor: MotionSensor,
FisheyeSensor: FisheyeSensor,
StreamProfile: StreamProfile,
VideoStreamProfile: VideoStreamProfile,
MotionStreamProfile: MotionStreamProfile,
Expand Down
62 changes: 57 additions & 5 deletions wrappers/nodejs/src/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2026,8 +2026,8 @@ class RSSensor : public Nan::ObjectWrap, Options {
Nan::SetPrototypeMethod(tpl, "setRegionOfInterest", SetRegionOfInterest);
Nan::SetPrototypeMethod(tpl, "getRegionOfInterest", GetRegionOfInterest);
Nan::SetPrototypeMethod(tpl, "getDepthScale", GetDepthScale);
Nan::SetPrototypeMethod(tpl, "isDepthSensor", IsDepthSensor);
Nan::SetPrototypeMethod(tpl, "isROISensor", IsROISensor);
Nan::SetPrototypeMethod(tpl, "is", Is);
constructor_.Reset(tpl->GetFunction());
exports->Set(Nan::New("RSSensor").ToLocalChecked(), tpl->GetFunction());
}
Expand Down Expand Up @@ -2343,16 +2343,18 @@ class RSSensor : public Nan::ObjectWrap, Options {
info.GetReturnValue().Set(Nan::New(scale));
}

static NAN_METHOD(IsDepthSensor) {
static NAN_METHOD(Is) {
info.GetReturnValue().Set(Nan::Undefined());
int32_t stype = info[0]->IntegerValue();

auto me = Nan::ObjectWrap::Unwrap<RSSensor>(info.Holder());
if (!me) return;

bool is_depth = GetNativeResult<int>(rs2_is_sensor_extendable_to,
&me->error_, me->sensor_, RS2_EXTENSION_DEPTH_SENSOR, &me->error_);
bool is_ok = GetNativeResult<int>(rs2_is_sensor_extendable_to,
&me->error_, me->sensor_, static_cast<rs2_extension>(stype), &me->error_);
if (me->error_) return;

info.GetReturnValue().Set(Nan::New(is_depth));
info.GetReturnValue().Set(Nan::New(is_ok));
}

static NAN_METHOD(IsROISensor) {
Expand Down Expand Up @@ -4784,6 +4786,56 @@ void InitModule(v8::Local<v8::Object> exports) {
_FORCE_SET_ENUM(RS2_PLAYBACK_STATUS_PAUSED);
_FORCE_SET_ENUM(RS2_PLAYBACK_STATUS_STOPPED);
_FORCE_SET_ENUM(RS2_PLAYBACK_STATUS_COUNT);


// rs2_extension
_FORCE_SET_ENUM(RS2_EXTENSION_UNKNOWN);
_FORCE_SET_ENUM(RS2_EXTENSION_DEBUG);
_FORCE_SET_ENUM(RS2_EXTENSION_INFO);
_FORCE_SET_ENUM(RS2_EXTENSION_MOTION);
_FORCE_SET_ENUM(RS2_EXTENSION_OPTIONS);
_FORCE_SET_ENUM(RS2_EXTENSION_VIDEO);
_FORCE_SET_ENUM(RS2_EXTENSION_ROI);
_FORCE_SET_ENUM(RS2_EXTENSION_DEPTH_SENSOR);
_FORCE_SET_ENUM(RS2_EXTENSION_VIDEO_FRAME);
_FORCE_SET_ENUM(RS2_EXTENSION_MOTION_FRAME);
_FORCE_SET_ENUM(RS2_EXTENSION_COMPOSITE_FRAME);
_FORCE_SET_ENUM(RS2_EXTENSION_POINTS);
_FORCE_SET_ENUM(RS2_EXTENSION_DEPTH_FRAME);
_FORCE_SET_ENUM(RS2_EXTENSION_ADVANCED_MODE);
_FORCE_SET_ENUM(RS2_EXTENSION_RECORD);
_FORCE_SET_ENUM(RS2_EXTENSION_VIDEO_PROFILE);
_FORCE_SET_ENUM(RS2_EXTENSION_PLAYBACK);
_FORCE_SET_ENUM(RS2_EXTENSION_DEPTH_STEREO_SENSOR);
_FORCE_SET_ENUM(RS2_EXTENSION_DISPARITY_FRAME);
_FORCE_SET_ENUM(RS2_EXTENSION_MOTION_PROFILE);
_FORCE_SET_ENUM(RS2_EXTENSION_POSE_FRAME);
_FORCE_SET_ENUM(RS2_EXTENSION_POSE_PROFILE);
_FORCE_SET_ENUM(RS2_EXTENSION_TM2);
_FORCE_SET_ENUM(RS2_EXTENSION_SOFTWARE_DEVICE);
_FORCE_SET_ENUM(RS2_EXTENSION_SOFTWARE_SENSOR);
_FORCE_SET_ENUM(RS2_EXTENSION_DECIMATION_FILTER);
_FORCE_SET_ENUM(RS2_EXTENSION_THRESHOLD_FILTER);
_FORCE_SET_ENUM(RS2_EXTENSION_DISPARITY_FILTER);
_FORCE_SET_ENUM(RS2_EXTENSION_SPATIAL_FILTER);
_FORCE_SET_ENUM(RS2_EXTENSION_TEMPORAL_FILTER);
_FORCE_SET_ENUM(RS2_EXTENSION_HOLE_FILLING_FILTER);
_FORCE_SET_ENUM(RS2_EXTENSION_ZERO_ORDER_FILTER);
_FORCE_SET_ENUM(RS2_EXTENSION_RECOMMENDED_FILTERS);
_FORCE_SET_ENUM(RS2_EXTENSION_POSE);
_FORCE_SET_ENUM(RS2_EXTENSION_POSE_SENSOR);
_FORCE_SET_ENUM(RS2_EXTENSION_WHEEL_ODOMETER);
_FORCE_SET_ENUM(RS2_EXTENSION_GLOBAL_TIMER);
_FORCE_SET_ENUM(RS2_EXTENSION_UPDATABLE);
_FORCE_SET_ENUM(RS2_EXTENSION_UPDATE_DEVICE);
_FORCE_SET_ENUM(RS2_EXTENSION_L500_DEPTH_SENSOR);
_FORCE_SET_ENUM(RS2_EXTENSION_TM2_SENSOR);
_FORCE_SET_ENUM(RS2_EXTENSION_AUTO_CALIBRATED_DEVICE);
_FORCE_SET_ENUM(RS2_EXTENSION_COLOR_SENSOR);
_FORCE_SET_ENUM(RS2_EXTENSION_MOTION_SENSOR);
_FORCE_SET_ENUM(RS2_EXTENSION_FISHEYE_SENSOR);
_FORCE_SET_ENUM(RS2_EXTENSION_COUNT);

}

NODE_MODULE(node_librealsense, InitModule);
109 changes: 109 additions & 0 deletions wrappers/nodejs/test/test-sensor-extensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Copyright (c) 2017 Intel Corporation. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license
// that can be found in the LICENSE file.

'use strict';
/* global describe, it, before, after */
const assert = require('assert');
let rs2;
let pipeline;
try {
rs2 = require('node-librealsense');
} catch (e) {
rs2 = require('../index.js');
}

let device;
let frameset;
let dev_info;
let motion_product_list = ["0AD5", "0AFE", "0AFF", "0B00", "0B01", "0B3A", "0B3D"];
const ctx = new rs2.Context();
let devices = ctx.queryDevices().devices;
assert(devices.length > 0); // Device must be connected
device = devices[0]
dev_info = device.getCameraInfo();


describe('Sensor extensions test', function() {
before(function() {
// const ctx = new rs2.Context();
// let devices = ctx.queryDevices().devices;
// assert(devices.length > 0); // Device must be connected
// device = devices[0]
// dev_info = device.getCameraInfo();
});

after(function() {
rs2.cleanup();
});

it('Testing constructor - 0 argument', () => {
assert.throws(() => {
new rs2.Align();
});
});

it('Testing ColorSensor extention', () => {
var products_list = ["0AA5, 0B48, 0AD3, 0AD4, 0AD5, 0B01, 0B07, 0B3A, 0B3D"];
let rtn = device.getCameraInfo();
if (products_list.includes(rtn.productId))
{
const sensors = device.querySensors();
let is_found = false;
for (let i = 0; i < sensors.length; i++) {
if (sensors[i] instanceof rs2.ColorSensor) {
const sensor = sensors[i];
const profile = sensor.getStreamProfiles()[0];
assert(profile.streamType === rs2.stream.STREAM_COLOR && profile.format == rs2.format.FORMAT_RGB8);
is_found = true;
}
}
assert(is_found);
}
});

it('Testing FisheyeSensor extention', () => {
var products_list = ["0AD5", "0AFE", "0AFF", "0B00", "0B01"];
let rtn = device.getCameraInfo();
if (products_list.includes(rtn.productId))
{
const sensors = device.querySensors();
let is_found = false;
for (let i = 0; i < sensors.length; i++) {
if (sensors[i] instanceof rs2.FisheyeSensor) {
const sensor = sensors[i];
const profile = sensor.getStreamProfiles()[0];
assert(profile.streamType === rs2.stream.STREAM_COLOR && profile.format == rs2.format.FORMAT_RGB8);
is_found = true;
}
}
assert(is_found);

}
});

if (motion_product_list.includes(dev_info.productId))
{
it('Testing MotionSensor extention', () => {
var products_list = ["0AD5", "0AFE", "0AFF", "0B00", "0B01", "0B3A", "0B3D"];
let rtn = device.getCameraInfo();
if (products_list.includes(rtn.productId))
{
const sensors = device.querySensors();
let is_found = false;
for (let i = 0; i < sensors.length; i++) {
if (sensors[i] instanceof rs2.MotionSensor) {
const sensor = sensors[i];
const profile = sensor.getStreamProfiles()[0];
assert([rs2.stream.STREAM_GYRO, rs2.stream.STREAM_ACCEL].includes(profile.streamType))
assert([rs2.format.FORMAT_MOTION_RAW, rs2.format.FORMAT_MOTION_XYZ32F].includes(profile.format));
is_found = true;
}
}
assert(is_found);

}
});
};

});

0 comments on commit 936a22b

Please sign in to comment.