Publish and Subscribe to TD data - Lesson 3

@staff
I think there is something wrong with the code “multiple_broadcaster.py” which is in class 3 - Publish and Transform to TF data". I tried to run the code in exercise 2.1, unsuccessfully . I also runned the original code from ~/turtle_tf_3d/exercises_scritps: The “turtle_broadcaster_test.py”. However I am facing the following error:

user:~/catkin_ws$ rosrun transform turtle_broadcaster.py
[INFO] [1576513195.348095, 0.000000]: Retrieveing Model indexes
[INFO] [1576513195.435272, 360.124000]: Final robots_index_dict = {‘turtle1’: 3, ‘turtle2’: 2}
[INFO] [1576513195.487578, 360.156000]: Error, The _robots_models_dict is not ready = ‘turtle1’
[INFO] [1576513195.488370, 360.156000]: Error, The _robots_models_dict is not ready = ‘turtle2’
[INFO] [1576513196.489284, 360.752000]: Ready…Starting to Publish TF data now…

I have already changed the name of the “robot_name” in line 14 before “/world” argument to turtle1
and did not work. I also searched in roswiki an example and tried to use the following line which they put below the if__name__ = 'main’: block:
turtlename = rosy.get_param(’~turtle’)

Well Could you help me to solve this please?

thanks

Hi :slight_smile:
make sure you are have launched the simulations. If I remember correctly you have to launch the two simulations first in two different Terminals, and then in a 3rd run the broadcaster

Hi @simon.steinmann91 @staff thanks for the reply​:smiley:. About the issue I don’t think it is necessary to launch the simulations in 2 different terminals before executing the python script. The head of the exercise 2.1 asks to stop all kind of launch which could be running, and then run the python script which will broadcast the turtles Tf regarding the world , and so later launch the listener. So what previous simulations launchs were you referring about? Because the gazebo models (turtle icleaner and can) are already in the Gazebo screen, so spawn the urdf through a launch file is not necessary in this case I imagine.
I am not too good in programming, unfortunately, but I think that maybe it is missing to define or get_param to the robot_model. In case assign turtle1 and turtle2 to robot_model ( I don’t know how to do this in this script context.) ?? Because the error is in the block that robot_model is used within range in robot_name_list. Well I am not sure unfortunately how I can repair this error, and I really tried it, to keep advancing in classes, but in this moment I am stuck here, :confused::

Hi,

So could you indicate exactly the unit and the commands you are using to reproduce the error?

rosrun transform turtle_broadcaster.py

Transform is not a package done in the course. Could you share the python file you are executing?

Just to have the ideas clear on what the exact issue you have is.

yes @duckfrost @staff I am studying the ROS Beginners module - The “TF in ROS” - The class 3: “Publish & Subscribe to TF data.”
In this moment I am doing the exercise 2.1 which is described below:

In this exercise, you are going to create your first TF publisher to publish the position and orientation of both turtle1 and turtle2.

1.- First step: Stop any launch you had from previous exercises. For example, the roslaunch turtle_tf_3d irobot_follow_turtle.launch .

2.- Create a new ROS package that has rospy and turtle_tf_3d as dependencies.

3.- Create a python script that contains the code introduced above (Python Program {U2.1.1.py}).

4.- Execute your Python script:

Execute in WebShell #1

rosrun your_package your_tf_broadcaster.py

5.-Now, launch the following, which activates the TF topic listener in another WebShell. Then, based on the TF of both turtle1 and turtle2, this listener will calculate the direction and speed necessary to make the iRobot follow the turtle.

Execute in WebShell #2

roslaunch turtle_tf_3d run_turtle_tf_listener.launch

6.- Check that everything is working as it should with the tf_echo, rqt_tf_tree, and RVIZ tools

So, I have created the package Transform, with the command “catkin_create_pkg transform rospy turtle_tf_3d”
And inside this pkg I have created the script directory and inside it I have created the python script named “turtle_broadcaster.py”. The code inside turtle broadcaster is exactly the same code of “multiple_broadcaster.py” given in the beginning of the class.

#! /usr/bin/env python
import rospy
import time
import tf
from turtle_tf_3d.get_model_gazebo_pose import GazeboModel

def handle_turtle_pose(pose_msg, robot_name):
br = tf.TransformBroadcaster()

br.sendTransform((pose_msg.position.x,pose_msg.position.y,pose_msg.position.z),
                 (pose_msg.orientation.x,pose_msg.orientation.y,pose_msg.orientation.z,pose_msg.orientation.w),
                 rospy.Time.now(),
                 robot_name,
                 "/world")

def publisher_of_tf():

rospy.init_node('publisher_of_tf_node', anonymous=True)
robot_name_list = ["turtle1","turtle2"]
gazebo_model_object = GazeboModel(robot_name_list)


for robot_name in robot_name_list:
    pose_now = gazebo_model_object.get_model_pose(robot_name)

# Leave enough time to be sure the Gazebo Model logs have finished
time.sleep(1)
rospy.loginfo("Ready..Starting to Publish TF data now...")

rate = rospy.Rate(5) # 5hz
while not rospy.is_shutdown():
    for robot_name in robot_name_list:
        pose_now = gazebo_model_object.get_model_pose(robot_name)
        if not pose_now:
            print "The " + str(robot_name) + "'s Pose is not yet available...Please try again later"
        else:
            handle_turtle_pose(pose_now, robot_name)
    rate.sleep()

if name == ‘main’:
try:
publisher_of_tf()
except rospy.ROSInterruptException:
pass

So this is the code which did not work…
How can I share my code in a more organized way? I have seen that some guys did this in other posts…thanks

Well @staff I am sorry. The fact is that this message was not an ERROR, as I thought. It was just a warning “hidden” inside some function used in the script. I thought that was an error because I did not see in anywhere the script this warning message written…so when it appeared:
[INFO] [1576513195.487578, 360.156000]: Error, The _robots_models_dict is not ready = ‘turtle1’
[INFO] [1576513195.488370, 360.156000]: Error, The _robots_models_dict is not ready = ‘turtle2’

I thought that was an error and I didn’t kept with the listener to see that things would work…