Bound urban route clearance preference and expose Nav2 costmap diagnostics
This commit is contained in:
@@ -15,6 +15,7 @@ from geometry_msgs.msg import TransformStamped, Twist
|
||||
from lifecycle_msgs.msg import Transition
|
||||
from lifecycle_msgs.srv import ChangeState
|
||||
from nav2_msgs.action import BackUp, ComputePathToPose, FollowPath, Spin
|
||||
from nav2_msgs.msg import Costmap
|
||||
from nav_msgs.msg import Odometry
|
||||
from rclpy.action import ActionClient
|
||||
from rclpy.node import Node
|
||||
@@ -33,6 +34,11 @@ class RosNavigation(Node):
|
||||
self.condition = threading.Condition()
|
||||
self.action_lock = threading.Lock()
|
||||
self.pose = None
|
||||
self.costmaps = {}
|
||||
self.last_planner_diagnostic = None
|
||||
for name in ("global_costmap", "local_costmap"):
|
||||
self.create_subscription(Costmap, "/"+name+"/costmap_raw",
|
||||
lambda value, owner=name: self.receive_costmap(owner, value), 1)
|
||||
self.action_handle = self.terminal = self.latest_command = None
|
||||
self.command_sequence = 0
|
||||
self.action_sequence = 0
|
||||
@@ -52,6 +58,22 @@ class RosNavigation(Node):
|
||||
self.spin_client = ActionClient(self, Spin, '/spin')
|
||||
self.backup_client = ActionClient(self, BackUp, '/backup')
|
||||
|
||||
def receive_costmap(self, name, message):
|
||||
metadata = message.metadata
|
||||
if metadata.size_x * metadata.size_y != len(message.data) or len(message.data) > 320*320:
|
||||
return # Bounded read-only diagnostics; never a planning input.
|
||||
receipt = dict(received_at=time.monotonic(), frame_id=message.header.frame_id,
|
||||
stamp_ns=message.header.stamp.sec*1_000_000_000+message.header.stamp.nanosec,
|
||||
resolution=metadata.resolution, width=metadata.size_x, height=metadata.size_y,
|
||||
origin=[metadata.origin.position.x, metadata.origin.position.y],
|
||||
data=list(message.data))
|
||||
with self.condition:
|
||||
self.costmaps[name] = receipt
|
||||
|
||||
def diagnostic(self):
|
||||
with self.condition:
|
||||
return dict(costmaps=dict(self.costmaps), last_planner=self.last_planner_diagnostic)
|
||||
|
||||
@staticmethod
|
||||
def await_result(future, timeout):
|
||||
done = threading.Event()
|
||||
@@ -144,6 +166,10 @@ class RosNavigation(Node):
|
||||
# Do not leave work from a timed-out HTTP transaction as authority.
|
||||
self.await_result(handle.cancel_goal_async(), .2)
|
||||
raise
|
||||
with self.condition:
|
||||
self.last_planner_diagnostic = dict(completed_at=time.monotonic(),
|
||||
start=list(pose), goal=list(goal), goal_yaw=yaw, status=result.status,
|
||||
costmaps=dict(self.costmaps))
|
||||
return (result.result.path if result.status == GoalStatus.STATUS_SUCCEEDED else None,
|
||||
result.status)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user