Skip to content

Commit

Permalink
Simulation.h: fix type-matching and const errors in templates.
Browse files Browse the repository at this point in the history
 * 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.
  • Loading branch information
rpoyner-tri committed Apr 5, 2016
1 parent 59373bc commit 878315a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions drake/systems/Simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ inline bool handle_realtime_factor(const TimePoint& wall_clock_start_time,
template <typename System>
void simulate(const System& sys, double ti, double tf,
const typename System::template StateVector<double>& 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<double> x(xi), x1est, xdot0, xdot1;
Expand All @@ -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.
Expand All @@ -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);
Expand Down Expand Up @@ -162,7 +163,7 @@ void simulate(const System& sys, double ti, double tf,
*/
template <typename System>
void simulate(const System& sys, double t0, double tf,
const typename System::template StateVectorType<double>& x0) {
const typename System::template StateVector<double>& x0) {
simulate(sys, t0, tf, x0, default_simulation_options);
}

Expand Down

0 comments on commit 878315a

Please sign in to comment.