Sonar
Follow along: Sonar Sensor Operation Example
The program launching process along with parameter settings are all simplified and set up on the Jupyter Notebook Environment.
- Open the 02_sonar.ipynb Jupyter Notebook
- Import the necessary python libraries and modules
- Follow and Execute the example codes
(The Jetson Board used for these examples are => Jetson Nano)
Open the following jupyter notebook:
02_sonar.ipynb
To run the cells within the notebook use Ctrl + Enter
Import the necessary python libraries and modules
import rospy
from std_msgs.msg import Float32MultiArray
Create zetabot Node
sonar Topic Subscribe
Check message in data array format
def process_sonar(msg):
rospy.loginfo("data[0]: {},data[1]: {},data[2]: {},data[3]: {}".format(msg.data[0], msg.data[1], msg.data[2], msg.data[3]))
def start_node():
rospy.init_node('zetabot')
rospy.Subscriber("sonar", Float32MultiArray, process_sonar)
rospy.spin()
try:
start_node()
except rospy.ROSInterruptException as err:
print(err)
Create zetabot Node
sonar Topic Subscribe
Check the message according to the direction
def process_sonar(msg):
rospy.loginfo("Front: {}, Right: {}, Back: {}, Left: {}".format(msg.data[0], msg.data[1], msg.data[2], msg.data[3]))
def start_node():
rospy.init_node('zetabot')
rospy.Subscriber("sonar", Float32MultiArray, process_sonar)
rospy.spin()
try:
start_node()
except rospy.ROSInterruptException as err:
print(err)