Quantcast
Channel: ROS Answers: Open Source Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 84

ImportError: No module named robot_messages.msg

$
0
0
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=DLVyc9hOvk8 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()

Viewing all articles
Browse latest Browse all 84

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>