Skip to content

Commit eb5d232

Browse files
author
cl03
committed
listen to ball obstacle active topic
1 parent 46d6bd1 commit eb5d232

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

bitbots_navigation/bitbots_path_planning/bitbots_path_planning/map.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __init__(self, node: Node, buffer: tf2.Buffer) -> None:
3838
self.config_inflation_blur: int = self.node.config.map.inflation.blur
3939
self.config_inflation_dialation: int = self.node.config.map.inflation.dialate
4040
self.config_obstacle_value: int = self.node.config.map.obstacle_value
41+
self.ball_obstacle_active: bool = True
4142

4243
def set_ball(self, ball: PoseWithCovarianceStamped) -> None:
4344
"""
@@ -60,7 +61,7 @@ def _render_balls(self) -> None:
6061
cv2.circle(
6162
self.map,
6263
self.to_map_space(ball.x, ball.y)[::-1],
63-
round(self.config_ball_diameter * self.resolution),
64+
round(self.config_ball_diameter / 2 * self.resolution),
6465
self.config_obstacle_value,
6566
-1,
6667
)
@@ -140,10 +141,17 @@ def update(self) -> None:
140141
Regenerates the costmap based on the ball and robot buffer
141142
"""
142143
self.clear()
143-
self._render_balls()
144+
if self.ball_obstacle_active:
145+
self._render_balls()
144146
self._render_robots()
145147
self.inflate()
146148

149+
def avoid_ball(self, state: bool) -> None:
150+
"""
151+
Activates or deactivates the ball obstacle
152+
"""
153+
self.ball_obstacle_active = state
154+
147155
def get_map(self) -> np.ndarray:
148156
"""
149157
Returns the costmap as an numpy array

bitbots_navigation/bitbots_path_planning/bitbots_path_planning/path_planning.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from rclpy.duration import Duration
88
from rclpy.executors import MultiThreadedExecutor
99
from rclpy.node import Node
10-
from std_msgs.msg import Empty
10+
from std_msgs.msg import Bool, Empty
1111

1212
from bitbots_path_planning.controller import Controller
1313
from bitbots_path_planning.map import Map
@@ -58,6 +58,13 @@ def __init__(self) -> None:
5858
5,
5959
callback_group=MutuallyExclusiveCallbackGroup(),
6060
)
61+
self.create_subscription(
62+
Bool,
63+
"ball_obstacle_active",
64+
lambda msg: self.map.avoid_ball(msg.data),
65+
5,
66+
callback_group=MutuallyExclusiveCallbackGroup(),
67+
)
6168

6269
# Publisher
6370
self.cmd_vel_pub = self.create_publisher(Twist, "cmd_vel", 1)
@@ -106,7 +113,7 @@ def main(args=None):
106113
node = PathPlanning()
107114

108115
# choose number of threads by number of callback_groups + 1 for simulation time
109-
ex = MultiThreadedExecutor(num_threads=7)
116+
ex = MultiThreadedExecutor(num_threads=8)
110117
ex.add_node(node)
111118
ex.spin()
112119

0 commit comments

Comments
 (0)