一、安装ros
清华源安装
1、
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'
2、
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
sudo apt-get update
3、
sudo apt-get install ros-kinetic-desktop-full
4、
sudo rosdep init
rosdep update
这里可能会出错 解决的办法是这个:https://blog.csdn.net/nanianwochengshui/article/details/105702188
第一步:
首先进入github.com/ros/rosdistro去把这个包下载下来。
第二步:
修改这个包中rosdep/source.list.d/下的文件20-default.list,将这个文件中指向raw.githubusercontent.com的url地址全部修改为指向本地文件的地址,也就是该下载好的包的地址:以下是我修改好的样例:
# os-specific listings first
yaml file:///home/xxx/rosdistro/rosdep/osx-homebrew.yaml osx
# generic
yaml file:///home/xxx/rosdistro/rosdep/base.yaml
yaml file:///home/xxx/rosdistro/rosdep/python.yaml
yaml file:///home/xxx/rosdistro/rosdep/ruby.yaml
gbpdistro file:///home/xxx/rosdistro/releases/fuerte.yaml fuerte
# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
***注意:***在py语言中:url本地文件地址格式是:file://+文件地址,后面更改其他文件中地址的时候也一样。
第三步:
修改/usr/lib/python2.7/dist-packages/rosdep2/main.py中的默认的url的地址,但是经过代码阅读,该文件中并不存在指向raw.githubusercontent.com的代码。而且经过对代码的分析,提示报错的代码就在该文件中:
def command_init(options):
try:
data = download_default_sources_list()
except URLError as e:
print('ERROR: cannot download default sources list from:\n%s\nWebsite may be down.' % (DEFAULT_SOURCES_LIST_URL))
return 4
except DownloadFailure as e:
print('ERROR: cannot download default sources list from:\n%s\nWebsite may be down.' % (DEFAULT_SOURCES_LIST_URL))
由于其调用了download_default_sources_list()这个函数
而该函数就在/usr/lib/python2.7/dist-packages/rosdep2该文件夹下面的sources_list.py文件里面。而这个文件里面的代码则进行了访问raw.githubusercontent.com的操作,因此修改该默认url即可。
# default file to download with 'init' command in order to bootstrap
# rosdep
DEFAULT_SOURCES_LIST_URL = 'file:///home/xxx/rosdistro/rosdep/sources.list.d/20-default.list'
# seconds to wait before aborting download of rosdep data
总结:该步实际并不是修改 main.py 文件里面默认url的指向地址,而是修改同文件夹下的sources_list.py文件里面的代码
第四步:
修改以下两个文件里面的代码:
/usr/lib/python2.7/dist-packages/rosdep2/rep3.py
/usr/lib/python2.7/dist-packages/rosdistro/__init__.py
下面是我分别修改后的样例:
/usr/lib/python2.7/dist-packages/rosdep2/rep3.py文件:
# location of targets file for processing gbpdistro files
REP3_TARGETS_URL = 'file:///home/xxx/rosdistro/releases/targets.yaml'
# seconds to wait before aborting download of gbpdistro data
/usr/lib/python2.7/dist-packages/rosdistro/__init__.py的文件:
# index information
DEFAULT_INDEX_URL = 'file:///home/xxx/rosdistro/index-v4.yaml'
def get_index_url():
然后进行sudo rosdep init :
5 、配置ROS环境
echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
6、安装依赖项
sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential
7、测试ROS是否安装成功
roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key
rosrun rqt_graph rqt_graph
二、编译carla中的ros_bridge
首先进入下面的链接:https://carla.readthedocs.io/en/latest/build_linux/
这个是carla的说明链接
目前用到的是0.9.8版本的。左边是目录,右边是说明。右下角可以调整版本。
首先左边搜ros_bridge
按照B步骤进行编译即可
这里需要注意的是首先git clone下载的那个,需要手动到下面的网站下载0.9.8版本的
https://github.com/carla-simulator/ros-bridge
下面是进行的步骤
mkdir -p ~/carla-ros-bridge/catkin_ws/src
cd ~/carla-ros-bridge
git clone https://github.com/carla-simulator/ros-bridge.git
cd catkin_ws/src
ln -s ../../ros-bridge
source /opt/ros/kinetic/setup.bash
cd ..
rosdep update
rosdep install --from-paths src --ignore-src -r
catkin_make
三、装好以后按照下面的步骤进行联合调试
carla_bridge
1 启动carla
SDL_VIDEODRIVER=offscreen ./CarlaUE4.sh -opengl
2 配置环境变量
export PYTHONPATH=$PYTHONPATH:/PythonAPI/carla/dist/carla-.egg
在我的电脑具体为:
export PYTHONPATH=$PYTHONPATH:/home/wl/software/carla098/PythonAPI/carla/dist/carla-0.9.8-py2.7-linux-x86_64.egg
sudo cp /home/xu/anaconda3/envs/carla_ros/x86_64-conda_cos6-linux-gnu/sysroot/lib/libstdc++.so.6.0.26 /usr/lib/x86_64-linux-gnu/
roslaunch carla_ros_bridge carla_ros_bridge.launch
roslaunch carla_ros_bridge carla_ros_bridge_with_example_ego_vehicle.launch
1 设置地图
/ros-bridge/carla_ego_vehicle 文件夹中的 carla_eg0_vehicle.py文件
self.world = client.load_world('Town05')
2 设置车辆
/ros-bridge/carla_ego_vehicle 文件夹中的 carla_eg0_vehicle.py文件
# blueprint = secure_random.choice(self.world.get_blueprint_library().filter(self.actor_filter))
blueprint = self.world.get_blueprint_library().filter(self.actor_filter)[0]
# self.world.get_blueprint_library().filter(self.actor_filter)中存放了27种车型 [0]为选择第一种车型
3 设置ros传输图片大小
/home/xu/carla-ros-bridge/catkin_ws/src/ros-bridge/carla_ego_vehicle/config 文件夹中 有sensors.json文件 在该文件中可以调整图片大小.
4 自定义车辆位置
在/home/xu/software/carla/CARLA_0.9.9.4/PythonAPI/examples/manual_control.py 文件中可以定义车辆位置;
spawn_points = self.map.get_spawn_points() # 从地图中获取可以选择的初始点;
spawn_point = random.choice(spawn_points) if spawn_points else carla.Transform() # 随机挑选
spawn_point.location.x = 54 # 手动给定具体的点
spawn_point.location.y = -190
spawn_point.rotation.yaw = 0
self.player = self.world.try_spawn_actor(blueprint, spawn_point) # 生成actor
四、QTcreater要配置ros
sudo gedit /usr/share/app-install/desktop/qtcreator:qtcreator.desktop
找到exuc 那行
改成
Exec=bash -i -c qtcreator %F