Ros:TurtleBot 1(Getting Position through Subscriber)

Intro:

If you have ever been dreamt of exclusively learning robotics your wish has been granted ROS Robot Operating  Systems.

Here we can make use make our own robot program it and get the output as we can with the actual robot.

So Lets dive  in it.                    

Today we are going to look how to get turtlebot moving and get its position.

Sounds  Simple right? I’ll ask you in few minutes

We would use linux OS

Software install:

ROS

Python

Linux

Git

Create Catkin WorkSpace

Install turtleBot packages

Done! We have just started

Command 1 : roscore : Used to initialize ROS Master

Command 2 :roslaunch  turtlebot_gazebo  turtlebot_world.launch

Command 3:roslaunch  turtlebot_teleop  keyboard_teleop.launch

 Command 4:rosrun location_monitor location_monitor_node.py

We need to program location_monitor_node.py  for subscriber  node

Program:

#!/usr/bin/env python

import rospy
from nav_msgs.msg import Odometry

def callback(msg):
x = msg.pose.pose.position.x
y = msg.pose.pose.position.y
rospy.loginfo(‘x: {}, y:{}’.format(x,y))

def main():
rospy.init_node(‘location_monitor’)
rospy.Subscriber(“/odom”,Odometry,callback)
rospy.spin()

if __name__ == “__main__”:
main()

Output:

Position of Turtlebot on Suscriber Node

1 thought on “Ros:TurtleBot 1(Getting Position through Subscriber)”

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.