Basic introduction and practice of Cyber RT_Hello Apollo

Enter the cloud experimental environment

Insert image description here
<1> Create the experimental project directory for this section. After creation, the project directory will look as follows:
cyber_demo
|-- cyber_01
|-- demo_main
| |-- BUILD
| |-- main.cc
|–BUILD
|–cyberfile.xml
| –cyber_demo.BUILD
Insert image description here

Modular


<2> Write the BUILD and cyberfile.xml files related to Apollo package management.

load("//tools/install:install.bzl", "install", "install_src_files")

install(
    name = "install",
    data = [
        "cyber_demo.BUILD",
        "cyberfile.xml",
    ],
    deps = [
        "//cyber_demo/cyber_01/demo_main:install",
    ],
)

install_src_files(
    name = "install_src",
    src_dir = ["."],
    dest = "cyber_demo/src",
    filter = "*",
    deps = [
        "//cyber_demo/cyber_01/demo_main:install_src",
    ]
)

The install rule can install the target defined in the module BUILD file to the local warehouse;
the install_src rule directly installs the file to the local warehouse according to specific rules and retains the source code directory structure;
cyberfile.xml is a module description file, used to describe a module made into software Package related information, such as package name, version number, and dependent software packages. The content of cyberfile.xml in this example is as follows:

cyberfile.xml

<package>
  <name>cyber_demo</name>
  <version>1.0.0</version>
  <description>
   cyber_demo
  </description>
  <maintainer email="AD-platform">AD-platform@baidu.com</maintainer>
  <type>module</type>
  <src_path>//cyber_demo</src_path>
  <license>BSD</license>
  <author>Apollo</author>
  <depend type="binary"  repo_name="cyber">cyber-dev</depend>
  <builder>bazel</builder>
</package>

Packaged within the module

<3> Write source files and BUILD files;
output the "hello Apollo" content through main.cc.

main.cc

#include<cyber/cyber.h>

int main(int argc, char const *argv[])
{
    
    
    apollo::cyber::Init(argv[0]);
    AINFO << "hello Apollo";
    AWARN << "hello Apollo";
    AERROR << "hello Apollo";
    AFATAL << "hello Apollo";
    return 0;
}

After writing the source file main.cc, you can instantiate Bazel's built-in cc_binary rule to build the source file main.cc into an independent executable binary file. The content of the BUILD file is as follows
BUILD

load("//tools/install:install.bzl", "install", "install_src_files")

install(
    name = "install",
    data = [
        "cyber_demo.BUILD",
        "cyberfile.xml",
    ],
    deps = [
        "//cyber_demo/cyber_01/demo_main:install",
    ],
)

install_src_files(
    name = "install_src",
    src_dir = ["."],
    dest = "cyber_demo/src",
    filter = "*",
    deps = [
        "//cyber_demo/cyber_01/demo_main:install_src",
    ]
)

<4> Compile code directory
Execute buildtool compilation instructions in the apollo_workspace directory

After buildtool build -p cyber_demo
is compiled, the system will generate the executable file main in the /opt/apollo/neo/bin directory, as shown in the figure below: In
Insert image description here
order to be able to see the results, use the following command to print the output results to the window, command As follows:
export GLOG_alsologtostderr=1
<5> Run the executable file.
In the /opt/apollo/neo/bin directory, execute the following command:
./main
After the execution is completed, you can see that the command line window prints "hello Apollo" content.

Insert image description here

Guess you like

Origin blog.csdn.net/qq_42817360/article/details/132726407