How can I publish Position in rviz ?
Hello, I am new in ROS and I have a little question.
I want to publish a starting position and goal position on rviz but I didn't succeed. I don't know where is the error in my code and/or if it possible or not because I have seen no information about it on the internet.
This in ROS2 Foxy and I use the turtlebot3.
Thank you for your help, I let you my code here :
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
from geometry_msgs.msg import PoseWithCovarianceStamped, PoseStamped
class MinimalPublisher(Node):
def __init__(self):
super().__init__('minimal_publisher')
self.publisher_ = self.create_publisher(PoseWithCovarianceStamped , '/initialpose', 10)
self.pose_callback()
self.publisher_ = self.create_publisher(PoseStamped , '/goal_pose', 10)
self.goal_callback()
def pose_callback(self):
self.msg = PoseWithCovarianceStamped()
self.msg.header.frame_id = "/base_link"
self.msg.pose.pose.position.x = 0.7
self.msg.pose.pose.position.y = 0.5
self.msg.pose.pose.position.z = 0.1
self.publisher_.publish(self.msg)
def goal_callback(self):
self.goal = PoseStamped()
# self.msg.header.frame_id = "/base_link"
self.goal.pose.position.x = 0.7
self.goal.pose.position.y = 0.5
self.goal.pose.position.z = 0.1
self.publisher_.publish(self.goal)
print("done")
def main(args=None):
rclpy.init(args=args)
minimal_publisher = MinimalPublisher()
rclpy.spin(minimal_publisher)
minimal_publisher.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
"but I didn't succeed" — please provide more details. What all have you tried and what are your findings?
First I launched rviz and i also do in a shell "ros2 topic echo /initialpose". By doing that i can see on the rviz if the position is well published and with echo I can also if something is published on the topic.
The result is : - I can see that I publish well on the topic /initialpose - Nothing happened in rviz interface
Furthermore for setting the goal position, when I echo goal pose I hear nothing so maybe my syntaxis is wrong ?