ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
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
3

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

VictorLamoine gravatar image

updated 2020-12-08 03:16:57 -0600

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.y = 0.0
        p.orientation.z = 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 image gvdhoorn  ( 2019-02-27 05:13:50 -0600 )edit
1

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

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

Question Tools

1 follower

Stats

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

Seen: 7,062 times

Last updated: Dec 08 '20