예제 #1
0
void PoseSeqItem::convert(BodyPtr orgBody)
{
    if(!orgBody){
        return;
    }
    
    const Listing& convInfoTop = *ownerBodyItem->body()->info()->findListing("poseConversionInfo");
    if(convInfoTop.isValid()){
        for(int i=0; i < convInfoTop.size(); ++i){
            const Mapping& convInfo = *convInfoTop[i].toMapping();
            const Listing& targets = *convInfo["targetBodies"].toListing();
            for(int j=0; j < targets.size(); ++j){
                if(targets[j].toString() == orgBody->name()){

                    beginEditing();
                    if(endEditing(convertSub(orgBody, convInfo))){
                        
                        clearFileInformation();
                        BodyPtr body = ownerBodyItem->body();
                        seq->setTargetBodyName(body->name());
                        format m(_("Pose seq \"%1%\" has been converted. Its target has been changed from %2% to %3%"));
                        MessageView::mainInstance()->notify(str(m % name() % orgBody->name() % body->name()));
                        
                        return;
                    }
                }
            }
        }
    }
}
예제 #2
0
void PoseSeq::store(Mapping& archive, const BodyPtr body) const
{
    archive.write("type", "PoseSeq");
    archive.write("name", name(), DOUBLE_QUOTED);
    archive.write("targetBody", body->name(), DOUBLE_QUOTED);

    Listing& refsNode = *archive.createListing("refs");
    
    for(PoseRefList::const_iterator p = refs.begin(); p != refs.end(); ++p){
        const PoseRef& ref = *p;
        MappingPtr refNode = refsNode.newMapping();
        refNode->write("time", ref.time());
        if(ref.maxTransitionTime() > 0.0){
            refNode->write("maxTransitionTime", ref.maxTransitionTime());
        }
        const string& name = ref.name();
        if((storedNames.find(name) == storedNames.end() /* && !ref.isExternalReference()*/) ||
           name.empty()){
            const_cast<PoseSeq*>(this)->storedNames.insert(name);
            MappingPtr childNode = refNode->createMapping("refer");
            ref.poseUnit()->store(*childNode, body);
        } else {
            refNode->write("refer", name, DOUBLE_QUOTED);
        }
    }
}
예제 #3
0
bool PoseSeq::restore(const Mapping& archive, const BodyPtr body)
{
    setTargetBodyName(archive.get("targetBody", body->name()));
                                   
    const Listing& refs = *archive.findListing("refs");

    if(!refs.isValid()){
        return false;
    }
        
    PoseSeq::iterator current = begin();
    
    for(int i=0; i < refs.size(); ++i){
        const Mapping& ref = *refs[i].toMapping();

        bool isInserted = false;

        double time = ref["time"].toDouble();
        
        const ValueNode& referred = ref["refer"];

        if(referred.isScalar()){
            const string& name = referred;
            if(!name.empty()){
                current = insert(current, time, name);
                isInserted = true;
            }
        } else if(referred.isMapping()){
            const Mapping& mReferred = *referred.toMapping();
            const string& type = mReferred["type"];
            PoseUnitPtr poseUnit;
            if(type == "Pose"){
                poseUnit = new Pose();
            } else if(type == "PronunSymbol"){
                poseUnit = new PronunSymbol();
            }
            /*
              else if(type == "PoseSeq"){
              poseUnit = createLocalPoseSeq();
              }
            */
            if(poseUnit && poseUnit->restore(mReferred, body)){
                poseUnit->name_ = mReferred["name"];
                current = insert(current, time, poseUnit);
                isInserted = true;
            }
        }

        if(isInserted){
            current->setMaxTransitionTime(ref.get("maxTransitionTime", 0.0));
        }
    }

    return true;
}
예제 #4
0
void BodyLinkViewImpl::update()
{
    currentLink = 0;
    
    if(!currentBodyItem){
        nameLabel.setText("");
        return;
    }

    propertyWidgetConnections.block();
    stateWidgetConnections.block();
    
    BodyPtr body = currentBodyItem->body();
    const vector<int>& selectedLinkIndices =
        LinkSelectionView::mainInstance()->getSelectedLinkIndices(currentBodyItem);

    if(selectedLinkIndices.empty()){
        currentLink = body->rootLink();
    } else {
        currentLink = body->link(selectedLinkIndices.front());
    }

    if(currentLink){
        nameLabel.setText(QString("%1 / %2").arg(body->name().c_str()).arg(currentLink->name().c_str()));
        updateLink();
    } else {
        nameLabel.setText(body->name().c_str());
    }

    if(currentBodyItem->isLeggedBody()){
        zmpBox.show();
    } else {
        zmpBox.hide();
    }

    updateKinematicState(false);
            
    updateCollisions();

    stateWidgetConnections.unblock();
    propertyWidgetConnections.unblock();
}
bool OpenHRPControllerItem::start(Target* target)
{
    ncHelper = getDefaultNamingContextHelper();
    
    if(!ncHelper->isAlive()){
        return false;
    }

#ifdef OPENHRP_3_0
    typedef OpenHRP::ControllerFactory_var ControllerServer_var;
    typedef OpenHRP::ControllerFactory ControllerServer;
#elif OPENHRP_3_1
    typedef OpenHRP::Controller_var ControllerServer_var;
    typedef OpenHRP::Controller ControllerServer;
#endif
        
    ControllerServer_var server = ncHelper->findObject<ControllerServer>(controllerServerName.c_str());
    
    // do null check here

    bool serverReady = ncHelper->isObjectAlive(server);

    if(!serverReady){

        // invoke the controller command
        if(!controllerServerCommand.empty()){
            if(controllerServerProcess.state() != QProcess::NotRunning){
                controllerServerProcess.kill();
                controllerServerProcess.waitForFinished(100);
            }
            string command(controllerServerCommand);
#ifdef _WIN32
            if(filesystem::path(controllerServerCommand).extension() != ".exe"){
                command += ".exe";
            }
            // quote the command string to support a path including spaces
            controllerServerProcess.start(QString("\"") + command.c_str() + "\"");
#else
            controllerServerProcess.start(command.c_str());
#endif

            if(!controllerServerProcess.waitForStarted()){
                mv->put(fmt(_("Controller server process \"%1%\" cannot be executed.")) % command);
                if(!filesystem::exists(command)){
                    mv->putln(_(" This file does not exist."));
                } else {
                    mv->putln("");
                }

            } else {
                mv->putln(fmt(_("Controller server process \"%1%\" has been executed by %2%."))
                          % command % name());
                
                for(int i=0; i < 20; ++i){
                    controllerServerProcess.waitForReadyRead(10);
                    server = ncHelper->findObject<ControllerServer>(controllerServerName.c_str());
                    serverReady = ncHelper->isObjectAlive(server);
                    if(serverReady){
                        if(!signalReadyStandardOutputConnected){
                            controllerServerProcess.sigReadyReadStandardOutput().connect(
                                boost::bind(&OpenHRPControllerItem::onReadyReadServerProcessOutput, this));
                            signalReadyStandardOutputConnected = true;
                        }
                        break;
                    }
                }
            }
        }
    }

    if(!serverReady){
        mv->putln(fmt(_("Controller server object \"%1%\" is not found in the name server."))
                  % controllerServerName);
        if(controllerServerProcess.state() != QProcess::NotRunning){
            controllerServerProcess.kill();
        }
        return false;
    }

    BodyPtr body = target->body();

#ifdef OPENHRP_3_0
    controller = server->create(body->name().c_str());
    // do null check here
    mv->putln(fmt(_("The CORBA object of controller \"%1%\" has been created by the factory \"%2%\"."))
              % name() % controllerServerName);

#elif OPENHRP_3_1
    controller = server;
    controller->setModelName(body->name().c_str());
    controller->initialize();
    mv->putln(fmt(_("The CORBA object \"%1%\" of controller \"%2%\" has been obtained."))
              % controllerServerName % name());
#endif

    timeStep_ = target->worldTimeStep();

    dynamicsSimulator.reset(new DynamicsSimulator_impl(body));
    
    controller->setDynamicsSimulator(dynamicsSimulator->_this());
    controller->setTimeStep(timeStep_);
    controller->start();

    return true;
}