Elib 0.7
C# library for e-Puck robot
|
Sercom wraps serial communication with e-Puck. Main goal is to keep application responsive, although the used serial communication could be very unresponsive. More...
Classes | |
class | ansGuard |
ansGuard stores OkfCallback, KofCallback design especially for commands and uid for better identification and debugging | |
class | KofCallbackDef |
wraps the pair of Kofcallback and the arguments for Kofcallback functions | |
class | myQueue |
class | node |
class | OkfCallbackDef |
wraps the pair of Rcallback "f" and the arguments "data" for Rcallback functions | |
class | priorQueue |
Public Member Functions | |
Sercom (string portName, int serialPortWriteTimeout, int serialPortReadTimeout) | |
Initializes a new instance of the Sercom class. | |
Sercom (string portName) | |
Initializes a new instance of the Sercom class with default values. | |
void | Start () |
Opens the Bluetooth connection and turn the BTCom protocol on. | |
void | Write (string command, OkfCallback okf, KofCallback kof, object state, double timeout) |
Writes the specified command to notSent queue until it can be sent over serial connection. Each command waits until the commands before him arer sent and confirmed or their timeout elapses. /. | |
void | Dispose () |
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. It takes under 0.5 sec for e-Puck. | |
override string | ToString () |
Writes the characteristic of underlying SerialPort connection. | |
Public Attributes | |
const int | defWriteTimeout = 2000 |
Maximum of miliseconds, which are spent on unsuccessful writing to serial port. Default value in ms, which is set to SerialPort. If serial port can not write for defWriteTimeout in ms, than Elib exception is raised. | |
const int | defReadTimeout = SerialPort.InfiniteTimeout |
Default value. It is infinite, because the serial port do not have to contain any answer. | |
const string | Help = "\n\"A\" Accelerometer\r\n\"B,#\" Body led 0=off 1=on 2=inverse\r\n\"C\" Selector position\r\n\"D,#,#\" Set motor speed left,right\r\n\"E\" Get motor speed left,right\r\n\"F,#\" Front led 0=off 1=on 2=inverse\r\n\"G\" IR receiver\r\n\"H\"\t Help\r\n\"I\" Get camera parameter\r\n\"J,#,#,#,#\" Set camera parameter mode,width,heigth,zoom(1,4 or 8)\r\n\"K\" Calibrate proximity sensors\r\n\"L,#,#\" Led number,0=off 1=on 2=inverse\r\n\"N\" Proximity\r\n\"O\" Light sensors\r\n\"P,#,#\" Set motor position left,right\r\n\"Q\" Get motor position left,right\r\n\"R\" Reset e-puck\r\n\"S\" Stop e-puck and turn off leds\r\n\"T,#\" Play sound 1-5 else stop sound\r\n\"U\" Get microphone amplitude\r\n\"V\" Version of SerCom\r\n" |
A textual help about BTCom protocol, which is stored on e-Puck. | |
const string | RestartMessage = "r\r\f\aWELCOME to the SerCom protocol on e-Puck\r\nthe EPFL education robot type \"H\" for help\r\n" |
A message, which is sent from e-Puck after a restart. | |
const string | Version = "v,Version 1.1.3 September 2006\r\n" |
Static Public Attributes | |
static readonly List< char > | StableAnsCommandsChars = new List<char>( stableAnsCommands.Keys) |
A textual commands, which have always an identical answer. | |
Protected Member Functions | |
virtual void | Dispose (bool disposing) |
Releases unmanaged (close serial port) and - optionally - managed resources (stop threads in nice way). | |
void | OnFree (object sender, EventArgs ev) |
Raises Free event, if some handler is set. | |
void | OnWorking (object sender, EventArgs ev) |
Raises Working event, if some handler is set. | |
Properties | |
int | WidthImg [get] |
The width of last taken picture. | |
int | HeightImg [get] |
The height of last taken picture. | |
int | ModeImg [get] |
The colour mode of last taken picture. It can be black and white or colourful. | |
bool | FullImgBytes [get] |
If an image in LastImg is set to true , Sercom.FullImgBytes stores image. If it returns false , a picture has not been taken yet or Sercom.FullImgBytes are saving a picture right now. | |
byte[] | LastImgBytes [get] |
Bytes from bitmap of last taken picture. | |
int | NotSent [get] |
Number of commands waiting to be sent over serial connection. | |
int | NotAnswered [get, set] |
Number of commands waiting to be sent or to an answer of the sent command. | |
Events | |
static EventHandler | Free |
Sercom offers events Free, which is raised, if Sercom processed some commands and now he has no command to process. | |
static EventHandler | Working |
Sercom offers events Working, which is raised, if Sercom he has had no command to process and now is processing some commands. |
Sercom wraps serial communication with e-Puck. Main goal is to keep application responsive, although the used serial communication could be very unresponsive.
More sent commands does not mean better control of e-Puck.
Consider following example. We want to accelerate fluently from 0 to 1 speed in 100steps(0,01;0,02;....;0,98;1,00) using Epuck.Motors(double,double,OkfActuators,KofCallback,object,double). We send commands to BTCom program on e-Puck. Sercom puts the commands in queue and the commands will be sent in with gaps greater than L, because the commands wait until the previous command is confirmed. Therefor the acceleration lasts more than 100*L. If Epuck.Motors(double,double,OkfActuators,KofCallback,object,double) is called with gaps smaller than L, the acceleration is slower than it should be.
Luckily, most of commands are confirmed even with low battery until 0.1 seconds, but calibration of IR sensors, reseting e-Puck and shooting an image takes much more time. Calibration of IR sensors takes more than 1 second. Reseting e-Puck last more than 1.5 sec and capturing a colourful image 40 * 40 takes around 0.5 sec.
Elib.Sercom.Sercom | ( | string | portName, |
int | serialPortWriteTimeout, | ||
int | serialPortReadTimeout | ||
) |
Initializes a new instance of the Sercom class.
portName | Name of the serial port. |
serialPortWriteTimeout | The serial port write time out. |
serialPortReadTimeout | The serial port read time out. |
Elib.Sercom.Sercom | ( | string | portName | ) |
Initializes a new instance of the Sercom class with default values.
portName | Name of the serial port. |
virtual void Elib.Sercom.Dispose | ( | bool | disposing | ) | [protected, virtual] |
Releases unmanaged (close serial port) and - optionally - managed resources (stop threads in nice way).
disposing | true to release both managed and unmanaged resources; false to release only unmanaged resources. |
void Elib.Sercom.Dispose | ( | ) |
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. It takes under 0.5 sec for e-Puck.
void Elib.Sercom.OnFree | ( | object | sender, |
EventArgs | ev | ||
) | [protected] |
Raises Free event, if some handler is set.
sender | Parameter for the event |
ev | Parameter for the event |
void Elib.Sercom.OnWorking | ( | object | sender, |
EventArgs | ev | ||
) | [protected] |
Raises Working event, if some handler is set.
sender | Parameter for the event. |
ev | Parameter for the event. |
void Elib.Sercom.Start | ( | ) |
Opens the Bluetooth connection and turn the BTCom protocol on.
override string Elib.Sercom.ToString | ( | ) |
Writes the characteristic of underlying SerialPort connection.
void Elib.Sercom.Write | ( | string | command, |
OkfCallback | okf, | ||
KofCallback | kof, | ||
object | state, | ||
double | timeout | ||
) |
Writes the specified command to notSent queue until it can be sent over serial connection. Each command waits until the commands before him arer sent and confirmed or their timeout elapses. /.
command | The command. |
okf | The received callback. |
kof | The not received callback. |
state | The state. |
timeout | The timeout after, which is called notrecieved callback and the command is considered undelivered. |
writes tests if input command is in range of characters for sercom protocol, but it doesn't ensures good structure after first character!
const int Elib.Sercom.defReadTimeout = SerialPort.InfiniteTimeout |
Default value. It is infinite, because the serial port do not have to contain any answer.
const int Elib.Sercom.defWriteTimeout = 2000 |
Maximum of miliseconds, which are spent on unsuccessful writing to serial port. Default value in ms, which is set to SerialPort. If serial port can not write for defWriteTimeout in ms, than Elib exception is raised.
const string Elib.Sercom.Help = "\n\"A\" Accelerometer\r\n\"B,#\" Body led 0=off 1=on 2=inverse\r\n\"C\" Selector position\r\n\"D,#,#\" Set motor speed left,right\r\n\"E\" Get motor speed left,right\r\n\"F,#\" Front led 0=off 1=on 2=inverse\r\n\"G\" IR receiver\r\n\"H\"\t Help\r\n\"I\" Get camera parameter\r\n\"J,#,#,#,#\" Set camera parameter mode,width,heigth,zoom(1,4 or 8)\r\n\"K\" Calibrate proximity sensors\r\n\"L,#,#\" Led number,0=off 1=on 2=inverse\r\n\"N\" Proximity\r\n\"O\" Light sensors\r\n\"P,#,#\" Set motor position left,right\r\n\"Q\" Get motor position left,right\r\n\"R\" Reset e-puck\r\n\"S\" Stop e-puck and turn off leds\r\n\"T,#\" Play sound 1-5 else stop sound\r\n\"U\" Get microphone amplitude\r\n\"V\" Version of SerCom\r\n" |
A textual help about BTCom protocol, which is stored on e-Puck.
We suppose, that Elib is used with BTCom version 1.1.3, so we know how the help looks like.
const string Elib.Sercom.RestartMessage = "r\r\f\aWELCOME to the SerCom protocol on e-Puck\r\nthe EPFL education robot type \"H\" for help\r\n" |
A message, which is sent from e-Puck after a restart.
We suppose, that Elib is used with BTCom version 1.1.3, so we know how the help looks like.
readonly List<char> Elib.Sercom.StableAnsCommandsChars = new List<char>( stableAnsCommands.Keys) [static] |
A textual commands, which have always an identical answer.
const string Elib.Sercom.Version = "v,Version 1.1.3 September 2006\r\n" |
We suppose, that Elib is used with BTCom version 1.1.3, so we know the version.
bool Elib.Sercom.FullImgBytes [get] |
If an image in LastImg is set to true
, Sercom.FullImgBytes stores image. If it returns false
, a picture has not been taken yet or Sercom.FullImgBytes are saving a picture right now.
int Elib.Sercom.HeightImg [get] |
The height of last taken picture.
byte [] Elib.Sercom.LastImgBytes [get] |
Bytes from bitmap of last taken picture.
int Elib.Sercom.ModeImg [get] |
The colour mode of last taken picture. It can be black and white or colourful.
int Elib.Sercom.NotAnswered [get, set] |
Number of commands waiting to be sent or to an answer of the sent command.
int Elib.Sercom.NotSent [get] |
Number of commands waiting to be sent over serial connection.
int Elib.Sercom.WidthImg [get] |
The width of last taken picture.
EventHandler Elib.Sercom.Free [static] |
EventHandler Elib.Sercom.Working [static] |