当前位置: 首页>>代码示例>>C++>>正文


C++ OdeAgent::getController方法代码示例

本文整理汇总了C++中OdeAgent::getController方法的典型用法代码示例。如果您正苦于以下问题:C++ OdeAgent::getController方法的具体用法?C++ OdeAgent::getController怎么用?C++ OdeAgent::getController使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OdeAgent的用法示例。


在下文中一共展示了OdeAgent::getController方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: restart

	/**************************Reset Function***************************************************************/
	virtual bool restart(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& global)
	{
		std::cout << "\n begin restart " << currentCycle << "\n";

		std::cout<<"Current Cycle"<<this->currentCycle<<std::endl;


		//Temporary variable storing the pointer to the controller if the latter should not be resetted
		AbstractController* temp_controller;

		//OdeAgent* temp_agent;

		// We would like to have 10 runs!
		// after it we must clean all and return false because we don't want a new restart
		if (this->currentCycle == repeat_number) // This will be delete all after finish simulation!!!!!!
		{



			//clean robots
			while (global.agents.size() > 0)
			{
				OdeAgent* agent = *global.agents.begin();
				AbstractController* controller = agent->getController();
				OdeRobot* robot = agent->getRobot();
				AbstractWiring* wiring = agent->getWiring();

				global.configs.erase(std::find(global.configs.begin(),
						global.configs.end(), controller));
				delete controller;///////////////////////////////////////////////This will finally delete which is OK

				delete robot;
				delete wiring;

				delete (agent);
				global.agents.erase(global.agents.begin());
			}

			// clean the playgrounds
			while (global.obstacles.size() > 0)
			{
				std::vector<AbstractObstacle*>::iterator iter =
						global.obstacles.begin();
				delete (*iter);
				global.obstacles.erase(iter);
			}
			std::cout << "end.";
			return false; // don't restart, just quit
		}

		// Now we must delete all robots and agents from the simulation and create new robots and agents.
		// BUT NOT CONTROLLER for learning
		while (global.agents.size() > 0)
		{
			//	  std::cout << "\n MAIN WHILE LOOP" << currentCycle << "\n";
			OdeAgent* agent = *global.agents.begin();


			AbstractController* controller = agent->getController();

			OdeRobot* robot = agent->getRobot();
			AbstractWiring* wiring = agent->getWiring();

			global.configs.erase(std::find(global.configs.begin(),
					global.configs.end(), controller));


			delete robot;
			delete wiring;

			//DON'T delete controller if DON't want to reset controller!------------------------------------------------------(FRANK)
			if(delete_controller)
			{
			delete controller;
			//this calls destroy:

			} else { // instead save the pointer in a temporary variable
				temp_controller = controller;
		//		temp_agent = agent;
			}

			//Need to add put the current controller to temp controller?????----STILL NOT IMPLEMENT-----------------------------(FRANK)

			//delete (agent);


			global.agents.erase(global.agents.begin());
			//	  std::cout << "\n END OF MAIN WHILE LOOP" << currentCycle << "\n";

		}

        ///////////////Recreate Robot Start//////////////////////////////////////////////////////////////////////////////////////
		//1) Activate IR sensors
    FourWheeledConf fconf =FourWheeledRPos::getDefaultConf();

		///2) relative sensors
		for (int i=0; i < number_spheres; i++)
		{
			fconf.rpos_sensor_references.push_back(obst.at(i)->getMainPrimitive());
//.........这里部分代码省略.........
开发者ID:pmanoonpong,项目名称:gorobots_edu,代码行数:101,代码来源:main.cpp

示例2: restart

    // starting function (executed once at the beginning of the simulation loop)
    virtual bool restart(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& global)
    {

        std::cout << "\n begin restart " << currentCycle << "\n";

        std::cout<<"Current Cycle"<<this->currentCycle<<std::endl;

        // remove agents
        while (global.agents.size() > 0)
        {
            OdeAgent* agent = *global.agents.begin();

            AbstractController* controller = agent->getController();

            OdeRobot* robot = agent->getRobot();
            AbstractWiring* wiring = agent->getWiring();

            global.configs.erase(std::find(global.configs.begin(),
                                           global.configs.end(), controller));

            delete robot;
            delete wiring;

            global.agents.erase(global.agents.begin());

        }
        // clean the playgrounds
        while (global.obstacles.size() > 0)
        {
            std::vector<AbstractObstacle*>::iterator iter =
                global.obstacles.begin();
            delete (*iter);
            global.obstacles.erase(iter);
        }
        boxPrimitives.clear();
        relative_sensor_obst.clear();
        grippables.clear();

        ///////////////Recreate Robot Start//////////////////////////////////////////////////////////////////////////////////////
        /**************************************************************************************************
        ***			Set up Environment
        **************************************************************************************************/
        setup_Playground(global);

        /**************************************************************************************************
        ***			Set up 4 landmark and 1 goal spheres
        **************************************************************************************************/

        generate_spheres(global);

        /**************************************************************************************************
        ***			Set up 3 pushable boxes and add the first one as graspable
        ************************************************************************************************/

        generate_boxes(global);
        grippables.push_back(boxPrimitives[0]);
//		grippables.push_back(boxPrimitives[1]);
//		grippables.push_back(boxPrimitives[2]);

        /**************************************************************************************************
        ***			Set up robot and controller
        **************************************************************************************************/

        //1) Activate IR sensors
        FourWheeledConfGripper fconf = FourWheeledRPosGripper::getDefaultConf();

        ///2) relative sensors
        for (unsigned int i=0; i < relative_sensor_obst.size(); i++) {
            fconf.rpos_sensor_references.push_back(relative_sensor_obst.at(i)->getMainPrimitive());
        }
        vehicle = new FourWheeledRPosGripper(odeHandle, osgHandle, fconf);

        /****Initial position of Nimm4******/
        Pos pos(0.0 , 0.0 , 1.0);
        //setting position and orientation
        vehicle->place(osg::Matrix::rotate(0, 0, 0, 1) *osg::Matrix::translate(pos));

        // only set new grippables otherwise keep old controller
        qcontroller->setGrippablesAndVehicle(vehicle,grippables);
        global.configs.push_back(qcontroller);

        // create pointer to one2onewiring
        AbstractWiring*  wiring = new One2OneWiring(new ColorUniformNoise(0.1));

        // create pointer to agent
        OdeAgent* agent = new OdeAgent(global);

        agent->init(qcontroller, vehicle, wiring);///////////// Initial controller!!!
        global.agents.push_back(agent);


        std::cout << "\n end restart " << currentCycle << "\n";
        // restart!

        qcontroller->setReset(false);


        return true;

//.........这里部分代码省略.........
开发者ID:dowei14,项目名称:ai4-esn,代码行数:101,代码来源:main.cpp


注:本文中的OdeAgent::getController方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。