Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gst: set_trigger & software_trigger added for aravissrc #927

Closed
wants to merge 4 commits into from

Conversation

WhaSukGO
Copy link
Contributor

@WhaSukGO WhaSukGO commented Sep 2, 2024

Overview

  • set-trigger and software-trigger have been added to aravissrc
  • Tested on iRAYPLE's A5051CU545E
 - USB3.0 interface, 5Gbps theoretical transfer bandwidth, power supply via USB interface
 - Compatible with USB3.0 Vision protocol and GenICam standard
 - Support Software Trigger/Hardware Trigger/Free Run Mode
 - Resolution: 800 × 600
 - Frame Rate: 545 fps
$ arv-tool-0.10 features PixelFormat
Dahua Technology  (USB3)
        Enumeration  : [RW] 'PixelFormat'
            EnumEntry   : 'BayerGB10Packed'
            EnumEntry   : 'BayerRG10Packed'
            EnumEntry   : 'BayerGB10'
            EnumEntry   : 'BayerRG10'
            EnumEntry   : 'BayerGB8'
            EnumEntry   : 'BayerRG8'

Example

  • set-trigger(bool) and software-trigger(func) are added
# export GST_PLUGIN_PATH=$GST_PLUGIN_PATH:<ARAVIS_ROOT>/build/gst

$ gst-inspect-1.0 aravissrc

  ...

  set-trigger         : Configures the camera in trigger mode
                        flags: readable, writable
                        Boolean. Default: false
  typefind            : Run typefind before negotiating (deprecated, non-functional)
                        flags: readable, writable, deprecated
                        Boolean. Default: false
  usb-mode            : USB mode (synchronous/asynchronous)
                        flags: readable, writable
                        Enum "GstArvUsbMode" Default: 1, "default"
                           (0): sync             - Synchronous
                           (1): async            - Asynchronous
                           (1): default          - Default
  v-binning           : CCD vertical binning
                        flags: readable, writable
                        Integer. Range: 1 - 2147483647 Default: -1 

Element Actions:
  "software-trigger" :  void user_function (GstElement* object);

Python

arv-software-trigger.py
import gi
import threading
import time

gi.require_version('Gst', '1.0')
from gi.repository import Gst, GLib

# Initialize GStreamer
Gst.init(None)

def main():

    # File to save timestamps
    output_file = open("timestamps.txt", "w")

    def on_handoff(fakesink, buffer, pad, user_data):
        # Retrieve the timestamp from the buffer
        timestamp = buffer.pts
        # Convert to nanoseconds and write to file
        output_file.write(f"{timestamp}\n")

    # Create GStreamer elements
    aravissrc = Gst.ElementFactory.make("aravissrc", "source")
    aravissrc.set_property("exposure", 1700)
    aravissrc.set_property("do-timestamp", True)
    aravissrc.set_property("set-trigger", True) 

    bayer_caps = Gst.Caps.from_string("video/x-bayer,format=rggb,width=800,height=600")
    bayer2rgb = Gst.ElementFactory.make("bayer2rgb", "bayer2rgb")

    videoconvert = Gst.ElementFactory.make("videoconvert", "videoconvert")
    
    fakesink = Gst.ElementFactory.make("fakesink", "fakesink")
    fakesink.set_property("signal-handoffs", True)

    # Create a new pipeline
    pipeline = Gst.Pipeline.new("mypipeline")

    # Add elements to the pipeline
    pipeline.add(aravissrc)
    pipeline.add(bayer2rgb)
    pipeline.add(videoconvert)
    pipeline.add(fakesink)

    # Link the elements with the capsfilter in between
    aravissrc.link_filtered(bayer2rgb, bayer_caps)
    bayer2rgb.link(videoconvert)
    videoconvert.link(fakesink)

    # Connect the handoff signal to the callback function
    fakesink.connect("handoff", on_handoff, None)

    # Function to trigger the camera
    def trigger_camera():
        while True:
            time.sleep(0.002)  # Sleep for 2 milliseconds (500fps)
            aravissrc.emit("software-trigger")

    # Create and start the trigger thread
    trigger_thread = threading.Thread(target=trigger_camera)
    trigger_thread.daemon = True  # Daemonize thread so it exits when the main program does
    trigger_thread.start()

    # Start the pipeline
    pipeline.set_state(Gst.State.PLAYING)

    # Run the pipeline
    loop = GLib.MainLoop()
    try:
        loop.run()
    except KeyboardInterrupt:
        pass

    # Clean up
    pipeline.set_state(Gst.State.NULL)
    output_file.close()

if __name__ == "__main__":
    main()

Result

Figure_1

@WhaSukGO WhaSukGO changed the title gst: set_trigger & software_trigger added for aravissrc gst: set_trigger & software_trigger added for aravissrc Sep 2, 2024
Copy link
Contributor

@EmmanuelP EmmanuelP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your pull request.

It would be better to make the trigger property take a string, which would also allow to change the trigger source to all available values.

gst/gstaravis.c Outdated Show resolved Hide resolved
gst/gstaravis.c Outdated
@@ -1111,6 +1137,19 @@ gst_aravis_class_init (GstAravisClass * klass)
GST_TYPE_ARV_USB_MODE, ARV_UV_USB_MODE_DEFAULT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property
(gobject_class, PROP_SET_TRIGGER,
g_param_spec_boolean("set-trigger",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/set-trigger/trigger/

string property

gst/gstaravis.c Outdated
@@ -417,6 +427,12 @@ gst_aravis_set_caps (GstBaseSrc *src, GstCaps *caps)
return result;
}

static void
gst_aravis_trigger (GstAravis *src) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/gst_aravis_trigger/gst_aravis_software_trigger/

gst/gstaravis.c Outdated
gst_aravis_signals[SIGNAL_SOFTWARE_TRIGGER] =
g_signal_new ("software-trigger", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstAravisClass,
trigger), NULL, NULL, NULL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/trigger/software_trigger/

gst/gstaravis.c Outdated
@@ -1131,6 +1170,8 @@ gst_aravis_class_init (GstAravisClass * klass)
gstbasesrc_class->get_times = GST_DEBUG_FUNCPTR (gst_aravis_get_times);

gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_aravis_create);

klass->trigger = gst_aravis_trigger;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/trigger/software_trigger/

@WhaSukGO
Copy link
Contributor Author

WhaSukGO commented Sep 3, 2024

@EmmanuelP Appreciate your feedback! I'll get them by today 👍

@EmmanuelP
Copy link
Contributor

Thanks.

I have pushed your patch with some tweaks making it actually use the software trigger.

@EmmanuelP EmmanuelP closed this Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants