ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

rviz Fixed frame error No TF Data

asked 2021-06-09 05:13:18 -0500

Fxaxo gravatar image

updated 2021-06-09 12:58:06 -0500

i tried to visualize a UM7 Sensor from Redshift Labs ! with rotopic list i receive my /imu/data ! with rostopic echo i receive all my needed Data ( the Orientation of the Sensor ) and i can include the /imu/data in rviz IMU and can see that Messages receivin ! i can also include the Fabio_TF in the fixed Frame but when i try to start it i wont receive any Data in the rviz Window and there is the Error No TF Data marked in yellow!

this is my Publisher Node;

#!/usr/bin/env python3

import rospy                    # Library to use Python
import numpy as np
from geometry_msgs.msg import Point, Pose, Quaternion
from sensor_msgs.msg import Imu
from std_msgs.msg import Float32, Header    # Library to use IMU
from um7py import UM7Serial

############################################### Name of the Imu ######
imuData_pub = rospy.Publisher("/imu/data", Imu, queue_size=10)

############################################### Tranformation from Euler to Quat ######
def euler_to_quat(yaw, pitch, roll):
    q0 = np.sin(roll/2) * np.cos(pitch/2) * np.cos(yaw/2) - np.cos(roll/2) * np.sin(pitch/2) * np.sin(yaw/2)
    q1 = np.cos(roll/2) * np.sin(pitch/2) * np.cos(yaw/2) + np.sin(roll/2) * np.cos(pitch/2) * np.sin(yaw/2)
    q2 = np.cos(roll/2) * np.cos(pitch/2) * np.sin(yaw/2) - np.sin(roll/2) * np.sin(pitch/2) * np.cos(yaw/2)
    q3 = np.cos(roll/2) * np.cos(pitch/2) * np.cos(yaw/2) + np.sin(roll/2) * np.sin(pitch/2) * np.sin(yaw/2)
    return [q0, q1, q2, q3]

############################################## Read the Sensor
def read_um7():
    um7_serial = UM7Serial(port_name='/dev/ttyUSB0')

    for packet in um7_serial.recv_broadcast(num_packets = 1000):

        yaw = packet.yaw
        roll = packet.roll
        pitch = packet.pitch

        w1 = packet.roll_rate
        w2 = packet.pitch_rate
        w3 = packet.yaw_rate

############################################ Formula to change the Euler to Quaternion
        q0 = np.sin(roll/2) * np.cos(pitch/2) * np.cos(yaw/2) - np.cos(roll/2) * np.sin(pitch/2) * np.sin(yaw/2)
        q1 = np.cos(roll/2) * np.sin(pitch/2) * np.cos(yaw/2) + np.sin(roll/2) * np.cos(pitch/2) * np.sin(yaw/2)
        q2 = np.cos(roll/2) * np.cos(pitch/2) * np.sin(yaw/2) - np.sin(roll/2) * np.sin(pitch/2) * np.cos(yaw/2)
        q3 = np.cos(roll/2) * np.cos(pitch/2) * np.cos(yaw/2) + np.sin(roll/2) * np.sin(pitch/2) * np.sin(yaw/2)

############################################ Start Header Msgs
        Fabio_Imu.header.seq = 0            # Growing Var   
        Fabio_Imu.header.stamp = rospy.Time.now()   # Timestamp
        Fabio_Imu.header.frame_id = "Fabio_TF"  # Name of Frame

        Fabio_Imu.orientation.x = q0            # Quat Data in orient. Lib
        Fabio_Imu.orientation.y = q1
        Fabio_Imu.orientation.z = q2
        Fabio_Imu.orientation.w = q3

        #Fabio_Imu.angular_velocity.x = Quaternion[0]
        #Fabio_Imu.angular_velocity.y = Quaternion[0]
        #Fabio_Imu.angular_velocity.z = Quaternion[0]

        #Fabio_Imu.linear_acceleration.x = Quaternion[0]
        #Fabio_Imu.linear_acceleration.y = Quaternion[0]
        #Fabio_Imu.linear_acceleration.z = Quaternion[0]

        imuData_pub.publish(Fabio_Imu)      # Publish the Node

########################################################
############################## Main ####################
########################################################

if __name__ == '__main__':
    rospy.loginfo('UM7_Sensor started')         # just print command
    rospy.init_node('test_1_IMU')               # Name of Init_Node
    Fabio_Imu = Imu()
    while not ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-06-09 22:50:17 -0500

janindu gravatar image

This is because you are not publishing a frame to the tf tree. Add the following lines to your code and you should be able to visualize it on fixed frame world.

At the top, add :

import tf2_ros
import geometry_msgs.msg

After

imuData_pub.publish(Fabio_Imu)      # Publish the Node

Add the following

br = tf2_ros.TransformBroadcaster()
t = geometry_msgs.msg.TransformStamped()

t.header.stamp = Fabio_Imu.header.stamp
t.header.frame_id = "world"
t.child_frame_id = "Fabio_TF"

t.transform.translation.x = 0.0
t.transform.translation.y = 0.0
t.transform.translation.z = 0.0

t.transform.rotation = Fabio_Imu.orientation
br.sendTransform(t)
edit flag offensive delete link more

Comments

it worked !!! Thank you very much !!

Fxaxo gravatar image Fxaxo  ( 2021-06-10 03:22:34 -0500 )edit

Question Tools

Stats

Asked: 2021-06-09 05:13:18 -0500

Seen: 2,059 times

Last updated: Jun 09 '21