void SimulationEngine::addAgent(AgentInitialParameters& agentConditions)
	{
		// std::cout << "addAgent " << force(Vector2D(0,0)) << std::endl;

		Agent* newAgent = new Agent();
		if (newAgent != NULL) {
			newAgent->init(agentConditions);
			// std::cout << "addAgent " << force(Vector2D(0,0)) << std::endl;
			newAgent->setForceFunction(this->force);
			newAgent->setRadiusFunction(this->rad);
			_agents.push_back(newAgent);
		}
	}
Esempio n. 2
0
int main(int argc, char** argv) {
	list<PlotOption> plotoptions;
	int port = 1;

	int index = contains(argv, argc, "-g");
	if (index > 0 && argc > index) {
		plotoptions.push_back(PlotOption(GuiLogger, atoi(argv[index])));

	}
	if (contains(argv, argc, "-f") != 0)
		plotoptions.push_back(PlotOption(File));
	if (contains(argv, argc, "-n") != 0)
		plotoptions.push_back(PlotOption(MatrixViz));
	if (contains(argv, argc, "-l") != 0)
		singleline = false;
	index = contains(argv, argc, "-p");
	if (index > 0 && argc > index)
		port = atoi(argv[index]);
	if (contains(argv, argc, "-h") != 0) {
		printf("Usage: %s [-g N] [-f] [-n] [p PORT]\n", argv[0]);
		printf("\t-g N\tstart guilogger with interval N\n\t-f\twrite logfile\n");
		printf("\t-n\tstart neuronviz\n");
		printf("\t-p PORT\t COM port number, default 1\n");
		printf("\t-h\tdisplay this help\n");
		exit(0);
	}

	GlobalData globaldata;
	dacbot_serial* robot;
	Agent* agent;
	initializeConsole();

	// Different controllers

	AbstractController* controller = new MuscleRunbotController("muscleRunbotController","0.1");
	// one2onewiring gives full range of robot actuators
	AbstractWiring* wiring = new One2OneWiring(new WhiteUniformNoise(), true);

	//****************Finetuning for real robot experiments
	//((AmosIIControl*) controller)->  ---Access to controller parameters
	//see  $(AMOSIICONT)/amosIIcontrol.cpp for controller classes

	//robot         = new AmosIISerialV2("/dev/ttyS0");     // using serial port
	robot = new dacbot_serial("/dev/ttyUSB0"); // using USB-to-serial adapter


	agent = new Agent(plotoptions);
	agent->init(controller, robot, wiring);
	// if you like, you can keep track of the robot with the following line.
	// this assumes that your robot returns its position, speed and orientation.
	// agent->setTracMkOptions(TrackRobot(true,false,false, false,"systemtest"));

	globaldata.agents.push_back(agent);
	globaldata.configs.push_back(robot);
	globaldata.configs.push_back(controller);

	showParams(globaldata.configs);
	printf("\nPress c to invoke parameter input shell\n");
	printf("The output of the program is more fun then useful ;-).\n");
	printf(" The number are the sensors and the position there value.\n");
	printf(" You probably want to use the guilogger with e.g.: -g 10\n");

	cmd_handler_init();
	long int t=0;

	initscr();
	cbreak();
	//noecho();
	intrflush(stdscr,FALSE);
	keypad(stdscr,TRUE);
	nodelay(stdscr,TRUE);

	/*cout<<"Options: Press a= Obstacle Avoidance ON/OFF"<<endl;
	cout<<"Options: Press b= BJC ON/OFF"<<endl;
	cout<<"Options: Press e= Reflex ON/OFF"<<endl;

	cout << "hi brf"<< endl;
	*/while(!stop) {//!stop

		agent->step(noise,t);
		//std::cout << "hifgvf" << t <<endl;


		 if(control_c_pressed()) {

			 if(!handleConsole(globaldata)) {
				 stop=1;
			 }
			 cmd_end_input();
		 }


		 t++;
	};
	delete robot;
	delete agent;
	closeConsole();
	fprintf(stderr,"terminating\n");
	// should clean up but what costs the world
	return 0;
}