ROS Q&A | How to know the Pose of a robot (Python) ?

ROS Q&A | How to know the Pose of a robot (Python) ?

 

Here you have an example of how to read the Pose of a robot in Python, answering a question made in ROS Answers

Q: Hello ! I want to know the pose of turtlebot (x,y,z, z rotation) respect to the point from which it started. What is the best way to do that in python?

A:Hello! As you suggest in your last message, the best practice for doing that is to use the odom topic. For that, you can create a simple subscriber in Python that gets the data you need, which is, position and orientation respect to an starting point. The code for a simple subscriber could be like this:

#! /usr/bin/env python

import rospy
from nav_msgs.msg import Odometry

def callback(msg):
    print msg.pose.pose

rospy.init_node('check_odometry')
odom_sub = rospy.Subscriber('/odom', Odometry, callback)
rospy.spin()

This code basically subscribes to the odom topic, and prints the pose component of the message, which contains the position and orientation values.

 

The following steps take throught the development as shown in the video.

We can check the names of all the published topics with the following command (Enter in a Shell)

$ rostopic list

Check for /odom topic in the output of the command. We can now check the information being published on this topic using the following command

$ rostopic echo /odom -n1

The output of the above command should be as shown in the image below (x0x≈0, y0y≈0)

  • Next we will create a subscriber. Use the following commands to create a new package and a subscriber script file.

cd ~/catkin_ws/src catkin_create_pkg check_odometry cd check_odometry mkdir src launch

  • Now we will create a script named inside the check_odometry/src/ directory. Add the following code to the script file
#!/usr/bin/env python

import rospy
from nav_msgs.msg import Odometry

def callback(msg):
    print(msg.pose.pose)
    
rospy.init_node('check_odometry')
odom_sub = rospy.Subscriber('/odom', Odometry, callback)
rospy.spin()
  • We will now create a launch file with name inside the check_odometry/launch/ directory with the following content
<launch>
    <node pkg="check_odometry" type="check_odom.py" name="check_odometry" output="screen" />
</launch>
  • Lets launch this launch file with the following command in SHELL

$ roslaunch check_odometry check_odom.launch

The above command should start publishing a stream of Odometry messages (the pose part) as shown in this image

  • Now let us move the robot slightly using the keyboard_teleop and observe the /odom message

$ roslaunch turtlebot_teleop keyboard_teleop.launch

  • Now we can start the launch file again see the change in the location of the robot

This finishes the steps in the Video tutorial.

Worldwide ROS Events

Worldwide ROS Events

This article shares all Non-profit ROS Evens around the world to promote the exchange ideas and communication between ROS learners.

 

The largest and most active ROS Meetups in the world


1. Silicon Valley Robotics

ros-meetups-group-1

Host City: Silicon Valley, San Francisco

About: Silicon Valley Robotics is a non-profit business association that promotes the innovation and commercialization of robotics technologies. They hold an event every two weeks. You can share your robot or robotics-related project with the robotics students at Silicon Valley CTE, offer your ideas to robotics startups or get the opportunity to be hired by a robotics-related company.

 

2. Robot Developer Group 

ros-meetups-groups-2

Host City: San Francisco, CA

About: Their sessions will showcase the latest in new robot platforms, software, hardware and sensor technologies.  A community dedicated to moving the robotics industry forward by bringing the best robotics minds in the area together to network, brainstorm, collaborate, and take real action to execute ideas and visions.

 

3. Learn/Teach ROS Fast

ros-meetups-groups-3

Host City: Barcelona, Kontich (Belgium), Vancouver, Murrieta (USA), Cambridge, Punjab (India), Cairo (Egypt)…more than 30 cities

About: A ROS learning community for students or teachers or anybody who interested in learn or teach ROS in an effective way.  In their events you can to meet other ROS enthusiasts, join together to learn how to smooth the ROS learning curve and start ROS project quickly.

Meetups topics include: ROS Navigation, ROS introduction, Using OpenAI with ROS , Self-driving cars using ROS, RPS-Industrial, Apply ROS to real robots, etc.

 

4. ROS in Chicago 

Host City: Chicago (University of Illinois – Chicago campus)

About: A group for people interested in making robots who use/want to use ROS (Robotic Operating System) in the Chicago-land area. Topic will be covered from software development to hardware implementation, as well as all aspects in artificial intelligence

 

5. Vancouver ROS User Group

Host City: Vancouver

About: A ROS group in Vancouver which is open to anyone interested in using ROS to design and develop robots for real world applications. Their prime focus is on collaborative service robots that can safety interact with humans and share what they have learned.

Meetups topics include: Sensors, Intro to Robot Simulators, Drones, Application of Computer Vision, Robot mapping using SLAM, etc.

 

6. Tokyo ROS Meetup 

Host City: Tokyo

About: This group is for people interested in robotics who want to use and learn more about ROS and is open to all interested and will try to strengthen the network between the international and local ROS community.

 

7. ROS on the Rocks

Host City: Boulder, Loveland

About: ROS Users Group in the Rocky Mountain region. The group will focus specifically on ROS, and ROS-Industrial.

Meetups topcis include: Introduction to ROS through a Robotic Manipulator

 

8. ROS Seattle Meetup 

Host City: Seattle

About: This is a bi-monthly user group for developers learning or using the ROS. Most meetings consist of community show and tell and a featured talk.

 

 

Other Events


 

About: Learn a method to teach ROS fast with no hassle. The aim of this webinar is to show you how to change your classes from passive listening to active practising.

 

About: A webinar series designed to help you equip your team with ROS fast.

 

About: ROS Japan Users Google Group. (Group email: ros-japan-users@googlegroups.com) They will hold ROS Events from time to time.

 

About:The seminar covered overview for introduction, navigation, moveit, UAV, and community briefly by speakers from various groups in Korea. (*This is a past event, but you can still find the presentation slides and other useful ROS materials on their website.)

ROS Q&A | How to solve the error “ImportError : No module named xxxx.msg”

ROS Q&A | How to solve the error “ImportError : No module named xxxx.msg”

The question that we solved today can be found on the following link:

https://answers.ros.org/question/271620/importerror-no-module-named-xxxxmsg/

ROS Question:

I migrate an installation from one computer to another, switching from Ubuntu 12.04 to 16.04 and from indigo ros to kinetic When I run my installation that has about 30 packages most of the things seem to start well except for a package that fails to make an import I specify that I do not have this error on the computer of the previous configuration, or everything is identical in my programs, except the denomination of indigo and kinetic The error is as follows: From my_folder_msgs.msg import my_file as My_fileMsg
ImportError : No module named my_folder_msgs.msg

Of course, my_folder_msgs.msg exists and appears when I call: rosmsg list.

Would anyone have an idea?


Answer:

When we are developing using ROS, it’s common to define our custom ROS Messages, but sometimes we get stuck about how to use our ROS Messages. A common scenario is that my ROS Messages are identified with rosmsg list but when we try to use the message on our nodes (let’s say a python file), there are errors importing. In this video answer, we solve this error by answering a real question.

When we use our custom messages, even if they are listed with,rosmsg list they only can be used by our nodes after they be compiled.

I have created a video ( https://www.youtube.com/watch?v=NKeebwRNvv8 ) that answers exactly this question.

The steps explained in the video can be done in your own computer but we highly recommend you following the steps using ROSDS (ROS Development Studio), since it’s a free platform and you don’t have to install ROS in your local machine :

Step1. Create a ROSject in ROSDS (ROS Development Studio)

As we said previously, you can easily follow the steps using ROSDS. The advantage is that you can use ROS without having to install ROS. The only thing you need is a Web Browser. In order to create an account, please go to this link.

Once you have an account, you can create a ROSject pressing the button that is shown once you login. Once the ROSject is created, you can open it. At this moment you should have a web Desktop. Now you just need to open a Web Shell and run the commands below.

Step 2. Create a ROS package

We create a package to start to reproduce the problem in it.

$ cd ~/catkin_ws/src
$ catkin_create_pkg my_folder_msgs

The user had a problem with the custom messages, we can create it with the following steps.

$ cd my_folder_msgs
$ mkdir msg
$ touch msg/my_file.msg

Then we put a test message into the my_file.msg file with the following code.

float32 rosds

As a test, we create a python file called question.py under the my_folder_msgs/src directory with the following commands:

mkdir -p ~/catkin_ws/src/my_folder_msgs/src
touch ~/catkin_ws/src/my_folder_msgs/src/question.py

After having created the question.py file, we add the following content to it

#! /usr/bin/env python
from my_folder_msgs.msg import my_file as My_fileMsg
print '\n\nYes, it worked!!!'

If we execute the file now with the python question.py command we got the same error as the question.

ImportError: No module named my_folder_msgs.msg

Step 3. Compile messages

It turns out you have to compile your message before you can use it in the package.

  1. You have to compile your message. For that, you have to touch the package.xml and CMakeLists.txt located on ~/catkin_ws/src/my_folder_msgs.  The original file generate by ROS actually contains the lines you need but comment out. You just have to remove the comment to use it. In package.xml remove the comments before the line <build_depend>message_generation</build_depend> and  <exec_depend>message_runtime</exec_depend> . In the CMakeLists.txt, you have to add message_generation and std_msgs into the find_package(), so it becomes find_package(catkin REQUIRED message_generation std_msgs). After that you have to uncomment  the add_message_files() part and add my_file.msg in it and finally uncomment the generate_messages() part. After preparing the package.xml and CMakeLists.txt, you run catkin_make on your catkin_ws with cd ~/catkin_ws; catkin_make
  2. After the message is compiled, you have to source the setup.bash like: ource ~/catkin_ws/devel/setup.bash
  3. Now you can import your messages without any problem:
cd ~/catkin_ws/src/my_folder_msgs/src;
python question.py

Take away today:

In order to use your customized message, remember to compile and source it before you import it into another file.

Please, remember to subscribe to our channel on YouTube and press the bell if you to be notified of new videos we publish. Additionally, feel free to leave your thoughts on the commends section of the video (https://www.youtube.com/watch?v=NKeebwRNvv8).

ROS courses related:

Pin It on Pinterest