Skip to content

Commit 4780b46

Browse files
Saurav AgarwalSaurav Agarwal
authored andcommitted
Documenting and linting
1 parent 0763f8a commit 4780b46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+6404
-5208
lines changed

.github/workflows/ci_docker.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: 'CI docker base'
1616
uses: ./.github/docker-base-action
1717
with:
18-
base_tag: pytorch2.2.1
18+
base_tag: pytorch2.2.1-cuda12.3.1-ros2humble
1919
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
2020
dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }}
2121
github_token: ${{ secrets.GITHUB_TOKEN }}
@@ -24,7 +24,7 @@ jobs:
2424
- name: 'CI docker base'
2525
uses: ./.github/docker-base-action
2626
with:
27-
base_tag: pytorch2.2.1-cuda12.3.1
27+
base_tag: pytorch2.2.1-ros2humble
2828
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
2929
dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }}
3030
github_token: ${{ secrets.GITHUB_TOKEN }}
@@ -33,7 +33,7 @@ jobs:
3333
- name: 'CI docker base'
3434
uses: ./.github/docker-base-action
3535
with:
36-
base_tag: pytorch2.2.1-cuda12.3.1-ros2humble
36+
base_tag: pytorch2.2.1
3737
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
3838
dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }}
3939
github_token: ${{ secrets.GITHUB_TOKEN }}
@@ -42,7 +42,7 @@ jobs:
4242
- name: 'CI docker base'
4343
uses: ./.github/docker-base-action
4444
with:
45-
base_tag: pytorch2.2.1-ros2humble
45+
base_tag: pytorch2.2.1-cuda12.3.1
4646
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
4747
dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }}
4848
github_token: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,63 @@
1-
# CoverageControl
2-
The library provides a simulation environment, algorithms, and PyTorch models for the coverage control problem.
3-
Key features:
4-
- The core library `CoverageControlCore` is written in C++ and CUDA for fast computation
1+
See full documentation at [https://KumarRobotics.github.io/CoverageControl/](https://KumarRobotics.github.io/CoverageControl/)
2+
3+
## Introduction
4+
5+
Coverage control is the problem of navigating a robot swarm to collaboratively monitor features or a phenomenon of interest not known _a priori_.
6+
The library provides a simulation environment, algorithms, and GNN-based architectures for the coverage control problem.
7+
<img align="right" width="300" src="doc/graphics/LPAC.gif">
8+
9+
**Key features:**
10+
- The core library `CoverageControlCore` is written in `C++` and `CUDA` to handle large-scale simulations
511
- There are `python` bindings that interface with the core library
6-
- Several algorithms are implemented for comparison and baselines
7-
- PyTorch models in both `C++` and `python`
12+
- Several Centroidal Voronoi Tessellation (CVT)-based algorithms (aka Lloyd's algorithms)
13+
- Learnable Perception-Action-Communication (LPAC) architecture for the coverage control problem is implemented in `PyTorch` and `PyTorch Geometric`
14+
- GPU and CPU parallelization using `CUDA` and `OpenMP`
15+
16+
---
17+
18+
## Citation
19+
```
20+
@article{agarwal2024lpac,
21+
title = {LPAC: Learnable Perception-Action-Communication Loops with
22+
Applications to Coverage Control},
23+
author = {Saurav Agarwal and Ramya Muthukrishnan and
24+
Walker Gosrich and Vijay Kumar and Alejandro Ribeiro},
25+
year = {2024},
26+
eprint = {2401.04855},
27+
archivePrefix = {arXiv},
28+
primaryClass = {cs.RO}
29+
}
30+
```
31+
32+
> [LPAC: Learnable Perception-Action-Communication Loops with Applications to Coverage Control.](https://doi.org/10.48550/arXiv.2401.04855)
33+
> Saurav Agarwal, Ramya Muthukrishnan, Walker Gosrich, Vijay Kumar, and Alejandro Ribeiro.
34+
> arXiv preprint arXiv:2401.04855 (2024).
35+
36+
37+
## Open Source Libraries
38+
- [PyTorch](https://pytorch.org/)
39+
- [PyTorch Geometric](https://pytorch-geometric.readthedocs.io/en/latest/)
40+
- [Eigen](http://eigen.tuxfamily.org/index.php?title=Main_Page)
41+
- [pybind11](https://pybind11.readthedocs.io/en/stable/)
42+
- [CGAL](https://www.cgal.org/)
43+
- [JSON for Modern C++](https://github.com/nlohmann/json)
44+
- [CUDA Samples](https://github.com/NVIDIA/cuda-samples)
45+
- [gnuplot-iostream](http://stahlke.org/dan/gnuplot-iostream/)
46+
- [hungarian-algorithm-cpp](https://github.com/mcximing/hungarian-algorithm-cpp)
47+
- [toml++](https://marzer.github.io/tomlplusplus/index.html)
48+
49+
50+
## Support and Funding
51+
The work was performed at the [GRASP Laboratory](https://www.grasp.upenn.edu/) and the [Alelab](https://alelab.seas.upenn.edu/), University of Pennsylvania, USA.
52+
53+
This work was supported in part by grants ARL DCIST CRA W911NF-17-2-0181 and ONR N00014-20-1-2822.
54+
55+
56+
## Contributors
57+
- [Saurav Agarwal](https://www.saurav.fyi/)
58+
- Ramya Muthukrishnan
859

960

10-
## Installation
11-
See [Installation](https://github.com/AgarwalSaurav/CoverageControl/wiki)
61+
## License
62+
The library is licensed under the [GPL-3.0 License](https://www.gnu.org/licenses/gpl-3.0.html).
63+
The documentation is not under the GPL-3.0 License and is licensed under the [CC BY-NC-SA 4.0 License](https://creativecommons.org/licenses/by-nc-sa/4.0/).

cppsrc/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ set(dependencies_list Eigen3::Eigen m stdc++fs OpenMP::OpenMP_CXX pthread boost_
6767

6868
add_library(${PROJECT_NAME} SHARED ${sources_list})
6969
target_include_directories(${PROJECT_NAME} PRIVATE "${PROJECT_BINARY_DIR}")
70+
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_INSTALL_INCLUDEDIR}")
7071
target_link_libraries(${PROJECT_NAME} PRIVATE compiler_flags CGAL::CGAL)
7172
target_link_libraries(${PROJECT_NAME} PUBLIC ${dependencies_list})
7273
set_target_properties(${PROJECT_NAME} PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}")

cppsrc/core/include/CoverageControl/algorithms/centralized_cvt.h

Lines changed: 113 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -5,115 +5,136 @@
55
66
* Repository: https://github.com/KumarRobotics/CoverageControl
77
*
8-
* The CoverageControl library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8+
* Copyright (c) 2024, Saurav Agarwal
99
*
10-
* The CoverageControl library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10+
* The CoverageControl library is free software: you can redistribute it and/or
11+
* modify it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or (at your
13+
* option) any later version.
1114
*
12-
* You should have received a copy of the GNU General Public License along with CoverageControl library. If not, see <https://www.gnu.org/licenses/>.
15+
* The CoverageControl library is distributed in the hope that it will be
16+
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
18+
* Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License along with
21+
* CoverageControl library. If not, see <https://www.gnu.org/licenses/>.
1322
*/
1423

1524
/*!
1625
* \file centralized_cvt.h
1726
* \brief Contains the class CentralizedCVT
1827
*/
1928

20-
#ifndef COVERAGECONTROL_ALGORITHMS_CENTRALIZED_CVT_H_
21-
#define COVERAGECONTROL_ALGORITHMS_CENTRALIZED_CVT_H_
29+
#ifndef CPPSRC_CORE_INCLUDE_COVERAGECONTROL_ALGORITHMS_CENTRALIZED_CVT_H_
30+
#define CPPSRC_CORE_INCLUDE_COVERAGECONTROL_ALGORITHMS_CENTRALIZED_CVT_H_
2231

23-
#include <vector>
32+
#include <omp.h>
33+
34+
#include <algorithm>
2435
#include <fstream>
2536
#include <iostream>
37+
#include <queue>
2638
#include <random>
27-
#include <algorithm>
2839
#include <set>
29-
#include <queue>
30-
#include <omp.h>
40+
#include <vector>
3141

32-
#include "../parameters.h"
33-
#include "../typedefs.h"
34-
#include "../coverage_system.h"
42+
#include "CoverageControl/algorithms/abstract_controller.h"
43+
#include "CoverageControl/coverage_system.h"
44+
#include "CoverageControl/parameters.h"
45+
#include "CoverageControl/typedefs.h"
3546

3647
namespace CoverageControl {
3748

38-
/*!
39-
* The coverage control algorithm uses centralized Centroidal Voronoi Tessellation (CVT) or Lloyd's algorithm on accumulated local map of individual robots, i.e., a robot has knowledge only about the regions it has visited.
40-
* Communication radius is not considered.
41-
* The algorithm is online---it takes localized actions based on the current robot positions.
42-
**/
43-
class CentralizedCVT {
44-
private:
45-
Parameters const params_;
46-
size_t num_robots_ = 0;
47-
CoverageSystem &env_;
48-
Voronoi voronoi_;
49-
PointVector robot_global_positions_;
50-
PointVector goals_, actions_;
51-
std::vector <double> voronoi_mass_;
52-
53-
bool continue_flag_ = false;
54-
55-
public:
56-
CentralizedCVT (
57-
Parameters const &params,
58-
size_t const &num_robots,
59-
CoverageSystem &env) :
60-
params_{params},
61-
num_robots_{num_robots},
62-
env_{env} {
63-
64-
robot_global_positions_ = env_.GetRobotPositions();
65-
actions_.resize(num_robots_);
66-
goals_ = robot_global_positions_;
67-
voronoi_mass_.resize(num_robots_, 0);
68-
voronoi_ = Voronoi(robot_global_positions_, env_.GetSystemExploredIDFMap(), Point2(params_.pWorldMapSize, params_.pWorldMapSize), params_.pResolution);
69-
ComputeGoals();
70-
}
71-
72-
PointVector GetActions() { return actions_; }
73-
74-
auto GetGoals() { return goals_; }
75-
76-
auto &GetVoronoi() { return voronoi_; }
77-
78-
void ComputeGoals() {
79-
voronoi_ = Voronoi(robot_global_positions_, env_.GetSystemExploredIDFMap(), Point2(params_.pWorldMapSize, params_.pWorldMapSize), params_.pResolution);
80-
auto voronoi_cells = voronoi_.GetVoronoiCells();
81-
for(size_t iRobot = 0; iRobot < num_robots_; ++iRobot) {
82-
goals_[iRobot] = voronoi_cells[iRobot].centroid();
83-
voronoi_mass_[iRobot] = voronoi_cells[iRobot].mass();
84-
}
85-
}
86-
87-
bool Step() {
88-
continue_flag_ = false;
89-
robot_global_positions_ = env_.GetRobotPositions();
90-
ComputeGoals();
91-
auto voronoi_cells = voronoi_.GetVoronoiCells();
92-
for(size_t iRobot = 0; iRobot < num_robots_; ++iRobot) {
93-
actions_[iRobot] = Point2(0, 0);
94-
Point2 diff = goals_[iRobot] - robot_global_positions_[iRobot];
95-
double dist = diff.norm();
96-
/* if(dist < 0.1 * params_.pResolution) { */
97-
/* continue; */
98-
/* } */
99-
if(dist < kEps) {
100-
continue;
101-
}
102-
if(env_.CheckOscillation(iRobot)) {
103-
continue;
104-
}
105-
double speed = dist / params_.pTimeStep;
106-
/* double speed = 2 * dist * voronoi_mass_[iRobot]; */
107-
speed = std::min(params_.pMaxRobotSpeed, speed);
108-
Point2 direction(diff);
109-
direction.normalize();
110-
actions_[iRobot] = speed * direction;
111-
continue_flag_ = true;
112-
}
113-
return continue_flag_;
114-
}
115-
116-
};
49+
/*!
50+
* \addtogroup cpp_api
51+
* @{
52+
* \class CentralizedCVT
53+
* @}
54+
* The coverage control algorithm uses centralized Centroidal Voronoi
55+
*Tessellation (CVT) or Lloyd's algorithm on accumulated local map of individual
56+
*robots, i.e., a robot has knowledge only about the regions it has visited.
57+
* Communication radius is not considered.
58+
* The algorithm is online---it takes localized actions based on the current
59+
*robot positions.
60+
**/
61+
class CentralizedCVT : public AbstractController {
62+
private:
63+
Parameters const params_;
64+
size_t num_robots_ = 0;
65+
CoverageSystem &env_;
66+
Voronoi voronoi_;
67+
PointVector robot_global_positions_;
68+
PointVector goals_, actions_;
69+
std::vector<double> voronoi_mass_;
70+
71+
bool is_converged_ = false;
72+
73+
public:
74+
CentralizedCVT(Parameters const &params, CoverageSystem &env)
75+
: CentralizedCVT(params, params.pNumRobots, env) {}
76+
CentralizedCVT(Parameters const &params, size_t const &num_robots,
77+
CoverageSystem &env)
78+
: params_{params}, num_robots_{num_robots}, env_{env} {
79+
robot_global_positions_ = env_.GetRobotPositions();
80+
actions_.resize(num_robots_);
81+
goals_ = robot_global_positions_;
82+
voronoi_mass_.resize(num_robots_, 0);
83+
voronoi_ = Voronoi(robot_global_positions_, env_.GetSystemExploredIDFMap(),
84+
Point2(params_.pWorldMapSize, params_.pWorldMapSize),
85+
params_.pResolution);
86+
ComputeGoals();
87+
}
88+
89+
PointVector GetActions() { return actions_; }
90+
91+
auto GetGoals() { return goals_; }
92+
93+
auto &GetVoronoi() { return voronoi_; }
94+
95+
void ComputeGoals() {
96+
voronoi_ = Voronoi(robot_global_positions_, env_.GetSystemExploredIDFMap(),
97+
Point2(params_.pWorldMapSize, params_.pWorldMapSize),
98+
params_.pResolution);
99+
auto voronoi_cells = voronoi_.GetVoronoiCells();
100+
for (size_t iRobot = 0; iRobot < num_robots_; ++iRobot) {
101+
goals_[iRobot] = voronoi_cells[iRobot].centroid();
102+
voronoi_mass_[iRobot] = voronoi_cells[iRobot].mass();
103+
}
104+
}
105+
106+
bool IsConverged() const { return is_converged_; }
107+
108+
bool ComputeActions() {
109+
is_converged_ = true;
110+
robot_global_positions_ = env_.GetRobotPositions();
111+
ComputeGoals();
112+
auto voronoi_cells = voronoi_.GetVoronoiCells();
113+
for (size_t iRobot = 0; iRobot < num_robots_; ++iRobot) {
114+
actions_[iRobot] = Point2(0, 0);
115+
Point2 diff = goals_[iRobot] - robot_global_positions_[iRobot];
116+
double dist = diff.norm();
117+
/* if (dist < 0.1 * params_.pResolution) { */
118+
/* continue; */
119+
/* } */
120+
if (dist < kEps) {
121+
continue;
122+
}
123+
if (env_.CheckOscillation(iRobot)) {
124+
continue;
125+
}
126+
double speed = dist / params_.pTimeStep;
127+
/* double speed = 2 * dist * voronoi_mass_[iRobot]; */
128+
speed = std::min(params_.pMaxRobotSpeed, speed);
129+
Point2 direction(diff);
130+
direction.normalize();
131+
actions_[iRobot] = speed * direction;
132+
is_converged_ = false;
133+
}
134+
return true;
135+
}
136+
137+
};
117138

118139
} /* namespace CoverageControl */
119-
#endif /* COVERAGECONTROL_ALGORITHMS_CENTRALIZED_CVT_H_ */
140+
#endif // CPPSRC_CORE_INCLUDE_COVERAGECONTROL_ALGORITHMS_CENTRALIZED_CVT_H_

0 commit comments

Comments
 (0)