Skip to content

Latest commit

 

History

History
56 lines (36 loc) · 2.43 KB

basic_usage.rst

File metadata and controls

56 lines (36 loc) · 2.43 KB

Basic Usage

On this page

Creating a simple robot

For this first example, we'll use the built-in :cppKilosim::Kilobot robot. Place this in a src folder within your project's root directory. If you want to use a different robot model (or make your own), see the Advanced Usage section.

To create the code that runs on your robot, you need to create a class that inherits from :cppKilosim::Kilobot, as shown below. This needs to implement the following functions (based on the Kilobot API):

  • :cppKilosim::Kilobot::setup: Runs once at the beginning of the simulation. (Note: This is run when the robot is initialized, not when it's placed in the World, so you don't yet have access to World-related values like position.)
  • :cppKilosim::Kilobot::update: Runs once per simulation step.
  • :cppKilosim::Kilobot::message_rx: Runs when the robot receiver a message from another robot.
  • :cppKilosim::Kilobot::message_tx: Creates the message that the robot will transmit.
  • :cppKilosim::Kilobot::message_tx_success: Runs when the robot successfully transmits a message.

For more details of the Kilobot API, see the documentation for the :cppKilosim::Kilobot class and the Kilobot API.

Below is an example of the minimum requirements for your robot class, which you can use as a template for your own robot. You can also download this directory: minimal_kilobot.py </../examples/example_kilobot.cpp>

/../examples/example_kilobot.cpp

First Simulation

Setting up CMake

Using the Viewer

  • Add it to the main function
  • Call it once per step (or less frequently)

Configuration and Parameters

Configuration files are defined as JSON files and can be loaded with a ConfigParser. The contents of flat JSON files can be automatically saved with your data using the Logger. (Support for saving JSON objects and arrays to HDF5 may be added in the future if someone needs/wants it.)

There are no fixed requirements for the contents of the configuration files; it's an un-opinionated convenience tool for importing and using whatever (atomic) parameters you want.

Logging

  • Create a Logger
  • Creating aggregator functions
  • Call every couple steps/seconds