Coverage Control Library
Loading...
Searching...
No Matches
Quick Start

Parameters

The library uses toml files to specify the configuration parameters for the environment and the robot models.
The class CoverageControl::Parameters is used to load the configuration file and access the parameters.

params = CoverageControl.Parameters("params/coverage_control_params.toml")
Class to store parameters.
Definition parameters.h:50

See params/coverage_control_params.toml for an example configuration file.

Python Interface

Import the coverage_control library and the ClairvoyantCVT algorithm.

import coverage_control as cc
from coverage_control import ClairvoyantCVT as CoverageAlgorithm

You can choose one of the following algorithms instead of ClairvoyantCVT:

  • ClairvoyantCVT
  • CentralizedCVT
  • DecentralizedCVT
  • NearOptimalCVT

Create a CoverageControl::Parameters object and load the configuration file:

params = cc.Parameters() # for default parameters

Create a simulation environment:

env = cc.CoverageSystem(params)

Plot the initial environment (needs gnuplot installed):

env.PlotInitMap("init_map");

Print the initial coverage cost:

init_cost = env.GetObjectiveValue()
print(f"Initial Coverage cost: {init_cost:.2e}")

Create a controller using the CoverageAlgorithm and the environment:

Execute the algorithm:

for i in range(0, params.pEpisodeSteps):
# Compute actions to be taken by the robots
controller.ComputeActions();
# Get actions from the controller
actions = controller.GetActions()
# Send actions to the environment
if env.StepActions(actions):
print(f"Error in step {i}")
break
if controller.IsConverged():
print(f"Converged in step {i}")
break

Print improvement in cost:

current_cost = env.GetObjectiveValue()
print(f"Improvement %: {100 * (init_cost - current_cost)/init_cost:.2f}")

Plot the final state of the environment:

env.PlotSystemMap("final_map");

See python/scripts/coverage_env/coverage_simple.py and python/scripts/coverage_env/coverage_class.py for complete examples.


C++ Interface

Note
The C++ interface is not available in the pip package. You need to build the library from source. See the Installation guide for instructions.

Include the CoverageControl library, algorithms, and other necessary headers:

#include <iostream>
#include <memory>
#include <string>
Clairvoyant CVT algorithm.
The file contains the CoverageSystem class, which is the main class for the coverage control library.
Contains parameters.
Contains typedefs for the library.
Contains the class for Importance Density Function (IDF) for the world.

Typedefs and using statements for easier access to the library classes:

The CoverageSystem class is the main class for the coverage control library.
Class for Importance Density Function (IDF) for the world.
Definition world_idf.h:66
std::vector< Point2 > PointVector
Definition typedefs.h:51
Eigen::Vector2d Point2
Definition typedefs.h:44

Inside the main function, create a Parameters object:

Parameters params;

Create coverage system environment:

CoverageSystem env(params);
auto init_objective = env.GetObjectiveValue();
std::cout << "Initial objective: " << init_objective << std::endl;

Plot the initial environment:

env.PlotInitMap("init_map"); // Creates "init_map.png"

Create a controller using the CoverageAlgorithm and the environment:

CoverageAlgorithm algorithm(params, env);

Execute the algorithm:

for (int i = 0; i < params.pEpisodeSteps; ++i) {
algorithm.ComputeActions();
auto actions = algorithm.GetActions();
if (env.StepActions(actions)) {
std::cout << "Invalid action" << std::endl;
break;
}
if (algorithm.IsConverged()) {
break;
}
}

Print improvement in cost:

auto final_objective = env.GetObjectiveValue();
std::cout << "Improvement %: "
<< (init_objective - final_objective) / init_objective * 100
<< std::endl;

Plot the final state of the environment:

env.PlotSystemMap("final_map"); // Creates "final_map.png"

See cppsrc/main/coverage_algorithm.cpp for a complete example.

Compile and Run

Create a CMakeLists.txt file with the following content:

cmake_minimum_required(VERSION 3.16)
project(coveragecontrol)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
find_package(CoverageControl REQUIRED)
add_executable(coveragecontrol coveragecontrol.cpp) # Replace with your source file
target_link_libraries(coveragecontrol PRIVATE CoverageControl::CoverageControl)
install(TARGETS coveragecontrol DESTINATION ${CMAKE_INSTALL_BINDIR})

Build the program:

mkdir build
cd build
cmake ..
make
Run the program:
./coveragecontrol