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