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

  • checking the agent’s controller (C++, Python) state and possibly triggering some action, or

  • direcly setting the agent’s behavior (C++, Python) target

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

prepare

prepare

can

update

update

should

update

update

can

done

done

should

get_log_size

get_log_size

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};
};