栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

apollo学习之---Cyber RT下Python代码的创建及编译

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

apollo学习之---Cyber RT下Python代码的创建及编译

Cyber RT Python API : An Example

This document is an example demonstrating how to use Cyber RT Python API
to write your own Python3 programs. Please make sure you have built Apollo
successfully.

Step 1: Write your own code.

Save it as, say, path/to/my_demo.py.

#!/usr/bin/env python3

import sys

from cyber.python.cyber_py3 import cyber


cyber.init()

if not cyber.ok():
    print('Well, something went wrong.')
    sys.exit(1)

# Do your job here.
cyber.shutdown()
Step 2: Write Python rule for Bazel to build

Edit path/to/BUILD file, add the followng section:

load("@rules_python//python:defs.bzl", "py_binary")

# blablahblah...

# Add your own section here
py_binary(
    name = "my_demo",
    srcs = ["my_demo.py"],
    deps = [
        "//cyber/python/cyber_py3:cyber",
    ],
)

Note: Like C++, Python code is also managed by Bazel starting from Apollo 6.0.
Please refer to How to Build and Run Python Apps in Apollo for more on that.

Step 3: Build and run the demo program

Now you can run the following commands to build and run the demo program.

bazel build //path/to:my_demo
./bazel-bin/path/to/my_demo

Or simply run

bazel run //path/to:my_demo
More Examples …

Learn more Cyber RT Python examples under the examples and
tests directory.

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/360599.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号