Ejemplo n.º 1
0
        // Connect to SRV-1
        private bool Connect(string host, int port)
        {
            bool result = true;

            try
            {
                srv.Connect(host, port);
                srv.EnableFailsafeMode(0, 0);

                srv.FlipVideo(false);
                srv.SetQuality(7);
                srv.SetResolution(SRV1.VideoResolution.Small);

                // start left camera
                SRV1Camera camera = srv.GetCamera( );
                cameraPlayer.VideoSource = camera;
                cameraPlayer.Start( );

                versionLabel.Text           = srv.GetVersion( );
                receivedFirstDrivingCommand = false;

                // reset statistics
                statIndex = statReady = 0;

                // start timer
                timer.Start( );
            }
            catch
            {
                result = false;
                Disconnect( );
            }

            return(result);
        }
Ejemplo n.º 2
0
        // Connect to SVS
        private bool Connect(string host)
        {
            bool result = true;

            try
            {
                svs.Connect(host);
                svs.EnableFailsafeMode(0, 0);

                svs.FlipVideo(false);
                svs.SetQuality(7);
                svs.SetResolution(SRV1.VideoResolution.Small);

                // start left camera
                SRV1Camera leftCamera = svs.GetCamera(SVS.Camera.Left);
                leftCameraPlayer.VideoSource = leftCamera;
                leftCameraPlayer.Start( );

                // start right camera
                SRV1Camera rightCamera = svs.GetCamera(SVS.Camera.Right);
                rightCameraPlayer.VideoSource = rightCamera;
                rightCameraPlayer.Start( );

                versionLabel.Text           = svs.GetVersion( );
                receivedFirstDrivingCommand = false;

                // reset statistics
                statIndex = statReady = 0;

                // start timer
                timer.Start( );
            }
            catch
            {
                result = false;
                Disconnect( );
            }

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get SVS's camera.
        /// </summary>
        /// 
        /// <param name="camera">SVS camera to get.</param>
        /// 
        /// <returns>Returns <see cref="SRV1Camera"/> object, which is connected to SVS's Blackfin camera.
        /// Use <see cref="SRV1Camera.Start"/> method to start the camera and start receiving video
        /// frames from it.</returns>
        /// 
        /// <remarks><para>The method provides an instance of <see cref="SRV1Camera"/>, which can be used
        /// for receiving continuous video frames from the SVS board.
        /// In the case if only one image is required, the <see cref="GetImage"/> method can be used.</para>
        /// 
        /// <para>Sample usage:</para>
        /// <code>
        /// // get SRV-1 camera
        /// SRV1Camera camera = svs.GetCamera( SVS.Camera.Left );
        /// // set NewFrame event handler
        /// camera.NewFrame += new NewFrameEventHandler( video_NewFrame );
        /// // start the video source
        /// camera.Start( );
        /// // ...
        /// 
        /// private void video_NewFrame( object sender, NewFrameEventArgs eventArgs )
        /// {
        ///     // get new frame
        ///     Bitmap bitmap = eventArgs.Frame;
        ///     // process the frame
        /// }
        /// </code>
        /// </remarks>
        /// 
        /// <exception cref="NotConnectedException">Not connected to SVS. Connect to SVS board before using
        /// this method.</exception>
        /// 
        public SRV1Camera GetCamera( Camera camera )
        {
            if ( camera == Camera.Left )
            {
                if ( leftCamera == null )
                {
                    leftCamera = SafeGetCommunicator1( ).GetCamera( );
                }
                return leftCamera;
            }

            if ( rightCamera == null )
            {
                rightCamera = SafeGetCommunicator2( ).GetCamera( );
            }
            return rightCamera;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Disconnect from SVS device.
        /// </summary>
        /// 
        /// <remarks><para>The method disconnects from SVS board making all other methods
        /// unavailable (except <see cref="Connect"/> method). In the case if user
        /// obtained instance of left or right camera using <see cref="GetCamera"/>
        /// method, the video will be stopped automatically (and those <see cref="SRV1Camera"/>
        /// instances should be discarded).
        /// </para></remarks>
        /// 
        public void Disconnect( )
        {
            lock ( sync1 )
            {
                lock ( sync2 )
                {
                    hostAddress = null;

                    // signal cameras to stop
                    if ( leftCamera != null )
                    {
                        leftCamera.SignalToStop( );
                    }
                    if ( rightCamera != null )
                    {
                        rightCamera.SignalToStop( );
                    }

                    // wait until cameras stop or abort them
                    if ( leftCamera != null )
                    {
                        // wait for aroung 250 ms
                        for ( int i = 0; ( i < 5 ) && ( leftCamera.IsRunning ); i++ )
                        {
                            System.Threading.Thread.Sleep( 50 );
                        }
                        // abort camera if it can not be stopped
                        if ( leftCamera.IsRunning )
                        {
                            leftCamera.Stop( );
                        }
                        leftCamera = null;
                    }
                    if ( rightCamera != null )
                    {
                        // wait for aroung 250 ms
                        for ( int i = 0; ( i < 5 ) && ( rightCamera.IsRunning ); i++ )
                        {
                            System.Threading.Thread.Sleep( 50 );
                        }
                        // abort camera if it can not be stopped
                        if ( rightCamera.IsRunning )
                        {
                            rightCamera.Stop( );
                        }
                        rightCamera = null;
                    }

                    if ( communicator1 != null )
                    {
                        communicator1.Disconnect( );
                        communicator1 = null;
                    }
                    if ( communicator2 != null )
                    {
                        communicator2.Disconnect( );
                        communicator2 = null;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get camera object for the SRV-1 Blackfin robot/camera.
        /// </summary>
        /// 
        /// <returns>Returns <see cref="SRV1Camera"/> object, which is connected to SRV1 Blackfin camera.
        /// Use <see cref="SRV1Camera.Start"/> method to start the camera and start receiving video
        /// frames it.</returns>
        /// 
        /// <remarks><para>The method provides an instance of <see cref="SRV1Camera"/>, which can be used
        /// for receiving continuous video frames from the SRV-1 Blackfin camera.
        /// In the case if only one image is required, the <see cref="GetImage"/> method can be used.</para>
        /// 
        /// <para>Sample usage:</para>
        /// <code>
        /// // get SRV-1 camera
        /// SRV1Camera camera = srv.GetCamera( );
        /// // set NewFrame event handler
        /// camera.NewFrame += new NewFrameEventHandler( video_NewFrame );
        /// // start the video source
        /// camera.Start( );
        /// // ...
        /// 
        /// private void video_NewFrame( object sender, NewFrameEventArgs eventArgs )
        /// {
        ///     // get new frame
        ///     Bitmap bitmap = eventArgs.Frame;
        ///     // process the frame
        /// }
        /// </code>
        /// </remarks>
        /// 
        /// <exception cref="NotConnectedException">Not connected to SRV-1. Connect to SRV-1 robot/camera
        /// before using this method.</exception>
        /// 
        public SRV1Camera GetCamera( )
        {
            lock ( sync )
            {
                if ( socket == null )
                {
                    // handle error
                    throw new NotConnectedException( "Not connected to SRV-1." );
                }

                if ( camera == null )
                {
                    camera = new SRV1Camera( this );
                }
                return camera;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Disconnect from SRV-1 Blackfin robot.
        /// </summary>
        /// 
        /// <remarks><para>The method disconnects from SRV-1 robot making all other methods
        /// unavailable (except <see cref="Connect"/> method). In the case if user
        /// obtained instance of camera using <see cref="GetCamera"/> method, the video will
        /// be stopped automatically (and those <see cref="SRV1Camera"/> instances should be discarded).
        /// </para></remarks>
        /// 
        public void Disconnect( )
        {
            lock ( sync )
            {
                if ( thread != null )
                {
                    // signal camera to stop
                    if ( camera != null )
                    {
                        camera.SignalToStop( );
                    }

                    // signal worker thread to stop
                    stopEvent.Set( );
                    requestIsAvailable.Set( );
                    replyIsAvailable.Set( );

                    // finilze the camera
                    if ( camera != null )
                    {
                        // wait for aroung 250 ms
                        for ( int i = 0; ( i < 5 ) && ( camera.IsRunning ); i++ )
                        {
                            System.Threading.Thread.Sleep( 50 );
                        }
                        // abort camera if it can not be stopped
                        if ( camera.IsRunning )
                        {
                            camera.Stop( );
                        }
                        camera = null;
                    }

                    // wait for aroung 1 s
                    for ( int i = 0; ( i < 20 ) && ( thread.Join( 0 ) == false ); i++ )
                    {
                        System.Threading.Thread.Sleep( 50 );
                    }
                    // abort thread if it can not be stopped
                    if ( thread.Join( 0 ) == false )
                    {
                        thread.Abort( );
                    }

                    thread = null;

                    // release events
                    stopEvent.Close( );
                    stopEvent = null;

                    requestIsAvailable.Close( );
                    requestIsAvailable = null;

                    replyIsAvailable.Close( );
                    replyIsAvailable = null;
                }

                if ( socket != null )
                {
                    if ( socket.Connected )
                    {
                        socket.Disconnect( false );
                    }
                    socket.Close( );
                    socket = null;
                    endPoint = null;
                }
            }
        }