void run() { foldnodeplot.reset(new PlotPoints()); env->add(foldnodeplot); folddirplot.reset(new PlotLines(3)); env->add(folddirplot); pickplot.reset(new PlotSpheres()); env->add(pickplot); tofoldplot.reset(new PlotPoints()); env->add(tofoldplot); destplot.reset(new PlotPoints()); env->add(destplot); pickedNode = pickedNode2 = NULL; setupScene(); initStandardCloth(); facepicker.reset(new SoftBodyFacePicker(*this, viewer.getCamera(), cloth->softBody.get())); facepicker->setPickCallback(boost::bind(&CustomScene::pickCallback, this, _1)); addVoidKeyCallback('f', boost::bind(&CustomScene::doFold, this)); addVoidKeyCallback('g', boost::bind(&CustomScene::doRandomFolds, this, 3)); addVoidKeyCallback('h', boost::bind(&CustomScene::pickUpAndDrop, this)); addVoidKeyCallback('s', boost::bind(&CustomScene::saveCloth, this)); addVoidKeyCallback('l', boost::bind(&CustomScene::loadCloth, this)); addPreDrawCallback(boost::bind(&CustomScene::markFolds, this)); addPreDrawCallback(boost::bind(&CustomScene::drawPick, this)); addPreDrawCallback(boost::bind(&CustomScene::markNodesToFold, this)); startViewer(); setSyncTime(false); startFixedTimestepLoop(BulletConfig::dt); }
GrabbingScene::GrabbingScene(bool telekinesis) { pr2m.reset(new PR2Manager(*this)); m_lMonitor.reset(new MonitorForGrabbingWithTelekinesis(pr2m->pr2Left, env,telekinesis, pr2m->pr2->robot->GetLink(LEFT_GRIPPER_LEFT_FINGER_NAME), pr2m->pr2->robot->GetLink(LEFT_GRIPPER_RIGHT_FINGER_NAME))); m_rMonitor.reset(new MonitorForGrabbingWithTelekinesis(pr2m->pr2Right, env, telekinesis, pr2m->pr2->robot->GetLink(RIGHT_GRIPPER_LEFT_FINGER_NAME), pr2m->pr2->robot->GetLink(RIGHT_GRIPPER_RIGHT_FINGER_NAME))); pr2m->setHapticCb(hapticLeft0Hold, boost::bind(&GrabbingScene::closeLeft, this)); pr2m->setHapticCb(hapticLeft1Hold, boost::bind(&GrabbingScene::openLeft, this)); pr2m->setHapticCb(hapticRight0Hold, boost::bind(&GrabbingScene::closeRight, this)); pr2m->setHapticCb(hapticRight1Hold, boost::bind(&GrabbingScene::openRight, this)); if (telekinesis) { pr2m->armsDisabled = true; m_teleLeft.reset(new TelekineticGripper(pr2m->pr2Left)); m_teleRight.reset(new TelekineticGripper(pr2m->pr2Right)); env->add(m_teleLeft); env->add(m_teleRight); } float step = .01; Scene::VoidCallback cb = boost::bind(&GrabbingScene::drive, this, step, 0); addVoidKeyCallback(osgGA::GUIEventAdapter::KEY_Left, boost::bind(&GrabbingScene::drive, this, 0, step)); addVoidKeyCallback(osgGA::GUIEventAdapter::KEY_Right, boost::bind(&GrabbingScene::drive, this, 0, -step)); addVoidKeyCallback(osgGA::GUIEventAdapter::KEY_Up, boost::bind(&GrabbingScene::drive, this, -step, 0)); addVoidKeyCallback(osgGA::GUIEventAdapter::KEY_Down, boost::bind(&GrabbingScene::drive, this, step, 0)); }
void run() { foldnodeplot.reset(new PlotPoints()); env->add(foldnodeplot); folddirplot.reset(new PlotLines(3)); env->add(folddirplot); pickplot.reset(new PlotSpheres()); env->add(pickplot); pickedNode = NULL; leftManipAxes.reset(new PlotAxes); env->add(leftManipAxes); rightManipAxes.reset(new PlotAxes); env->add(rightManipAxes); // load the robot pr2m.reset(new PR2Manager(*this)); if (FlatteningConfig::useFakeGripper) { TelekineticGripper::Ptr fakeLeft(new TelekineticGripper(pr2m->pr2Left)); fakeLeft->setTransform(pr2m->pr2Left->getTransform()); env->add(fakeLeft); gleft.reset(new GenManip(fakeLeft)); TelekineticGripper::Ptr fakeRight(new TelekineticGripper(pr2m->pr2Right)); fakeRight->setTransform(pr2m->pr2Right->getTransform()); gright.reset(new GenManip(fakeRight)); env->add(fakeRight); pr2m->pr2->setTransform(btTransform(btQuaternion::getIdentity(), btVector3(0, 0, -100))); // out of view } else { gleft.reset(new GenManip(pr2m->pr2Left)); gright.reset(new GenManip(pr2m->pr2Right)); } // create the table const float table_height = .5; const float table_thickness = .05; tableExtents = GeneralConfig::scale * btVector3(.75,.75,table_thickness/2); tableTrans = btTransform(btQuaternion(0, 0, 0, 1), GeneralConfig::scale * btVector3(0.8, 0, table_height-table_thickness/2)); BoxObject::Ptr table(new BoxObject(0, tableExtents, tableTrans)); table->rigidBody->setFriction(0.1); env->add(table); cout << "table margin: " << table->rigidBody->getCollisionShape()->getMargin() << endl; // put the table in openrave /* OpenRAVE::KinBodyPtr raveTable = OpenRAVE::RaveCreateKinBody(rave->env); raveTable->SetName("table"); vector<OpenRAVE::AABB> v; v.push_back(OpenRAVE::AABB(util::toRaveTransform(table_trans, 1./pr2m->pr2->scale).trans, 1./pr2m->pr2->scale * util::toRaveVector(table_extents))); raveTable->InitFromBoxes(v, true); rave->env->AddKinBody(raveTable); */ #if 0 OpenRAVE::ViewerBasePtr raveViewer = OpenRAVE::RaveCreateViewer(rave->env, "qtcoin"); rave->env->AddViewer(raveViewer); raveViewer->main(true); #endif const int resx = 45, resy = 31; // const btScalar lenx = GeneralConfig::scale * 0.7, leny = GeneralConfig::scale * 0.5; const btScalar lenx = GeneralConfig::scale * 0.7/2, leny = GeneralConfig::scale * 0.5/2; // const btVector3 clothcenter = GeneralConfig::scale * btVector3(0.5, 0, table_height+0.01); const btVector3 clothcenter = GeneralConfig::scale * btVector3(0.3, 0.1, table_height+0.01); // cloth = makeSelfCollidingTowel(clothcenter, lenx, leny, resx, resy, env->bullet->softBodyWorldInfo); cloth.reset(new Cloth(resx, resy, lenx, leny, clothcenter, env->bullet->softBodyWorldInfo)); env->add(cloth); facepicker.reset(new SoftBodyFacePicker(*this, viewer.getCamera(), cloth->softBody.get())); facepicker->setPickCallback(boost::bind(&CustomScene::pickCallback, this, _1)); sbgripperleft.reset(new GenPR2SoftGripper(pr2m->pr2, gleft, true)); sbgripperleft->setGrabOnlyOnContact(true); sbgripperleft->setTarget(cloth); GenPR2SoftGripperAction leftAction(pr2m->pr2, gleft->baseManip()->manip, sbgripperleft); leftAction.setTarget(cloth); leftAction.setExecTime(1.); addVoidKeyCallback('a', boost::bind(&CustomScene::runGripperAction, this, leftAction)); addVoidKeyCallback('c', boost::bind(&CustomScene::graspPickedNode, this)); addVoidKeyCallback('f', boost::bind(&CustomScene::greedyFlattenSingle, this)); addVoidKeyCallback('F', boost::bind(&CustomScene::deepFlattenSingle, this)); addVoidKeyCallback('g', boost::bind(&CustomScene::liftCloth, this)); addPreDrawCallback(boost::bind(&CustomScene::markFolds, this)); addPreDrawCallback(boost::bind(&CustomScene::drawPick, this)); addPreDrawCallback(boost::bind(&CustomScene::drawManipAxes, this)); addPreDrawCallback(boost::bind(&GenPR2SoftGripper::dbgDraw, sbgripperleft.get(), this)); startViewer(); startFixedTimestepLoop(BulletConfig::dt); }