Ask Your Question
0

How to publish a pose in quaternion?

asked 2019-02-27 03:42:03 -0600

paul_shuvo gravatar image

I have all the values for point(x, y, z) and quaternion (w, qx, qy, qz). Do I just make a dict and publish it as a Pose topic?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-02-27 04:55:52 -0600

VictorLamoine gravatar image

You need to create a publisher and publish a geometry_msgs/Pose message.

#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Pose

def publisher():
    pub = rospy.Publisher('pose', Pose, queue_size=1)
    rospy.init_node('pose_publisher', anonymous=True)
    rate = rospy.Rate(2) # Hz
    while not rospy.is_shutdown():
        p = Pose()
        p.position.x = 0.5
        p.position.y = -0.1
        p.position.z = 1.0
        # Make sure the quaternion is valid and normalized
        p.orientation.x = 0.0
        p.orientation.x = 0.0
        p.orientation.x = 0.0
        p.orientation.w = 1.0
        pub.publish(p)
        rate.sleep()

if __name__ == '__main__':
    try:
        publisher()
    except rospy:
        pass
edit flag offensive delete link more

Comments

1

To add: see rospy/Overview/Messages for some other styles of msg initialisation in rospy.

gvdhoorn gravatar imagegvdhoorn ( 2019-02-27 05:13:50 -0600 )edit

you should edit your answer to -->> p.orientation.y = 0.0 and p.orientation.z = 0.0

Farid gravatar imageFarid ( 2019-12-12 06:19:04 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-02-27 03:42:03 -0600

Seen: 737 times

Last updated: Feb 27