subscribing to AMCL pose
Hi, I am a ROS beginner and this might seem like a silly doubt but I haven't found the solution on the forums yet.
I have a robot which is localizing using AMCL. I wish to write a subscriber that can subscribe to the amcl_pose topic and read the geometry_msgs/PoseWithCovarianceStamped to be used somewhere else.
This is the code that I have for now but I am receiving a lot of errors but I am unclear on what is going wrong
#include "ros/ros.h"
#include "geometry_msgs/PoseWithCovarianceStamped.h"
double poseAMCLx, poseAMCLy, poseAMCLa;
void poseAMCLCallback(const geometry_msgs::PoseWithCovarianceStamped::ConstPtr& msgAMCL)
{
poseAMCLx = msgAMCL->pose.pose.position.x;
poseAMCLy = msgAMCL->pose.pose.position.y;
poseAMCLa = msgAMCL->pose.pose.orientation.w;
//ROS_INFO(msgAMCL);
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "err_eval");
ros::NodeHandle n;
ros::Subscriber sub_amcl = n.subscribe<geometry_msgs::PoseWithCovarianceStamped>("amcl_pose", poseAMCLCallback);
ros::Rate loop_rate(10);
ros::spinOnce();
int count = 0;
while (ros::ok())
{
geometry_msgs::Pose error;
error.position.x = poseAMCLx;
error.position.y = poseAMCLy;
error.orientation.w = poseAMCLa;
pub.publish(error);
ros::spinOnce();
loop_rate.sleep();
count=count+1;
}
return 0;
}
`
maybe you could also post the errors you are receiving so we at least can guess what the actual problem is?