Writing a simple ROS package with a single subscriber should be simple, no? Well, it was a lot harder and more finicky than I thought. I needed to get the positions of the AR tags through the ar_pose_marker topic published by the ar_track_alvar noded. This is how I did it (after a lot of error messages).

In catkin_ws/src:

catkin_create_pkg ar_pkg ar_track_alvar ar_track_alvar_msgs std_msgs rospy roscpp

You should have a ar_pkg in catkin_ws/src. Go into the ar_pkg/src and create a file with:

nano ar_pose_status.cpp
#include "ros/ros.h"
#include "ar_track_alvar_msgs/AlvarMarkers.h"
void poseCallback(const ar_track_alvar_msgs::AlvarMarkers::ConstPtr& msg){
	double x = msg->markers[0].pose.pose.position.x;
	double y = msg->markers[0].pose.pose.position.y;
	double z = msg->markers[0].pose.pose.position.z;
	ROS_INFO("x: %f, y: %f z: %f", x, y, z);
}

int main(int argc, char **argv)
{
	ros::init(argc, argv, "ar_pose_status");
	ros::NodeHandle n;
	ros::Subscriber sub = n.subscribe("ar_pose_marker", 1000, poseCallback);
	ros::spin();
	return 0;
}

If you run catkin_make and get error saying it’s not executable just give the file executable permissions

chmod +x ar_pose_status.cpp

Add these two lines to the CMakeLists.txt file of ar_pkg

add_executable(ar_pose_status src/ar_pose_status.cpp)
target_link_libraries(ar_pose_status ${catkin_LIBRARIES})

back in /catkin_ws run:

catkin_make

Run the ar tracking from the last post (up until rostopic echo /ar_pose_marker) and then run:

rosrun ar_pkg ar_pose_status

To investigate the message format i ran rosmsg show /ar_pose_marker

and got a report back of all the information published to the pose topic!