When rviz does not update its visualization
Problem
In class on October 8, your instructor experienced an unexpected error fromrviz2
in which the visualization in the window did not refresh
correctly unless the window was resized. This was accompanied by an error
message in the console:
QObject::startTimer: Timers cannot have negative intervals
Solution
The error seems to have been caused by a problem in some portion of the persistent settings maintained byrviz2
. It can be resolved by
deleting these persistent settings with a command like this
rm -rv /.rviz2
rviz
.
Visualizing LaserScan data rviz
Under normal circumstances, you can use rviz
to display LaserScan
data directly, simply by adding a LaserScan display and pointing the new
display to the correct topic. If this works in your system, then you can
safely ignore this section.
However...
Problem
There seems to be a bug in certain versions ofrviz
which, under
certain circumstances, prevents rviz
from displaying LaserScan data
correctly. Symptoms of this bug include:
- A LaserScandisplay that does not actually show any laser scans, even though messages are being published on the appropriate topic.
- An error from rvizunder theLaserScandisplay complaining about transforms. The error might look something like this:Could not transform from [laser] to [world]
- Error messages in the console where rvizwas started, complaining about a full message queue. For example:[INFO] [1680813910.938522845] [rviz]: Message Filter dropping message: frame 'laser' at time 1680813905.944 for reason 'discarding message because the queue is full'
frame_id
of the LaserScan
is different from the global fixed
frame. In that case, rviz
must use tf
to look up the most recent
transformation between the two frames. If that transformation is changing
over time, then rviz
seems to fail in some cases to look up the most
recent transform correctly. Without this transform, rviz
cannot
display the data, because it does not know where the points should appear.)
Solution
The most straightforward way to work around this bug is to publish your laser scan data as aPointCloud
in addition to is normal
LaserScan
form. The PointCloud
display seems not to be
affected by this bug.
In Python, if you have a LaserScan
message object, you can
construct an equivalent PointCloud
message using code of this
general form:
def laser_scan_to_point_cloud(scan):
return PointCloud(header=scan.header, points = [ Point32(x=scan.ranges[i]*cos(scan.angle_min+i*scan.angle_increment), y=scan.ranges[i]*sin(scan.angle_min+i*scan.angle_increment), z=0.0) for i in range(len(scan.ranges)) ])
PointCloud
normally and visualize it in
rviz
using a PointCloud
display.