Ask Your Question
0

Is possible to use mutex in two different nodes?

asked 2019-01-19 12:03:09 -0500

joelsonmiller gravatar image

updated 2019-01-19 12:09:21 -0500

Hi, everyone! I'm using the motor drive md25 in raspberry pi with i2c communication. Now I need to add a Ultrasonic sensor that works with i2c too. The sensor and the motor drive work on different ROS nodes. How can I avoid crashing the i2c communication? Can i use mutex in different nodes? Does ROS provide tools to avoid this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-01-19 12:15:14 -0500

ahendrix gravatar image

ROS doesn't provide any mutex classes; those are provided by the Python standard library, the C++ standard library (in C++11 and newer), or pthreads, boost, or another threading library. (For example, boost has https://www.boost.org/doc/libs/1_67_0... ).

I have written and used mutexes across processes like this as part of my day job, and it took me about a week to build a well-tested, inter-process mutex using the available primitives from posix and pthreads. It is _possible_, but it's a lot of work and NOT a beginner project.

Instead, all of the ROS nodes that I've seen that need to do this write a single node that handles the mutexing internally, and publishes and subscribes to multiple topics. If you have two devices on the same I2C bus, you should write (or combine) the ROS nodes into a single node.

edit flag offensive delete link more

Comments

I'm surely a beginner. hahaha Thanks for your answer. ;)

joelsonmiller gravatar image joelsonmiller  ( 2019-01-19 12:22:04 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-01-19 12:03:09 -0500

Seen: 222 times

Last updated: Jan 19 '19