From 878315aa95dd1425ea20d98716be16ff51854a7b Mon Sep 17 00:00:00 2001 From: Rick Poyner Date: Mon, 4 Apr 2016 19:41:57 -0400 Subject: [PATCH] Simulation.h: fix type-matching and const errors in templates. * simulate(5-arg): don't modify the passed options struct. * restore const to options arg, to get sim(4) a fighting chance. * simulate(4-arg): fix a typo that defeats template resolution. --- drake/systems/Simulation.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drake/systems/Simulation.h b/drake/systems/Simulation.h index f199faab94a1..38ff15941292 100644 --- a/drake/systems/Simulation.h +++ b/drake/systems/Simulation.h @@ -103,8 +103,9 @@ inline bool handle_realtime_factor(const TimePoint& wall_clock_start_time, template void simulate(const System& sys, double ti, double tf, const typename System::template StateVector& xi, - SimulationOptions& options) { - if (options.realtime_factor < 0.0) options.realtime_factor = 0.0; + const SimulationOptions& options) { + SimulationOptions my_options = options; + if (my_options.realtime_factor < 0.0) my_options.realtime_factor = 0.0; TimePoint start = TimeClock::now(); typename System::template StateVector x(xi), x1est, xdot0, xdot1; @@ -117,15 +118,15 @@ void simulate(const System& sys, double ti, double tf, // Take steps from ti to tf. double t = ti; while (t < tf) { - if (!handle_realtime_factor(start, t, options.realtime_factor, - options.timeout_seconds)) { + if (!handle_realtime_factor(start, t, my_options.realtime_factor, + my_options.timeout_seconds)) { std::stringstream error_msg; error_msg << "The simulation is not keeping up with desired real-time factor. " - << "It is behind by more than " << options.timeout_seconds + << "It is behind by more than " << my_options.timeout_seconds << " (scaled) second at simulation time " << t; - if (options.warn_real_time_violation) { + if (my_options.warn_real_time_violation) { if (!rt_warning_printed) { std::cerr << "WARNING: " << error_msg.str() << std::endl; rt_warning_printed = true; // Suppress future warnings. @@ -134,7 +135,7 @@ void simulate(const System& sys, double ti, double tf, throw std::runtime_error(error_msg.str()); } } - const double dt = (std::min)(options.initial_step_size, tf - t); + const double dt = (std::min)(my_options.initial_step_size, tf - t); // Output is at t0, x0, u0. y = sys.output(t, x, u); @@ -162,7 +163,7 @@ void simulate(const System& sys, double ti, double tf, */ template void simulate(const System& sys, double t0, double tf, - const typename System::template StateVectorType& x0) { + const typename System::template StateVector& x0) { simulate(sys, t0, tf, x0, default_simulation_options); }