簡體   English   中英

從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);

您只需要將double data顯式復制到float。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM