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

ImportError: No module named robot_messages.msg

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

AkaTomo93 gravatar image

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

When I run this code I get :

ImportError: No module named robot_messages.msg

This is the code that is written on this tutorial: https://www.youtube.com/watch?v=DLVyc... 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):

        xd=x1-x2
        yd=y1-y2
    return math.sqrt(xd*xd+yd*yd)   

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

    def callback(self,msg):
        x=msg.pose.pose.position.x
        y=msg.pose.pose.position.y
        z=msg.pose.pose.position.z

        closest_name= None
        closest_distance= None

        for l_name, l_x, l_y in self._landmarks:
            dist=distance(x,y,l_x,l_y)
            if closest_distance is None or dist < closest_distance:
                closest_name = l_name
                closest_distance = dist

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


def main():
    rospy.init_node('location_monitor')
    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
    rospy.spin()

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

Comments

1

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 -0500 )edit
1

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 -0500 )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 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

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

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

Stats

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

Seen: 1,629 times

Last updated: Apr 20 '23