ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Import msg data python

asked 2018-07-10 04:36:23 -0600

NLBUURMAN gravatar image

updated 2018-07-10 10:00:14 -0600

Hi all, I use the Apriltags2_ros software, and the python coding. I got the software running, and I am able to detect the apriltag with id=0 with rostopic echo /tag_detections. 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
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-07-10 12:26:05 -0600

NEngelhard gravatar image

You should get this exception when running this program:

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

edit flag offensive delete link more

Comments

thanks, I solved it by now

NLBUURMAN gravatar image NLBUURMAN  ( 2018-07-18 06:57:12 -0600 )edit

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

NEngelhard gravatar image NEngelhard  ( 2018-07-19 00:47:42 -0600 )edit

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

Aniket_Gujarathi gravatar image Aniket_Gujarathi  ( 2018-12-13 02:04:10 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-07-10 04:36:23 -0600

Seen: 1,252 times

Last updated: Jul 10 '18