Ros ultrasonic sensor Rviz Error
I am trying to build a custom bot with a few different sensors publishing to nodes and using Rviz to visualize said nodes. I get this error in Rviz. Transform[sender=unknown_publisher] For frame[]:Fixed Frame [map] does not exist Now i am super new to Ros and Rviz so any guidance would be greatly appreciated.
here is the code
#!/usr/bin/env python3
# coding: latin-1
import RPi.GPIO as GPIO
import rospy
import time
import math
import numpy
import tf
from std_msgs.msg import Float64
from sensor_msgs.msg import Range, LaserScan
trigPin = 16
echoPin = 18
MAX_DISTANCE = 220 # define the maximum measuring distance, unit: cm
timeOut = MAX_DISTANCE*60 # calculate timeout according to the maximum measuring distance
range_msg = Range()
range_msg.radiation_type = 0
range_msg.field_of_view = 15
range_msg.min_range = 2
range_msg.max_range = 400
def pulseIn(pin,level,timeOut): # obtain pulse time of a pin under timeOut
t0 = time.time()
while(GPIO.input(pin) != level):
if((time.time() - t0) > timeOut*0.000001):
return 0;
t0 = time.time()
while(GPIO.input(pin) == level):
if((time.time() - t0) > timeOut*0.000001):
return 0;
pulseTime = (time.time() - t0)*1000000
return pulseTime
def getSonar(): # get the measurement results of ultrasonic module,with unit: cm
GPIO.output(trigPin,GPIO.HIGH) # make trigPin output 10us HIGH level
time.sleep(0.00001) # 10us
GPIO.output(trigPin,GPIO.LOW) # make trigPin output LOW level
pingTime = pulseIn(echoPin,GPIO.HIGH,timeOut) # read plus time of echoPin
distance = pingTime * 340.0 / 2.0 / 10000.0 # calculate distance with sound speed 340m/s
return distance
def setup():
GPIO.setmode(GPIO.BOARD) # use PHYSICAL GPIO Numbering
GPIO.setup(trigPin, GPIO.OUT) # set trigPin to OUTPUT mode
GPIO.setup(echoPin, GPIO.IN) # set echoPin to INPUT mode
def loop():
while(True):
distance = getSonar() # get distance
time.sleep(1)
if __name__ == '__main__': # Program entrance
print ('Program is starting...')
rospy.init_node('ultrasonic_trans')
pub = rospy.Publisher("/ultra", Range, queue_size=10)
rate = rospy.Rate(1)
setup()
while not rospy.is_shutdown():
range_msg.range = getSonar()
pub.publish(range_msg)
rate.sleep()
rospy.loginfo("Ultra Sonic Pub Closed")
Asked by matthewfwork on 2021-07-27 10:51:30 UTC
Comments
Please make sure you have read and understood the tf documentation. Also you are not setting any header on your range_ms (stamp, frame_id). Also please attach your tf tree, you can generate it with rqt_tf_tree
Asked by Humpelstilzchen on 2021-07-27 14:10:57 UTC