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

news2024/9/23 15:21:05

文章目录

  • 前言
  • 一、环境准备
      • 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 CarlaPainter

def do_something(data):
    pass


def 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 mode
        previous_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 vehicles
        spawn_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 vehicle
        blueprints_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 = None
            return

        other_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 actors
        ego_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 vehicle
        camera = 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 world
        world.tick()

        # save vehicles' trajectories to draw in the frontend
        trajectories = [[]]

        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 vehicle
            ego_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的安装及使用,确实是一个较只管的观测平台,如果能在基础上做控制的开发那就完美了。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2090582.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

数据库之心:MySQL 探索(一)mysql的安装和基本介绍

欢迎来到我们的MySQL博客!在这里,我们将深入探讨MySQL数据库系统的各个方面,包括基础知识、优化技巧、实践案例以及最新的行业趋势。 目录 前言 什么是数据库? 数据库产品 MySQL安装 解压 配置 添加环境变量 初始化MySQL …

计算机毕业设计PySpark+Scrapy高考推荐系统 高考志愿填报推荐系统 高考爬虫 协同过滤推荐算法 Vue.js Django Hadoop 大数据毕设

目  录 第1章 绪论 1.1 研究背景 1.2 国内外现状 1.2.1 国外研究现状 1.2.2 国内研究现状 1.3 主要研究内容 1.4 论文框架结构 第2章 相关开发技术与理论 2.1 前端技术 1.Vue框架技术 2.Element-Plus 2.2 后端技术 1&#xff0e…

linux下cpu多核运行程序以及运行时间统计

一、多核心运行程序 在linux下我们可以指定线程或者进程运行在指定的cpu核心上,操作方法如下: 1)运行进程指定cpu核心 taskset -c 2 ./app //-c指定运行的cpu核心号,从0计数,查看效果如下: 2&#xff09…

C++map容器中operator[ ]的实现原理

目录 一、operator[ ]函数介绍 二、insert函数介绍 三、operator[ ]函数实现原理 四、operator[ ]函数功能 一、operator[ ]函数介绍 mapped_type& operator[] (const key_type& k);在map容器中存储的是一个键值对value_type&#xff0c;其本质是pair<const key…

maya python调试(pycharm)

maya里面调试代码一直用的print。遇到复杂点的类就感觉有点束手束脚的&#xff0c;因此整理了一下maya调试的一些方法 1.万能的pdb调试 pdb 有2种用法 1.非侵入式方法 &#xff08;不用额外修改源代码&#xff0c;在命令行下直接运行就能调试&#xff09; 常规用法&#xf…

APP长文本内容编辑器功能实现方案

背景 CSDN APP 中原有编辑器页面为纯H5适配&#xff0c;整体用户交互体验差&#xff0c;如何优化APP端编辑器用户体验是我们团队需要思考的问题。下面我们以iOS为例展开讨论。 一、方案调研 我们分析了几款国内内容发布的APP&#xff0c;如知乎、今日头条、简书&#xff0c;…

有了它 一键掌握Vue新版本!

声明&#xff1a;此篇为 ai123.cn 原创文章&#xff0c;转载请标明出处链接&#xff1a;https://ai123.cn/#1 你是否也在为Vue生态中的快速更新而焦头烂额&#xff1f;ue 3.4版本发布&#xff0c;带来模板解析器重写和响应系统重构&#xff0c;提升了性能和开发体验。测试框架如…

《深入理解JAVA虚拟机(第2版)》- 第3章 - 学习笔记

第3章 垃圾收集器与内存分配策略 3.1 概述 垃圾收集器要完成三件事情&#xff1a; 什么样的内存需要回收什么时候回收如何回收 垃圾收集器主要关注的区域是&#xff1a;Java堆和方法区。因为程序计数器、虚拟机栈、本地方法栈是线程私有的&#xff0c;随着线程的结束所使用的…

2d椭圆拟合学习

算法来自论文《 Direct Least Square Fitting of Ellipses》 《NUMERICALLY STABLE DIRECT LEAST SQUARES FITTING OF ELLIPSES》 相关文章 论文阅读&#xff1a;直接拟合椭圆 Direct Least Square Fitting of Ellipseshttps://zhuanlan.zhihu.com/p/645391510Fitting Elli…

rsyslog交叉编译

文章目录 1、依赖库列表2、编译建议3、编译3.1、编译libestr3.2、编译libfastjson3.3、编译zlib3.4、编译libuuid3.5、编译libgpg-error3.6、编译libgcrypt3.7、编译openssl3.8、编译curl3.9、编译rsyslog该文档描述了如何交叉编译rsyslog到arm64嵌入式平台。 1、依赖库列表 li…

UE5开发——射击武器类拾取

整体框架&#xff1a; 拾取武器 要在 Unreal Engine 5 (UE5) 中实现一个按 E 键拾取武器的功能&#xff0c;您可以遵循以下步骤&#xff1a; ### 步骤 1: 创建拾取物品的基础类 1. 在 Content Browser 中创建一个新的 C 类&#xff0c;继承自 AActor 或者 AStaticMeshActor。…

pytorch交叉熵损失函数

nn.CrossEntropyLoss 是 PyTorch 中非常常用的损失函数,特别适用于分类任务。它结合了 nn.LogSoftmax 和 nn.NLLLoss(负对数似然损失)的功能,可以直接处理未经过 softmax 的 logits 输出,计算预测值与真实标签之间的交叉熵损失。 1. 交叉熵损失的原理 交叉熵损失衡量的是…

Visual Studio Code离线汉化

从官网下载Visual Studio Code安装包后&#xff0c; 下载Visual Studio Code&#xff1a;https://code.visualstudio.com/ 若因网络等问题无法在线安装语言包&#xff0c;可以尝试离线安装&#xff1a; 从官网下载语言包&#xff1a; Extensions for Visual Studio family …

线上考试系统部署(thirty-six day)

一、线上考试系统的数据 虚拟化技术部署 1、部署前端服务器 &#xff08;1&#xff09;将资源上传到服务器 scp -r dist/ root192.168.1.11:~ &#xff08;2&#xff09;创建基础容器 在服务器上 systemctl start docker.servicedocker pull centosdocker run -it --name …

基于RAG多层次的多代理架构来处理时序任务

《Agentic Retrieval-Augmented Generation for Time Series Analysis》这篇文章提出了一种新颖的时间序列分析方法&#xff0c;称为Agentic Retrieval-Augmented Generation&#xff08;RAG&#xff09;框架。它通过多层次的多代理架构来处理时间序列任务&#xff0c;其中主代…

【银河麒麟高级服务器操作系统】soft lockup软锁实例详细记录分析及处理建议

了解更多银河麒麟操作系统全新产品&#xff0c;请点击访问 麒麟软件产品专区&#xff1a;https://product.kylinos.cn 开发者专区&#xff1a;https://developer.kylinos.cn 文档中心&#xff1a;https://documentkylinos.cn 现象描述 启nginx服务&#xff0c;但是报了sof…

WebRTC协议下的视频汇聚融合技术:EasyCVR视频技术构建高效视频交互体验

视频汇聚融合技术是指将来自不同源、不同格式、不同网络环境的视频流进行集中处理、整合和展示的技术。随着视频监控、远程会议、在线教育、直播娱乐等领域的快速发展&#xff0c;视频数据的规模急剧增长&#xff0c;对视频处理能力和效率提出了更高要求。视频汇聚融合技术通过…

海外云手机实现海外社媒矩阵营销

如何利用社交媒体平台有效推广和带货&#xff0c;正成为众多企业和创业者关注的焦点。海外云手机解决各种网络和设备问题&#xff0c;成为跨境电商海外社媒矩阵建设的必备工具。 跨境电商的核心在于通过互联网连接不同国家的消费者与商品。社交媒体作为连接消费者与品牌的桥梁&…

vue nginx部署 配置 解决href = ‘/login路由‘ 跳转404问题

示例场景 <a :hrefthis.repDownloadUrl>下载平台</a><a href"/join" target"_blank">入驻平台</a><a href"/index" target"_blank" class"btn_login" style"color:#fff">nginx部署…

Datawhale X 李宏毅苹果书 AI夏令营 Task 2

课程内容 &#xff08;一&#xff09;术语解释 一 . Sigmoid函数与Hard Sigmoid 函数 &#xff08;1&#xff09;Sigmoid函数 Sigmoid函数&#xff0c;也称为逻辑函数&#xff08;Logistic function&#xff09;&#xff0c;是一种在数学、生物学、信息科学、神经网络等领域广…