GraspModuleIK

From OpenRAVE
Revision as of 01:56, 19 December 2011 by SteveHegenbart (Talk | contribs) (Using the grasping module for an neuronics-katana 5D arm)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The GraspModuleIK is a grasping plugin for the C++ API. The currently version uses both an IkSolver for the main path planning and an trajectory and collision detection algorithm to open and close the gripper for grabbing an object. Yet it has only implemented simple grasping positions and an 5D IkParameterization. Still, the module is designed for simple extensions to add also other robot models.

Sourceforge Directory

https://sourceforge.net/projects/orgraspmoduleik/

The GraspingModuleIK class

Attributes

The class keeps simple private attributes, mostly initialized when the module is created:

<source lang="cpp"> private:

   OpenRAVE::RobotBasePtr _probot;              ///< The active robot that will grab
   OpenRAVE::ModuleBasePtr _pikmodule;          ///< IkSolver module to get joint solutions
   OpenRAVE::ModuleBasePtr _pbasemanip;         ///< Basemanipulator to simulate the robots movement
   OpenRAVE::RobotBase::ManipulatorPtr _pmanip; ///< Active manipulator to load the ikSolver
   boost::shared_ptr<GraspParameters> _params;  ///< Grasping parameter struct
   enum handPosition {positionClose, positionOpen, positionBase};
   enum handMoveMode {openHand, closeHand};

</source>

The enumerations are used inside inner methods to change the gripper position. Yet the grasping module needs to be reinitialized to change the base pointers i.g. the robot and modules specified for the robot.

Public Methods

The main functions to use are the grasping function, releasing objects and the main move function (normally used after an object is grabbed, it can also be used without any object).

<source lang="cpp"> bool GraspTarget(boost::shared_ptr<GraspParameters> params); void ReleaseAllObjects(); bool ReleaseObject(OpenRAVE::KinBodyPtr target); bool MoveObjectToPosition(OpenRAVE::RAY ray); </source>

The GraspTarget will open the gripper if possible, then move to the target and grab it. The main usage of the module is as following:

  • Create the module
  • Call GraspTarget()
  • Call MoveObjectToPosition()
  • Call ReleaseObject() or ReleaseAllObjects()

GraspParameters

The GraspParameters struct is holding all informations to grab an object. It is defined as followed:

<source lang="cpp"> struct GraspParameters {

   OpenRAVE::KinBodyPtr _target;                   
       ///< The target which shall be grabbed
   OpenRAVE::dReal _standoff;                 
       ///< Standoff between target and robot in grab direction that will be held, in default this will be zero
   OpenRAVE::dReal _offset;                   
       ///< The offset in z direction from the basic point of the target where the robot will grab the target
   OpenRAVE::dReal _coarsestep;               
       ///< Coarse step value used to approach the target while closing the gripper
   OpenRAVE::dReal _finestep;                 
       ///< Fine step value used to approach the target while closing the gripper, this will be used after the coarse approximation
   int _grabDirection;            
       ///< The used grab direction to grab the target with the robot arm. Here the OpenRAVE DOF-Values DOF_X, DOF_Y and DOF_Z can be used
   int _ikParameterization;       
       ///< The ikParameterization for the robot used to initialize the ikSolver
   bool _avoidTargetCollision;     
       ///< If set, the gripper will step back a bit after there was a collision with the target while closing the gripper

};</source>

There is also an constructor defined for the struct, defining default values for all parameters except the target, the grabDirection and the ikParameterization.

<source lang="cpp"> GraspParameters(OpenRAVE::KinBodyPtr target, int grabDirection, int ikParameterization, OpenRAVE::dReal standoff = 0.0f,

                   OpenRAVE::dReal offset = 0.05f, OpenRAVE::dReal coarsestep = 0.1f, OpenRAVE::dReal finestep = 0.01f,
                   bool avoidTargetCollision = true)

</source>

Code Examples

Using the grasping module for an neuronics-katana 5D arm

The following code shows how to initialize the module, define some parameters and call the main methods to grab some cups. There are two cups in the environment, standing on a table, as well as a bottle of ketchup. The first cup will be grabbed and placed down between the second cup and the bottle. Then, the second cup will be grabbed and placed to the original position of the first cup.

<source lang="cpp"> // ***** Get target KinBody KinBodyPtr target = penv->GetKinBody("cup1"); std::string targetType; targetType = target->GetURI().substr(target->GetURI().find_last_of('/') + 1).c_str();

// ***** Initialize grasper and graspParameters GraspingModuleIK grasper(penv, probot);

dReal standoff = 0.0f; dReal offset = 0.5f;

RAY first; first.pos = target->GetTransform().trans; first.dir = Vector(0,0,1); first.dir.normalize3();

boost::shared_ptr<GraspParameters> params(new GraspParameters(target, (int)DOF_Z, (int)IkParameterization::Type_TranslationDirection5D, standoff, offset)); params->_coarsestep = 0.1f; params->_finestep = 0.01f; params->_avoidTargetCollision = false; params->_target = penv->GetKinBody("cup1");

// ***** Grasp target object grasper.GraspTarget(params);

// ***** Move object to new position and release it RAY ray; ray.pos = penv->GetKinBody("cup2")->GetTransform().trans; ray.pos.y = (ray.pos.y + penv->GetKinBody("ketchup")->GetTransform().trans.y) / 2.0; ray.pos.z += params->_offset; ray.dir = Vector(0,0,1); ray.dir.normalize3(); grasper.MoveObjectToPosition(ray); grasper.ReleaseAllObjects();

// ***** Grab new target and move it params->_target = penv->GetKinBody("cup2"); grasper.GraspTarget(params);

first.pos.z += params->_offset; grasper.MoveObjectToPosition(first); grasper.ReleaseAllObjects(); </source>