第一次编译这个工作空间建议将build和devel都删掉然后再进行编译,就在这个readme文档的文件夹下面,打开命令行使用catkin_make进行编译,或者最好自己新建一个工作空间,将src和scripts文件夹放进去然后再进行编译
编译不通过的话查看一下命令行里面的报错,是不是有什么功能包没有装,自己安装一下,CSDN上面应该有一个博客是教大家怎么通过一句命令自动安装工作空间中缺少的功能包,可以自己找一下,然后装好所有缺少的功能包之后再进行编译,由于有一个编译的先后问题,所以即使所有的功能包都装好了也不一定能一次编译通过,多编译几次就好了,但如果进度一直卡在一个地方,那就应该是你的功能包少装了
然后这个工作空间中我们的定位功能是通过cartographer实现的,这就需要大家自己在自己的电脑上面把cartographer装好,保证能正常运行,而且cartographer本身的源码也有一些地方需要改动。参考这个博客链接,绝对能装好,而且速度非常快:极速安装cartographer链接
运行的话直接运行在scripts文件夹下面的all_start.py文件,里面使用代码启动了主机所有的节点,实现了和另一台笔记本电脑的socket通信
#!/usr/bin/python3
import rospy
from std_msgs.msg import String
import os, commands
twice = 0
os.system("gnome-terminal -e roscore")
os.system("gnome-terminal -e 'python /home/lijinzhe/ros_ws/scripts/my_socker.py'")
def callback(msg):
global twice
string_load = msg.data
if string_load == 'load':
if twice >= 1:
print(string_load)
# kill cartographer node
result = commands.getoutput("ps a | grep my_backpack_2d.launch")
result_list = result.split(" ")
cartographer_ros_ID = result_list[0]
print("cartographer_ros_ID", cartographer_ros_ID)
os.system("gnome-terminal -e 'kill -9 {}'".format(cartographer_ros_ID))
print("cartographer_ros_ID killed")
# kill car_nav node
# result = commands.getoutput("ps a | grep car_nav.launch")
# result_list = result.split(" ")
# car_nav_ID = result_list[0]
# print("car_nav_ID", car_nav_ID)
# os.system("gnome-terminal -e 'kill -9 {}'".format(car_nav_ID))
# print("car_nav_ID killed")
# os.system("gnome-terminal -e 'roslaunch mbot_navigation car_nav.launch'")
os.system("gnome-terminal -e 'roslaunch cartographer_ros my_backpack_2d.launch'")
twice = twice + 1
elif string_load == 'start':
print(string_load)
os.system("gnome-terminal -e 'roslaunch mbot_navigation rviz_display.launch'")
os.system("gnome-terminal -e 'roslaunch mbot_navigation car_nav.launch'")
os.system("gnome-terminal -e 'roslaunch cartographer_ros my_backpack_2d.launch'")
os.system("gnome-terminal -e 'python /home/lijinzhe/ros_ws/scripts/notime_nav.py'")
os.system("gnome-terminal -e 'rostopic echo /pose_data'")
elif string_load == "restart":
print(string_load)
# kill notime_nav python node
result = commands.getoutput("ps a | grep notime")
result_list = result.split(" ")
notime_ID = result_list[0]
print("notime_ID", notime_ID)
os.system("kill -9 {}".format(notime_ID))
print("notime_ID killed")
# kill cartographer node
result = commands.getoutput("ps a | grep my_backpack_2d.launch")
result_list = result.split(" ")
cartographer_ros_ID = result_list[0]
print("cartographer_ros_ID", cartographer_ros_ID)
os.system("gnome-terminal -e 'kill -9 {}'".format(cartographer_ros_ID))
print("cartographer_ros_ID killed")
# kill car_nav node
result = commands.getoutput("ps a | grep car_nav.launch")
result_list = result.split(" ")
car_nav_ID = result_list[0]
print("car_nav_ID", car_nav_ID)
os.system("gnome-terminal -e 'kill -9 {}'".format(car_nav_ID))
print("car_nav_ID killed")
os.system("gnome-terminal -e 'roslaunch cartographer_ros my_backpack_2d.launch'")
os.system("gnome-terminal -e 'roslaunch mbot_navigation car_nav.launch'")
os.system("gnome-terminal -e 'python /home/lijinzhe/ros_ws/scripts/notime_nav.py'")
def listener():
# In ROS, nodes are uniquely named. If two nodes with the same
# name are launched, the previous one is kicked off. The
# anonymous=True flag means that rospy will choose a unique
# name for our 'listener' node so that multiple listeners can
# run simultaneously.
rospy.init_node('carto_start_listener', anonymous=True)
rospy.Subscriber("/finial_goal", String, callback)
# spin() simply keeps python from exiting until this node is stopped
rospy.spin()
if __name__ == '__main__':
listener()