I am not familiar with the output of ros2 topic echo /scan
, having never used it.
However, after a google, I found this, laser data is not avliable on rviz2 . but i am geting data while using terminal cmd topic echo., which shows an example of the output, like so:
header: stamp: sec: 1675073473 nanosec: 112333930 frame_id: laser angle_min: 0.0 angle_max: 6.2657318115234375 angle_increment: 0.01745329238474369 time_increment: 0.0005592841189354658 scan_time: 0.20134228467941284 range_min: 0.11999999731779099 range_max: 3.5 ranges: - 0.13099999725818634 - 0.12999999523162842 - 0.12999999523162842 - 0.1289999932050705 - 0.1289999932050705 - 0.1289999932050705 - 0.1289999932050705 - 0.1289999932050705 ................
So, assuming that each sample "message" has the text header
at the start, then this command should1 count your samples:
ros2 topic echo /scan | grep header | wc -l
1 Unless I've got completely the wrong end of the stick