using System.Runtime.InteropServices; namespace RobotNet10.RobotApp.MarkerDetection; /// /// P/Invoke declarations for marker_detection C API /// public static class MarkerDetectionNativeInterface { // Library path - adjust if needed private const string LibraryPath = "/usr/local/lib/libmarker_detection.so"; #region Creation / Destruction /// /// Create a rectangle marker detection instance /// /// Marker options /// TF3 buffer core (pass IntPtr.Zero if not using TF) /// Handle to marker detection instance [DllImport(LibraryPath, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr marker_detection_create_rectangle_md( ref md_rectangle_marker_options_t options, IntPtr tfBuffer); /// /// Create a segment marker detection instance /// /// Marker options /// TF3 buffer core (pass IntPtr.Zero if not using TF) /// Handle to marker detection instance [DllImport(LibraryPath, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr marker_detection_create_segment_md( ref md_segment_marker_options_t options, IntPtr tfBuffer); /// /// Destroy a marker detection instance /// /// Handle to marker detection instance [DllImport(LibraryPath, CallingConvention = CallingConvention.Cdecl)] public static extern void marker_detection_destroy(IntPtr handle); #endregion #region Control /// /// Enable or disable marker detection /// /// Handle to marker detection instance /// 1 to enable, 0 to disable [DllImport(LibraryPath, CallingConvention = CallingConvention.Cdecl)] public static extern void marker_detection_set_enable_detection(IntPtr handle, int enable); /// /// Set estimated marker pose to improve stability /// /// Handle to marker detection instance /// Estimated 2D pose (x, y, theta) relative to laser scan sensor frame [DllImport(LibraryPath, CallingConvention = CallingConvention.Cdecl)] public static extern void marker_detection_set_estimate_marker_pose(IntPtr handle, ref md_pose2d_t pose); #endregion #region Sensor Data Dispatch /// /// Dispatch laser scan data to marker detection /// /// Handle to marker detection instance /// Sensor ID (null-terminated string) /// Pointer to laser scan struct [DllImport(LibraryPath, CallingConvention = CallingConvention.Cdecl)] public static extern void marker_detection_dispatch_laserscan( IntPtr handle, [MarshalAs(UnmanagedType.LPUTF8Str)] string sensorId, ref md_laserscan_t scan); #endregion #region Getters /// /// Get current marker pose estimate /// /// Handle to marker detection instance /// Pointer to pose_stamped (must be freed with marker_detection_free_pose_stamped) or IntPtr.Zero if no pose available [DllImport(LibraryPath, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr marker_detection_get_marker_pose(IntPtr handle); #endregion #region Memory Management /// /// Free pose_stamped allocated by marker_detection_get_marker_pose /// /// Pointer to pose_stamped to free [DllImport(LibraryPath, CallingConvention = CallingConvention.Cdecl)] public static extern void marker_detection_free_pose_stamped(IntPtr p); /// /// Free C string allocated by the API /// /// Pointer to C string to free [DllImport(LibraryPath, CallingConvention = CallingConvention.Cdecl)] public static extern void marker_detection_free_cstring(IntPtr s); #endregion }