Fawkes API  Fawkes Development Version
OpenRaveThread Class Reference

OpenRAVE Thread. More...

#include "openrave_thread.h"

Inheritance diagram for OpenRaveThread:

List of all members.

Public Member Functions

 OpenRaveThread ()
 Constructor.
virtual ~OpenRaveThread ()
 Destructor.
virtual void init ()
 Initialize the thread.
virtual void loop ()
 Code to execute in the thread.
virtual void finalize ()
 Finalize the thread.
virtual
fawkes::OpenRaveEnvironment
get_environment () const
 Get pointer to OpenRaveEnvironment object.
virtual fawkes::OpenRaveRobotget_active_robot () const
 Get pointer to currently used OpenRaveRobot object.
virtual void set_active_robot (fawkes::OpenRaveRobot *robot)
 Set robot to be used.
virtual fawkes::OpenRaveRobotadd_robot (const std::string &filename_robot, bool autogenerate_IK)
 Add a new robot to the environment, and set it as the currently active one.
virtual void set_manipulator (fawkes::OpenRaveManipulator *manip, float trans_x=0.f, float trans_y=0.f, float trans_z=0.f, bool calibrate=0)
 Set OpenRaveManipulator object for robot, and calculate coordinate-system offsets or set them directly.
virtual void set_manipulator (fawkes::OpenRaveRobot *robot, fawkes::OpenRaveManipulator *manip, float trans_x=0.f, float trans_y=0.f, float trans_z=0.f, bool calibrate=0)
 Set OpenRaveManipulator object for robot, and calculate coordinate-system offsets or set them directly.
virtual void start_viewer () const
 Start Viewer.
virtual void run_planner (fawkes::OpenRaveRobot *=NULL, float sampling=0.01f)
 Run planner on previously set target.
virtual void run_graspplanning (const std::string &target_name, fawkes::OpenRaveRobot *robot=NULL)
 Run graspplanning script for a given target.
virtual bool add_object (const std::string &name, const std::string &filename)
 Add an object to the environment.
virtual bool delete_object (const std::string &name)
 Remove object from environment.
virtual bool rename_object (const std::string &name, const std::string &new_name)
 Rename object.
virtual bool move_object (const std::string &name, float trans_x, float trans_y, float trans_z, fawkes::OpenRaveRobot *robot=NULL)
 Move object in the environment.
virtual bool rotate_object (const std::string &name, float quat_x, float quat_y, float quat_z, float quat_w)
 Rotate object by a quaternion.
virtual bool rotate_object (const std::string &name, float rot_x, float rot_y, float rot_z)
 Rotate object along its axis.
virtual bool set_target_object (const std::string &name, fawkes::OpenRaveRobot *robot, float rot_x=0)
 Set an object as the target.
virtual bool attach_object (const std::string &name, fawkes::OpenRaveRobot *robot=NULL)
 Attach a kinbody to the robot.
virtual bool release_object (const std::string &name, fawkes::OpenRaveRobot *robot=NULL)
 Release a kinbody from the robot.
virtual bool release_all_objects (fawkes::OpenRaveRobot *robot=NULL)
 Release all grabbed kinbodys from the robot.

Protected Member Functions

virtual void run ()
 Stub to see name in backtrace for easier debugging.

Detailed Description

OpenRAVE Thread.

This thread maintains an active connection to OpenRAVE and provides an aspect to access OpenRAVE to make it convenient for other threads to use OpenRAVE.

Author:
Bahram Maleki-Fard

Constructor & Destructor Documentation

OpenRaveThread::OpenRaveThread ( )

Constructor.

Definition at line 44 of file openrave_thread.cpp.

OpenRaveThread::~OpenRaveThread ( ) [virtual]

Destructor.

Definition at line 57 of file openrave_thread.cpp.


Member Function Documentation

bool OpenRaveThread::add_object ( const std::string name,
const std::string filename 
) [virtual]

Add an object to the environment.

Parameters:
namename that should be given to that object
filenamepath to xml file of that object (KinBody)
Returns:
true if successful

Implements fawkes::OpenRaveConnector.

Definition at line 219 of file openrave_thread.cpp.

References fawkes::OpenRaveEnvironment::add_object().

Referenced by OpenRaveMessageHandlerThread::loop().

OpenRaveRobot * OpenRaveThread::add_robot ( const std::string filename_robot,
bool  autogenerate_IK 
) [virtual]

Add a new robot to the environment, and set it as the currently active one.

Parameters:
filename_robotpath to robot's xml file
autogenerate_IKif true: autogenerate IKfast IK solver for robot
Returns:
pointer to new OpenRaveRobot object

Implements fawkes::OpenRaveConnector.

Definition at line 197 of file openrave_thread.cpp.

References fawkes::LoggingAspect::logger, fawkes::OpenRaveRobot::load(), fawkes::OpenRaveEnvironment::add_robot(), fawkes::OpenRaveRobot::set_ready(), fawkes::OpenRaveEnvironment::load_IK_solver(), and set_active_robot().

bool OpenRaveThread::attach_object ( const std::string name,
fawkes::OpenRaveRobot robot = NULL 
) [virtual]

Attach a kinbody to the robot.

Parameters:
namename of the object
robotpointer to OpenRaveRobot that object is attached to
Returns:
true if successfull

Implements fawkes::OpenRaveConnector.

Definition at line 290 of file openrave_thread.cpp.

References fawkes::OpenRaveRobot::attach_object().

Referenced by OpenRaveMessageHandlerThread::loop().

bool OpenRaveThread::delete_object ( const std::string name) [virtual]

Remove object from environment.

Parameters:
namename of the object
Returns:
true if successful

Implements fawkes::OpenRaveConnector.

Definition at line 225 of file openrave_thread.cpp.

References fawkes::OpenRaveEnvironment::delete_object().

Referenced by OpenRaveMessageHandlerThread::loop().

void OpenRaveThread::finalize ( ) [virtual]

Finalize the thread.

This method is executed just before the thread is canceled and destroyed. It is always preceeded by a call to prepare_finalize(). If this is not the case this is a failure. The condition can be checked with the boolean variable finalize_prepared.

This method is meant to be used in conjunction with aspects and to cover thread inter-dependencies. This routine MUST bring the thread into a safe state such that it may be canceled and destroyed afterwards. If there is any reason that this cannot happen make your prepare_finalize() reports so.

This method is called by the thread manager just before the thread is being cancelled. Here you can do whatever steps are necessary just before the thread is cancelled. Note that you thread is still running and might be in the middle of a loop, so it is not a good place to give up on all resources used. Mind segmentation faults that could happen. Protect the area with a mutex that you lock at the beginning of your loop and free in the end, and that you lock at the beginning of finalize and then never unlock. Also not that the finalization may be canceled afterwards. The next thing that happens is that either the thread is canceled and destroyed or that the finalization is canceled and the thread has to run again.

Finalize is called on a thread just before it is deleted. It is guaranteed to be called on a fully initialized thread (if no exception is thrown in init()) (this guarantee holds in the Fawkes framework).

The default implementation does nothing besides throwing an exception if prepare_finalize() has not been called.

Exceptions:
Exceptionthrown if prepare_finalize() has not been called.
See also:
prepare_finalize()
cancel_finalize()

Reimplemented from fawkes::Thread.

Definition at line 81 of file openrave_thread.cpp.

References fawkes::OpenRaveEnvironment::destroy().

OpenRaveRobot * OpenRaveThread::get_active_robot ( ) const [virtual]

Get pointer to currently used OpenRaveRobot object.

Returns:
pointer

Implements fawkes::OpenRaveConnector.

Definition at line 108 of file openrave_thread.cpp.

OpenRaveEnvironment * OpenRaveThread::get_environment ( ) const [virtual]

Get pointer to OpenRaveEnvironment object.

Returns:
pointer

Implements fawkes::OpenRaveConnector.

Definition at line 99 of file openrave_thread.cpp.

void OpenRaveThread::init ( ) [virtual]

Initialize the thread.

This method is meant to be used in conjunction with aspects. Some parts of the initialization may only happen after some aspect of the thread has been initialized. Implement the init method with these actions. It is guaranteed to be called just after all aspects have been initialized and only once in the lifetime of the thread. Throw an exception if any problem occurs and the thread should not run.

Just because your init() routine suceeds and everything looks fine for this thread does not automatically imply that it will run. If it belongs to a group of threads in a ThreadList and any of the other threads fail to initialize then no thread from this group is run and thus this thread will never run. In that situation finalize() is called for this very instance, prepare_finalize() however is not called.

See also:
Fawkes Thread Aspects

Reimplemented from fawkes::Thread.

Definition at line 63 of file openrave_thread.cpp.

References fawkes::LoggingAspect::logger, fawkes::Logger::log_error(), fawkes::Thread::name(), fawkes::OpenRaveEnvironment::create(), fawkes::OpenRaveEnvironment::enable_debug(), and fawkes::OpenRaveEnvironment::lock().

void OpenRaveThread::loop ( ) [virtual]

Code to execute in the thread.

Implement this method to hold the code you want to be executed continously. If you do not implement this method, the default is that the thread will exit. This is useful if you choose to only implement once().

Reimplemented from fawkes::Thread.

Definition at line 88 of file openrave_thread.cpp.

bool OpenRaveThread::move_object ( const std::string name,
float  trans_x,
float  trans_y,
float  trans_z,
fawkes::OpenRaveRobot robot = NULL 
) [virtual]

Move object in the environment.

Distances are given in meters

Parameters:
namename of the object
trans_xtransition along x-axis
trans_ytransition along y-axis
trans_ztransition along z-axis
robotif given, move relatively to robot (in most simple cases robot is at position (0,0,0) anyway, so this has no effect)
Returns:
true if successful

Implements fawkes::OpenRaveConnector.

Definition at line 243 of file openrave_thread.cpp.

References fawkes::OpenRaveEnvironment::move_object().

Referenced by OpenRaveMessageHandlerThread::loop().

bool OpenRaveThread::release_all_objects ( fawkes::OpenRaveRobot robot = NULL) [virtual]

Release all grabbed kinbodys from the robot.

Parameters:
robotpointer to OpenRaveRobot that objects are released from
Returns:
true if successfull

Implements fawkes::OpenRaveConnector.

Definition at line 317 of file openrave_thread.cpp.

References fawkes::OpenRaveRobot::release_all_objects().

Referenced by OpenRaveMessageHandlerThread::loop().

bool OpenRaveThread::release_object ( const std::string name,
fawkes::OpenRaveRobot robot = NULL 
) [virtual]

Release a kinbody from the robot.

Parameters:
namename of the object
robotpointer to OpenRaveRobot that object is released from
Returns:
true if successfull

Implements fawkes::OpenRaveConnector.

Definition at line 304 of file openrave_thread.cpp.

References fawkes::OpenRaveRobot::release_object().

Referenced by OpenRaveMessageHandlerThread::loop().

bool OpenRaveThread::rename_object ( const std::string name,
const std::string new_name 
) [virtual]

Rename object.

Parameters:
namecurrent name of the object
new_namenew name of the object
Returns:
true if successful

Implements fawkes::OpenRaveConnector.

Definition at line 232 of file openrave_thread.cpp.

References fawkes::OpenRaveEnvironment::rename_object().

Referenced by OpenRaveMessageHandlerThread::loop().

bool OpenRaveThread::rotate_object ( const std::string name,
float  quat_x,
float  quat_y,
float  quat_z,
float  quat_w 
) [virtual]

Rotate object by a quaternion.

Parameters:
namename of the object
quat_xx value of quaternion
quat_yy value of quaternion
quat_zz value of quaternion
quat_ww value of quaternion
Returns:
true if successful

Implements fawkes::OpenRaveConnector.

Definition at line 253 of file openrave_thread.cpp.

References fawkes::OpenRaveEnvironment::rotate_object().

Referenced by OpenRaveMessageHandlerThread::loop().

bool OpenRaveThread::rotate_object ( const std::string name,
float  rot_x,
float  rot_y,
float  rot_z 
) [virtual]

Rotate object along its axis.

Rotation angles should be given in radians.

Parameters:
namename of the object
rot_x1st rotation, along x-axis
rot_y2nd rotation, along y-axis
rot_z3rd rotation, along z-axis
Returns:
true if successful

Implements fawkes::OpenRaveConnector.

Definition at line 263 of file openrave_thread.cpp.

References fawkes::OpenRaveEnvironment::rotate_object().

virtual void OpenRaveThread::run ( ) [inline, protected, virtual]

Stub to see name in backtrace for easier debugging.

See also:
Thread::run()

Reimplemented from fawkes::Thread.

Definition at line 84 of file openrave_thread.h.

void OpenRaveThread::run_graspplanning ( const std::string target_name,
fawkes::OpenRaveRobot robot = NULL 
) [virtual]

Run graspplanning script for a given target.

Parameters:
target_namename of targeted object (KinBody)
robotrobot to use planner on. If none is given, the currently used robot is taken

Implements fawkes::OpenRaveConnector.

Definition at line 183 of file openrave_thread.cpp.

References fawkes::OpenRaveEnvironment::run_graspplanning().

void OpenRaveThread::run_planner ( fawkes::OpenRaveRobot robot = NULL,
float  sampling = 0.01f 
) [virtual]

Run planner on previously set target.

Parameters:
robotrobot to use planner on. If none is given, the currently used robot is taken
samplingsampling time between each trajectory point (in seconds)

Implements fawkes::OpenRaveConnector.

Definition at line 170 of file openrave_thread.cpp.

References fawkes::OpenRaveEnvironment::run_planner().

void OpenRaveThread::set_active_robot ( fawkes::OpenRaveRobot robot) [virtual]

Set robot to be used.

Parameters:
robotOpenRaveRobot that should be used implicitly in other methods

Implements fawkes::OpenRaveConnector.

Definition at line 117 of file openrave_thread.cpp.

Referenced by add_robot().

void OpenRaveThread::set_manipulator ( fawkes::OpenRaveManipulator manip,
float  trans_x = 0.f,
float  trans_y = 0.f,
float  trans_z = 0.f,
bool  calibrate = 0 
) [virtual]

Set OpenRaveManipulator object for robot, and calculate coordinate-system offsets or set them directly.

Make sure to update manip angles before calibrating! Uses default OpenRaveRobot object.

Parameters:
manippointer to OpenRAVManipulator that is set for robot
trans_xtransition offset on x-axis
trans_ytransition offset on y-axis
trans_ztransition offset on z-axis
calibratedecides whether to calculate offset (true )or set them directly (false; default)

Implements fawkes::OpenRaveConnector.

Definition at line 152 of file openrave_thread.cpp.

void OpenRaveThread::set_manipulator ( fawkes::OpenRaveRobot robot,
fawkes::OpenRaveManipulator manip,
float  trans_x = 0.f,
float  trans_y = 0.f,
float  trans_z = 0.f,
bool  calibrate = 0 
) [virtual]

Set OpenRaveManipulator object for robot, and calculate coordinate-system offsets or set them directly.

Make sure to update manip angles before calibrating!

Parameters:
robotpointer to OpenRaveRobot object, explicitly set
manippointer to OpenRAVManipulator that is set for robot
trans_xtransition offset on x-axis
trans_ytransition offset on y-axis
trans_ztransition offset on z-axis
calibratedecides whether to calculate offset (true )or set them directly (false; default)

Implements fawkes::OpenRaveConnector.

Definition at line 133 of file openrave_thread.cpp.

References fawkes::OpenRaveRobot::set_manipulator(), fawkes::OpenRaveRobot::calibrate(), and fawkes::OpenRaveRobot::set_offset().

bool OpenRaveThread::set_target_object ( const std::string name,
fawkes::OpenRaveRobot robot,
float  rot_x = 0 
) [virtual]

Set an object as the target.

Currently the object should be cylindric, and stand upright. It may also be rotated on its x-axis, but that rotation needs to be given in an argument to calculate correct position for endeffecto. This is only temporary until proper graps planning for 5DOF in OpenRAVE is provided.

Parameters:
namename of the object
robotpointer to OpenRaveRobot that the target is set for
rot_xrotation of object on x-axis (radians)
Returns:
true if IK solvable

Implements fawkes::OpenRaveConnector.

Definition at line 277 of file openrave_thread.cpp.

References fawkes::OpenRaveEnvironment::get_env_ptr(), and fawkes::OpenRaveRobot::set_target_object_position().

void OpenRaveThread::start_viewer ( ) const [virtual]

Start Viewer.

Implements fawkes::OpenRaveConnector.

Definition at line 160 of file openrave_thread.cpp.

References fawkes::OpenRaveEnvironment::start_viewer().


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