Tasks#
At the begin of a simulation, prepare
(C++
, Python
) is called: override it to initialize the task.
The base implementation is empty, therefore it is not required to call it.
During the simulation, update
(C++
, Python
) is called before a behavior is executed: override it to with higher-level logic specific to your task, which should possibly interacting with the lower-level navigation controller by
yet, task are free to interact in any other way. The base implementation is empty, therefore it is not required to call it.
To let the simulation know that it can terminates, you should override done
(C++
, Python
) returning whether the task has finished. The base implementation returns false
, resulting in a never-ending task.
At the end of the simulation, close
(C++
, Python
) is called: override it to clean-up any step performed during prepare
.
When events meaningful for the task happens, they can be logged using log_event
(C++
, Python
), passing a sequence of float as payload. In case you want to log data, you should override get_log_size (:cpp:func:`C++ <navground::sim::Task::get_log_size>`, :py:meth:`Python <navground.sim.Task.get_log_size>`), returning the size of the payload, which should not change between events. The base implementation returns ``0
, signalling that it won’t log data.
Warning
In case you log data of a different size, an exception will be raised.
Virtual methods#
C++ method |
Python method |
override |
---|---|---|
can |
||
should |
||
can |
||
should |
||
should |
Class skeleton#
#include "navground/sim/task.h"
namespace sim = navground::sim;
struct MyTask : public sim::Task {
// CAN override
// executed at the start of the simulation
// void prepare(sim::Agent *agent, sim::World *world) override;
// CAN override
// executed at the end of the simulation
// void close() override;
// CAN override
// executed during the the simulation, should update the target
// or call the controller
void update(sim::Agent *agent, sim::World *world, ng_float_t time) override;
// CAN override
// return if we are done or not
bool done() override;
// Set the log size to a constant value
static constexpr log_size = 0;
// CAN override
// return the size of the data with log for each event
// do not override or return 0 if you are not logging anything
// should return a constant
unsigned get_log_size() const override { return log_size};
};
from navground import sim
class MyTask(sim.Task):
# Set the log size to a constant value
LOG_SIZE = 0
# CAN override
# executed at the start of the simulation
# def prepare(self, agent: sim.Agent, world: sim.World) -> None: ...
# CAN override
# executed at the end of the simulation
# def close(self) -> None: ...
# CAN override
# executed during the the simulation, should update the state
def update(self, agent: sim.Agent, world: sim.World, time: float) -> None:
...
# CAN override
# return if we are done or not
def done(self) -> bool:
...
# CAN override
# return the size of the data with log for each event
# do not override or return 0 if you are not logging anything
# should return a constant
def get_log_size(self) -> int:
return self.LOG_SIZE