예제 #1
0
파일: SVS.cs 프로젝트: EnergonV/BestCS
 /// <summary>
 /// Set video resolution for both cameras.
 /// </summary>
 /// 
 /// <param name="resolution">Video resolution to set.</param>
 /// 
 /// <remarks>
 /// <para><note>Setting higher <see cref="SetQuality">quality level</see> and resolution
 /// may increase delays for other requests sent to SVS. So if
 /// robot is used not only for video, but also for controlling servos/motors, and higher
 /// response level is required, then do not set very high quality and resolution.
 /// </note></para>
 /// </remarks>
 /// 
 /// <exception cref="NotConnectedException">Not connected to SVS. Connect to SVS board before using
 /// this method.</exception>
 /// 
 public void SetResolution( SRV1.VideoResolution resolution )
 {
     SafeGetCommunicator1( ).SetResolution( resolution );
     SafeGetCommunicator2( ).SetResolution( resolution );
 }
예제 #2
0
파일: SVS.cs 프로젝트: EnergonV/BestCS
        /// <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;
                    }
                }
            }
        }
예제 #3
0
파일: SVS.cs 프로젝트: EnergonV/BestCS
 /// <summary>
 /// Control motors connected to SVS board using predefined commands.
 /// </summary>
 /// 
 /// <param name="command">Motor command to send to the SVS board.</param>
 /// 
 /// <remarks><para><note>Controlling SVS motors with this method is only available
 /// after at least one direct motor command is sent, which is done using <see cref="StopMotors"/> or
 /// <see cref="RunMotors"/> methods.</note></para></remarks>
 /// 
 /// <exception cref="NotConnectedException">Not connected to SVS. Connect to SVS board before using
 /// this method.</exception>
 /// 
 public void ControlMotors( SRV1.MotorCommand command )
 {
     SafeGetCommunicator1( ).ControlMotors( command );
 }
예제 #4
0
파일: SVS.cs 프로젝트: EnergonV/BestCS
        /// <summary>
        /// Connect to SVS board.
        /// </summary>
        /// 
        /// <param name="ipAddress">IP address of SVS board.</param>
        /// 
        /// <remarks><para>The method establishes connection to SVS board. If it succeeds then
        /// other methods can be used to manipulate the board.</para>
        /// 
        /// <para><note>The method calls <see cref="Disconnect"/> before making any connection
        /// attempts to make sure previous connection is closed.</note></para>
        /// </remarks>
        /// 
        /// <exception cref="ConnectionFailedException">Failed connecting to SVS.</exception>
        /// 
        public void Connect( string ipAddress )
        {
            // close previous connection
            Disconnect( );

            lock ( sync1 )
            {
                lock ( sync2 )
                {
                    try
                    {
                        communicator1 = new SRV1( );
                        communicator2 = new SRV1( );

                        communicator1.Connect( ipAddress, 10001 );
                        communicator2.Connect( ipAddress, 10002 );

                        hostAddress = ipAddress;
                    }
                    catch
                    {
                        Disconnect( );

                        throw new ConnectionFailedException( "Failed connecting to SVS." );
                    }
                }
            }
        }