kinectkinect-sdkkinect-interaction

Setting Kinect's ElevationAngle randomly throws COM based InvalidOperationException


I'm working on the Kinect tilt control (similar to those in the Kinect Explorer toolkit sample but composed just of a Scrollbar). This works well but setting the tilt angle:

CurrentKinectSensor.ElevationAngle = value;

causes randomly the System.InvalidOperationException caused by underlying COM:

This API has returned an exception from an HRESULT: 0x800704D5

System.InvalidOperationException was unhandled
HResult=-2146233079
Message=This API has returned an exception from an HRESULT: 0x800704D5
Source=Microsoft.Kinect
InnerException: System.Runtime.InteropServices.COMException
HResult=-2147023659
Message=The operation could not be completed. A retry should be performed. (Exception 
from HRESULT: 0x800704D5)
ErrorCode=-2147023659
InnerException: 

I can deal with it only by handling the exception but I do not exactly understand what is the reason.

So far I found that it is somehow related to the fact of setting the new value of the ElevationAngle property before the Kinect finishes physical tilt of the previous change of the Kinect controller.

It increases the probability of the exception to be thrown - in other words if you set the ElevationAngle property too frequently, the exception occurs.

The minimum acceptable delay between setting the ElevationAngle was tested to be about 750ms but I guess it depends on the angle to be changed as it may last longer.

How do I know that the Kinect sensor has finished its physical tilting operation and is ready for the next one?


Solution

  • There is no way you can tell when the Kinect is finished tilting but you are overseeing one time. MSDN says the following

    To reduce wear, your application should change the elevation angle no more than once per second. In addition, you must allow at least 20 seconds of rest after 15 consecutive changes.

    So the error can be throw in two situations, either by changing the values to fast after one another or not letting the camera rest after 15 ways.

    Just ALWAYS put a try-catch around the getter/setter of the Kinect Angle.