我試圖分配一個幾何點的值(它有 x、y、z。它們都是 float64。如果你想檢查它:http : //docs.ros.org/en/noetic/api/geometry_msgs /html/msg/Point.html ) 到 float64 變數。但是當我編譯代碼時出現下一個錯誤:
錯誤:在 'msg.nav_msgs::Odometry_std::allocator<void >::pose.geometry_msgs::PoseWithCovariance_std::allocator<void >::pose.geometry_msgs::Pose_std::allocator<void > 中請求成員 'data' ::position.geometry_msgs::Point_std::allocator<void >::y',它是非型別別'const _y_type {aka const double}'
y = (msg.pose.pose.position.y).data;
代碼如下:
#include <geometry_msgs/Point.h>
#include <std_msgs/Float64.h>
//Creo la variable con la informacion a publicar
std_msgs::Float64 y;
void controlMensajeRecibido(const geometry_msgs::Point& msg)
{
y = msg.y;
}
int main(int argc, char **argv)
{
//inicio comunicacion con sistema ROS
ros::init(argc, argv, "coordenadas");
ros::NodeHandle nh;
//Me suscribo al t
ros::Subscriber sub = nh.subscribe("/ardrone/odometry/pose/pose/position", 1000, &controlMensajeRecibido);
//creamos un objeto publicador
ros::Publisher pub =nh.advertise<std_msgs::Float64>("/pid_y/state", 1000);
pub.publish(y); //publico
//cedemos control a ROS
ros::spin();
}
如果變數是正確的型別,我不知道為什么它不允許我這樣做。如果有人可以幫助我,那就太棒了。感謝你
uj5u.com熱心網友回復:
std_msgs::Float64有一個“ data”型別的欄位float64。鍵入std_msgs::Float64 不等于場“ y”型的float64在 geometry_msgs::Point。
void controlMensajeRecibido(const geometry_msgs::Point& msg)
{
y.data = msg.y;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/331745.html
上一篇:讀取字符后無法輸入整數
