Closed zbabqr closed 2 years ago
Hi,
Can you provide the code? Also which bag file may have issue?
Below is a short program to print out the data of messages on the the /uwb_endorange_info from the eee_01.bag
#!/usr/bin/python
import argparse
import sys
import os
import rospy
import rosbag
from uwb_driver.msg import UwbRange
from geometry_msgs.msg import TwistStamped
from geometry_msgs.msg import PoseStamped
from geometry_msgs.msg import PoseWithCovarianceStamped
# Some topics needs utf8 to decode
reload(sys)
sys.setdefaultencoding('utf8')
if __name__ == '__main__':
inbag = rosbag.Bag("/mnt/1FDD5C4564388F8F/DATASETS/NTU_VIRAL/eee_01/eee_01.bag",'r')
for topic, msg, t in inbag.read_messages():
if topic in ['/uwb_endorange_info']:
print "topic:", topic, " Stamp: ", msg.header.stamp.to_sec(), "Dis: ", msg.distance, "Panchor: ", msg.responder_location.x, msg.responder_location.y, msg.responder_location.z
You should see the print out like this
The following is my code:
import roslib import rosbag import rospy import cv2 from sensor_msgs.msg import Image from cv_bridge import CvBridge from cv_bridge import CvBridgeError
path='./eee_01/left/image_raw/' if name == 'main': bridge = CvBridge() with rosbag.Bag('./eee_01/eee_01.bag', 'r') as bag: for topic, msg, t in bag.read_messages("/left/image_raw"): try: cv_image = bridge.imgmsg_to_cv2(msg,"bgr8") except CvBridgeError as e: print(e) timeq = msg.header.stamp.to_sec() timestr = "{:.6f}".format(timeq) image_name = timestr + ".png"
cv2.imshow("cv_image", cv_image)
cv2.waitKey(1)
print(image_name)
with open("./eee_01/IMUData.txt", 'w') as IMU_file:
IMU_file.write("TimeStamps GyroscopeX GyroscopeY GyroscopeZ AccelerometerX AccelerometerY AccelerometerZ\n")
for topic, msg, t in bag.read_messages("/imu/imu"):
acc_x = "%.6f" % msg.linear_acceleration.x
acc_y = "%.6f" % msg.linear_acceleration.y
acc_z = "%.6f" % msg.linear_acceleration.z
w_y = "%.6f" % msg.angular_velocity.y
w_x = "%.6f" % msg.angular_velocity.x
w_z = "%.6f" % msg.angular_velocity.z
timeimu = "%.6f" % msg.header.stamp.to_sec()
imudata = timeimu + " " + w_x + " " + w_y + " " + w_z + " " + acc_x + " " + acc_y + " " + acc_z
IMU_file.write(imudata)
IMU_file.write('\n')
IMU_file.close()
for topic, msg, t in bag.read_messages("/uwb_endorange_info"):
timeUWB = "%.6f" % msg.header.stamp.to_sec()
requester_id = msg.requester_id
responder_id = msg.responder_id
uwbData = timeUWB + " " + str(requester_id) + " " + str(responder_id)
print(uwbData)
#UWB_file.write(uwbData)
#UWB_file.write('\n')
I use python 3.7
It looks like you're missing the import of the uwb message definition. Can you git clone the package https://github.com/ntu-aris/uwb_driver to the workspace, catkin make / build the workspace, add from uwb_driver.msg import UwbRange
to the beginning of python script, and try again?
Below is a short modification of your code to make it work. I am using python 3.6
import roslib
import rosbag
import rospy
import rosbag
from uwb_driver.msg import UwbRange # Install from https://github.com/ntu-aris/uwb_driver
bag = rosbag.Bag("/mnt/1FDD5C4564388F8F/DATASETS/NTU_VIRAL/eee_01/eee_01.bag",'r')
for topic, msg, t in bag.read_messages("/uwb_endorange_info"):
timeUWB = "%.6f" % msg.header.stamp.to_sec()
requester_id = msg.requester_id
responder_id = msg.responder_id
uwbData = timeUWB + " " + str(requester_id) + " " + str(responder_id)
print(uwbData)
hello, I want to parse the UWB data from the rosbag. However, when I use the topic name"/uwb_endorange_info", I get an error: (unicode error) 'utf-8' codec can't decode byte 0xa1 in position 1548: invalid start byte. Do I use the wrong topic name?