Float64 到 Float32
Float64 to Float32
我正在尝试发送一个 ROS std_msgsFloat32 一个 float64 但是,它不会自动向下转换。如何安全地将 std_msgs::Float64 转换为 std_msgs::Float32?
有向下转换问题的代码:
//currentLocation.theta is a Float64, thetaPublish accepts Float32
thetaPublish.publish(currentLocation.theta);
你应该可以做到这一点:
std_msgs::Float32 theta32;
theta32.data = static_cast<float>(theta.data);
thetaPublish.publish(theta32);
您只需明确地将双精度 data
复制到浮点数。
我正在尝试发送一个 ROS std_msgsFloat32 一个 float64 但是,它不会自动向下转换。如何安全地将 std_msgs::Float64 转换为 std_msgs::Float32?
有向下转换问题的代码:
//currentLocation.theta is a Float64, thetaPublish accepts Float32
thetaPublish.publish(currentLocation.theta);
你应该可以做到这一点:
std_msgs::Float32 theta32;
theta32.data = static_cast<float>(theta.data);
thetaPublish.publish(theta32);
您只需明确地将双精度 data
复制到浮点数。