Robotics StackExchange | Archived questions

Publishing to Initialpose Programmatically on Turtlebot Navigation

I am trying to write a code to set my turtlebot3 in rviz to the initial pose of the robot in gazebo. I've followed the instructions of the Ros wiki : Writing a simple publisher (http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28python%29) and the two threads on ros/ask: https://answers.ros.org/question/205308/publishing-to-initialpose-programmatically-on-turtlebot-navigation/ and https://answers.ros.org/question/114631/robot-estimated-pose/

This is my code:

!/usr/bin/env python

import rospy from geometry_msgs.msg import PoseWithCovarianceStamped

rospy.init_node('pub_initpose_node' anonymous=True)
pub = rospy.Pub('/initialpose', PoseWithCovarianceStamped, queue_size=10)

    initpose_msg = PoseWithCovarianceStamped()
    initpose_msg.header.frame_id = "map"
    initpose_msg.pose.pose.position.x=0.0
    initpose_msg.pose.pose.position.y=0.0
    initpose_msg.pose.pose.position.z=0
    initpose_msg.pose.covariance=[0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.06853891945200942]
    initpose_msg.pose.pose.orientation.w=1.0

    rate = rospy.Rate(10) # 10Hz

    while not rospy.is_shutdown():
        pub.publish(initpose_msg)
        rate.sleep()

When I try to run this node with

rosrun turtlebot3navigation pubinitpose.py

I get the answer:

*[rosrun] Couldn't find executable named pubinitpose.py below /home/lslabon/catkinws/src/turtlebot3/turtlebot3navigation [rosrun] Found the following, but they're either not files, [rosrun] or not executable: [rosrun] /home/lslabon/catkinws/src/turtlebot3/turtlebot3navigation/rviz/pubinitpose.py*

Why is my code not executable? I tried different ones but got always the same message...

Thanks for your help!

PS: I am using ros melodic on Ubunutu 18.

Asked by lslabon on 2020-09-10 08:25:39 UTC

Comments

Answers