Hi Janardhan,

As you can see, the current sensor driver framework and uORB are tightly
integrated.

The reason why I introduced the uORB framework from px4 to NuttX is
primarily because it is based on pub-sub,which provides great flexibility
in sharing messages between multiple applications.
Therefore, I recommend using uORB to operate sensors, but the prerequisite
is that the sensor driver must be implemented according to sensor_ops, for
instance, in nuttx/drivers/sensors/bmi160_uorb.c.

Currently, you are directly operating the sensor through a character
device, which might have some issues. I suspect the main reason could be an
incorrect flag when calling the open function or a mismatch between the len
passed to the read function and the sensor size. Of course, there could be
other reasons as well.
You can refer to uORB's unit tests or uorb_listener tool to operate a
specific sensor topic.
Additionally, you can refer to the following code snippet for reference:

  struct sensor_accel accel_data;
  struct pollfd fds;
  int fd;
  int ret;
  int i;

  fd = orb_subscribe_multi(ORB_ID(sensor_accel_uncal), 0);

  fds.fd = fd;
  fds.events = POLLIN;

  while(1)
    {
      if (poll(&fds, 1, ACC_TIMEOUT) > 0)
        {
          if (fds.revents & POLLIN)
            {
              ret = orb_copy(meta, fd, &accel_data);

#ifdef CONFIG_DEBUG_UORB
              if (ret == OK && meta->o_cb != NULL)
                {
                  meta->o_cb(ORB_ID(sensor_accel_uncal), &accel_data);
                }
#endif
            }
        }
      else if (errno != EINTR)
        {
          snerr("Waited for %d milliseconds without a message. "
                        "Giving up. err:%d", ACC_TIMEOUT, errno);
          break;
        }
    }

  orb_unsubscribe(fd);

BR,

Donny

Alan C. Assis <acas...@gmail.com> 于2024年6月12日周三 21:37写道:

> Hi Janardhan,
>
> uORB is used for example in the NuttX sensors subsystem and also please
> take a look at apps/system/uorb
>
> BR,
>
> Alan
>
> On Wed, Jun 12, 2024 at 10:17 AM Janardhan Silwal <
> janardhansil...@outlook.com> wrote:
>
> > Hi community,
> >
> > I have trying to get a inter-task message exchange, a sub/pub to work on
> > my board.
> >
> > Being specific I would like to get uORB, the one used in PX4 on nuttx. I
> > could find much of usable example of that combing through.
> >
> > I was wondering if any of you have implemented uORB on nuttx or something
> > similar. It would be great help if you share a linknor something that I
> > could refer to and get working on my code.
> >
> > Thank you.
> >
> > Best regards,
> > Janardhan
> >
> >
>

Reply via email to