Skip to content

Commit 89c6349

Browse files
Merge remote-tracking branch 'upstream/main' into DynamicParamPatterns
Signed-off-by: Nils-ChristianIseke <nilsmailiseke@gmail.com>
2 parents 50da3c1 + 20b6fe5 commit 89c6349

File tree

265 files changed

+4612
-1145
lines changed

Some content is hidden

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

265 files changed

+4612
-1145
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313

1414
---
1515

16+
## Description of testing performed
17+
<!--
18+
For example: Linting validation using -> pre-commit run --all,
19+
Package testing using -> colcon test --packages-select <modified package>,
20+
or functional testing of changes on the robot or in simulation
21+
-->
22+
1623
## Description of contribution in a few bullet points
1724

1825
<!--

.github/workflows/lint.yml

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,34 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
linter: [xmllint, cpplint, uncrustify, pep257, flake8]
14+
linter: [xmllint, cpplint, uncrustify, pep257, flake8, mypy]
1515
steps:
1616
- uses: actions/checkout@v4
17+
18+
- name: Install typeshed for mypy
19+
if: matrix.linter == 'mypy'
20+
run: sudo apt update && sudo apt install -y python3-typeshed
21+
1722
- uses: ros-tooling/action-ros-lint@v0.1
1823
with:
1924
linter: ${{ matrix.linter }}
2025
distribution: rolling
2126
package-name: "*"
27+
arguments: ${{ matrix.linter == 'mypy' && '--config tools/pyproject.toml' || '' }}
2228

23-
ament_lint_mypy:
24-
name: ament_mypy
29+
pre-commit:
30+
name: pre-commit
2531
runs-on: ubuntu-latest
26-
container:
27-
image: rostooling/setup-ros-docker:ubuntu-noble-ros-rolling-ros-base-latest
28-
strategy:
29-
matrix:
30-
mypy_packages:
31-
- "nav2_smac_planner"
3232
steps:
33-
- uses: actions/checkout@v4
34-
35-
- name: Install typeshed
36-
run: sudo apt update && sudo apt install -y python3-typeshed
37-
38-
- uses: ros-tooling/action-ros-lint@v0.1
39-
with:
40-
linter: mypy
41-
distribution: rolling
42-
package-name: "${{ join(matrix.mypy_packages, ' ') }}"
43-
arguments: --config tools/pyproject.toml
33+
- uses: actions/checkout@v4
34+
- uses: actions/setup-python@v5
35+
- uses: pre-commit/action@v3.0.1
36+
env:
37+
SKIP: >-
38+
ament_lint_cmake,
39+
ament_cpplint,
40+
ament_uncrustify,
41+
ament_xmllint,
42+
ament_flake8,
43+
ament_pep257,
44+
ament_mypy

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,10 @@ repos:
9595
language: system
9696
types: [python]
9797
entry: ament_pep257
98+
- id: ament_mypy
99+
name: ament_mypy
100+
description: Check Python code style using mypy.
101+
language: system
102+
types: [python]
103+
args: ["--config", "tools/pyproject.toml"]
104+
entry: ament_mypy

nav2_amcl/include/nav2_amcl/amcl_node.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "pluginlib/class_loader.hpp"
4848
#include "rclcpp/node_options.hpp"
4949
#include "sensor_msgs/msg/laser_scan.hpp"
50+
#include "nav2_util/service_server.hpp"
5051
#include "std_srvs/srv/empty.hpp"
5152
#include "tf2_ros/message_filter.h"
5253
#include "tf2_ros/transform_broadcaster.h"
@@ -206,7 +207,8 @@ class AmclNode : public nav2_util::LifecycleNode
206207
* @brief Initialize state services
207208
*/
208209
void initServices();
209-
rclcpp::Service<std_srvs::srv::Empty>::SharedPtr global_loc_srv_;
210+
nav2_util::ServiceServer<std_srvs::srv::Empty,
211+
std::shared_ptr<nav2_util::LifecycleNode>>::SharedPtr global_loc_srv_;
210212
/*
211213
* @brief Service callback for a global relocalization request
212214
*/
@@ -216,7 +218,8 @@ class AmclNode : public nav2_util::LifecycleNode
216218
std::shared_ptr<std_srvs::srv::Empty::Response> response);
217219

218220
// service server for providing an initial pose guess
219-
rclcpp::Service<nav2_msgs::srv::SetInitialPose>::SharedPtr initial_guess_srv_;
221+
nav2_util::ServiceServer<nav2_msgs::srv::SetInitialPose,
222+
std::shared_ptr<nav2_util::LifecycleNode>>::SharedPtr initial_guess_srv_;
220223
/*
221224
* @brief Service callback for an initial pose guess request
222225
*/
@@ -226,7 +229,8 @@ class AmclNode : public nav2_util::LifecycleNode
226229
std::shared_ptr<nav2_msgs::srv::SetInitialPose::Response> response);
227230

228231
// Let amcl update samples without requiring motion
229-
rclcpp::Service<std_srvs::srv::Empty>::SharedPtr nomotion_update_srv_;
232+
nav2_util::ServiceServer<std_srvs::srv::Empty,
233+
std::shared_ptr<nav2_util::LifecycleNode>>::SharedPtr nomotion_update_srv_;
230234
/*
231235
* @brief Request an AMCL update even though the robot hasn't moved
232236
*/

nav2_amcl/src/amcl_node.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,18 +1564,21 @@ AmclNode::initPubSub()
15641564
void
15651565
AmclNode::initServices()
15661566
{
1567-
global_loc_srv_ = create_service<std_srvs::srv::Empty>(
1568-
"reinitialize_global_localization",
1567+
global_loc_srv_ = std::make_shared<nav2_util::ServiceServer<std_srvs::srv::Empty,
1568+
std::shared_ptr<nav2_util::LifecycleNode>>>(
1569+
"reinitialize_global_localization", shared_from_this(),
15691570
std::bind(&AmclNode::globalLocalizationCallback, this, std::placeholders::_1,
15701571
std::placeholders::_2, std::placeholders::_3));
15711572

1572-
initial_guess_srv_ = create_service<nav2_msgs::srv::SetInitialPose>(
1573-
"set_initial_pose",
1573+
initial_guess_srv_ = std::make_shared<nav2_util::ServiceServer<nav2_msgs::srv::SetInitialPose,
1574+
std::shared_ptr<nav2_util::LifecycleNode>>>(
1575+
"set_initial_pose", shared_from_this(),
15741576
std::bind(&AmclNode::initialPoseReceivedSrv, this, std::placeholders::_1, std::placeholders::_2,
15751577
std::placeholders::_3));
15761578

1577-
nomotion_update_srv_ = create_service<std_srvs::srv::Empty>(
1578-
"request_nomotion_update",
1579+
nomotion_update_srv_ = std::make_shared<nav2_util::ServiceServer<std_srvs::srv::Empty,
1580+
std::shared_ptr<nav2_util::LifecycleNode>>>(
1581+
"request_nomotion_update", shared_from_this(),
15791582
std::bind(&AmclNode::nomotionUpdateCallback, this, std::placeholders::_1, std::placeholders::_2,
15801583
std::placeholders::_3));
15811584
}

nav2_amcl/src/map/map.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ map_t * map_alloc(void)
4949
// Allocate storage for main map
5050
map->cells = (map_cell_t *) NULL;
5151

52+
// Initialize max_occ_dist to 0.0
53+
map->max_occ_dist = 0.0;
54+
5255
return map;
5356
}
5457

nav2_amcl/src/map/map_cspace.cpp

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
#include "nav2_amcl/map/map.hpp"
2626

2727
/*
28-
* @class CellData
28+
* @struct CellData
2929
* @brief Data about map cells
3030
*/
31-
class CellData
31+
struct CellData
3232
{
33-
public:
3433
map_t * map_;
3534
unsigned int i_, j_;
3635
unsigned int src_i_, src_j_;
36+
float occ_dist;
3737
};
3838

3939
/*
@@ -82,9 +82,7 @@ class CachedDistanceMap
8282
*/
8383
bool operator<(const CellData & a, const CellData & b)
8484
{
85-
return a.map_->cells[MAP_INDEX(
86-
a.map_, a.i_,
87-
a.j_)].occ_dist > a.map_->cells[MAP_INDEX(b.map_, b.i_, b.j_)].occ_dist;
85+
return a.occ_dist > b.occ_dist;
8886
}
8987

9088
/*
@@ -118,7 +116,9 @@ void enqueue(
118116
CachedDistanceMap * cdm,
119117
unsigned char * marked)
120118
{
121-
if (marked[MAP_INDEX(map, i, j)]) {
119+
const int map_index = MAP_INDEX(map, i, j);
120+
121+
if (marked[map_index]) {
122122
return;
123123
}
124124

@@ -130,18 +130,13 @@ void enqueue(
130130
return;
131131
}
132132

133-
map->cells[MAP_INDEX(map, i, j)].occ_dist = distance * map->scale;
134-
135-
CellData cell;
136-
cell.map_ = map;
137-
cell.i_ = i;
138-
cell.j_ = j;
139-
cell.src_i_ = src_i;
140-
cell.src_j_ = src_j;
133+
map->cells[map_index].occ_dist = distance * map->scale;
141134

142-
Q.push(cell);
135+
Q.emplace(CellData{map, static_cast<unsigned int>(i), static_cast<unsigned int>(j),
136+
static_cast<unsigned int>(src_i), static_cast<unsigned int>(src_j),
137+
map->cells[map_index].occ_dist});
143138

144-
marked[MAP_INDEX(map, i, j)] = 1;
139+
marked[map_index] = 1;
145140
}
146141

147142
/*
@@ -164,16 +159,18 @@ void map_update_cspace(map_t * map, double max_occ_dist)
164159
// Enqueue all the obstacle cells
165160
CellData cell;
166161
cell.map_ = map;
162+
int loop_map_index;
167163
for (int i = 0; i < map->size_x; i++) {
168164
cell.src_i_ = cell.i_ = i;
169165
for (int j = 0; j < map->size_y; j++) {
170-
if (map->cells[MAP_INDEX(map, i, j)].occ_state == +1) {
171-
map->cells[MAP_INDEX(map, i, j)].occ_dist = 0.0;
166+
loop_map_index = MAP_INDEX(map, i, j);
167+
if (map->cells[loop_map_index].occ_state == +1) {
168+
map->cells[loop_map_index].occ_dist = 0.0;
172169
cell.src_j_ = cell.j_ = j;
173-
marked[MAP_INDEX(map, i, j)] = 1;
170+
marked[loop_map_index] = 1;
174171
Q.push(cell);
175172
} else {
176-
map->cells[MAP_INDEX(map, i, j)].occ_dist = max_occ_dist;
173+
map->cells[loop_map_index].occ_dist = max_occ_dist;
177174
}
178175
}
179176
}
@@ -182,27 +179,27 @@ void map_update_cspace(map_t * map, double max_occ_dist)
182179
CellData current_cell = Q.top();
183180
if (current_cell.i_ > 0) {
184181
enqueue(
185-
map, current_cell.i_ - 1, current_cell.j_,
186-
current_cell.src_i_, current_cell.src_j_,
187-
Q, cdm, marked);
182+
map, current_cell.i_ - 1, current_cell.j_,
183+
current_cell.src_i_, current_cell.src_j_,
184+
Q, cdm, marked);
188185
}
189186
if (current_cell.j_ > 0) {
190187
enqueue(
191-
map, current_cell.i_, current_cell.j_ - 1,
192-
current_cell.src_i_, current_cell.src_j_,
193-
Q, cdm, marked);
188+
map, current_cell.i_, current_cell.j_ - 1,
189+
current_cell.src_i_, current_cell.src_j_,
190+
Q, cdm, marked);
194191
}
195192
if (static_cast<int>(current_cell.i_) < map->size_x - 1) {
196193
enqueue(
197-
map, current_cell.i_ + 1, current_cell.j_,
198-
current_cell.src_i_, current_cell.src_j_,
199-
Q, cdm, marked);
194+
map, current_cell.i_ + 1, current_cell.j_,
195+
current_cell.src_i_, current_cell.src_j_,
196+
Q, cdm, marked);
200197
}
201198
if (static_cast<int>(current_cell.j_) < map->size_y - 1) {
202199
enqueue(
203-
map, current_cell.i_, current_cell.j_ + 1,
204-
current_cell.src_i_, current_cell.src_j_,
205-
Q, cdm, marked);
200+
map, current_cell.i_, current_cell.j_ + 1,
201+
current_cell.src_i_, current_cell.src_j_,
202+
Q, cdm, marked);
206203
}
207204

208205
Q.pop();

nav2_amcl/src/sensors/laser/likelihood_field_model.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ LikelihoodFieldModel::LikelihoodFieldModel(
3535
z_hit_ = z_hit;
3636
z_rand_ = z_rand;
3737
sigma_hit_ = sigma_hit;
38-
map_update_cspace(map, max_occ_dist);
38+
39+
// recompute cspace only when necessary, i.e. if:
40+
// - max_occ_dist changed
41+
// OR
42+
// - cspace was not computed yet, i.e. when map->max_occ_dist == 0.0 (and hence different from
43+
// max_occ_dist)
44+
if (map->max_occ_dist != max_occ_dist) {
45+
map_update_cspace(map, max_occ_dist);
46+
}
3947
}
4048

4149
double

nav2_amcl/src/sensors/laser/likelihood_field_model_prob.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ LikelihoodFieldModelProb::LikelihoodFieldModelProb(
4343
beam_skip_distance_ = beam_skip_distance;
4444
beam_skip_threshold_ = beam_skip_threshold;
4545
beam_skip_error_threshold_ = beam_skip_error_threshold;
46-
map_update_cspace(map, max_occ_dist);
46+
47+
// recompute cspace only when necessary, i.e. if:
48+
// - max_occ_dist changed
49+
// OR
50+
// - cspace was not computed yet, i.e. when map->max_occ_dist == 0.0 (and hence different from
51+
// max_occ_dist)
52+
if (map->max_occ_dist != max_occ_dist) {
53+
map_update_cspace(map, max_occ_dist);
54+
}
4755
}
4856

4957
// Determine the probability for the given pose

nav2_behavior_tree/include/nav2_behavior_tree/behavior_tree_engine.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "behaviortree_cpp/behavior_tree.h"
2424
#include "behaviortree_cpp/bt_factory.h"
25+
#include "behaviortree_cpp/loggers/groot2_publisher.h"
2526
#include "behaviortree_cpp/xml_parsing.h"
2627

2728
#include "rclcpp/rclcpp.hpp"
@@ -85,6 +86,18 @@ class BehaviorTreeEngine
8586
const std::string & file_path,
8687
BT::Blackboard::Ptr blackboard);
8788

89+
/**
90+
* @brief Add Groot2 monitor to publish BT status changes
91+
* @param tree BT to monitor
92+
* @param server_port Groot2 Server port, first of the pair (server_port, publisher_port)
93+
*/
94+
void addGrootMonitoring(BT::Tree * tree, uint16_t server_port);
95+
96+
/**
97+
* @brief Reset groot monitor
98+
*/
99+
void resetGrootMonitor();
100+
88101
/**
89102
* @brief Function to explicitly reset all BT nodes to initial state
90103
* @param tree Tree to halt
@@ -97,6 +110,9 @@ class BehaviorTreeEngine
97110

98111
// Clock
99112
rclcpp::Clock::SharedPtr clock_;
113+
114+
// Groot2 monitor
115+
std::unique_ptr<BT::Groot2Publisher> groot_monitor_;
100116
};
101117

102118
} // namespace nav2_behavior_tree

0 commit comments

Comments
 (0)