Home > database >  I can't assign the value of a geometry point to a variable
I can't assign the value of a geometry point to a variable

Time:10-23

I was trying to assign the value of a geometry point (it has x,y,z. All of them are float64. If you want to check it: http://docs.ros.org/en/noetic/api/geometry_msgs/html/msg/Point.html ) to a float64 variable. But when I compile the code the next error appears:

error: request for member ‘data’ in ‘msg.nav_msgs::Odometry_std::allocator<void >::pose.geometry_msgs::PoseWithCovariance_std::allocator<void >::pose.geometry_msgs::Pose_std::allocator<void >::position.geometry_msgs::Point_std::allocator<void >::y’, which is of non-class type ‘const _y_type {aka const double}’

y = (msg.pose.pose.position.y).data;

And the code is the following:

#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();
}

I don't know why it doesn't let me do it if the variable is the correct type. If anyone can help me it'll be amazing. Thank u

CodePudding user response:

std_msgs::Float64 has a field "data" of type float64. Type of std_msgs::Float64 is not equal to field "y" of type float64 in geometry_msgs::Point.

void controlMensajeRecibido(const geometry_msgs::Point& msg)
{
  y.data = msg.y;
}
  • Related