I am trying to move the motors of my Kinect. It looks pretty simple but it does not work and my app get frozen. I am doing it with Visual Studio 2013 and WPF, this is my code:
Code behind:
private void MotorSliderValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
Angle.Content = (int)MotorSlider.Value;
}
private void ButtonClick(object sender, RoutedEventArgs e)
{
sensor.ElevationAngle = (int)Angle.Content;
}
XAML:
<Slider x:Name="MotorSlider" HorizontalAlignment="Left" Height="23" Margin="10,10,0,0" Grid.Row="2" VerticalAlignment="Top" Width="262" Maximum="27" SmallChange="1" Minimum="-27" ValueChanged="MotorSliderValueChanged"/>
<Label x:Name="Angle" Content="0" HorizontalAlignment="Left" Height="32" Margin="277,10,0,0" Grid.Row="2" VerticalAlignment="Top" Width="43" FontSize="18"/>
<Button Content="Change angle" HorizontalAlignment="Left" Height="32" Margin="336,10,0,0" Grid.Row="2" VerticalAlignment="Top" Width="102" Click="ButtonClick"/>
Any clue why it gets freeze?, it drows an System.InvalidOperationException: This API has returned an exception from an HRESULT: 0x8007000D
Thank you.
This could be due a consequence of moving the motorized tilt too fast (i.e. setting too fast the ElevationAngle
property).
According to the official documentation:
You must allow at least 20 seconds of rest after 15 consecutive changes. If your application exceeds these limits, the tilt motor may experience a lock period during which attempting to set the elevation angle will result in an error code.
This is also confirmed in the "Community Additions" section of the same page:
If the tilt motor limits are exceeded and the runtime has locked the tilt motor to allow it to rest, attempts to access this property result in throwing an InvalidOperationException during the tilt motor lock period.
To solve this issue, I have seen in a sample from Microsoft (I do not remember which sample) that, after changing the ElevationAngle
property, they explicitly avoid any other changes of this property for a period of 1,35 seconds.
Furthermore, if you try to change the ElevationAngle
property while Kinect sensor is not running, you can obtain an InvalidOperationException
. From the same aforementioned page:
If the ElevationAngle property is accessed while the Kinect sensor is not running (i.e., the Start method has not been called), an InvalidOperationException will be thrown.
User contributions licensed under CC BY-SA 3.0