ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

ImportError: No module named robot_messages.msg

asked 2016-10-28 16:27:08 -0600

AkaTomo93 gravatar image

updated 2016-10-28 17:02:17 -0600

When I run this code I get :

ImportError: No module named robot_messages.msg

This is the code that is written on this tutorial: and the person is able to run it at 27:50 min mark, but I am not.

I have no idea what could be the problem. I made two packages. One by the name location_monitor and other by the name robot_messages. In the robot_messages I made file LandmarkDistance.msg which looks like this:

string name # Name of the landmark
float64 location # distance from landmark in meters

I tried searching for the forum and making a seperate package just for the messages, but I just don't know what the problem could be.

#!/usr/bin/env python

import math
import rospy
from nav_msgs.msg import Odometry
from robot_messages.msg import LandmarkDistance

    def distance(x1,y1,x2,y2):

    return math.sqrt(xd*xd+yd*yd)   

class LandmarkMonitor(object):
    def __init__(self, pub, landmarks):
        self._landmarks= landmarks

    def callback(self,msg):

        closest_name= None
        closest_distance= None

        for l_name, l_x, l_y in self._landmarks:
            if closest_distance is None or dist < closest_distance:
                closest_name = l_name
                closest_distance = dist

        ld= LandmarkDistance() closest_name
        ld.distance= closest_distance
        rospy.loginfo('closest: {} and the distance is {}' .format(closest_name,closest_distance))

def main():
    landmarks= []
    landmarks.append(("Cube", 0.31,-0.99))
    landmarks.append(("Dumpster", 0.11,-2.42))
    landmarks.append(("Cylinder", -1.14,-2.88))
    landmarks.append(("Barrier", -2.59,-0.83))
    landmarks.append(("Bookshelf", -0.09,0.53))

    pub= rospy.Publisher('closest_landmark', LandmarkDistance)
    monitor= LandmarkMonitor(pub, landmarks)

    rospy.Subscriber("/odom", Odometry, monitor.callback)
    # spin() simply keeps python from exiting until this node is stopped

if __name__ == '__main__':
edit retag flag offensive close merge delete



Just to make sure:

  1. both pkgs are in a catkin workspace
  2. after creating the pkgs, you ran catkin_make in the workspace root (not in src)
  3. after catkin_make, you ran source /path/to/catkin_ws/devel/setup.bash

And then rosrun location_monitor .. results in that error?

gvdhoorn gravatar image gvdhoorn  ( 2016-10-29 04:00:35 -0600 )edit

First, make sure your msg being successfully built by doing "rosmsg show robot_messages/Landmark....". Please post the output of that command here

DavidN gravatar image DavidN  ( 2016-10-29 05:09:02 -0600 )edit

Thank you for helping me out guys. I'm actually not sure what I did to fix this. I just woke up the next morning ran the code and it was working. I'm really not sure what I did but thank you for trying to help anyway :)

AkaTomo93 gravatar image AkaTomo93  ( 2016-10-29 09:15:03 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2023-04-20 09:04:17 -0600

Make sure to add generate_messages() to your CMakeLists.txt of package,This will solve your error:)

generate_messages( DEPENDENCIES std_msgs )

then re-run catkin_make and then resource setup.bash

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-10-28 16:27:08 -0600

Seen: 1,544 times

Last updated: Apr 20