-
Notifications
You must be signed in to change notification settings - Fork 0
/
cv_layer.py
70 lines (54 loc) · 2.06 KB
/
cv_layer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import rclpy
from rclpy.node import Node
from nav2_costmap_2d.layer import CostmapLayer
class SensorsMapSubscriber(Node):
def __init__(self):
super().__init__('sensors_map_subscriber') # TODO: FIgure out the real topic
self.subscription = self.create_subscription(
String,
'cv_grid_out',
self.callback,
10)
self.subscription # prevent unused variable warning
def callback(self, msg):
self.get_logger().info('Received: %s' % msg.data)
class CVMapSubscriber(Node):
def __init__(self):
super().__init__('cv_map_subscriber') # TODO: Figure out the real topic
self.subscription = self.create_subscription(
String,
'snsr_grid_out',
self.callback,
10)
self.subscription # prevent unused variable warning
def callback(self, msg):
self.get_logger().info('Received: %s' % msg.data)
class LayerCV(CostmapLayer):
def __init__(self):
super().__init__()
def on_initialize(self):
# Create a subscriber to the sensors map topic
self.sensors_map_subscriber = SensorsMapSubscriber()
# Create a subscriber to the CV map topic
self.cv_map_subscriber = CVMapSubscriber()
# Initialize the costmap layer
self.initialize('cv_layer', 'master_grid', 'cv_layer', False)
def update_bounds(self, robot_x, robot_y, robot_yaw, min_x, min_y, max_x, max_y):
# Update costmap bounds based on the robot's position and orientation
# Set the values of min_x, min_y, max_x, and max_y accordingly
pass
def update_costs(self, master_grid, min_i, min_j, max_i, max_j):
# Update the cost values in the specified region of the costmap
# You can use master_grid to access the underlying costmap and modify its values
pass
def main():
rclpy.init()
node = LayerCV()
try:
node.on_initialize()
rclpy.spin(node)
finally:
node.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()