0
$\begingroup$

Rosanswers logo

I am using a Raspberry pi 2 with ubuntu 14.04 and ros Indigo installed. I want to make a robot which would make a map of the surroundings and then autonomously navigate in it. I have sonars and no other sensors. So my question is how can write the GPIO code in ROS node thats going to publish and populate my range/sensor.msg so that my Raspberry Pi can communicate with the sonars?

It would also be help full if you can take a look at this question and see if you can help. http://answers.ros.org/question/231269/can-i-rely-on-the-navigation-tutorials-when-working-with-sonar/

Thanks & Regards, Mukut


Originally posted by mukut_noob on ROS Answers with karma: 35 on 2016-04-25

Post score: 0


Original comments

Comment by JohnDoe2991 on 2016-04-25:
It depends on your sonar sensors. What kind of output signal do they have? Analog signal, SPI, I2C, USB? A good starting point would be wiringPi if you want to use the GPIO

Comment by mukut_noob on 2016-04-25:
Thanks john for your fast reply! I am using a HC-SR04. It works fine with the digital pins of my Raspberry pi. So I think it's digital.

Comment by JohnDoe2991 on 2016-04-25:
Yes, it is a digital signal, where you can measure the time and calculate the distance to the object. A short google search also found this Pi driver. But either with this driver or wiringPi, you have tow write the node yourself.

Comment by mukut_noob on 2016-04-25:
Okay, so all I have to do is to include this driver in the node right? Also can you take a look at my other question?

Comment by JohnDoe2991 on 2016-04-26:
You need to compile and load the driver first. It is documented on the github page. I cannot answer your second question, I don't know anything about mapping.

Comment by mukut_noob on 2016-04-26:
So it can also be written in python? It would be the same? And in that case I need not need any external GPIO library like the wiring Pi because it has its own library, RPi.GPIO. Is it possible?

Comment by JohnDoe2991 on 2016-04-27:
It should be possible. I haven't used RPi.GPIO yet, but after a short google search I found that it also supports interrupts (described here). In theory it will work, but I don't know how precise it will be.

Comment by mukut_noob on 2016-04-27:
okay. So its better with wiringpi.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Summary of the comments: To use the Pi's GPIO in ROS, you have to use a third party library, for example wiringPi (C++) or RPi.GPIO (Python). Both examples support interrupts (examples: wiringPi, RPi.GPIO), which you need to measure the time the sound signal of your HC-SR04 needs to travel to an object and back to the sensor.

Alternatively, there's a driver for the Raspberry Pi and the HC-SR04 here (Github). I have never used this driver, so I cannot say if it works or not.

Also think about the fact, that the default Raspbian is not a realtime operating system. The measured times are not consistent and may vary depending on the Pi's CPU load. You should test the variation in your system before trusting any measurements.


Originally posted by JohnDoe2991 with karma: 305 on 2016-04-27

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by mukut_noob on 2016-04-27:
Yes I have tested it and I am using Ubuntu 14.04 on my Pi. And I will be use either wiringpi or RPi.GPIO. I think it would be more precise.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.