Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Collapse
Brand Logo

ModalAI Forum

  1. ModalAI Support Forum
  2. FAQs
  3. Libmodal Pipe voxl-tflite-server aI_detection helper

Libmodal Pipe voxl-tflite-server aI_detection helper

Scheduled Pinned Locked Moved FAQs
5 Posts 2 Posters 953 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Philemon BennerP Offline
    Philemon BennerP Offline
    Philemon Benner
    Regular
    wrote on last edited by
    #1

    Hey,
    i'm trying to get the ai_detection_t published by voxl-flite-server, decoded in a libmodal pipe that is subscribing to the tflite_data pipe. I had a look at the examples from libmodal pipe and pipe_client_set_camera_helper_cb() from libmodal pipe.But i don't really understand how get the buffer to put it's contents into a ai_detection_t object. My attempt was the following:
    Init:

    int ch = pipe_client_get_next_available_channel();
    pipe_client_set_simple_helper_cb(ch, callback, 0);
    flag = CLIENT_FLAG_EN_SIMPLE_HELPER;
    pipe_client_open(ch,"tflite_data", "tflite_data-client", 
    CLIENT_FLAG_EN_SIMPLE_HELPER, sizeof(ai_detection_t))
    

    callback:

    void callback(__attribute__((unused)) int ch, char* data, int bytes, void* context)
    {
        ai_detection_t detection;
        int bytes_read = read(bytes,(char*)&detection,sizeof(ai_detection_t));
        spdlog::info("Bytes Read: {}",bytes_read);
    }
    

    It's working but bytes read is always -1. Unforunately i'm not really familiar with buffers and how they work.Help would be appreciated.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi,

      When you enable the simple helper you don't need to perform the reads yourself, the helper will read data from the pipe and pass it to the callback via the data pointer (the bytes field is the number of bytes the helper read). Also, while your operations in that callback will generally finish before a new detection arrives, we strongly recommend having the buffer for the pipe be larger than just 1 of the thing you're trying to deal with in case something gets backed up. We generally say to have an integer multiple of whatever you're trying to process i.e. 16*sizeof(ai_detection_t)

      1 Reply Last reply
      0
      • Philemon BennerP Offline
        Philemon BennerP Offline
        Philemon Benner
        Regular
        wrote on last edited by
        #3

        @Alex-Gardner Thanks for the answer. Is there a better way of putting the data into the ai_detection_t object?

        void detection_handler(int ch, char* data, int bytes, void* context)
        {
            ai_detection_t detection;
            memcpy(&detection, data, bytes);
        }
        
        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          When using the simple helper we usually just work with pointers and use the memory where it is:

          void detection_handler(int ch, char* data, int bytes, void* context)
          {
              ai_detection_t* detections = (ai_detection_t*) data;
          }
          

          Which would also let you dereference multiple if you know that there've been more than one:

          void detection_handler(int ch, char* data, int bytes, void* context)
          {
              num_detections = bytes/sizeof(ai_detection_t);
              ai_detection_t* detections = (ai_detection_t*) data;
          
              for (int i = 0; i < num_detections; i++) {
                  detections[i]. //Your code here
              }
          }
          

          If you're heart set on copying it into stack memory, you can just do that with

          void detection_handler(int ch, char* data, int bytes, void* context)
          {
              ai_detection_t detection = *((ai_detection_t*) data);
          }
          
          1 Reply Last reply
          0
          • Philemon BennerP Offline
            Philemon BennerP Offline
            Philemon Benner
            Regular
            wrote on last edited by
            #5

            Thank you for the Answer

            1 Reply Last reply
            0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            ModalAI
            Categories Recent Tags ModalAI.com Docs
            © 2026 ModalAI® · Accelerating autonomy for smaller, smarter, safer drones · Powered by NodeBB
            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups