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.
Class to store parameters.
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:
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):
controller.ComputeActions();
actions = controller.GetActions()
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/system_env/coverage_simple.py and python/system_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 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.
CoverageControl::ClairvoyantCVT CoverageAlgorithm
std::vector< Point2 > PointVector
Inside the main
function, create a Parameters
object:
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");
Create a controller using the CoverageAlgorithm
and the environment:
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");
See cppsrc/main/coverage_algorithm.cpp for a complete example.
Compile and Run
Create a CMakeLists.txt
file with the following content:
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)
target_link_libraries(coveragecontrol PRIVATE CoverageControl::CoverageControl)
install(TARGETS coveragecontrol DESTINATION ${CMAKE_INSTALL_BINDIR})
cmake_minimum_required(VERSION 3.16) if(DEFINED SKBUILD_PROJECT_VERSION) set(PROJECT_VERSION $
Build the program:
mkdir build
cd build
cmake ..
make
Run the program: