AForge.Video.Kinect.Kinect.SetMotorTilt C# (CSharp) Method

SetMotorTilt() public method

Set motor's tilt value.
Motor tilt has to be in the [-31, 31] range. Some error occurred with the device. Check error message.
public SetMotorTilt ( int angle ) : void
angle int Tilt value to set, [-31, 30] degrees.
return void
        public void SetMotorTilt( int angle )
        {
            lock ( sync )
            {
                CheckDevice( );

                // check if value is in valid range
                if ( ( angle < -31 ) || ( angle > 31 ) )
                {
                    throw new ArgumentOutOfRangeException( "angle", "Motor tilt has to be in the [-31, 31] range." );
                }

                int result = KinectNative.freenect_set_tilt_degs( rawDevice, angle );
                if ( result != 0 )
                {
                    throw new DeviceErrorException( "Failed setting motor tilt. Error code: " + result );
                }
            }
        }

Usage Example

Beispiel #1
0
        // Connect to Kinect cameras
        private bool Connect()
        {
            bool ret = false;

            Cursor = Cursors.WaitCursor;

            if (Kinect.DeviceCount != 0)
            {
                int deviceID = devicesCombo.SelectedIndex;

                try
                {
                    kinectDevice = Kinect.GetDevice(deviceID);

                    if (videoCamera == null)
                    {
                        videoCamera = kinectDevice.GetVideoCamera();
                        videoCamera.CameraMode = (videoModeCombo.SelectedIndex == 0) ? VideoCameraMode.Color :
                            ((videoModeCombo.SelectedIndex == 1) ? VideoCameraMode.Bayer : VideoCameraMode.InfraRed);
                        videoCameraPlayer.VideoSource = videoCamera;
                        videoCameraPlayer.Start();
                    }

                    if (depthCamera == null)
                    {
                        depthCamera = kinectDevice.GetDepthCamera();
                        depthCameraPlayer.VideoSource = depthCamera;
                        depthCameraPlayer.Start();
                    }

                    ledColorCombo.SelectedIndex = 0;

                    if (tiltUpDown.Value != 0)
                    {
                        tiltUpDown.Value = 0;
                    }
                    else
                    {
                        kinectDevice.SetMotorTilt((int)tiltUpDown.Value);
                    }

                    timer.Start();

                    ret = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed connecting to Kinect device.\n" + ex.Message,
                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    Disconnect();
                }
            }

            Cursor = Cursors.Default;

            return ret;
        }