Skip to content

Commit 84a7df2

Browse files
Saurav AgarwalSaurav Agarwal
authored andcommitted
Clean doc and directory checks
1 parent f15f12a commit 84a7df2

File tree

8 files changed

+408
-274
lines changed

8 files changed

+408
-274
lines changed

.github/workflows/ghaction-doxygen-ghpages.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
on:
22
release:
33
types: [published]
4+
push:
5+
paths:
6+
- 'doc/**'
47
permissions:
58
contents: write
69

cppsrc/core/include/CoverageControl/coverage_system.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ namespace CoverageControl {
6666
* library.
6767
*/
6868
class CoverageSystem {
69-
protected:
7069
Parameters const params_; //!< Parameters for the coverage system
7170
WorldIDF world_idf_; //!< World IDF
7271
size_t num_robots_ = 0; //!< Number of robots
@@ -404,13 +403,17 @@ class CoverageSystem {
404403
std::vector<int> robot_status(num_robots_, 0);
405404
PlotSystemMap(dir_name, step, robot_status);
406405
}
406+
void PlotSystemMap(std::string const &) const;
407407
void PlotSystemMap(std::string const &, int const &,
408408
std::vector<int> const &) const;
409409
void PlotMapVoronoi(std::string const &, int const &);
410410
void PlotMapVoronoi(std::string const &, int const &, Voronoi const &,
411411
PointVector const &) const;
412412
void PlotWorldMap(std::string const &, std::string const &) const;
413413
void PlotWorldMapRobots(std::string const &, std::string const &) const;
414+
void PlotInitMap(std::string const &filename) const {
415+
PlotInitMap("./", filename);
416+
}
414417
void PlotInitMap(std::string const &, std::string const &) const;
415418
void PlotRobotLocalMap(std::string const &, int const &, int const &);
416419
void PlotRobotSystemMap(std::string const &, int const &, int const &);

cppsrc/core/include/CoverageControl/plotter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class Plotter {
107107
* Voronoi const &); */
108108
/* void PlotMap(MapType const &, PointVector const &, PointVector const &); */
109109

110-
void GnuplotCommands(Gnuplot &gp);
110+
bool GnuplotCommands(Gnuplot &gp);
111111
void StreamMap(Gnuplot &gp, MapType const &map);
112112
void PlotMap(Gnuplot &gp, bool begin = true);
113113
void PlotLine(Gnuplot &gp, int marker_sz, std::string color,

cppsrc/core/python_bindings/core_binds.h

Lines changed: 285 additions & 238 deletions
Large diffs are not rendered by default.

cppsrc/core/src/coverage_system.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ namespace CoverageControl {
3434
CoverageSystem::CoverageSystem(Parameters const &params)
3535
: CoverageSystem(params, params.pNumFeatures, params.pNumRobots) {}
3636

37-
CoverageSystem::CoverageSystem(Parameters const &params,
38-
int const num_features, int const num_robots)
37+
CoverageSystem::CoverageSystem(Parameters const &params, int const num_features,
38+
int const num_robots)
3939
: params_{params}, world_idf_{WorldIDF(params_)} {
4040
// Generate Bivariate Normal Distribution from random numbers
4141
std::srand(
@@ -466,6 +466,17 @@ void CoverageSystem::RecordPlotData(std::vector<int> const &robot_status,
466466
plotter_data_.push_back(data);
467467
}
468468

469+
void CoverageSystem::PlotSystemMap(std::string const &filename) const {
470+
std::vector<int> robot_status(num_robots_, 0);
471+
Plotter plotter("./", params_.pWorldMapSize * params_.pResolution,
472+
params_.pResolution);
473+
plotter.SetScale(2);
474+
plotter.SetPlotName(filename);
475+
plotter.PlotMap(system_map_, robot_global_positions_,
476+
robot_positions_history_, robot_status,
477+
params_.pCommunicationRange);
478+
}
479+
469480
void CoverageSystem::PlotSystemMap(std::string const &dir_name, int const &step,
470481
std::vector<int> const &robot_status) const {
471482
Plotter plotter(dir_name, params_.pWorldMapSize * params_.pResolution,

cppsrc/core/src/plotter.cpp

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@
3131

3232
namespace CoverageControl {
3333

34-
void Plotter::GnuplotCommands(Gnuplot &gp) {
35-
std::filesystem::path path{dir};
36-
if (not std::filesystem::exists(path)) {
37-
std::cerr << "Directory does not exist" << std::endl;
38-
throw std::runtime_error{"Directory does not exist"};
34+
[[nodiscard]] bool Plotter::GnuplotCommands(Gnuplot &gp) {
35+
36+
std::filesystem::path map_filename{std::filesystem::weakly_canonical(dir + "/" + plot_name)};
37+
std::filesystem::path dir_path{map_filename.parent_path()};
38+
if (!std::filesystem::exists(dir_path)) {
39+
std::cerr << "Directory does not exist: " << dir_path << std::endl;
40+
return 1;
3941
}
40-
std::string map_filename{std::filesystem::absolute(path / plot_name)};
41-
gp << "set o '" << map_filename << "'\n";
42+
gp << "set o '" << map_filename.string() << "'\n";
4243
gp << "set terminal pngcairo enhanced font 'Times," << font_sz << "' size "
4344
<< image_sz << "," << image_sz << "\n";
4445
gp << "set palette defined (-5 'black', -1 '" << color_unknown
@@ -48,6 +49,7 @@ void Plotter::GnuplotCommands(Gnuplot &gp) {
4849
gp << "set xrange [0:" << range_max << "]\n";
4950
gp << "set yrange [0:" << range_max << "]\n";
5051
if (unset_colorbox) gp << "unset colorbox\n";
52+
return 0;
5153
}
5254

5355
void Plotter::StreamMap(Gnuplot &gp, MapType const &map) {
@@ -91,15 +93,21 @@ void Plotter::PlotPoints(Gnuplot &gp, int point_type, int marker_size,
9193

9294
void Plotter::PlotMap(MapType const &map) {
9395
Gnuplot gp;
94-
GnuplotCommands(gp);
96+
if (GnuplotCommands(gp)) {
97+
std::cerr << "Error in GnuplotCommands" << std::endl;
98+
return;
99+
}
95100
PlotMap(gp);
96101
gp << "\n";
97102
StreamMap(gp, map);
98103
}
99104

100105
void Plotter::PlotMap(MapType const &map, PointVector const &positions) {
101106
Gnuplot gp;
102-
GnuplotCommands(gp);
107+
if (GnuplotCommands(gp)) {
108+
std::cerr << "Error in GnuplotCommands" << std::endl;
109+
return;
110+
}
103111
PlotMap(gp);
104112
PlotPoints(gp, 7, marker_sz, color_robot);
105113
gp << "\n";
@@ -116,7 +124,10 @@ void Plotter::PlotMap(MapType const &map, PointVector const &positions,
116124
std::vector<std::list<Point2>> const &trajectories,
117125
std::vector<int> const &robot_status) {
118126
Gnuplot gp;
119-
GnuplotCommands(gp);
127+
if (GnuplotCommands(gp)) {
128+
std::cerr << "Error in GnuplotCommands" << std::endl;
129+
return;
130+
}
120131
PlotMap(gp);
121132

122133
for (size_t i = 0; i < positions.size(); ++i) {
@@ -154,7 +165,10 @@ void Plotter::PlotMap(MapType const &map, PointVector const &positions,
154165
std::vector<int> const &robot_status,
155166
double const &communication_range) {
156167
Gnuplot gp;
157-
GnuplotCommands(gp);
168+
if (GnuplotCommands(gp)) {
169+
std::cerr << "Error in GnuplotCommands" << std::endl;
170+
return;
171+
}
158172
PlotMap(gp);
159173

160174
for (size_t i = 0; i < positions.size(); ++i) {
@@ -202,7 +216,10 @@ void Plotter::PlotMap(MapType const &map, PointVector const &positions,
202216
std::vector<std::list<Point2>> const &voronoi,
203217
std::vector<std::list<Point2>> const &trajectories) {
204218
Gnuplot gp;
205-
GnuplotCommands(gp);
219+
if (GnuplotCommands(gp)) {
220+
std::cerr << "Error in GnuplotCommands" << std::endl;
221+
return;
222+
}
206223
PlotMap(gp);
207224

208225
PlotLine(gp, marker_sz, color_robot, false);
@@ -238,7 +255,10 @@ void Plotter::PlotMap(MapType const &map, PointVector const &positions,
238255
Voronoi const &voronoi,
239256
std::vector<std::list<Point2>> const &trajectories) {
240257
Gnuplot gp;
241-
GnuplotCommands(gp);
258+
if (GnuplotCommands(gp)) {
259+
std::cerr << "Error in GnuplotCommands" << std::endl;
260+
return;
261+
}
242262
PlotMap(gp);
243263

244264
PlotLine(gp, marker_sz, color_robot, false);
@@ -276,7 +296,10 @@ void Plotter::PlotMap(MapType const &map, PointVector const &positions,
276296
void Plotter::PlotMap(MapType const &map, PointVector const &positions,
277297
PointVector const &goals, Voronoi const &voronoi) {
278298
Gnuplot gp;
279-
GnuplotCommands(gp);
299+
if (GnuplotCommands(gp)) {
300+
std::cerr << "Error in GnuplotCommands" << std::endl;
301+
return;
302+
}
280303
PlotMap(gp);
281304

282305
PlotLine(gp, half_marker_sz, color_voronoi, false); // voronoi
@@ -322,7 +345,10 @@ void Plotter::PlotMap(MapType const &map, PointVector const &positions,
322345
std::vector<std::list<Point2>> const &trajectories,
323346
PointVector const &frontiers) {
324347
Gnuplot gp;
325-
GnuplotCommands(gp);
348+
if (GnuplotCommands(gp)) {
349+
std::cerr << "Error in GnuplotCommands" << std::endl;
350+
return;
351+
}
326352

327353
PlotMap(gp);
328354
PlotLine(gp, marker_sz, color_robot);

doc/config/DoxygenLayout.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
<publicstaticmethods title=""/>
3030
<publicattributes title=""/>
3131
<publicstaticattributes title=""/>
32-
<protectedtypes title=""/>
33-
<protectedslots title=""/>
34-
<protectedmethods title=""/>
35-
<protectedstaticmethods title=""/>
36-
<protectedattributes title=""/>
37-
<protectedstaticattributes title=""/>
32+
<!-- <protectedtypes title=""/> -->
33+
<!-- <protectedslots title=""/> -->
34+
<!-- <protectedmethods title=""/> -->
35+
<!-- <protectedstaticmethods title=""/> -->
36+
<!-- <protectedattributes title=""/> -->
37+
<!-- <protectedstaticattributes title=""/> -->
3838
<packagetypes title=""/>
3939
<packagemethods title=""/>
4040
<packagestaticmethods title=""/>

doc/manual/quick_start.md

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@ You can choose one of the following algorithms instead of `ClairvoyantCVT`:
2222
Create a `CoverageControl::Parameters` object and load the configuration file:
2323
```python
2424
params = CoverageControl.Parameters() # for default parameters
25-
params.load("params/coverage_control_params.toml") # load the configuration file
25+
params.load("params/coverage_control_params.toml") # Alternatively, load a configuration file
2626
```
2727

2828
Create a simulation environment:
2929
```python
30-
env = CoverageControl.Environment(params)
30+
env = CoverageControl.CoverageSystem(params)
31+
```
32+
33+
Plot the initial environment:
34+
```python
35+
env.PlotInitMap("init_map");
3136
```
3237

3338
Print the initial coverage cost:
@@ -64,6 +69,12 @@ current_cost = env.GetObjectiveValue()
6469
print("Improvement %: " + str('{:.2f}'.format(100 * (init_cost - current_cost)/init_cost)))
6570
```
6671

72+
Plot the final state of the environment:
73+
```cpp
74+
env.PlotSystemMap("final_map");
75+
```
76+
77+
6778
See \ref python/tests/coverage_simple.py and \ref python/tests/coverage_class.py for complete examples.
6879

6980
---
@@ -77,7 +88,7 @@ Include the `CoverageControl` library, algorithms, and other necessary headers:
7788
#include <CoverageControl/world_idf.h>
7889
#include <CoverageControl/coverage_system.h>
7990

80-
#include <CoverageControl/algorithms/near_optimal_cvt.h>
91+
#include <CoverageControl/algorithms/clairvoyant_cvt.h>
8192

8293
#include <iostream>
8394
#include <memory>
@@ -103,47 +114,80 @@ Parameters params;
103114
Create coverage system environment:
104115
```cpp
105116
CoverageSystem env(params);
106-
auto init_objective = env->GetObjectiveValue();
117+
auto init_objective = env.GetObjectiveValue();
107118
std::cout << "Initial objective: " << init_objective << std::endl;
108119
```
109120
110-
To plot the initial environment use the function `PlotInitMap(dir_name, init_map)` :
121+
Plot the initial environment:
111122
```cpp
112-
env.PlotInitMap("./", "init_map");
123+
env.PlotInitMap("init_map"); // Creates "init_map.png"
113124
```
114125

115126
Create a controller using the `CoverageAlgorithm` and the environment:
116127
```cpp
117-
CoverageAlgorithm algorithm(params, *env);
128+
CoverageAlgorithm algorithm(params, env);
118129
```
119130
120131
Execute the algorithm:
121132
```cpp
122-
for (int ii = 0; ii < params.pEpisodeSteps; ++ii) {
133+
for (int i = 0; i < params.pEpisodeSteps; ++i) {
123134
algorithm.ComputeActions();
124135
auto actions = algorithm.GetActions();
125-
if (env->StepActions(actions)) {
136+
if (env.StepActions(actions)) {
126137
std::cout << "Invalid action" << std::endl;
127138
break;
128139
}
129-
if (algorithm.IsConverged() {
140+
if (algorithm.IsConverged()) {
130141
break;
131142
}
132143
}
133144
```
134145

135146
Print improvement in cost:
136147
```cpp
137-
auto current_objective = env->GetObjectiveValue();
148+
auto final_objective = env.GetObjectiveValue();
138149
std::cout << "Improvement %: "
139150
<< (init_objective - final_objective) / init_objective * 100
140151
<< std::endl;
141152
```
142153

154+
Plot the final state of the environment:
155+
```cpp
156+
env.PlotSystemMap("final_map"); // Creates "final_map.png"
157+
```
158+
143159
See \ref cppsrc/main/coverage_algorithm.cpp for a complete example.
144160

161+
### Compile and Run
162+
163+
Create a `CMakeLists.txt` file with the following content:
164+
```python
165+
cmake_minimum_required(VERSION 3.16)
166+
project(coveragecontrol)
145167

168+
set(CMAKE_BUILD_TYPE Release)
169+
set(CMAKE_CXX_STANDARD 17)
170+
set(CMAKE_CXX_STANDARD_REQUIRED True)
146171

172+
find_package(CoverageControl REQUIRED)
173+
174+
add_executable(coveragecontrol coveragecontrol.cpp) # Replace with your source file
175+
target_link_libraries(coveragecontrol PRIVATE CoverageControl::CoverageControl)
176+
install(TARGETS coveragecontrol DESTINATION ${CMAKE_INSTALL_BINDIR})
177+
```
178+
179+
Build the program:
180+
```bash
181+
mkdir build
182+
cd build
183+
cmake ..
184+
make
185+
```
186+
187+
Run the program:
188+
```bash
189+
./coveragecontrol
190+
```
147191

148192

149193

0 commit comments

Comments
 (0)