Пример #1
0
int main(int argc, char** argv)
{
	// Get the parameters for the experiment from the command line
	if (argc != 4) {
		cout << "freq left_throttle right_throttle" << endl;
		return 0;
	}
	// Get the frequency of the voltage signal from the first argument
	double freq = atof(argv[1]);
	// Create a command from the driver that contains the duty ratios and
	// directions.
	SimPacket sim_command;
	sim_command.left_power = atof(argv[2]);
	sim_command.right_power = atof(argv[3]);
	// Create computer, simulator, and event listener. 
	Computer* computer = new Computer(freq);
	Simulator<SimEvent>* sim = new Simulator<SimEvent>(computer);
	ComputerListener* l = new ComputerListener(computer);
	// Add an event listener to plot the voltage signals
	sim->addEventListener(l);
	// Inject the driver command into the simulation at time 0
	Bag<Event<SimEvent> > input;
	SimEvent cmd(sim_command);
	Event<SimEvent> event(computer,cmd);
	input.insert(event);
	sim->computeNextState(input,0.0);
	// Run the simulation 
	while (sim->nextEventTime() <= 0.004)
		sim->execNextEvent();
	// Clean up and exit
	delete sim; delete computer; delete l;
	return 0;
}
Пример #2
0
int main()
{
	// Create the circuit
	CircuitExt* model = new CircuitExt();
	// Create an atomic model to simulate it
	Hybrid<OMC_ADEVS_IO_TYPE>* hybrid_model =
		new Hybrid<OMC_ADEVS_IO_TYPE>(
		model,
		new corrected_euler<OMC_ADEVS_IO_TYPE>(model,1E-5,0.01),
		new linear_event_locator<OMC_ADEVS_IO_TYPE>(model,1E-5));
	// Create the simulator
	Simulator<OMC_ADEVS_IO_TYPE>* sim =
		new Simulator<OMC_ADEVS_IO_TYPE>(hybrid_model);
	model->print_state();
	// Simulate to t = 1
	while (sim->nextEventTime() <= 1.0)
	{
		sim->execNextEvent();
		model->print_state();
	}
	// Inject an input
	Bag<Event<double> > input_bag;
	input_bag.insert(Event<double>(hybrid_model,0.5));
	sim->computeNextState(input_bag,1.0);
	// Simulate from t=1 to t=5
	while (sim->nextEventTime() <= 3.0)
	{
		sim->execNextEvent();
		model->print_state();
	}
	// Done, cleanup
	delete sim;
	delete hybrid_model;
	return 0;
}
Пример #3
0
int main()
{
	CircuitExt* test_model = new CircuitExt();
	Hybrid<OMC_ADEVS_IO_TYPE>* hybrid_model =
		new Hybrid<OMC_ADEVS_IO_TYPE>(
		test_model,
		new rk_45<OMC_ADEVS_IO_TYPE>(test_model,1E-7,0.001),
		new linear_event_locator<OMC_ADEVS_IO_TYPE>(test_model,1E-7));
        // Create the simulator
        Simulator<OMC_ADEVS_IO_TYPE>* sim =
			new Simulator<OMC_ADEVS_IO_TYPE>(hybrid_model);
		// Check initial values
		test_model->print_state();
		// Run the simulation, testing the solution as we go
        while (sim->nextEventTime() <= 1.0)
		{
			sim->execNextEvent();
			test_model->print_state();
			test_model->test_state();
		}
		Bag<Event<double> > xb;
		Event<double> event(hybrid_model,0.0);
		xb.insert(event);
		sim->computeNextState(xb,1.0);
		while (sim->nextEventTime() <= 5.0)
		{
			sim->execNextEvent();
			test_model->print_state();
			test_model->test_state();
		}
        delete sim;
		delete hybrid_model;
        return 0;
}
Пример #4
0
int main()
{
	model = new Wrapper(new SimpleModel());
	Simulator<External*>* sim = new Simulator<External*>(model);
	Listener* l = new Listener();
	sim->addEventListener(l);
	// First input/output series. Internal event test.
	l->setExpected(1.0,FAST,1);
	Event<External*> e;
	e.model = model;
	e.value = new External(FAST,1);
	Bag<Event<External*> > x;
	x.insert(e);
	sim->computeNextState(x,0.0);
	assert(sim->nextEventTime() == 1.0);
	sim->execNextEvent();
	assert(output_happened);
	output_happened = false;
	// Second input/output series. External event test.
	l->setExpected(3.5,SLOW,1);
	x.clear();
	e.value = new External(SLOW,1);
	x.insert(e);
	sim->computeNextState(x,1.5);
	assert(!output_happened);
	assert(sim->nextEventTime() == 3.5);
	sim->execNextEvent();
	assert(output_happened);
	output_happened = false;
	// Third input/output series. Confluent event test
	l->setExpected(5.5,SLOW,2);
	x.clear();
	e.value = new External(STOP,1);
	x.insert(e);
	assert(sim->nextEventTime() == 5.5);
	sim->computeNextState(x,sim->nextEventTime());
	assert(output_happened);
	assert(sim->nextEventTime() == DBL_MAX);
	// Done. Try to clean up.
	assert(External::num_existing == 3);
	delete model;
	delete l;
	delete sim;
	assert(Internal::num_existing == 0);
	return 0;
}
Пример #5
0
int main()
{
	// Create the model
	Circuit* circuit = new Circuit();
	Hybrid<bool>* hybrid_model = new Hybrid<bool>(
			circuit,new corrected_euler<bool>(circuit,1E-5,0.01),
			new linear_event_locator<bool>(circuit,1E-5));
	// Create the simulator
	Simulator<bool>* sim = new Simulator<bool>(hybrid_model);
	sim->addEventListener(new StateListener(hybrid_model,circuit));
	// Simulate until the switch opens
	while (sim->nextEventTime() <= 1.0) sim->execNextEvent();
	// Open the switch
	Bag<Event<bool> > xb; xb.insert(Event<bool>(hybrid_model,0));
	sim->computeNextState(xb,1.0);
	// Simulate for another second
	while (sim->nextEventTime() <= 4.0) sim->execNextEvent();
	delete sim; delete hybrid_model;
	return 0;
}
Пример #6
0
int main(int argc, char** argv)
{
	// Get the parameters for the experiment from the command line
	if (argc != 4) {
		cout << "freq left_throttle right_throttle" << endl;
		return 0;
	}
	// Get the frequency of the voltage signal from the first argument
	double freq = atof(argv[1]);
	// Create a command from the driver that contains the duty ratios from
	// the second and third arguments.
	SimPacket sim_command;
	sim_command.left_power = atof(argv[2]);
	sim_command.right_power = atof(argv[3]);
	// Create the tank, simulator, and event listener. The arguments to the
	// tank are its initial position (x = y = 0), heading (theta = 0), and
	// the smallest interval of time that will separate any two reports of
	// the tank's state (0.02 seconds).
	Tank* tank = new Tank(freq,0.0,0.0,0.0,0.02);
	Simulator* sim = new Simulator(tank);
	TankEventListener* l = new TankEventListener(tank);
	// Add an event listener to compute the power dissipated in the motors
	sim->addEventListener(l);
	// Inject the driver command into the simulation at time zero
	ModelInputBag input;
	SimEvent cmd(sim_command);
	ModelInput event(tank,cmd);
	input.insert(event);
	sim->computeNextState(input,0.0);
	// Run the simulation for 3 seconds
	while (sim->nextEventTime() <= 3.0) sim->execNextEvent();
	// Write the result to the console
	cout << freq << " " << l->getPowerLost() << endl;
	// Clean up and exit
	delete sim; delete tank; delete l;
	return 0;
}