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

Ho to publish a transform between base_link and map

asked 2020-04-13 01:57:13 -0500

yanaing gravatar image

updated 2020-04-13 02:04:47 -0500

Hi, I am trying to move a robot through the map in the RVIZ. I have a robot URDF file and also a map. Is it possible to publish a transform between robot base link and map?

By assuming that it is possible, I am trying to is that,

  <launch>
    <arg name="model" default="$(find robot_description)/urdf/description.urdf"/>
    <arg name="gui" default="true" />
    <arg name="rvizconfig" default="$(find urdf_tutorial)/rviz/urdf.rviz" />

    <param name="use_sim_time" value="false"/>
    <param name="robot_description" command="$(find xacro)/xacro $(arg model)" />
    <param name="use_gui" value="$(arg gui)" />

    <node pkg="map_server" type="map_server" name="map_server" args="$(find lidar_simulation)/map/z_map_canteen_28_03_test1.yaml">
      <param name="frame_id" value="map" />
    </node>

    <node pkg="tf" type="static_transform_publisher" name="base_map" args="0 0 0 0 0 0 /odom /map 100" />
    <node pkg="tf" type="static_transform_publisher" name="base_link_odom" args="0 0 0 1.571 0 0 /map /base_link 100" />

    <node if="$(arg gui)" name="joint_state_publisher" pkg="joint_state_publisher_gui" type="joint_state_publisher_gui" />
    <node unless="$(arg gui)" name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />

    <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" />
    <node name="rviz" pkg="rviz" type="rviz" args="-d $(arg rvizconfig)" required="true" />

  </launch>

The above is the launch file. When I launch it, the RVIZ opens and can also visualize the robot and the map. example

To move the robot along with the map, I use topic_tools/transform package and publishing the topic with the following commands.

rosrun topic_tools transform /tf /tf tf2_msgs/TFMessage '[std_msgs.msgeader(0, rospy.Time.now(), "/map"), "/base_link", geometry_msgs.msg.Transform(geometry_msgs.msg.Vector3(1,1,0), geometry_msgs.msg.Quaternion(1.571,0,0,1))]' --import rospy std_msgs geometry_msgs

rosrun topic_tools transform /tf /tf tf2_msgs/TFMessage 'geometry_msgs.msg.TransformStamped [std_msgs.msg.Header(0, rospy.Time.now(), "/map"), "/base_link", geometry_msgs.msg.Transform(geometry_msgs.msg.Vector3(1,1,0), geometry_msgs.msg.Quaternion(1.571,0,0,1))]' --import rospy std_msgs geometry_msgs

Since, the /tf topic uses tf2_msgs/TFMessage and, the rosmsg types and details

But this not working by showing the error TypeError: Invalid number of arguments, args should be ['transforms'] args are( ) . Is there any way to move the robot along with the map or also do my currently trying ways correct?

Thanks for your attention.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-04-13 07:45:03 -0500

bob-ROS gravatar image

See this tutorial in c++ or python:

http://wiki.ros.org/tf2/Tutorials/Writing%20a%20tf2%20broadcaster%20%28C%2B%2B%29#How_to_broadcast_transforms

http://wiki.ros.org/tf2/Tutorials/Writing%20a%20tf2%20broadcaster%20%28Python%29

Rewrite the subscriber to a Timer based callback that takes e.g pose.x = pose.x + 0.1 per time iteration (or reading from a file etc) to move it.

You could otherwise manually in the terminal publish the transformation step by step by using:

rosrun tf2_ros static_transform_publisher 1 0 0 0 0 0 map base_link

Depends on what you are trying to do.

edit flag offensive delete link more

Comments

It works. But the node I have used it tf and therefor I used rosrun tf static_transform_publisher 1 1 0 1.571 0 0 map base_link 5000 and it worked, but it frequently changed to its original location and transform location. Thanks for your help.

yanaing gravatar image yanaing  ( 2020-04-13 08:18:38 -0500 )edit

Question Tools

3 followers

Stats

Asked: 2020-04-13 01:57:13 -0500

Seen: 4,592 times

Last updated: Apr 13 '20