Hi.
In turtle.cpp for ros2 turtlesim, normalizeAngle takes a float as an argument.
However, the data passed into the function is of size double when the function is called, and gets truncated to become nan.
...
ang_vel_ = vel->angular.z; // type of geometry_msgs::msg::Twist.angular.z is float64 (double)
...
orient_ = orient_ + ang_vel_ * dt; // orient_ is of type qreal, which is double
orient_ = normalizeAngle(orient_); // double-sized data gets truncated to nan
When a control program publishes to /cmd_vel a Twist message in which angular.z is set to a double-sized value, normalizeAngle ends up returning nan. As a result, orient_ becomes nan, and accordingly, theta, x, y of the turtle's Pose becomes nan in the subsequent lines. This effectively removes the turtle from the frame. The "clamping" logic fails to put the turtle back in the frame, as it compares nan with integers.
Hi. In
turtle.cpp
for ros2 turtlesim,normalizeAngle
takes afloat
as an argument. However, the data passed into the function is of sizedouble
when the function is called, and gets truncated to becomenan
.When a control program publishes to
/cmd_vel
a Twist message in whichangular.z
is set to adouble
-sized value,normalizeAngle
ends up returningnan
. As a result,orient_
becomesnan
, and accordingly,theta
,x
,y
of the turtle's Pose becomesnan
in the subsequent lines. This effectively removes the turtle from the frame. The "clamping" logic fails to put the turtle back in the frame, as it comparesnan
with integers.e.g., Published message:
Result:
![2](https://user-images.githubusercontent.com/10861633/124035243-4b9af600-d9ca-11eb-8e2e-250f48ce11c4.png)
Tested and confirmed on the
foxy-devel
branch, but this problem affects all ros2 branches.