Robotics StackExchange | Archived questions

Import msg data python

Hi all, I use the Apriltags2ros software, and the python coding. I got the software running, and I am able to detect the apriltag with id=0 with rostopic echo /tagdetections. Now I want to import the position's data in a python script, to be able to control my robot. What I have worked with some other apriltags software, though I had to switch to the new one due to changing circumstances. I had to change some things, but now it doesn't work anymore. Can somebody help me?

#!/usr/bin/env python

import rospy
from apriltags2_ros.msg import AprilTagDetection

class CameraPosition():
    def __init__(self):
        rospy.Subscriber("/tag_detections", AprilTagDetection, self.get_tags)

    def get_tags(self, msg):
        pos_x = msg.detections[0].pose.pose.position.x 

        print(pos_x)

if __name__ == "__main__":
    CameraPosition()
    rospy.spin()

sorry I had to do it this way; I want to do screenshots but I haven't got enough points yet. If I only get the x position I will figure the orientation and other positions out, I just need a bump in the right direction

rosmsg show apriltags2_ros/AprilTagDetection

int32[] id
float64[] size
geometry_msgs/PoseWithCovarianceStamped pose
  std_msgs/Header header
    uint32 seq
    time stamp
    string frame_id
  geometry_msgs/PoseWithCovariance pose
    geometry_msgs/Pose pose
      geometry_msgs/Point position
        float64 x
        float64 y
        float64 z
      geometry_msgs/Quaternion orientation
        float64 x
        float64 y
        float64 z
        float64 w
    float64[36] covariance

Asked by NLBUURMAN on 2018-07-10 04:36:23 UTC

Comments

Answers

You should get this exception when running this program:

rospy.exceptions.ROSInitException: client code must call rospy.init_node() first

Asked by NEngelhard on 2018-07-10 12:26:05 UTC

Comments

thanks, I solved it by now

Asked by NLBUURMAN on 2018-07-18 06:57:12 UTC

In this case, you should also write HOW you solved it so others can also benefit from this question.

Asked by NEngelhard on 2018-07-19 00:47:42 UTC

Could you please post how you solved the problem. I am getting the same issue

Asked by Aniket_Gujarathi on 2018-12-13 03:04:10 UTC