本文整理汇总了C++中Simulator::addEventListener方法的典型用法代码示例。如果您正苦于以下问题:C++ Simulator::addEventListener方法的具体用法?C++ Simulator::addEventListener怎么用?C++ Simulator::addEventListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Simulator
的用法示例。
在下文中一共展示了Simulator::addEventListener方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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: run_test
void run_test(dae_se1_system<double>* b,
ode_solver<double> *s,
event_locator<double>* l)
{
Hybrid<double>* model =
new Hybrid<double>(b,s,l);
SolutionPlotter* plotter = new SolutionPlotter(model,b);
Simulator<double>* sim = new Simulator<double>(model);
sim->addEventListener(plotter);
while (sim->nextEventTime() < 1.0)
{
sim->execNextEvent();
}
delete sim;
delete model;
delete plotter;
}
示例3: main
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;
}
示例4: main
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;
}
示例5: main
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;
}
示例6: run_test
void run_test(ode_system<PortValue<double> >* b,
ode_solver<PortValue<double> > *s,
event_locator<PortValue<double> >* l)
{
cerr << "Testing " << typeid(*s).name() << " , " << typeid(*l).name() << endl;
Hybrid<PortValue<double> >* ball =
new Hybrid<PortValue<double> >(b,s,l);
sampler* sample = new sampler(0.01);
Digraph<double>* model = new Digraph<double>();
model->add(ball);
model->add(sample);
model->couple(sample,0,ball,0);
model->couple(ball,0,sample,0);
SolutionChecker* checker = new SolutionChecker(ball);
Simulator<PortValue<double> >* sim = new Simulator<PortValue<double> >(model);
sim->addEventListener(checker);
while (sim->nextEventTime() < 10.0)
{
sim->execNextEvent();
}
delete sim;
delete model;
delete checker;
}