AForge.Robotics.Surveyor
Manipulation of Surveyor SRV-1 Blackfin robot/camera.
The class allows to manipulate with Surveyor SRV-1 Blackfin Robot
- getting video from its camera, manipulating motors and servos,
reading ultrasonic modules' values, sending direct commands, etc.
Sample usage:
SRV1 srv = new SRV1( );
// connect to SRV-1 robot
srv.Connect( "169.254.0.10", 10001 );
// stop motors
srv.StopMotors( );
// set video resolution and quality
srv.SetQuality( 7 );
srv.SetResolution( SRV1.VideoResolution.Small );
// get version string
string version = srv.GetVersion( );
// get robot's 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
}
Enumeration of predefined motors' commands.
This enumeration defines set of motors' commands, which can
be executed using method.
Controlling SRV-1 motors with these commands is only possible
after at least one direct motor command is sent, which is done using or
methods.
The IncreaseSpeed and DecreaseSpeed commands do not have any effect
unless another driving command is sent. In other words, these do not increase/decrease speed of
current operation, but affect speed of all following commands.
The RotateLeft and RotateRight commands may be useful only for the original
Surveyor SRV-1 Blackfin Robot.
For most of other robots, which may have different motors and moving base, these commands
will not be accurate – will not rotate for 20 degrees.
Robot drive forward.
Robot drive back.
Robot drive left.
Robot drive right.
Robot drift left.
Robot drift right.
Robot stop.
Robot drive back and right.
Robot drive back and left.
Robot rotate left 20 degrees.
Robot rotate right 20 degrees.
Increase motors' speed.
Decrease motors' speed.
Enumeration of Surveyor SRV-1 Blackfin cameras resolutions.
160x120
320x240
640x480
1280x1024
SRV-1 host address.
The property keeps SRV-1 IP address if the class is connected
to SRV-1 Blackfin robot/camera, otherwise it equals to .
SRV-1 port number.
The property keeps SRV-1 port number if the class is connected
to SRV-1 Blackfin robot/camera, otherwise it equals to 0.
Connection state.
The property equals to if the class is connected
to SRV-1 Blackfin robot/camera, otherwise it equals to .
The property is not updated by the class, when connection was lost or
communication failure was detected (which results into
exception). The property only shows status of method.
Initializes a new instance of the class.
Connect to SRV-1 Blackfin robot/camera.
IP address of SRV-1 robot.
Port number to connect to.
The method establishes connection to SRV-1 Blackfin robot/camera.
If it succeeds then other methods can be used to manipulate the robot.
The method calls before making any connection
attempts to make sure previous connection is closed.
Failed connecting to SRV-1.
Disconnect from SRV-1 Blackfin robot.
The method disconnects from SRV-1 robot making all other methods
unavailable (except method). In the case if user
obtained instance of camera using method, the video will
be stopped automatically (and those instances should be discarded).
Get camera object for the SRV-1 Blackfin robot/camera.
Returns object, which is connected to SRV1 Blackfin camera.
Use method to start the camera and start receiving video
frames it.
The method provides an instance of , 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 method can be used.
Sample usage:
// 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
}
Not connected to SRV-1. Connect to SRV-1 robot/camera
before using this method.
Enqueue communication request.
Array of bytes (command) to send to SRV-1 Blackfin robot/camera.
The method puts specified command into communication queue and leaves
immediately. Once internal communication thread becomes free from sending/receiving previous
commands/replies, it will send the queued command.
The method is useful for those SRV-1 commands, which does not assume any response data
in the command's reply.
Since the method only queues a communication request, it does not provide any status
of request's delivery and it does not generate any exceptions on failure.
Enqueue communication request and wait for reply.
Array of bytes (command) to send to SRV-1 Blackfin robot/camera.
Buffer to read response into.
Returns total bytes read into the response buffer.
The method puts specified command into communication queue and waits until
the command is sent to SRV-1 Blackfin robot and reply is received.
If SRV-1 responds with more data than response buffer can fit, then
the response buffer will take all the data it can store, but the rest of response
will be discarded. The only exception is image request - if response buffer is too
small to fit image response, then exception
is thrown. It is user's responsibility to provide response buffer of the correct
size. Check definition of the SRV-1
Control Protocol for information about supported commands and responses.
Not connected to SRV-1.
Connection lost or communicaton failure.
Response buffer is too small.
Get single image from the SRV-1 Blackfin camera.
Returns image received from the SRV-1 Blackfin camera or
if failed decoding provided response.
The method provides single video frame retrieved from the SRV-1 Blackfin
camera. However in many cases it is required to receive video frames one after another, so
the method is more preferred for continuous video frames.
Not connected to SRV-1. Connect to SRV-1 before using
this method.
Connection lost or communicaton failure. Try to reconnect.
Get SRV-1 firmware version string.
Returns SRV-1 version string.
Not connected to SRV-1. Connect to SRV-1 before using
this method.
Connection lost or communicaton failure. Try to reconnect.
Get SRV-1 running time.
Returns SRV-1 running time in milliseconds.
Not connected to SRV-1. Connect to SRV-1 before using
this method.
Connection lost or communicaton failure. Try to reconnect.
Failed parsing response from SRV-1.
Run motors connected to SRV-1 robot.
Left motor's speed, [-127, 127].
Right motor's speed, [-127, 127].
Time duration to run motors measured in number
of 10 milliseconds (0 for infinity), [0, 255].
The method provides direct access to motors setting specified,
speed to both motors connected to the SRV-1 robot. The maximum absolute speed
equals to 127, but the sign specifies direction of motor's rotation (forward or backward).
The method sends 'Mabc' SRV-1 command (see SRV-1
Control Protocol), which uses 2nd and 3rd timers for
controlling motors/servos.
Stop both motors.
The method stops both motors connected to the SRV-1 robot by calling
method specifying 0 for motors' speed.
Enables fail safe mode - setting motors' speed after timeout.
Left motor's speed, [-127, 127].
Right motor's speed, [-127, 127].
In the case if fail safe mode is enabled and no commands are received
by SRV-1 robot withing 2 seconds, motors' speed will be set to the specified values. The command
is very useful to instruct robot to stop if no other commands were sent
within 2 last seconds (probably lost connection).
Disable fail safe mode.
The method disable fail safe mode, which was set using
method.
Direct servos control of SRV-1 robot.
Left servo setting, [0, 100].
Right servo setting, [0, 100].
Servo settings represent timing pulse widths ranging
from 1ms to 2ms. 0 corresponds to a 1ms pulse, 100 corresponds to a 2ms pulse,
and 50 is midrange with a 1.5ms pulse.
The method sends 'sab' SRV-1 command (see SRV-1
Control Protocol), which controls 2nd bank of servos
using 6th and 7th timers.
Control SRV-1 robot's motors using predefined commands.
Motor command to send to the SRV-1 Blackfin robot.
Controlling SRV-1 motors with this method is only available
after at least one direct motor command is sent, which is done using or
methods.
Set video quality.
Video quality to set, [1, 8].
The method sets video quality, which is specified in [1, 8] range - 1 is
the highest quality level, 8 is the lowest quality level.
Setting higher quality level and resolution
may increase delays for other requests sent to SRV-1. 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.
Invalid quality level was specified.
Set video resolution.
Video resolution to set.
Setting higher quality level and resolution
may increase delays for other requests sent to SRV-1. 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.
Invalid resolution was specified.
Flip video capture or not (for use with upside-down camera).
Specifies if video should be flipped (),
or not ().
Ping ultrasonic ranging modules.
Returns array of ranges (distances) obtained from ultrasonic sensors. The ranges
are measured in inches.
The method sends 'p' SRV-1 command (see SRV-1
Control Protocol), which gets values from ultrasonic ranging modules attached to
pins 27, 28, 29, 30 with trigger on pin 18. Supports Maxbotics EZ0 and EZ1 ultrasonic modules.
Not connected to SRV-1. Connect to SRV-1 before using
this method.
Connection lost or communicaton failure. Try to reconnect.
Failed parsing response from SRV-1.
Read byte from I2C device.
I2C device ID (7 bit notation).
I2C device register to read.
Returns byte read from the specified register of the specified I2C device.
The IC2 device ID should be specified in 7 bit notation. This means that low bit of the ID
is not used for specifying read/write mode as in 8 bit notation. For example, if I2C device IDs are 0x44 for reading
and 0x45 for writing in 8 bit notation, then it equals to 0x22 device ID in 7 bit notation.
Not connected to SRV-1. Connect to SRV-1 before using
this method.
Connection lost or communicaton failure. Try to reconnect.
Failed parsing response from SRV-1.
Read word from I2C device.
I2C device ID (7 bit notation).
I2C device register to read.
Returns word read from the specified register of the specified I2C device.
The IC2 device ID should be specified in 7 bit notation. This means that low bit of the ID
is not used for specifying read/write mode as in 8 bit notation. For example, if I2C device IDs are 0x44 for reading
and 0x45 for writing in 8 bit notation, then it equals to 0x22 device ID in 7 bit notation.
Not connected to SRV-1. Connect to SRV-1 before using
this method.
Connection lost or communicaton failure. Try to reconnect.
Failed parsing response from SRV-1.
Write byte to I2C device.
I2C device ID (7 bit notation).
I2C device register to write to.
Byte to write to the specified register of the specified device.
The IC2 device ID should be specified in 7 bit notation. This means that low bit of the ID
is not used for specifying read/write mode as in 8 bit notation. For example, if I2C device IDs are 0x44 for reading
and 0x45 for writing in 8 bit notation, then it equals to 0x22 device ID in 7 bit notation.
Not connected to SRV-1. Connect to SRV-1 before using
this method.
Connection lost or communicaton failure. Try to reconnect.
Write two bytes to I2C device.
I2C device ID (7 bit notation).
I2C device register to write to.
First byte to write to the specified register of the specified device.
Second byte to write to the specified register of the specified device.
The IC2 device ID should be specified in 7 bit notation. This means that low bit of the ID
is not used for specifying read/write mode as in 8 bit notation. For example, if I2C device IDs are 0x44 for reading
and 0x45 for writing in 8 bit notation, then it equals to 0x22 device ID in 7 bit notation.
Not connected to SRV-1. Connect to SRV-1 before using
this method.
Connection lost or communicaton failure. Try to reconnect.
Provides access to video stream from Surveyor SRV-1 Blackfin camera.
The class allows to continuously receive video frames from
Surveyor SRV-1 Blackfin camera. It creates a background thread and periodically requests
new video frames from SRV-1 robot/camera, which are provided to user through
event. The video frame rate can be configured using
property, which sets time interval between frames.
In order to get instance of this class, use
or methods.
Sample usage:
// get SRV-1 camera
SRV1Camera camera = srv.GetCamera( );
// in the case you work with Surveyor SVS board
// the next line can be use
// 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
}
New frame event.
Notifies clients about new available frame from video source.
Since video source may have multiple clients, each client is responsible for
making a copy (cloning) of the passed video frame, because the video source disposes its
own original copy after notifying of clients.
Video source error event.
This event is used to notify clients about any type of errors occurred in
video source object, for example internal exceptions.
Video playing finished event.
This event is used to notify clients that the video playing has finished.
Frame interval.
The property sets the interval in milliseconds betwen frames. If the property is
set to 100, then the desired frame rate will be 10 frames per second.
Default value is set to 0 - get new frames as fast as possible.
Video source string.
The property keeps connection string, which was used to connect to SRV-1 Blackfin camera.
Received frames count.
Number of frames the video source provided from the moment of the last
access to the property.
Received bytes count.
Number of bytes the video source provided from the moment of the last
access to the property.
State of the video source.
Current state of video source object - running or not.
Start video source.
Starts video source and return execution to caller. Video source
object creates background thread and notifies about new frames with the
help of event.
Not connected to SRV-1. Connection to SRV-1
was closed using method. New
instance must be obtained using or
methods.
Signal video source to stop its work.
Signals video source to stop its background thread, stop to
provide new frames and free resources.
Wait for video source has stopped.
Waits for video source stopping after it was signalled to stop using
method.
Stop video source.
Stops video source aborting its thread.
Since the method aborts background thread, its usage is highly not preferred
and should be done only if there are no other options. The correct way of stopping camera
is signaling it to stop and then
waiting for background thread's completion.
Free resource.
Set video quality.
Video quality to set, [1, 8].
The method sets video quality, which is specified in [1, 8] range - 1 is
the highest quality level, 8 is the lowest quality level.
Setting higher quality level and resolution
may increase delays for other requests processed by class. 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.
Invalid quality level was specified.
Set video resolution.
Video resolution to set.
Setting higher quality level and resolution
may increase delays for other requests processed by class. 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.
Flip video capture or not (for use with upside-down camera).
Specifies if video should be flipped (),
or not ().
Worker thread.
Manipulation of Surveyor SVS (Stereo Vision System) board.
The class allows to manipulate with Surveyor SVS
board (stereo vision system) - getting video from both cameras, manipulating motors and servos,
reading ultrasonic modules' values, sending direct commands, etc.
This class essentially creates to instances of class to communicate
with both SVS's cameras (ports 10001 and 10002 are used) and directs all calls through them.
Sample usage:
SVS svs = new SVS( );
// connect to SVS board
svs.Connect( "169.254.0.10" );
// stop motors
svs.StopMotors( );
// set video resolution and quality
svs.SetQuality( 7 );
svs.SetResolution( SRV1.VideoResolution.Small );
// get version string
string version = svs.GetVersion( );
// get left 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
}
Enumeration of SVS's Blackfin cameras.
Since SVS board consists of two SRV-1 Blackfin cameras, the enumeration
is used by different methods to specify which one to access.
Left camera (default port number is 10000).
Right camera (default port number is 10001).
Enumeration of SVS's servos' banks.
First bank of the first () SRV-1 Blackfin camera,
timers 2 and 3 (marked as TMR2-1 and TMR3-1 on the SVS board). Note: these
timers on SVS board are supposed for controlling motors by default
(see and ), so use 0th
servos bank only when you've done proper configuration changes on SVS side.
Second bank of the first () SRV-1 Blackfin camera,
timers 6 and 7 (marked as TMR6-1 and TMR7-1 on the SVS board).
First bank of the second () SRV-1 Blackfin camera,
timers 2 and 3 (marked as TMR2-2 and TMR3-2 on the SVS board).
Second bank of the second () SRV-1 Blackfin camera,
timers 6 and 7 (marked as TMR6-2 and TMR7-2 on the SVS board).
SVS's host address.
The property keeps SVS's IP address if the class is connected
to SVS board, otherwise it equals to .
Connection state.
The property equals to if the class is connected
to SVS board, otherwise it equals to .
The property is not updated by the class, when connection was lost or
communication failure was detected (which results into
exception). The property only shows status of method.
Initializes a new instance of the class.
Connect to SVS board.
IP address of SVS board.
The method establishes connection to SVS board. If it succeeds then
other methods can be used to manipulate the board.
The method calls before making any connection
attempts to make sure previous connection is closed.
Failed connecting to SVS.
Disconnect from SVS device.
The method disconnects from SVS board making all other methods
unavailable (except method). In the case if user
obtained instance of left or right camera using
method, the video will be stopped automatically (and those
instances should be discarded).
Get SVS's camera.
SVS camera to get.
Returns object, which is connected to SVS's Blackfin camera.
Use method to start the camera and start receiving video
frames from it.
The method provides an instance of , which can be used
for receiving continuous video frames from the SVS board.
In the case if only one image is required, the method can be used.
Sample usage:
// 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
}
Not connected to SVS. Connect to SVS board before using
this method.
Get single image from the SVS board.
Camera to get image from.
Returns image received from the specified camera of the SVS board or
if failed decoding provided response.
The method provides single video frame retrieved from the specified SVS's
camera. However in many cases it is required to receive video frames one after another, so
the method is more preferred for continuous video frames.
Not connected to SRV-1. Connect to SRV-1 before using
this method.
Connection lost or communicaton failure. Try to reconnect.
Get direct access to one of the SVS's SRV-1 Blackfin cameras.
SRV-1 Blackfin to get direct access to.
Returns object connected to the requested
SRV-1 Blackfin camera.
The method provides direct access to one of the SVS's SRV-1
Blackfin cameras, so it could be possible to send some direct commands to it
using and methods.
Not connected to SVS. Connect to SVS board before using
this method.
Get SVS board's firmware version string.
Returns SVS's version string.
Not connected to SVS. Connect to SVS board before using
this method.
Connection lost or communicaton failure. Try to reconnect.
Get SVS's board's running time.
Returns SVS boards running time in milliseconds.
Not connected to SVS. Connect to SVS board before using
this method.
Connection lost or communicaton failure. Try to reconnect.
Failed parsing response from SVS.
Run motors connected to the SVS board.
Left motor's speed, [-127, 127].
Right motor's speed, [-127, 127].
Time duration to run motors measured in number
of 10 milliseconds (0 for infinity), [0, 255].
The method sets specified speed to both motors connected to
the SVS board. The maximum absolute speed equals to 127, but the sign specifies
direction of motor's rotation (forward or backward).
Not connected to SVS. Connect to SVS board before using
this method.
Stop both motors.
The method stops both motors connected to the SVS board by calling
method specifying 0 for motors' speed.
Not connected to SVS. Connect to SVS board before using
this method.
Enables fail safe mode - setting motors' speed after timeout.
Left motor's speed, [-127, 127].
Right motor's speed, [-127, 127].
In the case if fail safe mode is enabled and no commands are received
by SVS robot withing 2 seconds, motors' speed will be set to the specified values. The command
is very useful to instruct robot to stop if no other commands were sent
within 2 last seconds (probably lost connection).
Not connected to SVS. Connect to SVS board before using
this method.
Disable fail safe mode.
The method disable fail safe mode, which was set using
method.
Not connected to SVS. Connect to SVS board before using
this method.
Control motors connected to SVS board using predefined commands.
Motor command to send to the SVS board.
Controlling SVS motors with this method is only available
after at least one direct motor command is sent, which is done using or
methods.
Not connected to SVS. Connect to SVS board before using
this method.
Direct servos control of the SVS board.
SVS's servo bank to control.
Left servo setting, [0, 100].
Right servo setting, [0, 100].
The method performs servos control of the SVS board.
For and
banks it calls method for the corresponding
SRV-1 Blackfin camera. In the case of or ,
the method sends 'Sab' SRV-1 command (see SRV-1
Control Protocol) to the appropriate SRV-1 Blackfin camera.
Not connected to SVS. Connect to SVS board before using
this method.
Ping ultrasonic ranging modules.
SRV-1 Blackfin camera to check ultrasonic modules values.
Returns array of ranges (distances) obtained from ultrasonic sensors. The ranges
are measured in inches.
The method calls for the specified
SRV-1 Blackfin camera.
Not connected to SVS. Connect to SVS board before using
this method.
Connection lost or communicaton failure. Try to reconnect.
Failed parsing response from SVS.
Read byte from I2C device.
SRV-1 Blackfin camera to access I2C device on.
I2C device ID (7 bit notation).
I2C device register to read.
Returns byte read from the specified register of the specified I2C device.
The IC2 device ID should be specified in 7 bit notation. This means that low bit of the ID
is not used for specifying read/write mode as in 8 bit notation. For example, if I2C device IDs are 0x44 for reading
and 0x45 for writing in 8 bit notation, then it equals to 0x22 device ID in 7 bit notation.
Not connected to SVS. Connect to SVS board before using
this method.
Connection lost or communicaton failure. Try to reconnect.
Failed parsing response from SRV-1.
Read word from I2C device.
SRV-1 Blackfin camera to access I2C device on.
I2C device ID (7 bit notation).
I2C device register to read.
Returns word read from the specified register of the specified I2C device.
The IC2 device ID should be specified in 7 bit notation. This means that low bit of the ID
is not used for specifying read/write mode as in 8 bit notation. For example, if I2C device IDs are 0x44 for reading
and 0x45 for writing in 8 bit notation, then it equals to 0x22 device ID in 7 bit notation.
Not connected to SVS. Connect to SVS board before using
this method.
Connection lost or communicaton failure. Try to reconnect.
Failed parsing response from SRV-1.
Write byte to I2C device.
SRV-1 Blackfin camera to access I2C device on.
I2C device ID (7 bit notation).
I2C device register to write to.
Byte to write to the specified register of the specified device.
The IC2 device ID should be specified in 7 bit notation. This means that low bit of the ID
is not used for specifying read/write mode as in 8 bit notation. For example, if I2C device IDs are 0x44 for reading
and 0x45 for writing in 8 bit notation, then it equals to 0x22 device ID in 7 bit notation.
Not connected to SVS. Connect to SVS board before using
this method.
Connection lost or communicaton failure. Try to reconnect.
Write two bytes to I2C device.
SRV-1 Blackfin camera to access I2C device on.
I2C device ID (7 bit notation).
I2C device register to write to.
First byte to write to the specified register of the specified device.
Second byte to write to the specified register of the specified device.
The IC2 device ID should be specified in 7 bit notation. This means that low bit of the ID
is not used for specifying read/write mode as in 8 bit notation. For example, if I2C device IDs are 0x44 for reading
and 0x45 for writing in 8 bit notation, then it equals to 0x22 device ID in 7 bit notation.
Not connected to SVS. Connect to SVS board before using
this method.
Connection lost or communicaton failure. Try to reconnect.
Set video quality for both cameras.
Video quality to set, [1, 8].
The method sets video quality for both SVS cameras, which is specified in [1, 8] range - 1 is
the highest quality level, 8 is the lowest quality level.
Setting higher quality level 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.
Not connected to SVS. Connect to SVS board before using
this method.
Invalid quality level was specified.
Set video resolution for both cameras.
Video resolution to set.
Setting higher quality level 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.
Not connected to SVS. Connect to SVS board before using
this method.
Flip video capture for both cameras or not (for use with upside-down camera).
Specifies if video should be flipped (),
or not ().
Not connected to SVS. Connect to SVS board before using
this method.