#include <robotinocom.h>
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 ¶m) |
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 () |
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.
bool RobotinoCom::init | ( | bool | initWinsock2 = true |
) |
Initialize the communication.
initWinsock2 | Defines wether the Winsock2 interface should be initialized. Has no effect on platforms other than Windows. |
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().
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. |
nothing. |
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".
hostname | An IP address in string form. The port number may be added if separated by a colon. |
nothing. |
void RobotinoCom::close | ( | ) |
Close any connection immediately.
nothing. |
void RobotinoCom::setImagePort | ( | unsigned int | port | ) |
Sets the image port.
port | The port number used for images. |
nothing. |
unsigned int RobotinoCom::imagePort | ( | ) | const |
Retrieves the port number used for images.
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.
msecs | The server timeout in milliseconds. |
nothing. |
unsigned int RobotinoCom::timeout | ( | ) | const |
Retrieves the server timeout.
nothing. |
static std::string RobotinoCom::errorString | ( | int | error | ) | [static] |
Returns the english description of the error.
error | The error number to look for. |
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.
nothing. |
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.
nothing. |
bool RobotinoCom::isConnected | ( | ) | const |
Retrieves the current connection status.
nothing. |
RobotinoComError RobotinoCom::error | ( | ) | const |
Returns the error code of the last error. The error is cleared automatically by every call to connectToHost().
nothing. |
void RobotinoCom::clearError | ( | ) |
Sets the last error to RobotinoComError::NoError. Afterwards error() returns no error.
nothing. |
bool RobotinoCom::isValid | ( | ) | const |
Retrieves the state of the client object.
nothing. |
bool RobotinoCom::update | ( | ) |
Sends the currently set values to Robotino and waits for the answer.
nothing. |
bool RobotinoCom::receiveImage | ( | ) |
Blocks until an image is received or the connection is closed.
nothing. |
void RobotinoCom::setConnectedCallback | ( | RobotinoConnectedCb_t | f, | |
void * | data | |||
) |
Sends the current set values to Robotino.
nothing. | This callback function is called after connectToHost() has been called and a connection has been successfully established. |
f | The callback function. | |
data | User data that will be forwarded to the callback function. |
nothing. |
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.
f | The callback function. | |
data | User data that will be forwarded to the callback function. |
nothing. |
void RobotinoCom::setConnectionClosedCallback | ( | RobotinoConnectionClosedCb_t | f, | |
void * | data | |||
) |
void RobotinoCom::setRobotinoInfoReceivedCallback | ( | RobotinoInfoReceivedCb_t | f, | |
void * | data | |||
) |
This callback function is called when a RobotinoInfo object is received.
f | The callback function. | |
data | User data that will be forwarded to the callback function. |
nothing. |
void RobotinoCom::setRobotinoImageReceivedCallback | ( | RobotinoImageReceivedCb_t | f, | |
void * | data | |||
) |
This callback function is called when an image is received.
f | The callback function. | |
data | User data that will be forwarded to the callback function. |
nothing. |
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.
nothing. |
void RobotinoCom::unlockImage | ( | ) |
void RobotinoCom::setImageRequest | ( | bool | request | ) |
Signal Robotino that you are ready for receiving images or tell him to stop transmitting images.
request | TRUE to start receiving images, FALSE to stop it. |
nothing. |
unsigned int RobotinoCom::numMotors | ( | ) | const |
Retrieves the number of Robotinos motors.
nothing. |
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.
motor | The active motor, starting from 0. | |
rpm | The target speed in Rounds Per Minute |
nothing. |
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.
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. |
nothing. |
void RobotinoCom::getDriveLayout | ( | double * | rb, | |
double * | rw, | |||
double * | fctrl, | |||
double * | gear, | |||
double * | mer | |||
) |
Retrieves the layout parameters of the robots drive system.
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. |
nothing. |
void RobotinoCom::setVelocity | ( | double | vx, | |
double | vy, | |||
double | omega | |||
) |
Set the robots velocity.
vx | Velocity in x direction in mm/s. | |
vy | Velocity in y direction in mm/s. | |
omega | Angular velocity in deg/s. |
nothing. |
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.
motor | The active motors, starting from 0. | |
rpm | The additive speed in Rounds Per Minute. | |
priority | The scaling factor. |
nothing. |
float RobotinoCom::actualVelocity | ( | unsigned int | motor | ) |
Returns the actual velocity of the motor received by the last status message.
motor | The motor in question. |
nothing. |
void RobotinoCom::setKp | ( | unsigned int | motor, | |
float | value | |||
) |
void RobotinoCom::setKd | ( | unsigned int | motor, | |
float | value | |||
) |
void RobotinoCom::setKi | ( | unsigned int | motor, | |
float | value | |||
) |
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.
value | set point value. Range -100 to 100. |
float RobotinoCom::powerOutputCurrent | ( | float * | rawValue = NULL |
) | const |
The current delivered by the power output.
rawValue | Stores the raw value as measured by an 10bit adc, so range is from 0 to 1024 |
void RobotinoCom::encoderInput | ( | int * | velocity, | |
int * | position | |||
) | const |
Read the external encoder input
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 | ) |
reset | Set the current position to zero if true. Does nothing otherwise. |
float RobotinoCom::motorCurrent | ( | unsigned int | motor, | |
float * | rawValue = NULL | |||
) | const |
The current delivered by power amplifier for the given motor.
motor | The motor. Range [0;numMotors] | |
rawValue | Stores the raw value as measured by an 10bit adc, so range is from 0 to 1024 |
bool RobotinoCom::bumper | ( | ) | const |
Returns the state of Robotinos bumper.
nothing. |
unsigned int RobotinoCom::numDistanceSensors | ( | ) | const |
Returns the number of Robotinos distance sensors.
nothing. |
float RobotinoCom::distance | ( | unsigned int | n | ) | const |
Returns the reading of distance sensors.
n | The number of the sensor. Range [1;numDistanceSensors]. |
unsigned int RobotinoCom::adc | ( | const std::string & | name | ) | const |
Returns the raw reading of analog inputs.
name | The name of the sensor. |
nothing. |
float RobotinoCom::analogInput | ( | unsigned int | n | ) | const |
Returns the reading from an external analog input.
n | The number of the analog input. Range [0;numADC-1] |
nothing. |
void RobotinoCom::setDigitalOutput | ( | const std::string & | name, | |
bool | value | |||
) |
Sets the value of a specified digital output.
name | The name of the desired output. | |
value | The output value of the digital output. Low if value is FALSE, high otherwise. |
nothing. |
void RobotinoCom::setDigitalOutput | ( | unsigned int | n, | |
bool | value | |||
) |
Set the value of a specified digital output.
n | The number of the output. Range [0;numDigitalOutput-1] | |
value | The output value. Low if value is FALSE, high otherwise. |
nothing. |
bool RobotinoCom::digitalInput | ( | const std::string & | name | ) | const |
Retrieves the value of the referenced digital input.
name | The name of the desired Input. |
nothing. |
bool RobotinoCom::digitalInput | ( | unsigned int | n | ) | const |
Retrieves the value of the referenced digital input.
n | The number of the input. Range [0;numDigitalInput-1] |
nothing. |
unsigned int RobotinoCom::numADC | ( | ) | const |
Returns the number of analog digital converters.
nothing. |
unsigned int RobotinoCom::numDigitalInput | ( | ) | const |
Returns the number of digital inputs.
nothing. |
unsigned int RobotinoCom::numDigitalOutput | ( | ) | const |
Returns the number of digital outputs.
nothing. |
unsigned int RobotinoCom::numRelays | ( | ) | const |
void RobotinoCom::setRelay | ( | unsigned int | relay, | |
bool | close | |||
) |
relay | The relay to switch. Range [0;numRelays-1] | |
close | If true, the relay is closed. Otherwise the relay is opened. |
unsigned int RobotinoCom::serialLineFrequency | ( | ) | const |
Returns the serial line update frequency.
nothing. |
void RobotinoCom::setShutdown | ( | ) |
Shutdown Robotino. This will only work while a connection is established.
nothing. |
void RobotinoCom::setCameraParameters | ( | const RobotinoCameraParameters & | param | ) |
Set the camera parameters like resolution and compression.
param | The camera parameter set including resolution and compression. |
nothing. |
RobotinoCameraParameters RobotinoCom::cameraParameters | ( | ) | const |
Returns the camera parameters.
nothing. |
RobotinoComState RobotinoCom::state | ( | ) | const |
Returns the current communication state.
nothing. |
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.
image | The image, that should be saved. | |
fileName | The target filename of the image file. |
nothing. |
float RobotinoCom::motorTime | ( | unsigned int | motor | ) | const |
Retrieves the current motor time of the specified motor.
motor | The number of the desired motor. |
nothing. |
void RobotinoCom::resetPosition | ( | unsigned int | motor, | |
bool | reset | |||
) |
motor | The number of the desired motor. | |
reset | Set the current position of the motor to zero if true. Does nothing otherwise. |
int RobotinoCom::position | ( | unsigned int | motor | ) | const |
motor | The number of the desired motor. |
void RobotinoCom::resetMotorTime | ( | unsigned int | motor, | |
bool | reset | |||
) |
Resets the motor time of the given motor.
motor | The number of the motor. | |
reset | Set to TRUE to reset the specified motor timer. |
nothing. |
void RobotinoCom::setBrake | ( | unsigned int | motor, | |
bool | on | |||
) |
Controls the brake of the specified motor.
motor | The number of the desired motor. | |
on | TRUE to activate the brake, FALSE to unlock it. |
nothing. |
float RobotinoCom::msecsElapsed | ( | ) | const |
Milliseconds since the RobotinoCom object is created. The images' timestamp is given by this function.
nothing. |
NorthStarReadings RobotinoCom::northStarReadings | ( | ) | const |
Retrieves the current readings of the NorthStar tracking device.
nothing. |
void RobotinoCom::setNorthStarCommand | ( | const NorthStarCommand & | northStarCommand | ) |
Gives a command to the NorthStar tracking device.
northStarCommand | The command set for the NorthStar device. |
nothing. |
float RobotinoCom::current | ( | ) | const |
Retrieves the current power drain.
nothing. |
float RobotinoCom::voltageBatt1 | ( | ) | const |
Retrieves the voltage of the first battery.
nothing. |
float RobotinoCom::voltageBatt1plus2 | ( | ) | const |
Retrieves the voltage of both batteries.
nothing. |
RobotinoInfo RobotinoCom::robotinoInfo | ( | ) | const |
Retrieves informational messages from Robotino.
nothing. |
void RobotinoCom::setGripperEnabled | ( | bool | enable | ) |
Enable/Disable the gripper attached to Robotino's power output
enable | If true the gripper is enabled, otherwise the gripper is disabled |
bool RobotinoCom::isGripperEnabled | ( | ) | const |
void RobotinoCom::setGripperClosed | ( | bool | close | ) |
Open/Close the gripper attached to Robotino's power output
close | If true the gripper is closed, otherwise the gripper is opened. |
bool RobotinoCom::isGripperOpened | ( | ) | const |
bool RobotinoCom::isGripperClosed | ( | ) | const |
void RobotinoCom::setOdometry | ( | float | x, | |
float | y, | |||
float | phi | |||
) |
Set the odometry to the given position.
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.
x | x position in mm | |
y | y position in mm | |
phi | orientation in degree |
static unsigned int RobotinoCom::version | ( | ) | [static] |