ros2 run {turtlesim} {turtlesim_node}
ros2 topic list ## we publish sth relevant one.
ros2 topic info {interesting topic from list}
ros2 interface show {interesting type from the info above}
Depending on you need response or request, check the types (ex. float32, int, bool, ...)
ros2 service list
ros2 service type {interesting topic} # check the type of the service
ros2 interface show {interesting type from the type above}
ros2 pkg create {name_pkg} --build-type ament_python
cd src/{name_pkg}/{name_pkg}
touch {name_node}.py
chmod +x {name_node.py}
from turtlesim.msg import Pose
self.pose_ = None # variable to contain the content
self.pose_subscriber_ = self.create_subscription(
Pose, "turtle1/pose", self.callback_turtle_pose, 10) # msg_type, topic, fn, fq
def callback_turtle_pose(self, msg):
self.pose_ = msg # update pose through getting msg.
from geometry_msgs.msg import Twist
self.cmd_vel_publisher_ = self.create_publisher(
Twist, "turtle1/cmd_vel", 10) # publishes don't need a callback fn!