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

How do you make an /odom node for a physical robot in ros2?(rviz not showing updated /base_link)

asked 2021-06-10 16:25:45 -0600

rydb gravatar image

updated 2021-06-29 17:01:10 -0600

EDIT: deleting previous contents of post because ive made some progress on this and my problems are more specific now.

EDIT2: Odom publishes! rviz doesn't show updates though. I fixed my previous problem and put its answer in my response to 404robotnotfound, basically, createQuaternionMsgFromYaw() doesnt exist in ros2, but getting a rotational quaternion from SciPy from_eulur() does.

EDIT3: rviz now displays the odometry node! I just needed to set /odom as the the global fixed_frame and now /base_link is gradually moving away from /odom. I'll finish tying navigation2 to the /odom movement and post that and previous problems in the answer.

I'm trying to ROS2ify the ros1 odom node here but the new problem i've run into is that rviz2 isn't showing the updated /base_link that its subscribed to via /odom.

I've confirmed /base_link is updating with "ros2 topic echo odom", so I think its something with how I'm publishing my nodes?

image description

image description

edit retag flag offensive close merge delete

Comments

I understand your problem is being solved, but it would probably be good to leave your questions you had before the edits up there instead of removing them, so anyone who has the same problem can better understand what you were asking and hopefully benefit from the answers as well.

404RobotNotFound gravatar image 404RobotNotFound  ( 2021-06-29 16:07:03 -0600 )edit

This problem is a mix of multiple problems and having the old problems that have been solved in the question would be visual clutter, I'm thinking of posting an answer to the main question and addressing each of the problems I ran into in process of answering the main question in the answer.

rydb gravatar image rydb  ( 2021-06-29 16:55:14 -0600 )edit

@rydb: @404RobotNotFound is actually correct: it would be better to not delete contents from questions, as it makes the chronology of the Q&A really difficult to figure out.

If you'd like the most "recent state of affairs" to be the one that's the most visible, place later edits at the top. So instead of original - edit1 - edit2 - ..., do edit2 - edit1 - original.

gvdhoorn gravatar image gvdhoorn  ( 2021-06-30 02:37:49 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2021-06-26 07:25:09 -0600

404RobotNotFound gravatar image

updated 2021-06-29 16:04:54 -0600

The issue seems to be from the error of an invalid quaternion. Looking at the odom message that you are publishing, the quaternion values are [0,0,0,0] which is invalid. By default, it should at least be zero rotation which is [0,0,0,1].

While in ROS 2, tf::createQuaternionMsgFromYaw() does not exist, you can make a tf2::Quaternion tf2_quat and then use tf2_quat.setRPY(0.0, 0.0, th).

From there, you can use the tf2_geometry_msgs package to convert from a tf2::Quaternion to a geometry_msgs::Quaternion for the messages you are publishing.

Update after Edit 2:

How are you trying to visualize the odometry in rviz? I assume you are subscribing to an nav_msgs/Odometry message type to do that. Or are you just trying to use tf2 to handle all of the transforms and visualizations, so you might just be visualizing an axis that follows the base_link frame.

Based on your information "confirmed /base_link is updating with "ros2 topic echo odom"", then I assume it is an odometry message you are trying to visualize.

Steps on how to visualize an Odometry in rviz:

  1. Make sure you use rviz to subscribe to an nav_msgs/Odometry message. This is easy to add if you try to add by topic and select the right one.
  2. Probably make sure your global_frame_id in rviz is probably something like odom

However, looking at your node graph it seems the info is only published in TF.

In that case, you can just add the tf visualization in rviz, or add an Axes and set its frame to base_link while having the global frame in odom

edit flag offensive delete link more

Comments

I forgot to tag that i'm using python to do this, python equivalents don't exist for these libraries, but I've found that scipy works as an alternative for createQuaternionMsgFromYaw(), and for potentially other conversions

from scipy.spatial.transform import Rotation

odom_sci = Rotation.from_euler('xyz', [0, 0, th], False)

#print(odom_sci.as_quat())
odom_quat = Quaternion()

odom_quat._x = odom_sci.as_quat()[0]
odom_quat._y = odom_sci.as_quat()[1]
odom_quat._z = odom_sci.as_quat()[2]
odom_quat._w = odom_sci.as_quat()[3]
rydb gravatar image rydb  ( 2021-06-29 15:44:31 -0600 )edit

I changed fixed_frame from /scan to /odom and now it displays movement properly! I'll add picture above

rydb gravatar image rydb  ( 2021-06-29 16:50:37 -0600 )edit
0

answered 2021-06-10 17:00:22 -0600

It really shouldn't be any different for ROS1 or ROS2 -- the math is the exact same. Its just about using the ROS2 version of the ROS1 toolset to publish that information. Your code sample looks about right -- you need to take your wheel ticks / speed and convert them into relative motion.

You should look at the ROS2 tutorials, there is still a bunch of things that are not converted to ROS2 yet (e.x. anything with namespace ros::), you're not properly name spacing the messages, you're using the TF1 API, etc. All of these things are covered with the basic ROS2 tutorials. I'd drop this task for a couple of days and learn that stuff first and then revisit it once you're more familiar with ROS2.

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2021-06-10 16:25:45 -0600

Seen: 1,036 times

Last updated: Jun 29 '21