45 const std::string& ns)
const 50 const std::string& ns)
56 if (x0.size() != environment.
getController()->getStateDimension())
58 if (msg) *msg +=
"BenchmarkTaskVaryingInitialState: dimension mismatch between x0_default and controller.\n";
67 double x01_step =
_x01_n < 2 ? x01_dir : x01_dir / ((double)
_x01_n - 1);
69 double x02_step =
_x02_n < 2 ? x02_dir : x02_dir / ((double)
_x02_n - 1);
74 for (
int i = 0; i <
_x01_n; ++i)
76 x0[0] = _x01_start + (double)i * x01_step;
78 for (
int j = 0; j <
_x02_n; ++j)
80 if (x0.size() > 1) x0[1] = _x02_start + (
double)j * x02_step;
83 PRINT_INFO(
"run: " << idx + 1 <<
"/" << _x01_n * _x02_n);
86 std::string ns_bench = ns +
"bench_" + std::to_string(idx) +
"/";
92 _main_task->performTask(environment, signal_target, msg, ns_bench);
107 if (msg) *msg +=
"BenchmarkTaskVaryingInitialState(): no main task specified.\n";
111 if (!
_main_task->verify(environment, msg))
return false;
113 int dim_x = environment.
getController()->getStateDimension();
117 *msg +=
"_x01_n > 0 required.\n";
121 if (
_x02_n <= 0 && dim_x < 2)
123 *msg +=
"_x01_n > 0 required if state dimension is > 1.\n";
129 *msg +=
"Dimension of x0_default does not match state dimension.\n";
141 #ifdef MESSAGE_SUPPORT 142 void BenchmarkTaskVaryingInitialState::toMessage(corbo::messages::BenchmarkTaskVaryingInitialState& message)
const 148 message.set_x01_n(
_x01_n);
152 message.set_x02_n(
_x02_n);
155 if (closed_loop_task)
156 closed_loop_task->toMessage(*message.mutable_closed_loop_control_task());
160 if (open_loop_task) open_loop_task->toMessage(*message.mutable_open_loop_control_task());
166 message.mutable_x0_default()->Resize(
_x0_default.size(),
false);
172 void BenchmarkTaskVaryingInitialState::fromMessage(
const corbo::messages::BenchmarkTaskVaryingInitialState& message, std::stringstream* issues)
174 switch (message.main_task_case())
176 case messages::BenchmarkTaskVaryingInitialState::kClosedLoopControlTask:
179 closed_loop_task->fromMessage(message.closed_loop_control_task(), issues);
183 case messages::BenchmarkTaskVaryingInitialState::kOpenLoopControlTask:
186 open_loop_task->fromMessage(message.open_loop_control_task(), issues);
193 if (issues) *issues <<
"BenchmarkTaskVaryingInitialState: selected task not implemented.\n";
Standard environment for control tasks.
Perform open-loop control task.
std::shared_ptr< OpenLoopControlTask > Ptr
A matrix or vector expression mapping an existing array of data.
void getAvailableSignals(const Environment &environment, SignalTargetInterface &signal_target, const std::string &ns="") const override
Retrieve available signals from the task.
Interface class for signal targets.
void reset() override
Reset task state.
void performTask(Environment &environment, SignalTargetInterface *signal_target=nullptr, std::string *msg=nullptr, const std::string &ns="") override
Perform task.
void reset()
Reset environment.
Eigen::VectorXd _x0_default
void sleep()
Sleep (current thread) for the specified duration.
TaskInterface::Ptr _main_task
std::shared_ptr< ClosedLoopControlTask > Ptr
PlantInterface::Ptr getPlantPtr()
Write access to the underlying plant.
bool verify(const Environment &environment, std::string *msg=nullptr) const override
Check if the environment and other settings satisfy all requirements for the given task...
const ControllerInterface::Ptr & getController() const
Read access to the underlying controller.
BenchmarkTaskVaryingInitialState()
Default constructor.
Representation of time durations.
Perform closed-loop control task.
#define PRINT_INFO(msg)
Print msg-stream.