Esempio n. 1
0
void BehaviorsModule::getBrainInstance ()
{

    if (brain_module == NULL)
        if (!import_modules())
            return;

    // drop old reference
    Py_XDECREF(brain_instance);
    // Grab instantiate and hold a reference to a new noggin.Brain.Brain()
    PyObject *dict = PyModule_GetDict(brain_module);
    PyObject *brain_class = PyDict_GetItemString(dict, "Brain");
    if (brain_class != NULL)
        brain_instance = PyObject_CallObject(brain_class, Py_BuildValue("ii", teamNumber, playerNumber));
    else
        brain_instance = NULL;

    if (brain_instance == NULL) {
        std::cout << "Error accessing Brain" << std::endl;
        if (PyErr_Occurred())
            PyErr_Print();
        else
            std::cout << "  No error available" << std::endl;
    }

    // Successfully reloaded
    error_state = (brain_instance == NULL);
}
Esempio n. 2
0
BehaviorsModule::BehaviorsModule(int teamNum, int playerNum)
    : error_state(false),
      brain_module(NULL),
      brain_instance(NULL),
      do_reload(0),
      pyInterface(),
      ledCommandOut(base()),
      motionRequestOut(base()),
      bodyMotionCommandOut(base()),
      headMotionCommandOut(base()),
      resetLocOut(base()),
      myWorldModelOut(base())
{
    std::cout << "BehaviorsModule::initializing" << std::endl;

    // Store team and player numbers
    teamNumber = teamNum;
    playerNumber = playerNum;

    // Initialize the PyInterface pointer
    set_interface_ptr(boost::shared_ptr<PyInterface> (&pyInterface));

    // Initialize the interpreter and C python extensions
    initializePython();

    // import noggin.Brain and instantiate a Brain reference
    import_modules();

    std::cout << "  Retrieving Brain.Brain instance" << std::endl;

    // Instantiate a Brain instance
    getBrainInstance();
}
Esempio n. 3
0
void BehaviorsModule::reload_hard ()
{
    std::cout << "Reloading Python interpreter" << std::endl;
    // finalize and reinitialize the Python interpreter
    Py_Finalize();
    // load C extension modules
    initializePython();
    // import noggin.Brain and instantiate a Brain reference
    import_modules();
    // Instantiate a Brain instance
    getBrainInstance();
}
Esempio n. 4
0
 int import_module(std::string mname) {
     try {
         module_name mod(mname);
         std::string base = ".";
         bool num_threads = 1;
         bool keep_proofs = false;
         env = import_modules(env, base, 1, &mod, num_threads, keep_proofs, ios);
     } catch (lean::exception & ex) {
         simple_pos_info_provider pp("import_module");
         lean::display_error(diagnostic(env, ios), &pp, ex);
         return 1;
     }
     return 0;
 }