2 #ifndef _VREP_VF_CONTROLLER_ 3 #define _VREP_VF_CONTROLLER_ 12 #include <boost/format.hpp> 14 #include <Eigen/Geometry> 16 #include <sawConstraintController/mtsVFController.h> 24 #include <boost/lexical_cast.hpp> 25 #include <boost/range/algorithm/copy.hpp> 51 return std::make_tuple(
"RobotMillTipTarget",
"IK_Group1_iiwa");
110 #ifndef IGNORE_ROTATION 148 mckp2 = eigentestJacobian.cast<
double>();
153 Eigen::MatrixXf eigenJacobian = eigentestJacobian;
161 auto & llim = std::get<vrep::VrepRobotArmDriver::JointLowerPositionLimit>(
currentArmState_);
162 std::vector<double> llimits(llim.begin(),llim.end());
166 auto & ulim = std::get<vrep::VrepRobotArmDriver::JointUpperPositionLimit>(
currentArmState_);
167 std::vector<double> ulimits(ulim.begin(),ulim.end());
171 auto & currentJointPos = std::get<vrep::VrepRobotArmDriver::JointPosition>(
currentArmState_);
172 std::vector<double> currentJointPosVec(currentJointPos.begin(),currentJointPos.end());
173 vctDoubleVec vctDoubleVecCurrentJoints(currentJointPosVec.size(),¤tJointPosVec[0]);
181 Eigen::Affine3d currentEndEffectorPose =
183 std::get<vrep::VrepRobotArmDriver::RobotTipName>(handleParams)
184 ,std::get<vrep::VrepRobotArmDriver::RobotTargetBaseName>(handleParams)
186 auto currentEigenT = currentEndEffectorPose.translation();
188 currentCisstT[0] = currentEigenT(0);
189 currentCisstT[1] = currentEigenT(1);
190 currentCisstT[2] = currentEigenT(2);
191 #ifndef IGNORE_ROTATION 193 ccr = currentEndEffectorPose.rotation();
194 #endif // IGNORE_ROTATION 198 Eigen::Affine3d desiredEndEffectorPose =
200 std::get<vrep::VrepRobotArmDriver::RobotTargetName>(handleParams)
201 ,std::get<vrep::VrepRobotArmDriver::RobotTargetBaseName>(handleParams)
203 auto desiredEigenT = desiredEndEffectorPose.translation();
205 desiredCisstT[0] = desiredEigenT(0);
206 desiredCisstT[1] = desiredEigenT(1);
207 desiredCisstT[2] = desiredEigenT(2);
208 #ifndef IGNORE_ROTATION 210 dcr = desiredEndEffectorPose.rotation();
211 #endif // IGNORE_ROTATION 215 auto inputDesired_dx = desiredCisstT - currentCisstT;
217 vct3 dx_translation, dx_rotation;
223 dxRotVec = dxRot.Axis() * dxRot.Angle();
224 dx_rotation[0] = dxRotVec[0];
225 dx_rotation[1] = dxRotVec[1];
226 dx_rotation[2] = dxRotVec[2];
230 Eigen::AngleAxis<float> tipToTarget_cisstToEigen;
232 Eigen::Matrix3f rotmat;
233 double theta = std::sqrt(dx_rotation[0]*dx_rotation[0]+dx_rotation[1]*dx_rotation[1]+dx_rotation[2]*dx_rotation[2]);
234 rotmat= Eigen::AngleAxisf(theta,Eigen::Vector3f(dx_rotation[0]/theta,dx_rotation[1]/theta,dx_rotation[2]/theta));
256 UpdateOptimizer(simulationTimeStep);
258 vctDoubleVec jointAngles_dt;
259 auto returncode = Solve(jointAngles_dt);
263 if(returncode != nmrConstraintOptimizer::NMR_OK) BOOST_THROW_EXCEPTION(std::runtime_error(
"VrepInverseKinematicsController: constrained optimization error, please investigate"));
273 BOOST_VERIFY(ret!=-1);
274 float futureAngle = currentAngle + jointAngles_dt[i];
279 str+=boost::lexical_cast<std::string>(jointAngles_dt[i]);
283 BOOST_LOG_TRIVIAL(trace) <<
"jointAngles_dt: "<< str;
287 BOOST_LOG_TRIVIAL(trace) <<
"\n desired dx: " << inputDesired_dx <<
" " << dx_rotation <<
"\noptimizer Calculated dx: " << optimizerCalculated_dx;
std::unique_ptr< mtsVFDataJointLimits > jointPositionLimitsVFP_
joints cannot go to certain position
ptrSimGetJointPosition simGetJointPosition
std::tuple< std::string,std::string > Params
Eigen::Affine3d getObjectTransform(int objectHandle, int relativeToObjectHandle=-1)
VrepInverseKinematicsController(size_t num_joints=7, mtsVFBase::CONTROLLERMODE cm=mtsVFBase::CONTROLLERMODE::JPOS)
ptrSimGetIkGroupHandle simGetIkGroupHandle
vrep::VrepRobotArmDriver::State currentArmState_
grl::InverseKinematicsController parent_type
Eigen::MatrixXf getJacobian(vrep::VrepRobotArmDriver &driver, bool jacobianOnly=false)
get the Jacobian as calculated by vrep in an Eigen::MatrixXf in column major format ...
std::string velocityLimitsName
std::tuple< std::string,std::string,std::string,std::size_t,std::string,std::size_t,std::string,std::size_t > Params
ptrSimSetJointPosition simSetJointPosition
static Params defaultParams()
VrepVFControllerParamsIndex
void updateKinematics()
check out sawConstraintController
std::unique_ptr< prmKinematicsState > desiredKinematicsStateP_
This will hold the xyz position and the rotation of where I want to go.
void construct(Params params=defaultParams())
std::string positionLimitsName
std::vector< int > jointHandles_
std::unique_ptr< mtsVFDataJointLimits > jointVelocityLimitsVFP_
need velocity limits for the joints
std::unique_ptr< mtsVFDataBase > followVFP_
std::unique_ptr< prmKinematicsState > currentKinematicsStateP_
This will hold the Jacobian.
std::tuple< JointScalar, JointScalar, JointScalar, JointScalar, JointScalar, TransformationMatrices, JointStateTag, JointScalar > State
std::shared_ptr< vrep::VrepRobotArmDriver > VrepRobotArmDriverP_
ptrSimSetExplicitHandling simSetExplicitHandling
ptrSimGetSimulationTimeStep simGetSimulationTimeStep