Go to the documentation of this file.
11 #include <mrpt/3rdparty/tclap/CmdLine.h>
17 TCLAP::CmdLine
cmd(
"system_control_rate_timer_example");
20 "1",
"rate1",
"rate1 (Hz)",
false, 500.0,
"rate (Hz)",
cmd);
22 "2",
"rate2",
"rate2 (Hz)",
false, 1500.0,
"rate (Hz)",
cmd);
26 const double TOTAL_EXECUTION_TIME = 5.0;
27 const double NOMINAL_RATE1 =
argRate1.getValue();
28 const double NOMINAL_RATE2 =
argRate2.getValue();
29 const unsigned int N = TOTAL_EXECUTION_TIME * NOMINAL_RATE1;
30 const unsigned int STEP_TIME1 = N / 2;
41 printf(
"Running for %f seconds...\n", TOTAL_EXECUTION_TIME);
43 for (
unsigned int i = 0; i < N; i++)
57 const double desiredRate =
58 (i < STEP_TIME1) ? NOMINAL_RATE1 : NOMINAL_RATE2;
65 controlref[i] = desiredRate;
69 "Measured rates (Hz) [black] / estimated "
70 "rates [red] / control action [blue]",
72 win.plot(rawRates,
"k.3");
74 win.plot(estimatedRates,
"r-");
75 win.plot(actionRates,
"b.2");
76 win.plot(controlref,
"m-");
78 win.axis(-0.15 * N, N, -500, 2.0 * std::max(NOMINAL_RATE1, NOMINAL_RATE2));
88 throw std::runtime_error(
"");
93 catch (
const std::exception& e)
A class for calling sleep() in a loop, such that the amount of sleep time will be computed to make th...
void resize(std::size_t N, bool zeroNewElements=false)
mrpt::gui::CDisplayWindow3D::Ptr win
TCLAP::ValueArg< double > argRate2("2", "rate2", "rate2 (Hz)", false, 1500.0, "rate (Hz)", cmd)
TCLAP::CmdLine cmd("system_control_rate_timer_example")
void setRate(const double rate_hz)
Changes the object loop rate (Hz)
Create a GUI window and display plots with MATLAB-like interfaces and commands.
double actualControlledRate() const
Gets the actual controller output: the rate (Hz) of the internal CRateTimer object.
bool sleep()
Sleeps for some time, such as the return of this method is 1/rate (seconds) after the return of the p...
double estimatedRateRaw() const
Last actual execution rate measured (Hz), without low-pass filtering.
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
double estimatedRate() const
Gets the latest estimated run rate (Hz), which comes from actual period measurement,...
TCLAP::ValueArg< double > argRate1("1", "rate1", "rate1 (Hz)", false, 500.0, "rate (Hz)", cmd)
Page generated by Doxygen 1.8.18 for MRPT 2.0.4 at Thu Sep 24 07:14:18 UTC 2020 | |