终端输入如下指令:
1、圆形机器人寻宝:
(1)随机点寻宝
第一个终端roslaunch mbot_gazebo slam.launch
第二个终端roslaunch mbot_navigation nav_maze_demo.launch
第三个终端roslaunch mbot_vision find_target.launch
使用圆形机器人随机点进行寻找宝藏,找到后返回
(2)指定点探索寻宝
第一个终端roslaunch mbot_gazebo slam.launch
第二个终端 roslaunch mbot_navigation exploring_slam_demo.launch
第三个终端roslaunch mbot_vision find_target_pro.launch
2、自己的机器人寻宝
终端使用命令相同
需要修改自己的xacro模型,将camera和lidar结合
遇到的问题:
1、首先是不能空格和tab键混用
TabError: inconsistent use of tabs and spaces in indentation
检查代码,要不全部用tab,要不全部用4个空格
2、opencv和古月老师版本不一致
ret,contours,hierachy=cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
ValueError: not enough values to unpack (expected 3, got 2)
这是因为新的opencv更改了版本,函数返回值只有两个,即
新的函数应该是
cnts,hierachy=cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPL
3、在填入命令时,因为自己的系统用的python3,与古月老师提供的代码有一些不兼容,修改一些括号,即print e改为print (e)有个问题没找着,直接用python2 hsv_test.py运行代码,提取出宝藏的rgb范围,这样解决了识别宝藏不全的问题
4、另外一个问题是在python程序里一定注意缩进多少,如果平行关系,下文缩进要与上文对齐。
5、第五个问题是我打错了字,耗费了一个多小时。。。。
前文本应该是
self.image_pub = rospy.Publisher("object_detect_image",Image,queue_size=1)
self.image_sub = rospy.Subscriber("/usb_cam/image_raw", Image, self.callback)
我打成了
self.image_pub = rospy.Publisher("object_detect_image",Image,queue_size=1)
self.image_pub = rospy.Subscriber("/usb_cam/image_raw", Image, self.callback)
后文是self.image_pub.publish(ros_img),这导致image_pub本应该是发布者,这里错误的变成订阅者,程序自然无法发布,然后终端报错是self.image_pub.publish(self.bridge.cv2_to_imgmsg(cv_image, "bgr8"))
AttributeError: 'Subscriber' object has no attribute 'publish'
我不管三七二十一无脑google,也没找到答案,最后仔细看程序才发现问题,说明遇到问题不一定是非要google有时候可以自己仔细看程序解决
6、错误的将“赋值=“写成“判断是否等==”,这导致机器人一直报找到宝藏却依旧在导航到设定点。