NVRemoteConnection Class Reference
[libipsaTools classes]

This class connects to an IPSRV instance and allows the sending of commands and receiving values. More...

#include <NVRemoteConnection.h>

Collaboration diagram for NVRemoteConnection:

Collaboration graph
[legend]

List of all members.

Public Member Functions

bool connect ()
std::vector< std::string > getBodyList ()
float getJointAngle (const std::string &jointName)
float getJointAngleRate (const std::string &jointName)
std::map< std::string, float > getJointAngleRates (const std::vector< std::string > &jointList)
std::map< std::string, float > getJointAngles (const std::vector< std::string > &jointList)
std::vector< float > getJointForce (const std::string &jointName, bool firstBody=true)
std::map< std::string,
std::vector< float > > 
getJointForces (const std::vector< std::string > &jointList)
std::vector< std::string > getJointList ()
float getJointPosition (const std::string &jointName)
float getJointPositionRate (const std::string &jointName)
std::map< std::string, float > getJointPositionRates (const std::vector< std::string > &jointList)
std::map< std::string, float > getJointPositions (const std::vector< std::string > &jointList)
std::vector< float > getJointTorque (const std::string &jointName, bool firstBody=true)
std::map< std::string,
std::vector< float > > 
getJointTorques (const std::vector< std::string > &jointList)
std::vector< std::string > getListForCommand (const std::string &commandName)
std::map< std::string, float > getMapForNodesAndCommand (const std::vector< std::string > &nodeList, float(NVRemoteConnection::*commandFunction)(const std::string &))
std::map< std::string,
std::vector< float > > 
getMapForNodesAndCommand (const std::vector< std::string > &nodeList, std::vector< float >(NVRemoteConnection::*commandFunction)(const std::string &, bool))
float getValueForCommand (const std::string &commandName, const std::string &nodeName)
std::vector< float > getVectorForCommand (const std::string &commandName, const std::string &nodeName, bool firstBody=true)
bool isConnected ()
 NVRemoteConnection (bool connectOnCreate=false, const std::string &hostname="localhost", unsigned int port=12345)
void scheduleOde (bool scheduleSimulation=true)
void sendCommands ()
void set3DVectorForCommandAndNode (const std::vector< float > &values, const std::string &commandName, const std::string &nodeName)
void setJointForce (const std::string &jointName, float force)
void setJointForce2 (const std::string &jointName, float force)
void setJointSpeed (const std::string &jointName, float speed)
void setJointSpeed2 (const std::string &jointName, float speed)
void setJointTorque (const std::string &jointName, float torque)
void setJointTorque2 (const std::string &jointName, float torque)
void setValueForCommandAndNode (const float &value, const std::string &commandName, const std::string &nodeName)
 ~NVRemoteConnection ()

Protected Member Functions

bool receiveAnswer (std::string &answer)

Private Attributes

std::ostringstream commandStream
CTCPSocketm_pSocket


Detailed Description

This class connects to an IPSRV instance and allows the sending of commands and receiving values.

Definition at line 33 of file NVRemoteConnection.h.


Constructor & Destructor Documentation

NVRemoteConnection::NVRemoteConnection ( bool  connectOnCreate = false,
const std::string &  hostname = "localhost",
unsigned int  port = 12345 
)

Creates a new NVRemoteConnection object initialised with a hostname and a port to connect to. Opens the connection to the remote host on creation.

Parameters:
connectOnCreate the connection is established if true, otherwise connect() must be called explicitely (default is false).
hostname Name of the host to connect to (default is localhost).
port Port on the remote host to connect to (default is 12345).

Definition at line 56 of file NVRemoteConnection.cpp.

References connect(), and m_pSocket.

NVRemoteConnection::~NVRemoteConnection (  ) 

Closes the remote connection upon deletion of the object.

Definition at line 68 of file NVRemoteConnection.cpp.

References m_pSocket.


Member Function Documentation

bool NVRemoteConnection::connect (  ) 

Connects to the remote viewer. This method is called by NVRemoteConnection::NVRemoteConnection if the parameter connectOnCreate is set to true.

Returns:
true if connection could be established, false otherwise.

Definition at line 655 of file NVRemoteConnection.cpp.

References m_pSocket, and CTCPSocket::openSocket().

Referenced by NVRemoteConnection().

std::vector< std::string > NVRemoteConnection::getBodyList (  ) 

This method sets the verbosity to 0 and afterwards calls the blist command. The returned answer is then split up into separate strings each containing the name of a body in the scene.

Returns:
bodyNameList: a std::vector which contains all body names as std::string objects.

Definition at line 482 of file NVRemoteConnection.cpp.

References getListForCommand().

float NVRemoteConnection::getJointAngle ( const std::string &  jointName  ) 

Parameters:
jointName the angle is returned for the joint with this name.
Returns:
jointAngle the current angle of the joint with the passed in name.

Definition at line 252 of file NVRemoteConnection.cpp.

References getValueForCommand().

Referenced by getJointAngles().

float NVRemoteConnection::getJointAngleRate ( const std::string &  jointName  ) 

Parameters:
jointName the anglerate is returned for the joint with this name.
Returns:
jointAngleRate the current anglerate of the joint with the passed in name.

Definition at line 263 of file NVRemoteConnection.cpp.

References getValueForCommand().

Referenced by getJointAngleRates().

std::map< std::string, float > NVRemoteConnection::getJointAngleRates ( const std::vector< std::string > &  jointList  ) 

Warning:
Currently this works only if the joint names are not empty. Otherwise no answer is returned and the operation just stops the execution of NVRemoteConnection until some answer is returned.
Parameters:
jointList an std::vector of joint names.
Returns:
angleRateMap: a map which maps the joint names to their current angelrate.

Definition at line 393 of file NVRemoteConnection.cpp.

References getJointAngleRate(), and getMapForNodesAndCommand().

std::map< std::string, float > NVRemoteConnection::getJointAngles ( const std::vector< std::string > &  jointList  ) 

Warning:
Currently this works only if the joint names are not empty. Otherwise no answer is returned and the operation just stops the execution of NVRemoteConnection until some answer is returned.
Parameters:
jointList an std::vector of joint names.
Returns:
angleMap: a map which maps the joint names to their current angle.

Definition at line 380 of file NVRemoteConnection.cpp.

References getJointAngle(), and getMapForNodesAndCommand().

std::vector< float > NVRemoteConnection::getJointForce ( const std::string &  jointName,
bool  firstBody = true 
)

Retrieves the forces appearing in the joint supplied as parameter.

Parameters:
jointName Name of the Open Inventor node in the scenegraph.
firstBody If true uses the first body connected to the joint for calculationg the forces otherwise the second one (default = true).
Returns:
forceVectorXYZ: an std::vector<float> of size 3 containing the forces in X, Y and Z direction (in the specified order).

Definition at line 198 of file NVRemoteConnection.cpp.

References getVectorForCommand().

Referenced by getJointForces().

std::map< std::string, std::vector< float > > NVRemoteConnection::getJointForces ( const std::vector< std::string > &  jointList  ) 

Warning:
Currently this works only if the joint names are not empty. Otherwise no answer is returned and the operation just stops the execution of NVRemoteConnection until some answer is returned.
Parameters:
jointList an std::vector of joint names.
Returns:
forceMap: a map which maps the joint names to their current force vector.

Definition at line 353 of file NVRemoteConnection.cpp.

References getJointForce(), and getMapForNodesAndCommand().

Referenced by sendCommands().

std::vector< std::string > NVRemoteConnection::getJointList (  ) 

This method sets the verbosity to 0 and afterwards calls the jlist command. The returned answer is then split up into separate strings each containing the name of a joint in the scene.

Returns:
jointNameList: a std::vector which contains all joint names as std::string objects.

Definition at line 469 of file NVRemoteConnection.cpp.

References getListForCommand().

Referenced by sendCommands().

float NVRemoteConnection::getJointPosition ( const std::string &  jointName  ) 

Parameters:
jointName the position is returned for the joint with this name.
Returns:
jointPosition the current position of the joint with the passed in name.

Definition at line 274 of file NVRemoteConnection.cpp.

References getValueForCommand().

Referenced by getJointPositions().

float NVRemoteConnection::getJointPositionRate ( const std::string &  jointName  ) 

Parameters:
jointName the positionrate is returned for the joint with this name.
Returns:
jointPositionRate the current positionrate of the joint with the passed in name.

Definition at line 285 of file NVRemoteConnection.cpp.

References getValueForCommand().

Referenced by getJointPositionRates().

std::map< std::string, float > NVRemoteConnection::getJointPositionRates ( const std::vector< std::string > &  jointList  ) 

Warning:
Currently this works only if the joint names are not empty. Otherwise no answer is returned and the operation just stops the execution of NVRemoteConnection until some answer is returned.
Parameters:
jointList an std::vector of joint names.
Returns:
positionRateMap: a map which maps the joint names to their current positionrate.

Definition at line 419 of file NVRemoteConnection.cpp.

References getJointPositionRate(), and getMapForNodesAndCommand().

std::map< std::string, float > NVRemoteConnection::getJointPositions ( const std::vector< std::string > &  jointList  ) 

Warning:
Currently this works only if the joint names are not empty. Otherwise no answer is returned and the operation just stops the execution of NVRemoteConnection until some answer is returned.
Parameters:
jointList an std::vector of joint names.
Returns:
positionMap: a map which maps the joint names to their current position.

Definition at line 406 of file NVRemoteConnection.cpp.

References getJointPosition(), and getMapForNodesAndCommand().

std::vector< float > NVRemoteConnection::getJointTorque ( const std::string &  jointName,
bool  firstBody = true 
)

Retrieves the torques appearing in the joint supplied as parameter.

Parameters:
jointName Name of the Open Inventor node in the scenegraph.
firstBody If true uses the first body connected to the joint for calculationg the torques otherwise the second one. Default is true.
Returns:
torqueVectorXYZ: an std::vector<float> of size 3 containing the torques in X, Y and Z direction (in the specified order).

Definition at line 215 of file NVRemoteConnection.cpp.

References getVectorForCommand().

Referenced by getJointTorques().

std::map< std::string, std::vector< float > > NVRemoteConnection::getJointTorques ( const std::vector< std::string > &  jointList  ) 

Warning:
Currently this works only if the joint names are not empty. Otherwise no answer is returned and the operation just stops the execution of NVRemoteConnection until some answer is returned.
Parameters:
jointList an std::vector of joint names.
Returns:
torqueMap: a map which maps the joint names to their current force vector.

Definition at line 367 of file NVRemoteConnection.cpp.

References getJointTorque(), and getMapForNodesAndCommand().

std::vector< std::string > NVRemoteConnection::getListForCommand ( const std::string &  commandName  ) 

This method sets the verbosity to 0 and afterwards calls the command specified as parameter. The returned answer is then split up into separate strings. The split occurs at the '
' (newline) character

Parameters:
commandName the command to send to the networkviewer (jlist or blist for example).
Returns:
stringList: a std::vector which contains all the std::string objects or an empty list on error.

Definition at line 434 of file NVRemoteConnection.cpp.

References commandStream, m_pSocket, receiveAnswer(), and CTCPSocket::send().

Referenced by getBodyList(), and getJointList().

std::map< std::string, float > NVRemoteConnection::getMapForNodesAndCommand ( const std::vector< std::string > &  nodeList,
float(NVRemoteConnection::*)(const std::string &)  commandFunction 
)

This method calls the supplied function for each of the elements in nodeList and returns a mapping between each nodeList element and the result of the function call.

Parameters:
nodeList an std::vector of std::strings (usually joint names)
commandFunction the function to call for each element (this must be a method of NVRemoteConnection which has the same signature as the function pointer).

Definition at line 326 of file NVRemoteConnection.cpp.

std::map< std::string, std::vector< float > > NVRemoteConnection::getMapForNodesAndCommand ( const std::vector< std::string > &  nodeList,
std::vector< float >(NVRemoteConnection::*)(const std::string &, bool)  commandFunction 
)

This method calls the supplied function for each of the elements in nodeList and returns a mapping between each nodeList element and the result of the function call.

Parameters:
nodeList an std::vector of std::strings (usually joint names)
commandFunction the function to call for each element (this must be a method of NVRemoteConnection which has the same signature as the function pointer).

Definition at line 299 of file NVRemoteConnection.cpp.

Referenced by getJointAngleRates(), getJointAngles(), getJointForces(), getJointPositionRates(), getJointPositions(), and getJointTorques().

float NVRemoteConnection::getValueForCommand ( const std::string &  commandName,
const std::string &  nodeName 
)

Assembles the command from commandName and nodeName parameter and returns the float value of the command.

Parameters:
commandName the command to send (must return a float value).
nodeName the name of the node the command uses to return a value.
Returns:
floatValue: the decoded float value or 0.0f on error.

Definition at line 230 of file NVRemoteConnection.cpp.

References commandStream, m_pSocket, receiveAnswer(), and CTCPSocket::send().

Referenced by getJointAngle(), getJointAngleRate(), getJointPosition(), and getJointPositionRate().

std::vector< float > NVRemoteConnection::getVectorForCommand ( const std::string &  commandName,
const std::string &  nodeName,
bool  firstBody = true 
)

Generic method which sends a command and a node name to the networkviewer and returns the answered vector. This method should be used by all other getX() commands.

Parameters:
commandName the name of the command to send to the viewer
nodeName name of the body or joint to query
firstBody bool for the jointtorque and jointforce commands. It tells which body to use.
Returns:
resultVector: an std::vector<float> of dimension 3 which contains the result values or 0.0f on error.

Definition at line 169 of file NVRemoteConnection.cpp.

References commandStream, m_pSocket, receiveAnswer(), and CTCPSocket::send().

Referenced by getJointForce(), and getJointTorque().

bool NVRemoteConnection::isConnected (  ) 

Returns the status of the remote connection.

Returns:
true if connected, false otherwise.

Definition at line 666 of file NVRemoteConnection.cpp.

References CTCPSocket::isConnected(), and m_pSocket.

bool NVRemoteConnection::receiveAnswer ( std::string &  answer  )  [protected]

Receives an answer from the socket and returns it.

Parameters:
answer contains the received answer or "" if a socket error occured.
Returns:
successful: is false if a failure occured and true otherwise.
Warning:
This command sets the socket to blocking mode at first and after the first succesfull read of data sets it to unblocking again. So make sure to call this method only when an answer to a command is expected, otherwise the application will hang.

Definition at line 620 of file NVRemoteConnection.cpp.

References m_pSocket, CTCPSocket::receive(), and CTCPSocket::setNonBlocking().

Referenced by getListForCommand(), getValueForCommand(), and getVectorForCommand().

void NVRemoteConnection::scheduleOde ( bool  scheduleSimulation = true  ) 

Sends the (un-)schedule command to the NetworkViewer to (stop)start the simulation.

Parameters:
scheduleSimulation schedules the simulation if true, otherwise unschedules it (default is true).

Definition at line 147 of file NVRemoteConnection.cpp.

References m_pSocket, and CTCPSocket::send().

Referenced by sendCommands().

void NVRemoteConnection::sendCommands (  ) 

Sends some commands and prints the answer if available. Currently interacts with a joint from the file joint-test.iv.

Warning:
may be removed sometime

Definition at line 81 of file NVRemoteConnection.cpp.

References getJointForces(), getJointList(), scheduleOde(), and setJointSpeed().

void NVRemoteConnection::set3DVectorForCommandAndNode ( const std::vector< float > &  values,
const std::string &  commandName,
const std::string &  nodeName 
)

Generic method which checks if the supplied value vector is of size 3 and afterwards assembles the command by appending commandName with nodeName and the three values of the value vector.

Parameters:
values a 3D vectors of the values to set on the node given by nodeName.
commandName the name of the command to send to the viewer.
nodeName the name of the node (usually a joint) on which the command should be executed.
Warning:
the command given by commandName must take 4 parameters. Otherwise this will not work.

Definition at line 500 of file NVRemoteConnection.cpp.

References commandStream, m_pSocket, and CTCPSocket::send().

void NVRemoteConnection::setJointForce ( const std::string &  jointName,
float  force 
)

Sets the force supplied as parameter on the joint specified in the first parameter.

Parameters:
jointName Name of the Open Inventor node in the scenegraph.
force the force value to set.

Definition at line 542 of file NVRemoteConnection.cpp.

References setValueForCommandAndNode().

void NVRemoteConnection::setJointForce2 ( const std::string &  jointName,
float  force2 
)

Sets the force2 supplied as parameter on the joint specified in the first parameter.

Parameters:
jointName Name of the Open Inventor node in the scenegraph.
force2 the force2 value to set.

Definition at line 554 of file NVRemoteConnection.cpp.

References setValueForCommandAndNode().

void NVRemoteConnection::setJointSpeed ( const std::string &  jointName,
float  speed 
)

Sets the speed supplied as parameter on the joint specified in the first parameter.

Parameters:
jointName Name of the Open Inventor node in the scenegraph.
speed the speed value to set.

Definition at line 566 of file NVRemoteConnection.cpp.

References setValueForCommandAndNode().

Referenced by sendCommands().

void NVRemoteConnection::setJointSpeed2 ( const std::string &  jointName,
float  speed2 
)

Sets the speed2 supplied as parameter on the joint specified in the first parameter.

Parameters:
jointName Name of the Open Inventor node in the scenegraph.
speed2 the speed2 value to set.

Definition at line 578 of file NVRemoteConnection.cpp.

References setValueForCommandAndNode().

void NVRemoteConnection::setJointTorque ( const std::string &  jointName,
float  torque 
)

Sets the torque supplied as parameter on the joint specified in the first parameter.

Parameters:
jointName Name of the Open Inventor node in the scenegraph.
torque the torque value to set.

Definition at line 590 of file NVRemoteConnection.cpp.

References setValueForCommandAndNode().

void NVRemoteConnection::setJointTorque2 ( const std::string &  jointName,
float  torque2 
)

Sets the torque2 supplied as parameter on the joint specified in the first parameter.

Parameters:
jointName Name of the Open Inventor node in the scenegraph.
torque2 the torque2 value to set.

Definition at line 602 of file NVRemoteConnection.cpp.

References setValueForCommandAndNode().

void NVRemoteConnection::setValueForCommandAndNode ( const float &  value,
const std::string &  commandName,
const std::string &  nodeName 
)

Generic method which assembles the command by appending commandName with nodeName and the given value.

Parameters:
value the value to set on the node given by nodeName.
commandName the name of the command to send to the viewer.
nodeName the name of the node (usually a joint) on which the command should be executed.
Warning:
the command given by commandName must take 2 parameters. Otherwise this will not work.

Definition at line 526 of file NVRemoteConnection.cpp.

References commandStream, m_pSocket, and CTCPSocket::send().

Referenced by setJointForce(), setJointForce2(), setJointSpeed(), setJointSpeed2(), setJointTorque(), and setJointTorque2().


Member Data Documentation

Instance of std::ostringstream used to assemble commands.

Definition at line 83 of file NVRemoteConnection.h.

Referenced by getListForCommand(), getValueForCommand(), getVectorForCommand(), set3DVectorForCommandAndNode(), and setValueForCommandAndNode().


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

Get IPSA - Inventor Physics Simulation API at SourceForge.net. Fast, secure and Free Open Source software downloads
Generated on Sat Mar 10 20:00:19 2012 for IPSA by  doxygen 1.5.8