ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROS Architecture - How to communicate between custom driver and ROS

asked 2015-05-04 11:01:37 -0500

aak2166 gravatar image

Hi all,

I am interested in reading incremental encoder counts from the GPIO on an IFC6410. I am not entirely sure how to run this cleanly on the ROS architecture, I will have monitor an interrupt on that pin with an external c program similar to this.

I will have to have my glib code update some kind of system variable, then read that in my external python or C++ class. Since environment variables can only hold strings, is there a clean way of doing this? Many thanks.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-05-04 11:20:45 -0500

gvdhoorn gravatar image

updated 2015-05-04 11:28:05 -0500

In my opinion, the cleanest way would probably be:

  • write a Linux kernel driver for monitoring the IRQ and keeping track of the encoder count. It could also do quadrature decoding for you if your encoder requires that
  • have the driver expose a (char) device that can be interacted with through appropriate IOCTLs
  • write a C++/Python/Whatever library that interacts with the (char) device and provides things like init(), reset(), read_count(), etc
  • write a ROS node that uses that library to periodically read out the encoder count, and publish it as a message.

Depending on your architecture, the ROS node could either publish raw encoder counts, or already attach some semantics to it by converting to an angle fi (which would require knowledge of the attached encoder, something which might not be appropriate at that level of abstraction).

Note that periodically does not necessarily mean that you'd use ros::Rate instances to regulate the polling cycle. The Linux Device Driver book has a section on Blocking IO that explains how a user space process may wait for an event in kernel space.

An alternative to a kernel driver could be the Linux user space GPIO interfaces (through sysfs or something similar) or whatever your particular board supports. But most user space interfaces incur some kind of overhead / latency, which a kernel driver would not have. The article you linked shows one possible way using sysfs and glib2, it also shows how to deal with interrupts; this could be sufficient, but that is something only you can decide based on your requirements. Integration a glib event processor with ROS has been done before, and should not pose too many problems.


Since environment variables can only hold strings [..]

Could you explain why you think you'd need to use environment variables for any of this?

edit flag offensive delete link more

Comments

Don't think I would need an environment variable per se, that was just the first thing that came to mind as a "system wide" mechanism for holding information. Thank you for your very comprehensive response!

aak2166 gravatar image aak2166  ( 2015-05-04 11:58:28 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2015-05-04 11:01:37 -0500

Seen: 319 times

Last updated: May 04 '15