import rclpy
from rclpy.node import Node
from sensor_msgs.msg import CompressedImage
import cv2
import numpy as np
class CompressedImageSubscriber(Node):
def __init__(self):
super().__init__('compressed_image_subscriber')
self.subscription = self.create_subscription(
CompressedImage,
'/image/detected/front_01', # Replace with your actual topic name
self.image_callback,
10)
self.subscription # prevent unused variable warning
def image_callback(self, msg):
self.get_logger().info(f'Received compressed image with format: {msg.format}')
try:
# Convert the byte array to a numpy array
np_arr = np.frombuffer(msg.data, np.uint8)
# Decode the compressed image data using OpenCV
# The '1' flag means to load the image in color (BGR format for OpenCV)
cv_image = cv2.imdecode(np_arr, cv2.IMREAD_COLOR)
if cv_image is not None:
# Display the image in a window
cv2.imshow("ROS2 Compressed Image View", cv_image)
cv2.waitKey(1) # Refresh the window every 1ms
else:
self.get_logger().error("Failed to decode image")
except Exception as e:
self.get_logger().error(f"Error processing image: {e}")
def main(args=None):
rclpy.init(args=args)
compressed_image_subscriber = CompressedImageSubscriber()
rclpy.spin(compressed_image_subscriber)
# Destroy the node explicitly
compressed_image_subscriber.destroy_node()
rclpy.shutdown()
cv2.destroyAllWindows() # Close all OpenCV windows
if __name__ == '__main__':
main()
This page documents the ROS Action APIs available in Nav2 for the humble distribution. These actions provide high-level interfaces for navigation tasks, planning, and recovery behaviors.
Available Actions (14 total)
Navigation Actions
Package: nav2_msgs
Navigate robot through a series of waypoints with optional task execution at each point
Package: nav2_msgs
Navigate robot through a sequence of poses in order
Package: nav2_msgs
Navigate robot to a specific pose with obstacle avoidance and recovery behaviors
Planning Actions
Package: nav2_msgs
Compute and actively track a route with dynamic replanning
Package: nav2_msgs
Compute an optimal path connecting multiple poses in sequence
Package: nav2_msgs
Compute an optimal path from current position to a target pose
Package: nav2_msgs
Compute a high-level route between waypoints using graph search
Package: nav2_msgs
Generate a smoother, kinematically feasible path from a discrete path
Controller Actions
Package: nav2_msgs
Execute path following using a specified controller with progress monitoring
Behaviors
Package: nav2_msgs
Provide assisted teleoperation with collision avoidance and safety checks
Package: nav2_msgs
Move robot backwards a specified distance with obstacle detection
Package: nav2_msgs
Drive robot forward in a specific direction for a given distance
Package: nav2_msgs
Rotate robot in place to a target yaw angle with collision checking
Package: nav2_msgs
Pause robot operation for a specified duration or until condition is met
Generated on 2025-08-08 09:48:43 UTC


一、错误写法
while(rclcpp::ok())
{
rclcpp::spin_some(node);
}
二、正确写法
rclcpp::spin(node);
三、正确写法
while(rclcpp::ok())
{
rclcpp::spin_some(node);
std::this_thread::sleep_for(std::chrono::milliseconds(100)); //需要休眠
}
root@nvidia-desktop:/home/nvidia/xi/nav2/robot_bringup/share#
root@nvidia-desktop:/home/nvidia/xi/nav2/robot_bringup/share#
root@nvidia-desktop:/home/nvidia/xi/nav2/robot_bringup/share# ros2 launch robot_bringup navigation_launch.py
[INFO] [launch]: All log files can be found below /root/.ros/log/2025-11-14-17-55-24-559950-nvidia-desktop-6604
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [controller_server-1]: process started with pid [6605]
[INFO] [smoother_server-2]: process started with pid [6607]
[INFO] [planner_server-3]: process started with pid [6609]
[INFO] [behavior_server-4]: process started with pid [6611]
[INFO] [bt_navigator-5]: process started with pid [6613]
[INFO] [waypoint_follower-6]: process started with pid [6615]
[INFO] [velocity_smoother-7]: process started with pid [6623]
[INFO] [lifecycle_manager-8]: process started with pid [6635]
[velocity_smoother-7] [INFO] [1763114125.006979028] [velocity_smoother]:
[velocity_smoother-7] velocity_smoother lifecycle node launched.
[velocity_smoother-7] Waiting on external lifecycle transitions to activate
[velocity_smoother-7] See https://design.ros2.org/articles/node_lifecycle.html for more information.
[controller_server-1] [INFO] [1763114125.064706326] [controller_server]:
[controller_server-1] controller_server lifecycle node launched.
[controller_server-1] Waiting on external lifecycle transitions to activate
[controller_server-1] See https://design.ros2.org/articles/node_lifecycle.html for more information.
[lifecycle_manager-8] [INFO] [1763114125.066550793] [lifecycle_manager_navigation]: Creating
[lifecycle_manager-8] [INFO] [1763114125.071142985] [lifecycle_manager_navigation]: Creating and initializing lifecycle service clients
[waypoint_follower-6] [INFO] [1763114125.074857264] [waypoint_follower]:
[waypoint_follower-6] waypoint_follower lifecycle node launched.
[waypoint_follower-6] Waiting on external lifecycle transitions to activate
[waypoint_follower-6] See https://design.ros2.org/articles/node_lifecycle.html for more information.
[waypoint_follower-6] [INFO] [1763114125.076540223] [waypoint_follower]: Creating
[smoother_server-2] [INFO] [1763114125.078633369] [smoother_server]:
[smoother_server-2] smoother_server lifecycle node launched.
[smoother_server-2] Waiting on external lifecycle transitions to activate
[smoother_server-2] See https://design.ros2.org/articles/node_lifecycle.html for more information.
[behavior_server-4] [INFO] [1763114125.085639515] [behavior_server]:
[behavior_server-4] behavior_server lifecycle node launched.
[behavior_server-4] Waiting on external lifecycle transitions to activate
[behavior_server-4] See https://design.ros2.org/articles/node_lifecycle.html for more information.
[smoother_server-2] [INFO] [1763114125.087414764] [smoother_server]: Creating smoother server
[controller_server-1] [INFO] [1763114125.103049823] [controller_server]: Creating controller server
[planner_server-3] [INFO] [1763114125.113090357] [planner_server]:
[planner_server-3] planner_server lifecycle node launched.
[planner_server-3] Waiting on external lifecycle transitions to activate
[planner_server-3] See https://design.ros2.org/articles/node_lifecycle.html for more information.
[planner_server-3] [INFO] [1763114125.122897478] [planner_server]: Creating
[bt_navigator-5] [INFO] [1763114125.140484046] [bt_navigator]:
[bt_navigator-5] bt_navigator lifecycle node launched.
[bt_navigator-5] Waiting on external lifecycle transitions to activate
[bt_navigator-5] See https://design.ros2.org/articles/node_lifecycle.html for more information.
[bt_navigator-5] [INFO] [1763114125.145020012] [bt_navigator]: Creating
[planner_server-3] [INFO] [1763114125.293919153] [global_costmap.global_costmap]:
[planner_server-3] global_costmap lifecycle node launched.
[planner_server-3] Waiting on external lifecycle transitions to activate
[controller_server-1] [INFO] [1763114125.294122103] [local_costmap.local_costmap]:
[controller_server-1] local_costmap lifecycle node launched.
[controller_server-1] Waiting on external lifecycle transitions to activate
[controller_server-1] See https://design.ros2.org/articles/node_lifecycle.html for more information.
[controller_server-1] [INFO] [1763114125.296174800] [local_costmap.local_costmap]: Creating Costmap
[planner_server-3] See https://design.ros2.org/articles/node_lifecycle.html for more information.
[planner_server-3] [INFO] [1763114125.305439793] [global_costmap.global_costmap]: Creating Costmap
[lifecycle_manager-8] [INFO] [1763114125.338718989] [lifecycle_manager_navigation]: Starting managed nodes bringup...
[lifecycle_manager-8] [INFO] [1763114125.338843760] [lifecycle_manager_navigation]: Configuring controller_server
[controller_server-1] [INFO] [1763114125.339294845] [controller_server]: Configuring controller interface
[controller_server-1] [INFO] [1763114125.339553828] [controller_server]: getting goal checker plugins..
[controller_server-1] [INFO] [1763114125.339640262] [controller_server]: Controller frequency set to 10.0000Hz
[controller_server-1] [INFO] [1763114125.339698888] [local_costmap.local_costmap]: Configuring
[controller_server-1] [INFO] [1763114125.351731414] [local_costmap.local_costmap]: Using plugin "obstacle_layer"
[controller_server-1] [INFO] [1763114125.360817810] [local_costmap.local_costmap]: zjlClearMod Subscribed to Topics: pointcloud
[controller_server-1] [INFO] [1763114125.373657463] [local_costmap.local_costmap]: Initialized plugin "obstacle_layer"
[controller_server-1] [INFO] [1763114125.373843100] [local_costmap.local_costmap]: Using plugin "inflation_layer"
[controller_server-1] [INFO] [1763114125.376033497] [local_costmap.local_costmap]: Initialized plugin "inflation_layer"
[controller_server-1] [INFO] [1763114125.399480228] [controller_server]: Created progress_checker : progress_checker of type nav2_controller::SimpleProgressChecker
[controller_server-1] [INFO] [1763114125.401125553] [controller_server]: Created goal checker : general_goal_checker of type nav2_controller::SimpleGoalChecker
[controller_server-1] [INFO] [1763114125.401508412] [controller_server]: Controller Server has general_goal_checker goal checkers available.
[controller_server-1] [INFO] [1763114125.402716765] [controller_server]: Created controller : FollowPath of type nav2_mppi_controller::MPPIController
[controller_server-1] [INFO] [1763114125.404634003] [controller_server]: Controller period is equal to model dt. Control sequence shifting is ON
[controller_server-1] [INFO] [1763114125.406519367] [controller_server]: ConstraintCritic instantiated with 1 power and 4.000000 weight.
[controller_server-1] [INFO] [1763114125.406586249] [controller_server]: Critic loaded : mppi::critics::ConstraintCritic
[controller_server-1] [INFO] [1763114125.407315485] [controller_server]: InflationCostCritic instantiated with 1 power and 300.000000 / 0.022874 weights. Critic will collision check based on footprint cost.
[controller_server-1] [INFO] [1763114125.407364734] [controller_server]: Critic loaded : mppi::critics::CostCritic
[controller_server-1] [INFO] [1763114125.407997392] [controller_server]: GoalCritic instantiated with 1 power and 8.000000 weight.
[controller_server-1] [INFO] [1763114125.408039121] [controller_server]: Critic loaded : mppi::critics::GoalCritic
[controller_server-1] [INFO] [1763114125.408418172] [controller_server]: GoalAngleCritic instantiated with 1 power, 8.000000 weight, and 0.460000 angular threshold.
[controller_server-1] [INFO] [1763114125.408450813] [controller_server]: Critic loaded : mppi::critics::GoalAngleCritic
[controller_server-1] [INFO] [1763114125.409054285] [controller_server]: ReferenceTrajectoryCritic instantiated with 1 power and 14.000000 weight
[controller_server-1] [INFO] [1763114125.409083278] [controller_server]: Critic loaded : mppi::critics::PathAlignCritic
[controller_server-1] [INFO] [1763114125.409560827] [controller_server]: Critic loaded : mppi::critics::PathFollowCritic
[controller_server-1] [INFO] [1763114125.410171436] [controller_server]: PathAngleCritic instantiated with 1 power and 3.100000 weight. Reversing not allowed.
[controller_server-1] [INFO] [1763114125.410203053] [controller_server]: Critic loaded : mppi::critics::PathAngleCritic
[controller_server-1] [INFO] [1763114125.410583064] [controller_server]: PreferForwardCritic instantiated with 1 power and 900.000000 weight.
[controller_server-1] [INFO] [1763114125.410615737] [controller_server]: Critic loaded : mppi::critics::PreferForwardCritic
[controller_server-1] [INFO] [1763114125.410912257] [controller_server]: TwirlingCritic instantiated with 1 power and 1.900000 weight.
[controller_server-1] [INFO] [1763114125.410940354] [controller_server]: Critic loaded : mppi::critics::TwirlingCritic
[controller_server-1] [INFO] [1763114125.420159458] [controller_server]: Optimizer reset
[controller_server-1] [INFO] [1763114125.426186953] [MPPIController]: Configured MPPI Controller: FollowPath
[controller_server-1] [INFO] [1763114125.426349261] [controller_server]: Controller Server has FollowPath controllers available.
[lifecycle_manager-8] [INFO] [1763114125.441087367] [lifecycle_manager_navigation]: Configuring smoother_server
[smoother_server-2] [INFO] [1763114125.441576532] [smoother_server]: Configuring smoother server
[smoother_server-2] [INFO] [1763114125.463808765] [smoother_server]: Created smoother : simple_smoother of type nav2_smoother::SimpleSmoother
[smoother_server-2] [INFO] [1763114125.466806705] [smoother_server]: Smoother Server has simple_smoother smoothers available.
[lifecycle_manager-8] [INFO] [1763114125.482905584] [lifecycle_manager_navigation]: Configuring planner_server
[planner_server-3] [INFO] [1763114125.483376541] [planner_server]: Configuring
[planner_server-3] [INFO] [1763114125.483449567] [global_costmap.global_costmap]: Configuring
[planner_server-3] [INFO] [1763114125.500676253] [global_costmap.global_costmap]: Using plugin "static_layer"
[planner_server-3] [INFO] [1763114125.511025596] [global_costmap.global_costmap]: Subscribing to the map topic (/map) with transient local durability
[planner_server-3] [INFO] [1763114125.514819269] [global_costmap.global_costmap]: Initialized plugin "static_layer"
[planner_server-3] [INFO] [1763114125.514911304] [global_costmap.global_costmap]: Using plugin "obstacle_layer"
[planner_server-3] [INFO] [1763114125.518363592] [global_costmap.global_costmap]: zjlClearMod Subscribed to Topics: scan
[planner_server-3] [INFO] [1763114125.530172496] [global_costmap.global_costmap]: Initialized plugin "obstacle_layer"
[planner_server-3] [INFO] [1763114125.530269778] [global_costmap.global_costmap]: Using plugin "inflation_layer"
[planner_server-3] [INFO] [1763114125.532828409] [global_costmap.global_costmap]: Initialized plugin "inflation_layer"
[planner_server-3] [INFO] [1763114125.561334833] [planner_server]: Created global planner plugin GridBased of type nav2_smac_planner/SmacPlannerHybrid
[planner_server-3] [INFO] [1763114125.561472437] [planner_server]: Configuring GridBased of type SmacPlannerHybrid
[planner_server-3] [INFO] [1763114125.566146422] [planner_server]: Even sized heuristic lookup table size set 600.000000, increasing size by 1 to make odd
[planner_server-3] [INFO] [1763114128.979197602] [global_costmap.global_costmap]: StaticLayer: Resizing costmap to 1622 X 3359 at 0.100000 m/pix
[planner_server-3] [INFO] [1763114130.658766537] [planner_server]: Configured plugin GridBased of type SmacPlannerHybrid with maximum iterations 1000000, max on approach iterations 1000, and not allowing unknown traversal. Tolerance 0.15.Using motion model: Dubin.
[planner_server-3] [INFO] [1763114130.658882381] [planner_server]: Planner Server has GridBased planners available.
[lifecycle_manager-8] [INFO] [1763114130.684366700] [lifecycle_manager_navigation]: Configuring behavior_server
[behavior_server-4] [INFO] [1763114130.684997790] [behavior_server]: Configuring
[behavior_server-4] [INFO] [1763114130.708697868] [behavior_server]: Creating behavior plugin backup of type nav2_behaviors/BackUp
[behavior_server-4] [INFO] [1763114130.710926794] [behavior_server]: Configuring backup
[behavior_server-4] [INFO] [1763114130.736108865] [behavior_server]: Creating behavior plugin drive_on_heading of type nav2_behaviors/DriveOnHeading
[behavior_server-4] [INFO] [1763114130.737611562] [behavior_server]: Configuring drive_on_heading
[behavior_server-4] [INFO] [1763114130.752007032] [behavior_server]: Creating behavior plugin assisted_teleop of type nav2_behaviors/AssistedTeleop
[behavior_server-4] [INFO] [1763114130.755076109] [behavior_server]: Configuring assisted_teleop
[behavior_server-4] [INFO] [1763114130.774864111] [behavior_server]: Creating behavior plugin wait of type nav2_behaviors/Wait
[behavior_server-4] [INFO] [1763114130.776271574] [behavior_server]: Configuring wait
[lifecycle_manager-8] [INFO] [1763114130.790616706] [lifecycle_manager_navigation]: Configuring bt_navigator
[bt_navigator-5] [INFO] [1763114130.791163921] [bt_navigator]: Configuring
[lifecycle_manager-8] [INFO] [1763114130.932958876] [lifecycle_manager_navigation]: Configuring waypoint_follower
[waypoint_follower-6] [INFO] [1763114130.933412073] [waypoint_follower]: Configuring
[waypoint_follower-6] [INFO] [1763114130.958373210] [waypoint_follower]: Created waypoint_task_executor : wait_at_waypoint of type nav2_waypoint_follower::WaitAtWaypoint
[lifecycle_manager-8] [INFO] [1763114130.960613624] [lifecycle_manager_navigation]: Configuring velocity_smoother
[velocity_smoother-7] [INFO] [1763114130.961055332] [velocity_smoother]: Configuring velocity smoother
[lifecycle_manager-8] [INFO] [1763114130.969885976] [lifecycle_manager_navigation]: Activating controller_server
[controller_server-1] [INFO] [1763114130.970203553] [controller_server]: Activating
[controller_server-1] [INFO] [1763114130.970305060] [local_costmap.local_costmap]: Activating
[controller_server-1] [INFO] [1763114130.970332644] [local_costmap.local_costmap]: Checking transform
[controller_server-1] [INFO] [1763114130.970902100] [local_costmap.local_costmap]: start
[controller_server-1] [WARN] [1763114130.971040504] [local_costmap.local_costmap]: costmap observation_subscribers_ 0 active
[controller_server-1] [WARN] [1763114131.173867507] [controller_server]: Parameter controller_server.verbose not found
[controller_server-1] [INFO] [1763114131.185856670] [controller_server]: Optimizer reset
[controller_server-1] [INFO] [1763114131.187711857] [MPPIController]: Activated MPPI Controller: FollowPath
[controller_server-1] [INFO] [1763114131.187819188] [controller_server]: Creating bond (controller_server) to lifecycle manager.
[lifecycle_manager-8] [INFO] [1763114131.305592421] [lifecycle_manager_navigation]: Server controller_server connected with bond.
[lifecycle_manager-8] [INFO] [1763114131.305769130] [lifecycle_manager_navigation]: Activating smoother_server
[smoother_server-2] [INFO] [1763114131.306710211] [smoother_server]: Activating
[smoother_server-2] [INFO] [1763114131.306826151] [smoother_server]: Creating bond (smoother_server) to lifecycle manager.
[lifecycle_manager-8] [INFO] [1763114131.425269066] [lifecycle_manager_navigation]: Server smoother_server connected with bond.
[lifecycle_manager-8] [INFO] [1763114131.425431502] [lifecycle_manager_navigation]: Activating planner_server
[planner_server-3] [INFO] [1763114131.426254725] [planner_server]: Activating
[planner_server-3] [INFO] [1763114131.426377448] [global_costmap.global_costmap]: Activating
[planner_server-3] [INFO] [1763114131.426410985] [global_costmap.global_costmap]: Checking transform
[planner_server-3] [INFO] [1763114131.426656848] [global_costmap.global_costmap]: start
[planner_server-3] [WARN] [1763114131.426714002] [global_costmap.global_costmap]: costmap observation_subscribers_ 0 active
[planner_server-3] [INFO] [1763114132.530031682] [planner_server]: Activating plugin GridBased of type SmacPlannerHybrid
[planner_server-3] [INFO] [1763114132.584121781] [planner_server]: Creating bond (planner_server) to lifecycle manager.
[lifecycle_manager-8] [INFO] [1763114132.699226264] [lifecycle_manager_navigation]: Server planner_server connected with bond.
[lifecycle_manager-8] [INFO] [1763114132.699396637] [lifecycle_manager_navigation]: Activating behavior_server
[behavior_server-4] [INFO] [1763114132.701951971] [behavior_server]: Activating
[behavior_server-4] [INFO] [1763114132.702090855] [behavior_server]: Activating backup
[behavior_server-4] [INFO] [1763114132.702131752] [behavior_server]: Activating drive_on_heading
[behavior_server-4] [INFO] [1763114132.702157929] [behavior_server]: Activating assisted_teleop
[behavior_server-4] [INFO] [1763114132.702181930] [behavior_server]: Activating wait
[behavior_server-4] [INFO] [1763114132.702216651] [behavior_server]: Creating bond (behavior_server) to lifecycle manager.
[lifecycle_manager-8] [INFO] [1763114132.817530004] [lifecycle_manager_navigation]: Server behavior_server connected with bond.
[lifecycle_manager-8] [INFO] [1763114132.817678488] [lifecycle_manager_navigation]: Activating bt_navigator
[bt_navigator-5] [INFO] [1763114132.818342346] [bt_navigator]: Activating
[bt_navigator-5] [INFO] [1763114132.957118618] [bt_navigator]: Creating bond (bt_navigator) to lifecycle manager.
[lifecycle_manager-8] [INFO] [1763114133.065892781] [lifecycle_manager_navigation]: Server bt_navigator connected with bond.
[lifecycle_manager-8] [INFO] [1763114133.066037009] [lifecycle_manager_navigation]: Activating waypoint_follower
[waypoint_follower-6] [INFO] [1763114133.066775525] [waypoint_follower]: Activating
[waypoint_follower-6] [INFO] [1763114133.066873448] [waypoint_follower]: Creating bond (waypoint_follower) to lifecycle manager.
[lifecycle_manager-8] [INFO] [1763114133.181582205] [lifecycle_manager_navigation]: Server waypoint_follower connected with bond.
[lifecycle_manager-8] [INFO] [1763114133.181714433] [lifecycle_manager_navigation]: Activating velocity_smoother
[velocity_smoother-7] [INFO] [1763114133.183211690] [velocity_smoother]: Activating
[velocity_smoother-7] [INFO] [1763114133.183391119] [velocity_smoother]: Creating bond (velocity_smoother) to lifecycle manager.
[lifecycle_manager-8] [INFO] [1763114133.303716543] [lifecycle_manager_navigation]: Server velocity_smoother connected with bond.
[lifecycle_manager-8] [INFO] [1763114133.303874883] [lifecycle_manager_navigation]: Managed nodes are active
[lifecycle_manager-8] [INFO] [1763114133.303912644] [lifecycle_manager_navigation]: Creating bond timer...
[bt_navigator-5] [INFO] [1763114181.285888872] [bt_navigator]: Begin navigating from current location (117.26, 178.09) to (117.00, 194.05)
[controller_server-1] [INFO] [1763114181.368861636] [controller_server]: Received a goal, begin computing control effort.
[controller_server-1] [WARN] [1763114181.369047081] [controller_server]: No goal checker was specified in parameter 'current_goal_checker'. Server will use only plugin loaded general_goal_checker . This warning will appear once.
[controller_server-1] [INFO] [1763114181.376368041] [controller_server]: Optimizer reset
[bt_navigator-5] [WARN] [1763114189.456848298] [BehaviorTreeEngine]: Behavior Tree tick rate 100.00 was exceeded!
[controller_server-1] [INFO] [1763114238.304461328] [controller_server]: Reached the goal!
[bt_navigator-5] [INFO] [1763114238.336899858] [bt_navigator]: Goal succeeded