Check if a sensor is available?

Hello,

I am using the C# wrapper and if I do not have a sensor connected and call nuitrack.init(), Unity itself crashes. Is there a check I could implement to see if a sensor is available to better handle this error?

@olga.kuzminykh

That depends to a certain extent currently on the type of sensor you are using.
There is no code inside nuitrack that can allow you to do this.
In C++ we use the openNI SDK to check for current orbbec sensors - and the realsense SDK to check for current intel sensors. This is handled in our internal code - BEFORE - we make any calls to the nuitrack system.

BUT having said this - it seems to be a bug in nuitrack that would crash unity instead of reporting a capturable error - to do have your init() wrapped in a try/catch block?

Westa

1 Like

I am using the Orbbec Astra and I do have the init wrapped inside a try/catch block.

if you are using astra - then you would need to add openni support to unity and add your own code to test for any astra sensors before calling the nuitrack.init() function.

I dont have any unity code handy right now - but this is how we would do the testing in c++ - the concepts are basically the same.

	openni::Device device;
	openni::VideoStream depth, ir;
	const char* deviceURI = openni::ANY_DEVICE;
	openni::Status rc = openni::STATUS_OK;


	/////////////////////////////////////////////////////////////////////////
	// initialise openNI to see what sensor it detects
	rc = openni::OpenNI::initialize();

	rc = device.open(deviceURI);
	if (rc == openni::STATUS_OK)
	{

		const openni::DeviceInfo& thisDevice = device.getDeviceInfo();

		char sn[32] = { 0 };
		char type[32] = { 0 };
		char firmware[32] = { 0 };

		int size = 12;
		device.getProperty(openni::DEVICE_PROPERTY_SERIAL_NUMBER, sn, &size);

		size = 12;
		device.getProperty(openni::DEVICE_PROPERTY_FIRMWARE_VERSION, firmware, &size);

		std::cout << "OpenNI Dev: " << thisDevice.getName() << " Ser: " << sn << " Firmware: " << firmware << " ProdID " << thisDevice.getUsbProductId() << std::endl;

		device.close();

	}

Westa

2 Likes

Thank you so much for your help, Westa. Your contributions have been invaluable on this forum. I shall give it a try.