Exemplo n.º 1
0
    KukaGraspExample(GUIHelperInterface* helper, int /* options */)
    :m_app(helper->getAppInterface()),
	m_guiHelper(helper),
//	m_options(options),
	m_kukaIndex(-1),
    m_time(0)
    {
        m_targetPos.setValue(0.5,0,1);
        m_worldPos.setValue(0, 0, 0);
		m_app->setUpAxis(2);
    }
Exemplo n.º 2
0
void	b3StridingMeshInterface::calculateAabbBruteForce(b3Vector3& aabbMin,b3Vector3& aabbMax)
{

	struct	AabbCalculationCallback : public b3InternalTriangleIndexCallback
	{
		b3Vector3	m_aabbMin;
		b3Vector3	m_aabbMax;

		AabbCalculationCallback()
		{
			m_aabbMin.setValue(b3Scalar(B3_LARGE_FLOAT),b3Scalar(B3_LARGE_FLOAT),b3Scalar(B3_LARGE_FLOAT));
			m_aabbMax.setValue(b3Scalar(-B3_LARGE_FLOAT),b3Scalar(-B3_LARGE_FLOAT),b3Scalar(-B3_LARGE_FLOAT));
		}

		virtual void internalProcessTriangleIndex(b3Vector3* triangle,int partId,int  triangleIndex)
		{
			(void)partId;
			(void)triangleIndex;

			m_aabbMin.setMin(triangle[0]);
			m_aabbMax.setMax(triangle[0]);
			m_aabbMin.setMin(triangle[1]);
			m_aabbMax.setMax(triangle[1]);
			m_aabbMin.setMin(triangle[2]);
			m_aabbMax.setMax(triangle[2]);
		}
	};

	//first calculate the total aabb for all triangles
	AabbCalculationCallback	aabbCallback;
	aabbMin.setValue(b3Scalar(-B3_LARGE_FLOAT),b3Scalar(-B3_LARGE_FLOAT),b3Scalar(-B3_LARGE_FLOAT));
	aabbMax.setValue(b3Scalar(B3_LARGE_FLOAT),b3Scalar(B3_LARGE_FLOAT),b3Scalar(B3_LARGE_FLOAT));
	InternalProcessAllTriangles(&aabbCallback,aabbMin,aabbMax);

	aabbMin = aabbCallback.m_aabbMin;
	aabbMax = aabbCallback.m_aabbMax;
}
Exemplo n.º 3
0
	void computeLocalInertia(b3Scalar mass, b3Vector3& localInertia)
	{
		btScalar elem = b3Scalar(0.4) * mass * m_radius*m_radius;
		localInertia.setValue(elem,elem,elem);
	}
Exemplo n.º 4
0
		AabbCalculationCallback()
		{
			m_aabbMin.setValue(b3Scalar(B3_LARGE_FLOAT),b3Scalar(B3_LARGE_FLOAT),b3Scalar(B3_LARGE_FLOAT));
			m_aabbMax.setValue(b3Scalar(-B3_LARGE_FLOAT),b3Scalar(-B3_LARGE_FLOAT),b3Scalar(-B3_LARGE_FLOAT));
		}
Exemplo n.º 5
0
    virtual void	stepSimulation(float deltaTime)
	{
		float dt = deltaTime;
		btClamp(dt,0.0001f,0.01f);

        m_time+=dt;
        m_targetPos.setValue(0.4-0.4*b3Cos( m_time), 0, 0.8+0.4*b3Cos( m_time));
        m_targetOri.setValue(0, 1.0, 0, 0);
        m_targetPos.setValue(0.2*b3Cos( m_time), 0.2*b3Sin( m_time), 1.1);
        
        
        int numJoints = m_robotSim.getNumJoints(m_kukaIndex);
        
        if (numJoints==7)
        {
            double q_current[7]={0,0,0,0,0,0,0};

            b3JointStates2 jointStates;
            
            if (m_robotSim.getJointStates(m_kukaIndex,jointStates))
            {
                //skip the base positions (7 values)
                b3Assert(7+numJoints == jointStates.m_numDegreeOfFreedomQ);
                for (int i=0;i<numJoints;i++)
                {
                    q_current[i] = jointStates.m_actualStateQ[i+7];
                }
            }
            // compute body position and orientation
			b3LinkState linkState;
            m_robotSim.getLinkState(0, 6, &linkState);
			
			m_worldPos.setValue(linkState.m_worldLinkFramePosition[0], linkState.m_worldLinkFramePosition[1], linkState.m_worldLinkFramePosition[2]);
            m_worldOri.setValue(linkState.m_worldLinkFrameOrientation[0], linkState.m_worldLinkFrameOrientation[1], linkState.m_worldLinkFrameOrientation[2], linkState.m_worldLinkFrameOrientation[3]);


            b3Vector3DoubleData targetPosDataOut;
            m_targetPos.serializeDouble(targetPosDataOut);
            b3Vector3DoubleData worldPosDataOut;
            m_worldPos.serializeDouble(worldPosDataOut);
            b3Vector3DoubleData targetOriDataOut;
            m_targetOri.serializeDouble(targetOriDataOut);
            b3Vector3DoubleData worldOriDataOut;
            m_worldOri.serializeDouble(worldOriDataOut);

            
			b3RobotSimulatorInverseKinematicArgs ikargs;
			b3RobotSimulatorInverseKinematicsResults ikresults;
			
         
			ikargs.m_bodyUniqueId = m_kukaIndex;
//			ikargs.m_currentJointPositions = q_current;
//			ikargs.m_numPositions = 7;
            ikargs.m_endEffectorTargetPosition[0] = targetPosDataOut.m_floats[0];
            ikargs.m_endEffectorTargetPosition[1] = targetPosDataOut.m_floats[1];
            ikargs.m_endEffectorTargetPosition[2] = targetPosDataOut.m_floats[2];
			
			//ikargs.m_flags |= B3_HAS_IK_TARGET_ORIENTATION;
            ikargs.m_flags |= B3_HAS_JOINT_DAMPING;

			ikargs.m_endEffectorTargetOrientation[0] = targetOriDataOut.m_floats[0];
			ikargs.m_endEffectorTargetOrientation[1] = targetOriDataOut.m_floats[1];
			ikargs.m_endEffectorTargetOrientation[2] = targetOriDataOut.m_floats[2];
			ikargs.m_endEffectorTargetOrientation[3] = targetOriDataOut.m_floats[3];
            ikargs.m_endEffectorLinkIndex = 6;
            
            // Settings based on default KUKA arm setting
            ikargs.m_lowerLimits.resize(numJoints);
            ikargs.m_upperLimits.resize(numJoints);
            ikargs.m_jointRanges.resize(numJoints);
            ikargs.m_restPoses.resize(numJoints);
            ikargs.m_jointDamping.resize(numJoints,0.5);
            ikargs.m_lowerLimits[0] = -2.32;
            ikargs.m_lowerLimits[1] = -1.6;
            ikargs.m_lowerLimits[2] = -2.32;
            ikargs.m_lowerLimits[3] = -1.6;
            ikargs.m_lowerLimits[4] = -2.32;
            ikargs.m_lowerLimits[5] = -1.6;
            ikargs.m_lowerLimits[6] = -2.4;
            ikargs.m_upperLimits[0] = 2.32;
            ikargs.m_upperLimits[1] = 1.6;
            ikargs.m_upperLimits[2] = 2.32;
            ikargs.m_upperLimits[3] = 1.6;
            ikargs.m_upperLimits[4] = 2.32;
            ikargs.m_upperLimits[5] = 1.6;
            ikargs.m_upperLimits[6] = 2.4;
            ikargs.m_jointRanges[0] = 5.8;
            ikargs.m_jointRanges[1] = 4;
            ikargs.m_jointRanges[2] = 5.8;
            ikargs.m_jointRanges[3] = 4;
            ikargs.m_jointRanges[4] = 5.8;
            ikargs.m_jointRanges[5] = 4;
            ikargs.m_jointRanges[6] = 6;
            ikargs.m_restPoses[0] = 0;
            ikargs.m_restPoses[1] = 0;
            ikargs.m_restPoses[2] = 0;
            ikargs.m_restPoses[3] = SIMD_HALF_PI;
            ikargs.m_restPoses[4] = 0;
            ikargs.m_restPoses[5] = -SIMD_HALF_PI*0.66;
            ikargs.m_restPoses[6] = 0;
            ikargs.m_jointDamping[0] = 10.0;
            ikargs.m_numDegreeOfFreedom = numJoints;
            
			if (m_robotSim.calculateInverseKinematics(ikargs,ikresults))
			{
                //copy the IK result to the desired state of the motor/actuator
                for (int i=0;i<numJoints;i++)
                {
                    b3RobotSimulatorJointMotorArgs t(CONTROL_MODE_POSITION_VELOCITY_PD);
                    t.m_targetPosition = ikresults.m_calculatedJointPositions[i];
                    t.m_maxTorqueValue = 100.0;
                    t.m_kp= 1.0;
					t.m_targetVelocity = 0;
					t.m_kd = 1.0;
                    m_robotSim.setJointMotorControl(m_kukaIndex,i,t);

                }
            }
		
        }
        
        
		m_robotSim.stepSimulation();
    }