예제 #1
0
 static void fk_1_proxy(const ModelHandler& model,
                        DataHandler & data,
                        const VectorXd_fx & q,
                        const VectorXd_fx & qdot )
 {
   forwardKinematics(*model,*data,q,qdot);
 }
예제 #2
0
 static void fk_2_proxy(const ModelHandler& model,
                        DataHandler & data,
                        const VectorXd_fx & q,
                        const VectorXd_fx & v,
                        const VectorXd_fx & a)
 {
   forwardKinematics(*model,*data,q,v,a);
 }
예제 #3
0
    //Evaluate the constraints for Chompification
    void TSRConstraint::evaluateConstraints(const MatX& qt, 
                                             MatX& h, 
                                             MatX& H)
    {
        //the pos is equivalent to the position of the 
        // end-effector in the robot frame. 
        double xyzrpy[6];
        
        //the position of the ee. 
        Transform pos;

        //get the position of the ee
        forwardKinematics( qt, pos );

        //get the position of the ee in the TSR frame
        endeffectorToTSRFrame( pos, xyzrpy );
        
        //the dimensionality of the configuration space
        size_t DoF = qt.size() ;
        
        //format h (constraint value vector).
        if (size_t(h.rows()) != _dim_constraint || h.cols() != 1)
        {
            h.resize(_dim_constraint, 1);
        }
        
        int current_dim = 0;

        std::vector< int > active_dims;
        
        for ( int i = 0; i < _dim_constraint; i ++ )
        {
            const int dim = _dimension_id[i];
            
            //if the robot's position goes over the TSR's upper bound:
            if ( xyzrpy[dim] > _Bw(dim, 1) ){
                h(current_dim) = xyzrpy[ dim ] - _Bw(dim, 1);
                active_dims.push_back( dim );
                current_dim ++;
            }
            //if the robot's position goes below the TSR's lower bound:
            else if ( xyzrpy[dim] < _Bw( dim, 0 ) ){
                h(current_dim) = xyzrpy[ dim ] - _Bw(dim, 0);
                active_dims.push_back( dim );
                current_dim ++;
            }
        }

        
        if ( current_dim != _dim_constraint ){
            h.conservativeResize( current_dim, 1 );
        }
        if ( H.rows() != current_dim || size_t( H.cols() ) != DoF ){
            H.resize( current_dim, DoF );
        }
        computeJacobian( qt, pos, H, active_dims );

    }
예제 #4
0
파일: FK.cpp 프로젝트: bchretien/RBDyn
void sForwardKinematics(const MultiBody& mb, MultiBodyConfig& mbc)
{
	checkMatchQ(mb, mbc);

	checkMatchBodyPos(mb, mbc);
	checkMatchJointConf(mb, mbc);
	checkMatchParentToSon(mb, mbc);

	forwardKinematics(mb, mbc);
}
예제 #5
0
 inline double
 kineticEnergy(const Model & model,
               Data & data,
               const Eigen::VectorXd & q,
               const Eigen::VectorXd & v,
               const bool update_kinematics)
 {
   data.kinetic_energy = 0.;
   
   if (update_kinematics)
     forwardKinematics(model,data,q,v);
   
   for(Model::Index i=1;i<(Model::Index)(model.nbody);++i)
     data.kinetic_energy += model.inertias[i].vtiv(data.v[i]);
   
   data.kinetic_energy *= .5;
   return data.kinetic_energy;
 }
예제 #6
0
파일: Bone.cpp 프로젝트: allen8807/RobotLib
        void Bone::forwardKinematics(const TransMatrixf& m,
                                     const map<unsigned int, AngDeg>& angles,
                                     map<unsigned int, TransMatrixf>& mats) const
        {
            TransMatrixf t = m;
            forwardKinematics(t,angles);
            mats[mId]=t;

            shared_ptr<const Bone> s = sister();
            if ( NULL != s.get() ){
                s->forwardKinematics(m,angles,mats);
            }

            shared_ptr<const Bone> c = child();
            if ( NULL != c.get() ){
                c->forwardKinematics(t,angles,mats);
            }
        }
예제 #7
0
 inline double
 potentialEnergy(const Model & model,
                 Data & data,
                 const Eigen::VectorXd & q,
                 const bool update_kinematics)
 {
   data.potential_energy = 0.;
   const Motion::ConstLinear_t & g = model.gravity.linear();
   SE3::Vector3 com_global;
   
   if (update_kinematics)
     forwardKinematics(model,data,q);
   
   for(Model::Index i=1;i<(Model::Index)(model.nbody);++i)
   {
     com_global = data.oMi[i].translation() + data.oMi[i].rotation() * model.inertias[i].lever();
     data.potential_energy += model.inertias[i].mass() * com_global.dot(g);
   }
   
   return data.potential_energy;
 }
예제 #8
0
void Wheels::updateGlobalPosition(long leftWheel, long rightWheel, long backWheel, double gyroAngle) {
	double localX, localY, localTheta;
	forwardKinematics(leftWheel, rightWheel, backWheel, localX, localY, localTheta);

	long cosRotation = SinLookupTable::getCosFromTenthDegrees(globalCurrentTheta);
	long sinRotation = SinLookupTable::getSinFromTenthDegrees(globalCurrentTheta);

	//double worldX = (localX * sinRotation) - (localY * cosRotation);
	//double worldY = (localX * cosRotation) + (localY * sinRotation);

	long worldX = (localX * cosRotation) - (localY * sinRotation);
	long worldY = (localX * sinRotation) + (localY * cosRotation);

	worldX /= LOOKUP_SCALE; // rotated from gyroscope
	worldY /= LOOKUP_SCALE;
	
	localCurrentX += worldX;
	localCurrentY += worldY;
	globalCurrentTheta = gyroAngle * 10;

	worldCurrentX += worldX;
	worldCurrentY += worldY;
}
예제 #9
0
void	btMultiBodyDynamicsWorld::solveConstraints(btContactSolverInfo& solverInfo)
{
	forwardKinematics();



	BT_PROFILE("solveConstraints");
	
	m_sortedConstraints.resize( m_constraints.size());
	int i; 
	for (i=0;i<getNumConstraints();i++)
	{
		m_sortedConstraints[i] = m_constraints[i];
	}
	m_sortedConstraints.quickSort(btSortConstraintOnIslandPredicate2());
	btTypedConstraint** constraintsPtr = getNumConstraints() ? &m_sortedConstraints[0] : 0;

	m_sortedMultiBodyConstraints.resize(m_multiBodyConstraints.size());
	for (i=0;i<m_multiBodyConstraints.size();i++)
	{
		m_sortedMultiBodyConstraints[i] = m_multiBodyConstraints[i];
	}
	m_sortedMultiBodyConstraints.quickSort(btSortMultiBodyConstraintOnIslandPredicate());

	btMultiBodyConstraint** sortedMultiBodyConstraints = m_sortedMultiBodyConstraints.size() ?  &m_sortedMultiBodyConstraints[0] : 0;
	

	m_solverMultiBodyIslandCallback->setup(&solverInfo,constraintsPtr,m_sortedConstraints.size(),sortedMultiBodyConstraints,m_sortedMultiBodyConstraints.size(), getDebugDrawer());
	m_constraintSolver->prepareSolve(getCollisionWorld()->getNumCollisionObjects(), getCollisionWorld()->getDispatcher()->getNumManifolds());
	
	/// solve all the constraints for this island
	m_islandManager->buildAndProcessIslands(getCollisionWorld()->getDispatcher(),getCollisionWorld(),m_solverMultiBodyIslandCallback);

#ifndef BT_USE_VIRTUAL_CLEARFORCES_AND_GRAVITY
	{
		BT_PROFILE("btMultiBody addForce");
		for (int i=0;i<this->m_multiBodies.size();i++)
		{
			btMultiBody* bod = m_multiBodies[i];

			bool isSleeping = false;
			
			if (bod->getBaseCollider() && bod->getBaseCollider()->getActivationState() == ISLAND_SLEEPING)
			{
				isSleeping = true;
			} 
			for (int b=0;b<bod->getNumLinks();b++)
			{
				if (bod->getLink(b).m_collider && bod->getLink(b).m_collider->getActivationState()==ISLAND_SLEEPING)
					isSleeping = true;
			} 

			if (!isSleeping)
			{
				//useless? they get resized in stepVelocities once again (AND DIFFERENTLY)
				m_scratch_r.resize(bod->getNumLinks()+1);			//multidof? ("Y"s use it and it is used to store qdd)
				m_scratch_v.resize(bod->getNumLinks()+1);
				m_scratch_m.resize(bod->getNumLinks()+1);

				bod->addBaseForce(m_gravity * bod->getBaseMass());

				for (int j = 0; j < bod->getNumLinks(); ++j) 
				{
					bod->addLinkForce(j, m_gravity * bod->getLinkMass(j));
				}
			}//if (!isSleeping)
		}
	}
#endif //BT_USE_VIRTUAL_CLEARFORCES_AND_GRAVITY
	

	{
		BT_PROFILE("btMultiBody stepVelocities");
		for (int i=0;i<this->m_multiBodies.size();i++)
		{
			btMultiBody* bod = m_multiBodies[i];

			bool isSleeping = false;
			
			if (bod->getBaseCollider() && bod->getBaseCollider()->getActivationState() == ISLAND_SLEEPING)
			{
				isSleeping = true;
			} 
			for (int b=0;b<bod->getNumLinks();b++)
			{
				if (bod->getLink(b).m_collider && bod->getLink(b).m_collider->getActivationState()==ISLAND_SLEEPING)
					isSleeping = true;
			} 

			if (!isSleeping)
			{
				//useless? they get resized in stepVelocities once again (AND DIFFERENTLY)
				m_scratch_r.resize(bod->getNumLinks()+1);			//multidof? ("Y"s use it and it is used to store qdd)
				m_scratch_v.resize(bod->getNumLinks()+1);
				m_scratch_m.resize(bod->getNumLinks()+1);
				bool doNotUpdatePos = false;

				{
					if(!bod->isUsingRK4Integration())
					{
						bod->computeAccelerationsArticulatedBodyAlgorithmMultiDof(solverInfo.m_timeStep, m_scratch_r, m_scratch_v, m_scratch_m);
					}
					else
					{						
						//
						int numDofs = bod->getNumDofs() + 6;
						int numPosVars = bod->getNumPosVars() + 7;
						btAlignedObjectArray<btScalar> scratch_r2; scratch_r2.resize(2*numPosVars + 8*numDofs);
						//convenience
						btScalar *pMem = &scratch_r2[0];
						btScalar *scratch_q0 = pMem; pMem += numPosVars;
						btScalar *scratch_qx = pMem; pMem += numPosVars;
						btScalar *scratch_qd0 = pMem; pMem += numDofs;
						btScalar *scratch_qd1 = pMem; pMem += numDofs;
						btScalar *scratch_qd2 = pMem; pMem += numDofs;
						btScalar *scratch_qd3 = pMem; pMem += numDofs;
						btScalar *scratch_qdd0 = pMem; pMem += numDofs;
						btScalar *scratch_qdd1 = pMem; pMem += numDofs;
						btScalar *scratch_qdd2 = pMem; pMem += numDofs;
						btScalar *scratch_qdd3 = pMem; pMem += numDofs;
						btAssert((pMem - (2*numPosVars + 8*numDofs)) == &scratch_r2[0]);

						/////						
						//copy q0 to scratch_q0 and qd0 to scratch_qd0
						scratch_q0[0] = bod->getWorldToBaseRot().x();
						scratch_q0[1] = bod->getWorldToBaseRot().y();
						scratch_q0[2] = bod->getWorldToBaseRot().z();
						scratch_q0[3] = bod->getWorldToBaseRot().w();
						scratch_q0[4] = bod->getBasePos().x();
						scratch_q0[5] = bod->getBasePos().y();
						scratch_q0[6] = bod->getBasePos().z();
						//
						for(int link = 0; link < bod->getNumLinks(); ++link)
						{
							for(int dof = 0; dof < bod->getLink(link).m_posVarCount; ++dof)
								scratch_q0[7 + bod->getLink(link).m_cfgOffset + dof] = bod->getLink(link).m_jointPos[dof];							
						}
						//
						for(int dof = 0; dof < numDofs; ++dof)								
							scratch_qd0[dof] = bod->getVelocityVector()[dof];
						////
						struct
						{
						    btMultiBody *bod;
                            btScalar *scratch_qx, *scratch_q0;

						    void operator()()
						    {
						        for(int dof = 0; dof < bod->getNumPosVars() + 7; ++dof)
                                    scratch_qx[dof] = scratch_q0[dof];
						    }
						} pResetQx = {bod, scratch_qx, scratch_q0};
						//
						struct
						{
						    void operator()(btScalar dt, const btScalar *pDer, const btScalar *pCurVal, btScalar *pVal, int size)
						    {
						        for(int i = 0; i < size; ++i)
                                    pVal[i] = pCurVal[i] + dt * pDer[i];
						    }

						} pEulerIntegrate;
						//
						struct
                        {
                            void operator()(btMultiBody *pBody, const btScalar *pData)
                            {
                                btScalar *pVel = const_cast<btScalar*>(pBody->getVelocityVector());

                                for(int i = 0; i < pBody->getNumDofs() + 6; ++i)
                                    pVel[i] = pData[i];

                            }
                        } pCopyToVelocityVector;
						//
                        struct
						{
						    void operator()(const btScalar *pSrc, btScalar *pDst, int start, int size)
						    {
						        for(int i = 0; i < size; ++i)
                                    pDst[i] = pSrc[start + i];
						    }
						} pCopy;
						//

						btScalar h = solverInfo.m_timeStep;
						#define output &m_scratch_r[bod->getNumDofs()]
						//calc qdd0 from: q0 & qd0	
						bod->computeAccelerationsArticulatedBodyAlgorithmMultiDof(0., m_scratch_r, m_scratch_v, m_scratch_m);
						pCopy(output, scratch_qdd0, 0, numDofs);
						//calc q1 = q0 + h/2 * qd0
						pResetQx();
						bod->stepPositionsMultiDof(btScalar(.5)*h, scratch_qx, scratch_qd0);
						//calc qd1 = qd0 + h/2 * qdd0
						pEulerIntegrate(btScalar(.5)*h, scratch_qdd0, scratch_qd0, scratch_qd1, numDofs);
						//
						//calc qdd1 from: q1 & qd1
						pCopyToVelocityVector(bod, scratch_qd1);
						bod->computeAccelerationsArticulatedBodyAlgorithmMultiDof(0., m_scratch_r, m_scratch_v, m_scratch_m);
						pCopy(output, scratch_qdd1, 0, numDofs);
						//calc q2 = q0 + h/2 * qd1
						pResetQx();
						bod->stepPositionsMultiDof(btScalar(.5)*h, scratch_qx, scratch_qd1);
						//calc qd2 = qd0 + h/2 * qdd1
						pEulerIntegrate(btScalar(.5)*h, scratch_qdd1, scratch_qd0, scratch_qd2, numDofs);
						//
						//calc qdd2 from: q2 & qd2
						pCopyToVelocityVector(bod, scratch_qd2);
						bod->computeAccelerationsArticulatedBodyAlgorithmMultiDof(0., m_scratch_r, m_scratch_v, m_scratch_m);
						pCopy(output, scratch_qdd2, 0, numDofs);
						//calc q3 = q0 + h * qd2
						pResetQx();
						bod->stepPositionsMultiDof(h, scratch_qx, scratch_qd2);
						//calc qd3 = qd0 + h * qdd2
						pEulerIntegrate(h, scratch_qdd2, scratch_qd0, scratch_qd3, numDofs);
						//
						//calc qdd3 from: q3 & qd3
						pCopyToVelocityVector(bod, scratch_qd3);
						bod->computeAccelerationsArticulatedBodyAlgorithmMultiDof(0., m_scratch_r, m_scratch_v, m_scratch_m);
						pCopy(output, scratch_qdd3, 0, numDofs);

						//
						//calc q = q0 + h/6(qd0 + 2*(qd1 + qd2) + qd3)
						//calc qd = qd0 + h/6(qdd0 + 2*(qdd1 + qdd2) + qdd3)						
						btAlignedObjectArray<btScalar> delta_q; delta_q.resize(numDofs);
						btAlignedObjectArray<btScalar> delta_qd; delta_qd.resize(numDofs);
						for(int i = 0; i < numDofs; ++i)
						{
							delta_q[i] = h/btScalar(6.)*(scratch_qd0[i] + 2*scratch_qd1[i] + 2*scratch_qd2[i] + scratch_qd3[i]);
							delta_qd[i] = h/btScalar(6.)*(scratch_qdd0[i] + 2*scratch_qdd1[i] + 2*scratch_qdd2[i] + scratch_qdd3[i]);							
							//delta_q[i] = h*scratch_qd0[i];
							//delta_qd[i] = h*scratch_qdd0[i];
						}
						//
						pCopyToVelocityVector(bod, scratch_qd0);
						bod->applyDeltaVeeMultiDof(&delta_qd[0], 1);						
						//
						if(!doNotUpdatePos)
						{
							btScalar *pRealBuf = const_cast<btScalar *>(bod->getVelocityVector());
							pRealBuf += 6 + bod->getNumDofs() + bod->getNumDofs()*bod->getNumDofs();

							for(int i = 0; i < numDofs; ++i)
								pRealBuf[i] = delta_q[i];

							//bod->stepPositionsMultiDof(1, 0, &delta_q[0]);
							bod->setPosUpdated(true);							
						}

						//ugly hack which resets the cached data to t0 (needed for constraint solver)
						{
							for(int link = 0; link < bod->getNumLinks(); ++link)
								bod->getLink(link).updateCacheMultiDof();
							bod->computeAccelerationsArticulatedBodyAlgorithmMultiDof(0, m_scratch_r, m_scratch_v, m_scratch_m);
						}
						
					}
				}
				
#ifndef BT_USE_VIRTUAL_CLEARFORCES_AND_GRAVITY
				bod->clearForcesAndTorques();
#endif //BT_USE_VIRTUAL_CLEARFORCES_AND_GRAVITY
			}//if (!isSleeping)
		}
	}

	clearMultiBodyConstraintForces();

	m_solverMultiBodyIslandCallback->processConstraints();
	
	m_constraintSolver->allSolved(solverInfo, m_debugDrawer);

	{
                BT_PROFILE("btMultiBody stepVelocities");
                for (int i=0;i<this->m_multiBodies.size();i++)
                {
                        btMultiBody* bod = m_multiBodies[i];

                        bool isSleeping = false;

                        if (bod->getBaseCollider() && bod->getBaseCollider()->getActivationState() == ISLAND_SLEEPING)
                        {
                                isSleeping = true;
                        }
                        for (int b=0;b<bod->getNumLinks();b++)
                        {
                                if (bod->getLink(b).m_collider && bod->getLink(b).m_collider->getActivationState()==ISLAND_SLEEPING)
                                        isSleeping = true;
                        }

                        if (!isSleeping)
                        {
                                //useless? they get resized in stepVelocities once again (AND DIFFERENTLY)
                                m_scratch_r.resize(bod->getNumLinks()+1);                 //multidof? ("Y"s use it and it is used to store qdd)
                                m_scratch_v.resize(bod->getNumLinks()+1);
                                m_scratch_m.resize(bod->getNumLinks()+1);

                                
                            {
                                if(!bod->isUsingRK4Integration())
                                {
									bool isConstraintPass = true;
                                    bod->computeAccelerationsArticulatedBodyAlgorithmMultiDof(solverInfo.m_timeStep, m_scratch_r, m_scratch_v, m_scratch_m, isConstraintPass);
                                }
				}
			}
		}
	}

	for (int i=0;i<this->m_multiBodies.size();i++)
	{
		btMultiBody* bod = m_multiBodies[i];
		bod->processDeltaVeeMultiDof2();
	}

}