Example #1
0
int main(int argc, char * argv[])
{
    Network yarp;
    cout << "Server name is : " << yarp.getNameServerName() << endl;
    if (!Network::checkNetwork())
    {
        cout << "yarp network is not available!" << endl;
        return 0;
    }

    ResourceFinder rf;
    rf.setVerbose(true);
    rf.setDefaultContext("visualSystem");
    rf.setDefaultConfigFile("visualSystem.ini"); //overridden by --from parameter
    rf.configure(argc, argv);

    //Get the parameters of the model
    cvz::core::CvzStack stack;
    int retinaX = rf.check("retinaW",Value(3)).asInt();
    int retinaY = rf.check("retinaH", Value(3)).asInt();
    int foveaX = rf.check("foveaW", Value(3)).asInt();
    int foveaY = rf.check("foveaH", Value(3)).asInt();

    /*************************************************/
    //Add V1
    configureV1Retina(&stack, retinaX, retinaY);
    configureV1Fovea(&stack, foveaX, foveaY);

    /*************************************************/
    //Add v2
    stringstream configV2;
    configV2
        << "type" << '\t' << cvz::core::TYPE_MMCM << endl
        << "name" << '\t' << "v2" << endl
        << "width" << '\t' << V2_W << endl
        << "height" << '\t' << V2_H << endl
        << "layers" << '\t' << V2_L << endl
        << "sigmaFactor" << '\t' << V2_SIGMA_FACTOR << endl
        << "learningRate" << '\t' << V2_LEARNING << endl << endl;

    //Add the proprioception
    configV2
        << "[modality_0]" << endl
        << "name" << '\t' << "gaze" << endl
        << "type" << '\t' << "yarpVector" << endl
        << "size" << '\t' << 3 << endl << endl;

    //Add the v1Retina
    configV2
        << "[modality_1]" << endl
        << "name" << '\t' << "v1Retina" << endl
        << "type" << '\t' << "yarpVector" << endl
        << "size" << '\t' << TOPDOWN_SIZE << endl << endl;

    configV2
        << "[modality_2]" << endl
        << "name" << '\t' << "v1Fovea" << endl
        << "type" << '\t' << "yarpVector" << endl
        << "size" << '\t' << TOPDOWN_SIZE << endl << endl;

    Property propV2;
    propV2.fromConfig(configV2.str().c_str());
    stack.addCvzFromProperty(propV2,false, "v2");

    //Add the head proprioception
    stack.addCvzFromConfigFile(std::string("icub_head.ini"),false, "gaze");

    //Connect the head to v2 -- I know this is non plausible
    stack.connectModalities("/gaze/v1", "/v2/gaze");
    stack.connectModalities("/v1Retina/out", "/v2/v1Retina");
    stack.connectModalities("/v1Fovea/out", "/v2/v1Fovea");

    //Make sure the graph is completed and all the connections are established
    stack.connectModalities();

    stack.configure(rf);
    

    RpcServer* ticker = NULL;
    StackTicker* tickerProcessor = NULL;
    //Start the RPC wrapper for commands
    bool isTickBased = rf.check("tickBased");


    StackRpcWrapper* rpc = new StackRpcWrapper(&stack, retinaX, retinaY, foveaX, foveaY, isTickBased);
    rpc->open("/visualSystem/rpc");
    rpc->useCallback();
    rpc->start();

    if (isTickBased)
    {
        ticker = new RpcServer();
        ticker->open("/visualSystem/ticker:i");
        //Start the ticker to synchronize with the arrival of data
        tickerProcessor = new StackTicker(rpc);
        ticker->setReader(*tickerProcessor);
    }

    stack.runModule();

    rpc->stop();
    rpc->close();
    delete rpc;
    if (ticker != NULL)
    {
        ticker->close();
        delete ticker;
        delete tickerProcessor;
    }

    return 0;
}