Skip to content

Commit

Permalink
Pull request #31: Fixed the asynchronous_grab example
Browse files Browse the repository at this point in the history
Merge in HSW_SDK/vimbax_ros2_driver from bugfix/asynchronous_grab to dev

* commit 'c2ba7f14fb1b9c60fde2da3ed93a4762be1b8320':
  Fixed the asynchronous_grab example
  • Loading branch information
Justus Braun [Allied Vision] authored and Justus Braun [Allied Vision] committed Mar 20, 2024
2 parents 3c1dc84 + c2ba7f1 commit 1296155
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions vimbax_camera_examples/vimbax_camera_examples/asynchronous_grab.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@

from sensor_msgs.msg import Image

last_frame_id = -1
frames_recv = 0
frames_missing = 0


def main():
Expand All @@ -39,7 +37,7 @@ def signal_handler(signum, frame):
signal.signal(signal.SIGTERM, signal_handler)

parser = argparse.ArgumentParser()
parser.add_argument("node_name")
parser.add_argument("node_namespace")
parser.add_argument("-i", "--info", action="store_true", help="Show frame infos")
parser.add_argument("-c", "--count", type=int, default=0, help="Frame count until stop stream")

Expand All @@ -52,28 +50,19 @@ def signal_handler(signum, frame):
def on_frame(msg: Image):
global last_frame_id
global frames_recv
global frames_missing
frame_id = int(msg.header.frame_id)
missing = frame_id - last_frame_id - 1

if frames_recv > 0:
frames_missing += missing
if args.info:
if missing > 0:
print(f"{missing} frame missing!")
print(f"Frame id {msg.header.frame_id} Size {msg.width}x{msg.height} "
+ f"Format {msg.encoding}")
else:
print(".", end='', flush=True)

frames_recv += 1
last_frame_id = frame_id
if args.count > 0 and frames_recv >= args.count:
stop_future.set_result(None)

node.create_subscription(Image, f"{args.node_name}/image_raw", on_frame, 10)
node.create_subscription(Image, f"{args.node_namespace}/image_raw", on_frame, 10)

rclpy.spin_until_future_complete(node, stop_future)

print(f"Received frames {frames_recv}")
print(f"Missing frames {frames_missing}")
print(f"\nReceived frames {frames_recv}")

0 comments on commit 1296155

Please sign in to comment.