RobotinoCom Class Reference

Provides complete commication with Robotino. More...

#include <robotinocom.h>

List of all members.

Public Member Functions

bool init (bool initWinsock2=true)
void connectToHost (const std::string &hostname, int port, bool startAsyncCommunicationAfterConnect=true)
void connectToHost (std::string hostname, bool startAsyncCommunicationAfterConnect=true)
void close ()
void setImagePort (unsigned int port)
unsigned int imagePort () const
void setTimeout (unsigned int msecs)
unsigned int timeout () const
void startAsyncCommunication ()
void stopAsyncCommunication ()
bool isConnected () const
RobotinoComError error () const
void clearError ()
bool isValid () const
bool update ()
bool receiveImage ()
void setConnectedCallback (RobotinoConnectedCb_t f, void *data)
void setErrorCallback (RobotinoErrorCb_t f, void *data)
void setConnectionClosedCallback (RobotinoConnectionClosedCb_t f, void *data)
void setRobotinoInfoReceivedCallback (RobotinoInfoReceivedCb_t f, void *data)
void setRobotinoImageReceivedCallback (RobotinoImageReceivedCb_t f, void *data)
const RobotinoImage *const lockImage ()
void unlockImage ()
void setImageRequest (bool request)
unsigned int numMotors () const
void setVelocity (unsigned int motor, float rpm)
void setDriveLayout (double rb=125.0f, double rw=40.0, double fctrl=900.0, double gear=16, double mer=2000)
void getDriveLayout (double *rb, double *rw, double *fctrl, double *gear, double *mer)
void setVelocity (double vx, double vy, double omega)
void addVelocity (unsigned int motor, float rpm, float priority)
float actualVelocity (unsigned int motor)
void setKp (unsigned int motor, float value)
void setKd (unsigned int motor, float value)
void setKi (unsigned int motor, float value)
void setPowerOutput (float value)
float powerOutputCurrent (float *rawValue=NULL) const
void encoderInput (int *velocity, int *position) const
void resetEncoderInputPosition (bool reset)
float motorCurrent (unsigned int motor, float *rawValue=NULL) const
bool bumper () const
unsigned int numDistanceSensors () const
float distance (unsigned int n) const
unsigned int adc (const std::string &name) const
float analogInput (unsigned int n) const
void setDigitalOutput (const std::string &name, bool value)
void setDigitalOutput (unsigned int n, bool value)
bool digitalInput (const std::string &name) const
bool digitalInput (unsigned int n) const
unsigned int numADC () const
unsigned int numDigitalInput () const
unsigned int numDigitalOutput () const
unsigned int numRelays () const
void setRelay (unsigned int relay, bool close)
unsigned int serialLineFrequency () const
void setShutdown ()
void setCameraParameters (const RobotinoCameraParameters &param)
RobotinoCameraParameters cameraParameters () const
RobotinoComState state () const
bool saveImageToFile (const RobotinoImage *image, const std::string &fileName)
float motorTime (unsigned int motor) const
void resetPosition (unsigned int motor, bool reset)
int position (unsigned int motor) const
void resetMotorTime (unsigned int motor, bool reset)
void setBrake (unsigned int motor, bool on)
float msecsElapsed () const
NorthStarReadings northStarReadings () const
void setNorthStarCommand (const NorthStarCommand &northStarCommand)
float current () const
float voltageBatt1 () const
float voltageBatt1plus2 () const
RobotinoInfo robotinoInfo () const
void setGripperEnabled (bool enable)
bool isGripperEnabled () const
void setGripperClosed (bool close)
bool isGripperOpened () const
bool isGripperClosed () const
void setOdometry (float x, float y, float phi)
void getOdometry (float *x, float *y, float *phi)

Static Public Member Functions

static std::string errorString (int error)
static unsigned int version ()


Detailed Description

Provides complete commication with Robotino.

This class establishes a connection to Robotino and allows you to control its outputs and retrieve its inputs. Motors and other output devices can be controlled, camera images, distance sensors, bumpers and other input devices can be read.


Member Function Documentation

bool RobotinoCom::init ( bool  initWinsock2 = true  ) 

Initialize the communication.

Parameters:
initWinsock2 Defines wether the Winsock2 interface should be initialized. Has no effect on platforms other than Windows.
Returns:
TRUE if connection was successful, FALSE otherwise.
Exceptions:
nothing. 

void RobotinoCom::connectToHost ( const std::string &  hostname,
int  port,
bool  startAsyncCommunicationAfterConnect = true 
)

Attempts to make a connection to the host and return immediately. Any connection or pending connection is closed immediately. When the connection succeeds, it emits connected(). isConnected() returns true from now on. If there is an error at any point, it emits error().

Parameters:
hostname An IP address in string form.
port The used port to connect to the host.
startAsyncCommunicationAfterConnect If true a seperate thread is started sending keep alive messages to Robotino. This prevents the connection to timeout if update ist not called by the user.
Exceptions:
nothing. 
See also:
isConnected, close

void RobotinoCom::connectToHost ( std::string  hostname,
bool  startAsyncCommunicationAfterConnect = true 
)

Attempts to make a connection to the host and return immediately. Any connection or pending connection is closed immediately. When the connection succeeds, it emits connected(). isConnected() returns true from now on. If there is an error at any point, it emits error(). This overload accepts host and port combinations of the form "HOSTNAME:PORT".

Parameters:
hostname An IP address in string form. The port number may be added if separated by a colon.
Exceptions:
nothing. 
See also:
isConnected, close

void RobotinoCom::close (  ) 

Close any connection immediately.

Exceptions:
nothing. 

void RobotinoCom::setImagePort ( unsigned int  port  ) 

Sets the image port.

Parameters:
port The port number used for images.
Exceptions:
nothing. 

unsigned int RobotinoCom::imagePort (  )  const

Retrieves the port number used for images.

Returns:
the image port number.
Exceptions:
nothing. 

void RobotinoCom::setTimeout ( unsigned int  msecs  ) 

Sets the server timeout. If update has not been called for more than timeout milliseconds the communication is closed by Robotino.

Parameters:
msecs The server timeout in milliseconds.
Exceptions:
nothing. 
See also:
update

unsigned int RobotinoCom::timeout (  )  const

Retrieves the server timeout.

Returns:
Server timeout in milliseconds.
Exceptions:
nothing. 

static std::string RobotinoCom::errorString ( int  error  )  [static]

Returns the english description of the error.

Parameters:
error The error number to look for.
Returns:
English description of given error number.
Exceptions:
nothing. 

void RobotinoCom::startAsyncCommunication (  ) 

After calling stopAsyncCommunication() this allows to restart the asynchronous communication. When connectToHost() is successful, i.e. the connected() signal is emitted, the asynchronous communication thread is started. This thread receives status messages from Robotino and sends KeepAlive messages to keep the connection open.

Exceptions:
nothing. 
See also:
stopAsyncCommunication, connectToHost

void RobotinoCom::stopAsyncCommunication (  ) 

By stopping the asynchronous communication thread its up to you to call receive() periodically. You are also responsible for sending control or KeepAlive messages. Otherwise the connection will time out.

Exceptions:
nothing. 
See also:
startAsyncCommunication

bool RobotinoCom::isConnected (  )  const

Retrieves the current connection status.

Returns:
TRUE if there is a usable connection, FALSE otherwise.
Exceptions:
nothing. 
See also:
connectToHost

RobotinoComError RobotinoCom::error (  )  const

Returns the error code of the last error. The error is cleared automatically by every call to connectToHost().

Returns:
The error code of the last encountered error.
Exceptions:
nothing. 
See also:
errorString, clearError, RobotinoComError, connectToHost

void RobotinoCom::clearError (  ) 

Sets the last error to RobotinoComError::NoError. Afterwards error() returns no error.

Exceptions:
nothing. 
See also:
error, errorString

bool RobotinoCom::isValid (  )  const

Retrieves the state of the client object.

Returns:
TRUE if the client was created, FALSE otherwise.
Exceptions:
nothing. 

bool RobotinoCom::update (  ) 

Sends the currently set values to Robotino and waits for the answer.

Returns:
TRUE on success, FALSE otherwise.
Exceptions:
nothing. 

bool RobotinoCom::receiveImage (  ) 

Blocks until an image is received or the connection is closed.

Returns:
TRUE on success, FALSE otherwise.
Exceptions:
nothing. 

void RobotinoCom::setConnectedCallback ( RobotinoConnectedCb_t  f,
void *  data 
)

Sends the current set values to Robotino.

Returns:
TRUE if sending was successful.
Exceptions:
nothing. This callback function is called after connectToHost() has been called and a connection has been successfully established.
Parameters:
f The callback function.
data User data that will be forwarded to the callback function.
Exceptions:
nothing. 
See also:
connectToHost, isConnected

void RobotinoCom::setErrorCallback ( RobotinoErrorCb_t  f,
void *  data 
)

This callback function is called after an error occurred. If a connection is established a the connectionClosed() callback is called afterwards.

Parameters:
f The callback function.
data User data that will be forwarded to the callback function.
Exceptions:
nothing. 
See also:
errorString

void RobotinoCom::setConnectionClosedCallback ( RobotinoConnectionClosedCb_t  f,
void *  data 
)

This callback function is called whenever a connection is closed, i.e. afer calling close() or after an error occured.

Parameters:
f The callback function.
data User data that will be forwarded to the callback function.
Exceptions:
nothing. 
See also:
close, error

void RobotinoCom::setRobotinoInfoReceivedCallback ( RobotinoInfoReceivedCb_t  f,
void *  data 
)

This callback function is called when a RobotinoInfo object is received.

Parameters:
f The callback function.
data User data that will be forwarded to the callback function.
Exceptions:
nothing. 

void RobotinoCom::setRobotinoImageReceivedCallback ( RobotinoImageReceivedCb_t  f,
void *  data 
)

This callback function is called when an image is received.

Parameters:
f The callback function.
data User data that will be forwarded to the callback function.
Exceptions:
nothing. 
See also:
lockImage, setImageRequest

const RobotinoImage* const RobotinoCom::lockImage (  ) 

Retrieve the latest image received. After successfully locking an image make sure to call unlockImage() when you finished using the data.

Returns:
A valid pointer to a RobotinoImage on success, NULL otherwise.
Exceptions:
nothing. 
See also:
unlockImage, setImageRequest, RobotinoImage

void RobotinoCom::unlockImage (  ) 

Release the image obtained by lockImage().

Exceptions:
nothing. 
See also:
lockImage

void RobotinoCom::setImageRequest ( bool  request  ) 

Signal Robotino that you are ready for receiving images or tell him to stop transmitting images.

Parameters:
request TRUE to start receiving images, FALSE to stop it.
Exceptions:
nothing. 
See also:
lockImage, setRobotinoImageReceivedCallback

unsigned int RobotinoCom::numMotors (  )  const

Retrieves the number of Robotinos motors.

Returns:
The number of motors.
Exceptions:
nothing. 
See also:
getDriveLayout, actualVelocity

void RobotinoCom::setVelocity ( unsigned int  motor,
float  rpm 
)

Set the velocity of the given motor. This overrides any previous set/addVelocity calls for the given motor.

Parameters:
motor The active motor, starting from 0.
rpm The target speed in Rounds Per Minute
Exceptions:
nothing. 
See also:
numMotors, actualVelocity

void RobotinoCom::setDriveLayout ( double  rb = 125.0f,
double  rw = 40.0,
double  fctrl = 900.0,
double  gear = 16,
double  mer = 2000 
)

Sets the layout of the robots drive system in order to drive with mm/s. Default values are for Robotino.

Parameters:
rb Distance from robot center to wheel center.
rw Radius of the wheels.
fctrl Frequency of control loop measuring the speed.
gear Gear
mer Motor encoder resolution.
Exceptions:
nothing. 
See also:
getDriveLayout

void RobotinoCom::getDriveLayout ( double *  rb,
double *  rw,
double *  fctrl,
double *  gear,
double *  mer 
)

Retrieves the layout parameters of the robots drive system.

Parameters:
rb Distance from robot center to wheel center.
rw Radius of the wheels.
fctrl Frequency of control loop measuring the speed.
gear Gear
mer Motor encoder resolution.
Exceptions:
nothing. 
See also:
setDriveLayout

void RobotinoCom::setVelocity ( double  vx,
double  vy,
double  omega 
)

Set the robots velocity.

Parameters:
vx Velocity in x direction in mm/s.
vy Velocity in y direction in mm/s.
omega Angular velocity in deg/s.
Exceptions:
nothing. 
See also:
addVelocity, actualVelocity

void RobotinoCom::addVelocity ( unsigned int  motor,
float  rpm,
float  priority 
)

The set velocity of the motor is calculated as the mean value of the added velocities scaled by priority.

Parameters:
motor The active motors, starting from 0.
rpm The additive speed in Rounds Per Minute.
priority The scaling factor.
Exceptions:
nothing. 
See also:
setVelocity, numMotors, actualVelocity

float RobotinoCom::actualVelocity ( unsigned int  motor  ) 

Returns the actual velocity of the motor received by the last status message.

Parameters:
motor The motor in question.
Returns:
The velocity of the motor in rounds per minute. If no status message has been received, or if there is no operational connection to Robotino, 0 is returned.
Exceptions:
nothing. 
See also:
setVelocity, numMotors

void RobotinoCom::setKp ( unsigned int  motor,
float  value 
)

Set the PID controllers proportional constant of the motor.

Parameters:
motor The active motor, starting from 0.
value The new proportional constant.
Exceptions:
nothing. 
See also:
setKd, setKi, numMotors

void RobotinoCom::setKd ( unsigned int  motor,
float  value 
)

Set the PID controllers differential constant of the motor.

Parameters:
motor The active motor, starting from 0.
value The new differential constant.
Exceptions:
nothing. 
See also:
setKp, setKi, numMotors

void RobotinoCom::setKi ( unsigned int  motor,
float  value 
)

Set the PID controllers integral constant of the motor.

Parameters:
motor The active motor, starting from 0.
value The new integral constant.
Exceptions:
nothing. 
See also:
setKp, setKd, numMotors

void RobotinoCom::setPowerOutput ( float  value  ) 

Set point for power output. Caution: You must not use this funtion to drive Robotino's gripper. The gripper will be physically destroyed if current is not limited. Use the *Gripper* functions instead.

Parameters:
value set point value. Range -100 to 100.
See also:
setGripperEnabled, isGripperEnabled, setGripperClosed, isGripperOpened, isGripperClosed

float RobotinoCom::powerOutputCurrent ( float *  rawValue = NULL  )  const

The current delivered by the power output.

Parameters:
rawValue Stores the raw value as measured by an 10bit adc, so range is from 0 to 1024
Returns:
Delivered current in A.

void RobotinoCom::encoderInput ( int *  velocity,
int *  position 
) const

Read the external encoder input

Parameters:
velocity Stores the actual velocity in ticks/s
position Stores the actual position in ticks since power on or resetEncoderInputPosition( true )

void RobotinoCom::resetEncoderInputPosition ( bool  reset  ) 

Parameters:
reset Set the current position to zero if true. Does nothing otherwise.
See also:
resetPosition, position

float RobotinoCom::motorCurrent ( unsigned int  motor,
float *  rawValue = NULL 
) const

The current delivered by power amplifier for the given motor.

Parameters:
motor The motor. Range [0;numMotors]
rawValue Stores the raw value as measured by an 10bit adc, so range is from 0 to 1024
Returns:
Delivered current in A.

bool RobotinoCom::bumper (  )  const

Returns the state of Robotinos bumper.

Returns:
TRUE if the bumper is active (i.e. has contact to something), FALSE otherwise.
Exceptions:
nothing. 

unsigned int RobotinoCom::numDistanceSensors (  )  const

Returns the number of Robotinos distance sensors.

Returns:
The number of distance sensors.
Exceptions:
nothing. 
See also:
distance

float RobotinoCom::distance ( unsigned int  n  )  const

Returns the reading of distance sensors.

Parameters:
n The number of the sensor. Range [1;numDistanceSensors].
Returns:
The sensor reading in Volts.
See also:
numDistanceSensors

unsigned int RobotinoCom::adc ( const std::string &  name  )  const

Returns the raw reading of analog inputs.

Parameters:
name The name of the sensor.
Returns:
The direct output of the given sensor.
Exceptions:
nothing. 
See also:
distance, analogInput

float RobotinoCom::analogInput ( unsigned int  n  )  const

Returns the reading from an external analog input.

Parameters:
n The number of the analog input. Range [0;numADC-1]
Returns:
The reading of the input in volts.
Exceptions:
nothing. 
See also:
numADC

void RobotinoCom::setDigitalOutput ( const std::string &  name,
bool  value 
)

Sets the value of a specified digital output.

Parameters:
name The name of the desired output.
value The output value of the digital output. Low if value is FALSE, high otherwise.
Exceptions:
nothing. 
See also:
numDigitalOutput

void RobotinoCom::setDigitalOutput ( unsigned int  n,
bool  value 
)

Set the value of a specified digital output.

Parameters:
n The number of the output. Range [0;numDigitalOutput-1]
value The output value. Low if value is FALSE, high otherwise.
Exceptions:
nothing. 
See also:
numDigitalOutput

bool RobotinoCom::digitalInput ( const std::string &  name  )  const

Retrieves the value of the referenced digital input.

Parameters:
name The name of the desired Input.
Returns:
TRUE if the input value is high, FALSE otherwise.
Exceptions:
nothing. 
See also:
numDigitalInput

bool RobotinoCom::digitalInput ( unsigned int  n  )  const

Retrieves the value of the referenced digital input.

Parameters:
n The number of the input. Range [0;numDigitalInput-1]
Returns:
TRUE if the value is high, FALSE otherwise.
Exceptions:
nothing. 
See also:
numDigitalInput

unsigned int RobotinoCom::numADC (  )  const

Returns the number of analog digital converters.

Returns:
The number of ADCs.
Exceptions:
nothing. 
See also:
adc, analogInput

unsigned int RobotinoCom::numDigitalInput (  )  const

Returns the number of digital inputs.

Returns:
The number of digital inputs.
Exceptions:
nothing. 
See also:
digitalInput

unsigned int RobotinoCom::numDigitalOutput (  )  const

Returns the number of digital outputs.

Returns:
The number of digital Outputs.
Exceptions:
nothing. 
See also:
setDigitalOutput

unsigned int RobotinoCom::numRelays (  )  const

Returns:
The number of relays.
See also:
setRelay

void RobotinoCom::setRelay ( unsigned int  relay,
bool  close 
)

Parameters:
relay The relay to switch. Range [0;numRelays-1]
close If true, the relay is closed. Otherwise the relay is opened.
See also:
numRelays

unsigned int RobotinoCom::serialLineFrequency (  )  const

Returns the serial line update frequency.

Returns:
The serial line frequency.
Exceptions:
nothing. 

void RobotinoCom::setShutdown (  ) 

Shutdown Robotino. This will only work while a connection is established.

Exceptions:
nothing. 
See also:
isConnected

void RobotinoCom::setCameraParameters ( const RobotinoCameraParameters param  ) 

Set the camera parameters like resolution and compression.

Parameters:
param The camera parameter set including resolution and compression.
Exceptions:
nothing. 
See also:
RobotinoCameraParameters, isConnected

RobotinoCameraParameters RobotinoCom::cameraParameters (  )  const

Returns the camera parameters.

Returns:
The current camera parameters, including resolution and compression level.
Exceptions:
nothing. 
See also:
setCameraParameters, RobotinoCameraParameters

RobotinoComState RobotinoCom::state (  )  const

Returns the current communication state.

Returns:
The current communication state.
Exceptions:
nothing. 
See also:
RobotinoComState, connectToHost, close, isConnected

bool RobotinoCom::saveImageToFile ( const RobotinoImage image,
const std::string &  fileName 
)

Save an image to disk. If no file extension is given, the extension is appended automatically according to the value of image->parameters.type.

Parameters:
image The image, that should be saved.
fileName The target filename of the image file.
Returns:
TRUE on success, FALSE otherwise.
Exceptions:
nothing. 
See also:
RobotinoImage, cameraParameters, lockImage

float RobotinoCom::motorTime ( unsigned int  motor  )  const

Retrieves the current motor time of the specified motor.

Parameters:
motor The number of the desired motor.
Returns:
The motor time of the given motor or 0 if the motor number is invalid.
Exceptions:
nothing. 
See also:
resetMotorTime

void RobotinoCom::resetPosition ( unsigned int  motor,
bool  reset 
)

Parameters:
motor The number of the desired motor.
reset Set the current position of the motor to zero if true. Does nothing otherwise.
See also:
position

int RobotinoCom::position ( unsigned int  motor  )  const

Parameters:
motor The number of the desired motor.
Returns:
The position of the motor estimated by counting the ticks generated by the motor's encoder.
See also:
resetPosition

void RobotinoCom::resetMotorTime ( unsigned int  motor,
bool  reset 
)

Resets the motor time of the given motor.

Parameters:
motor The number of the motor.
reset Set to TRUE to reset the specified motor timer.
Exceptions:
nothing. 
See also:
motorTime

void RobotinoCom::setBrake ( unsigned int  motor,
bool  on 
)

Controls the brake of the specified motor.

Parameters:
motor The number of the desired motor.
on TRUE to activate the brake, FALSE to unlock it.
Exceptions:
nothing. 

float RobotinoCom::msecsElapsed (  )  const

Milliseconds since the RobotinoCom object is created. The images' timestamp is given by this function.

Returns:
The elapsed time since object creation in milliseconds.
Exceptions:
nothing. 
See also:
saveImageToFile

NorthStarReadings RobotinoCom::northStarReadings (  )  const

Retrieves the current readings of the NorthStar tracking device.

Returns:
An object containing all current values concerning the NorthStar tracking.
Exceptions:
nothing. 
See also:
NorthStarReadings, setNorthStarCommand

void RobotinoCom::setNorthStarCommand ( const NorthStarCommand northStarCommand  ) 

Gives a command to the NorthStar tracking device.

Parameters:
northStarCommand The command set for the NorthStar device.
Exceptions:
nothing. 
See also:
NorthStarCommand

float RobotinoCom::current (  )  const

Retrieves the current power drain.

Returns:
The current drain in mA.
Exceptions:
nothing. 
See also:
voltageBatt1, voltageBatt1plus2

float RobotinoCom::voltageBatt1 (  )  const

Retrieves the voltage of the first battery.

Returns:
The remaining voltage in V.
Exceptions:
nothing. 
See also:
voltageBatt1plus2, current

float RobotinoCom::voltageBatt1plus2 (  )  const

Retrieves the voltage of both batteries.

Returns:
The remaining voltage of both batteries.
Exceptions:
nothing. 
See also:
voltageBatt1, current

RobotinoInfo RobotinoCom::robotinoInfo (  )  const

Retrieves informational messages from Robotino.

Returns:
An object containing messages and additional information.
Exceptions:
nothing. 
See also:
RobotinoInfo

void RobotinoCom::setGripperEnabled ( bool  enable  ) 

Enable/Disable the gripper attached to Robotino's power output

Parameters:
enable If true the gripper is enabled, otherwise the gripper is disabled

bool RobotinoCom::isGripperEnabled (  )  const

Returns:
Returns true, if the gripper was enabled by a previous call to setGripperEnabled( true ). Otherwise returns false.
See also:
setGripperEnabled

void RobotinoCom::setGripperClosed ( bool  close  ) 

Open/Close the gripper attached to Robotino's power output

Parameters:
close If true the gripper is closed, otherwise the gripper is opened.

bool RobotinoCom::isGripperOpened (  )  const

Returns:
Returns true if the gripper is opened.

bool RobotinoCom::isGripperClosed (  )  const

Returns:
Returns true if the gripper is closed.

void RobotinoCom::setOdometry ( float  x,
float  y,
float  phi 
)

Set the odometry to the given position.

Parameters:
x x position in mm
y y position in mm
phi orientation in degree

void RobotinoCom::getOdometry ( float *  x,
float *  y,
float *  phi 
)

Get the current position estimated by the odometry.

Parameters:
x x position in mm
y y position in mm
phi orientation in degree

static unsigned int RobotinoCom::version (  )  [static]

Returns the current RobotinoCom version.

Returns:
The current version.
Exceptions:
nothing. 


The documentation for this class was generated from the following file:

Generated on Fri Aug 17 15:09:42 2012 for robotinocom by  doxygen 1.5.5