Carla自动驾驶仿真十:Carlaviz三维可视化平台搭建

2024-08-31 07:52

本文主要是介绍Carla自动驾驶仿真十:Carlaviz三维可视化平台搭建,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

  • 前言
  • 一、环境准备
      • 1、docker安装
      • 2、websocket-client安装
      • 3、carlaviz代码下载
  • 二、carlaviz使用
      • 1、打开carla客户端
      • 2、输入启动命令
      • 3、进入carlaviz
      • 4、修改manual_control.py脚本
      • 5、运行manual_control.py脚本
      • 6、运行carlaviz官方脚本(推荐)


前言

Carlaviz是一个开源的可视化工具,主要用于Carla三维场景、传感器数据以及自车数据的可视化,能够作为观测平台使用,本文主要介绍Carlaviz的安装以及基本使用;


一、环境准备

1、docker安装

1)根据所属环境下载对应的docker,然后直接安装即可

点击进入docker官网下载

2、websocket-client安装

1)进入终端输入:pip3 install websocket_client

3、carlaviz代码下载

carlaviz github链接

1)打开终端输入 docker pull mjxu96/carlaviz:0.9.14,请下载与自己carla版本一致的carlaviz,只需修改后面的版本号,如下载0.9.15版本的carlaviz:

在这里插入图片描述

二、carlaviz使用

1、打开carla客户端

在这里插入图片描述

2、输入启动命令

1)windows
终端输入:docker run -it -p 8080-8081:8080-8081 mjxu96/carlaviz:0.9.14 --simulator_host host.docker.internal --simulator_port 2000,注意carla的版本号一定要对上;

2)linux
终端输入:docker run -it --network="host" mjxu96/carlaviz:0.9.14 --simulator_host localhost --simulator_port 2000,注意carla的版本号一定要对上‘

windows输入启动命令后结果:
在这里插入图片描述

3、进入carlaviz

1)打开浏览器输入http://localhost:8080/,或者从docker软件进入,进入carlaviz如下图所示,能够正确加载到路网相关信息,此时没有ego信息以及摄像头画面是正常的,是因为需要启动python脚本生成车辆以及摄像头;

在这里插入图片描述

4、修改manual_control.py脚本

1、启动前需要将manual_control.py中主车的名称改成ego
在这里插入图片描述

5、运行manual_control.py脚本

1)运行脚本后正确接收到主车信息,摄像头画面等信息;

在这里插入图片描述

6、运行carlaviz官方脚本(推荐)

1)我们也可以运行官方脚本,有激光雷达点云信息;

import carla
import random
import time
# from carla_painter import CarlaPainterdef do_something(data):passdef main():try:# initialize one painter# painter = CarlaPainter('localhost', 8089)client = carla.Client('localhost', 2000)client.set_timeout(10.0)world = client.get_world()for blue_print in world.get_blueprint_library():if blue_print.id.startswith("sensor"):print(blue_print)# set synchronous modeprevious_settings = world.get_settings()world.apply_settings(carla.WorldSettings(synchronous_mode=True,fixed_delta_seconds=1.0 / 30.0))# randomly spawn an ego vehicle and several other vehiclesspawn_points = world.get_map().get_spawn_points()blueprints_vehicles = world.get_blueprint_library().filter("vehicle.*")ego_transform = spawn_points[random.randint(0, len(spawn_points) - 1)]other_vehicles_transforms = []for _ in range(3):other_vehicles_transforms.append(spawn_points[random.randint(0, len(spawn_points) - 1)])blueprints_vehicles = [x for x in blueprints_vehicles if int(x.get_attribute('number_of_wheels')) == 4]# set ego vehicle's role name to let CarlaViz know this vehicle is the ego vehicleblueprints_vehicles[0].set_attribute('role_name', 'ego') # or set to 'hero'batch = [carla.command.SpawnActor(blueprints_vehicles[0], ego_transform).then(carla.command.SetAutopilot(carla.command.FutureActor, True))]results = client.apply_batch_sync(batch, True)if not results[0].error:ego_vehicle = world.get_actor(results[0].actor_id)else:print('spawn ego error, exit')ego_vehicle = Nonereturnother_vehicles = []batch = []for i in range(3):batch.append(carla.command.SpawnActor(blueprints_vehicles[i + 1], other_vehicles_transforms[i]).then(carla.command.SetAutopilot(carla.command.FutureActor, True)))# set autopilot for all these actorsego_vehicle.set_autopilot(True)results = client.apply_batch_sync(batch, True)for result in results:if not result.error:other_vehicles.append(result.actor_id)# attach a camera and a lidar to the ego vehiclecamera = None# blueprint_camera = world.get_blueprint_library().find('sensor.camera.rgb')blueprint_camera = world.get_blueprint_library().find('sensor.camera.instance_segmentation')# blueprint_camera = world.get_blueprint_library().find('sensor.camera.depth')blueprint_camera.set_attribute('image_size_x', '640')blueprint_camera.set_attribute('image_size_y', '480')blueprint_camera.set_attribute('fov', '110')blueprint_camera.set_attribute('sensor_tick', '0.1')transform_camera = carla.Transform(carla.Location(y=+3.0, z=5.0))camera = world.spawn_actor(blueprint_camera, transform_camera, attach_to=ego_vehicle)camera.listen(lambda data: do_something(data))lidar = None# blueprint_lidar = world.get_blueprint_library().find('sensor.lidar.ray_cast')blueprint_lidar = world.get_blueprint_library().find('sensor.lidar.ray_cast_semantic')blueprint_lidar.set_attribute('range', '30')blueprint_lidar.set_attribute('rotation_frequency', '10')blueprint_lidar.set_attribute('channels', '32')blueprint_lidar.set_attribute('lower_fov', '-30')blueprint_lidar.set_attribute('upper_fov', '30')blueprint_lidar.set_attribute('points_per_second', '56000')transform_lidar = carla.Transform(carla.Location(x=0.0, z=5.0))lidar = world.spawn_actor(blueprint_lidar, transform_lidar, attach_to=ego_vehicle)lidar.listen(lambda data: do_something(data))# tick to generate these actors in the game worldworld.tick()# save vehicles' trajectories to draw in the frontendtrajectories = [[]]while (True):world.tick()ego_location = ego_vehicle.get_location()trajectories[0].append([ego_location.x, ego_location.y, ego_location.z])# draw trajectories# painter.draw_polylines(trajectories)# draw ego vehicle's velocity just above the ego vehicleego_velocity = ego_vehicle.get_velocity()velocity_str = "{:.2f}, ".format(ego_velocity.x) + "{:.2f}".format(ego_velocity.y) \+ ", {:.2f}".format(ego_velocity.z)# painter.draw_texts([velocity_str],#             [[ego_location.x, ego_location.y, ego_location.z + 10.0]], size=20)time.sleep(0.05)finally:if previous_settings is not None:world.apply_settings(previous_settings)if lidar is not None:lidar.stop()lidar.destroy()if camera is not None:camera.stop()camera.destroy()if ego_vehicle is not None:ego_vehicle.destroy()if other_vehicles is not None:client.apply_batch([carla.command.DestroyActor(x) for x in other_vehicles])if __name__ == "__main__":

在这里插入图片描述

综上,完成carlaviz的安装及使用,确实是一个较只管的观测平台,如果能在基础上做控制的开发那就完美了。

这篇关于Carla自动驾驶仿真十:Carlaviz三维可视化平台搭建的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1123318

相关文章

SpringBoot中封装Cors自动配置方式

《SpringBoot中封装Cors自动配置方式》:本文主要介绍SpringBoot中封装Cors自动配置方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录SpringBoot封装Cors自动配置背景实现步骤1. 创建 GlobalCorsProperties

idea中创建新类时自动添加注释的实现

《idea中创建新类时自动添加注释的实现》在每次使用idea创建一个新类时,过了一段时间发现看不懂这个类是用来干嘛的,为了解决这个问题,我们可以设置在创建一个新类时自动添加注释,帮助我们理解这个类的用... 目录前言:详细操作:步骤一:点击上方的 文件(File),点击&nbmyHIgsp;设置(Setti

Python Dash框架在数据可视化仪表板中的应用与实践记录

《PythonDash框架在数据可视化仪表板中的应用与实践记录》Python的PlotlyDash库提供了一种简便且强大的方式来构建和展示互动式数据仪表板,本篇文章将深入探讨如何使用Dash设计一... 目录python Dash框架在数据可视化仪表板中的应用与实践1. 什么是Plotly Dash?1.1

一文详解SQL Server如何跟踪自动统计信息更新

《一文详解SQLServer如何跟踪自动统计信息更新》SQLServer数据库中,我们都清楚统计信息对于优化器来说非常重要,所以本文就来和大家简单聊一聊SQLServer如何跟踪自动统计信息更新吧... SQL Server数据库中,我们都清楚统计信息对于优化器来说非常重要。一般情况下,我们会开启"自动更新

使用Folium在Python中进行地图可视化的操作指南

《使用Folium在Python中进行地图可视化的操作指南》在数据分析和可视化领域,地图可视化是一项非常重要的技能,它能够帮助我们更直观地理解和展示地理空间数据,Folium是一个基于Python的地... 目录引言一、Folium简介与安装1. Folium简介2. 安装Folium二、基础使用1. 创建

Flask 验证码自动生成的实现示例

《Flask验证码自动生成的实现示例》本文主要介绍了Flask验证码自动生成的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习... 目录生成图片以及结果处理验证码蓝图html页面展示想必验证码大家都有所了解,但是可以自己定义图片验证码

基于Python开发PDF转PNG的可视化工具

《基于Python开发PDF转PNG的可视化工具》在数字文档处理领域,PDF到图像格式的转换是常见需求,本文介绍如何利用Python的PyMuPDF库和Tkinter框架开发一个带图形界面的PDF转P... 目录一、引言二、功能特性三、技术架构1. 技术栈组成2. 系统架构javascript设计3.效果图

使用DeepSeek搭建个人知识库(在笔记本电脑上)

《使用DeepSeek搭建个人知识库(在笔记本电脑上)》本文介绍了如何在笔记本电脑上使用DeepSeek和开源工具搭建个人知识库,通过安装DeepSeek和RAGFlow,并使用CherryStudi... 目录部署环境软件清单安装DeepSeek安装Cherry Studio安装RAGFlow设置知识库总

Python Excel实现自动添加编号

《PythonExcel实现自动添加编号》这篇文章主要为大家详细介绍了如何使用Python在Excel中实现自动添加编号效果,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1、背景介绍2、库的安装3、核心代码4、完整代码1、背景介绍简单的说,就是在Excel中有一列h=会有重复

Linux搭建Mysql主从同步的教程

《Linux搭建Mysql主从同步的教程》:本文主要介绍Linux搭建Mysql主从同步的教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux搭建mysql主从同步1.启动mysql服务2.修改Mysql主库配置文件/etc/my.cnf3.重启主库my