Apollo远程启动车辆-命令控制

新建远程控制车辆插件

(1)执行下面命令,新建插件文件夹remote control command demo

代码:buildtool create --template component remote_control_command_demo

执行成功后,执行Is 命令可以看到当前目录下生成了remote control command demo文件夹,如下图所示;

查看目录结构:代码:tree remote_control_command_demo

生成的目录结构如下:

remote_control_command_demo

|-- BUILD

|-- conf

|   |-- remote_control_command_demo.conf             -----------加载全局参数的文件

|   `-- remote_control_command_demo.pb.txt           -----------proto的配置文件

|-- cyberfile.xml                                    -----------编译的加载文件

|-- dag

|   `-- remote_control_command_demo.dag              -----------启动的dag文件

|-- launch

|   `-- remote_control_command_demo.launch           -----------启动的launch文件

|-- proto

|   |-- BUILD                                        -----------proto的编译文件

|   `-- remote_control_command_demo.proto            -----------proto的定义文件

|-- remote_control_command_demo.cc                   -----------功能实现文件

`-- remote_control_command_demo.h                    -----------功能定义文件

(2)插件已就位,启动在线编辑器,此处略过~

(3)将下列文件中的代码copy至remote control command demo对应的文件中

remote control command demo.cc:

代码:

#include "remote_control_command_demo/remote_control_command_demo.h"

#include <poll.h>

#include <cctype>

#include "cyber/common/file.h"

#include "cyber/record/record_reader.h"

using apollo::external_command::CommandStatus;

RemoteCotrolCommandDemo::RemoteCotrolCommandDemo() : command_id_(0), module_name_("demo") {}

bool RemoteCotrolCommandDemo::Init() {

    action_command_client_

            = std::make_shared<apollo::common::ClientWrapper<apollo::external_command::ActionCommand, CommandStatus>>(

                    node_, "/apollo/external_command/action");

    free_space_command_client_ = std::make_shared<

            apollo::common::ClientWrapper<apollo::external_command::FreeSpaceCommand, CommandStatus>>(

            node_, "/apollo/external_command/free_space");

    lane_follow_command_client_ = std::make_shared<

            apollo::common::ClientWrapper<apollo::external_command::LaneFollowCommand, CommandStatus>>(

            node_, "/apollo/external_command/lane_follow");

    return true;

}

bool RemoteCotrolCommandDemo::Proc() {

    int8_t revent = 0;  // short

    struct pollfd fd = {STDIN_FILENO, POLLIN, revent};

    switch (poll(&fd, 1, 100)) {

    case -1:

        std::cout << "Failed to read keyboard" << std::endl;

        return false;

    case 0:

        return true;

    default:

        char data[50];

        std::cin.getline(data, 50);

        std::string input_command_string = data;

        if (input_command_string == "pull_over") {

            // Pull over.

            // SendActionCommand(

            //     apollo::external_command::ActionCommandType::PULL_OVER);

            auto command = std::make_shared<apollo::external_command::ActionCommand>();

            FillCommandHeader(command);

            command->set_command(apollo::external_command::ActionCommandType::PULL_OVER);

            std::cout << "Sending action command: " << command->DebugString() << std::endl;

            auto response = action_command_client_->SendRequest(command);

            if (nullptr == response) {

                std::cout << "Command sending failed, please check the service is on!\n" << std::endl;

            } else {

                std::cout << "******Finish sending command.******\n" << std::endl;

            }

            //

        } else if (input_command_string == "stop") {

            // Stop planning.

            // SendActionCommand(apollo::external_command::ActionCommandType::STOP);

            auto command = std::make_shared<apollo::external_command::ActionCommand>();

            FillCommandHeader(command);

            command->set_command(apollo::external_command::ActionCommandType::STOP);

            std::cout << "Sending action command: " << command->DebugString() << std::endl;

            auto response = action_command_client_->SendRequest(command);

            if (nullptr == response) {

                std::cout << "Command sending failed, please check the service is on!\n" << std::endl;

            } else {

                std::cout << "******Finish sending command.******\n" << std::endl;

            }

            //

        } else if (input_command_string == "start") {

            // Start planning.

            // SendActionCommand(apollo::external_command::ActionCommandType::START);

            auto command = std::make_shared<apollo::external_command::ActionCommand>();

            FillCommandHeader(command);

            command->set_command(apollo::external_command::ActionCommandType::START);

            std::cout << "Sending action command: " << command->DebugString() << std::endl;

            auto response = action_command_client_->SendRequest(command);

            if (nullptr == response) {

                std::cout << "Command sending failed, please check the service is on!\n" << std::endl;

            } else {

                std::cout << "******Finish sending command.******\n" << std::endl;

            }

            //

        } else if (input_command_string == "free1") {

            apollo::external_command::Pose end_pose;

            end_pose.set_x(437556.02);

            end_pose.set_y(4432540.34);

            end_pose.set_heading(1.8);

            std::vector<apollo::external_command::Point> way_points;

            apollo::external_command::Point point1;

            apollo::external_command::Point point2;

            apollo::external_command::Point point3;

            apollo::external_command::Point point4;

            point1.set_x(437536.29);

            point1.set_y(4432560.69);

            point2.set_x(437536.29);

            point2.set_y(4432510.69);

            point3.set_x(437576.29);

            point3.set_y(4432510.69);

            point4.set_x(437576.29);

            point4.set_y(4432560.69);

            way_points.emplace_back(point1);

            way_points.emplace_back(point2);

            way_points.emplace_back(point3);

            way_points.emplace_back(point4);

            SendFreespaceCommand(way_points, end_pose);

        } else {

            std::cout << "Invalid input!" << input_command_string << std::endl;

        }

    }

    return true;

}

void RemoteCotrolCommandDemo::SendFreespaceCommand(

        const std::vector<apollo::external_command::Point>& way_points,

        const apollo::external_command::Pose& end) {

    auto command = std::make_shared<apollo::external_command::FreeSpaceCommand>();

    FillCommandHeader(command);

    // Copy way_points

    auto roi_point = command->mutable_drivable_roi();

    for (const auto& point : way_points) {

        roi_point->add_point()->CopyFrom(point);

    }

    // Copy end point

    command->mutable_parking_spot_pose()->CopyFrom(end);

    std::cout << "Sending lane follow command: " << command->DebugString() << std::endl;

    auto response = free_space_command_client_->SendRequest(command);

    if (nullptr == response) {

        std::cout << "Command sending failed, please check the service is on!\n" << std::endl;

    } else {

        std::cout << "******Finish sending command.******\n" << std::endl;

    }

}

remote control command demo.h:

代码:

#pragma once

#include <memory>

#include <string>

#include <vector>

#include "modules/common_msgs/external_command_msgs/action_command.pb.h"

#include "modules/common_msgs/external_command_msgs/chassis_command.pb.h"

#include "modules/common_msgs/external_command_msgs/command_status.pb.h"

#include "modules/common_msgs/external_command_msgs/free_space_command.pb.h"

#include "modules/common_msgs/external_command_msgs/lane_follow_command.pb.h"

#include "modules/common_msgs/external_command_msgs/path_follow_command.pb.h"

#include "modules/common_msgs/external_command_msgs/speed_command.pb.h"

#include "modules/common_msgs/external_command_msgs/valet_parking_command.pb.h"

#include "modules/common_msgs/planning_msgs/planning.pb.h"

#include "cyber/component/timer_component.h"

#include "cyber/cyber.h"

#include "modules/common/service_wrapper/client_wrapper.h"

#include "modules/common/util/message_util.h"

class RemoteCotrolCommandDemo final : public apollo::cyber::TimerComponent {

public:

    RemoteCotrolCommandDemo();

    bool Init() override;

    bool Proc() override;

private:

    template <typename T>

    void FillCommandHeader(const std::shared_ptr<T>& command);

    void SendFreespaceCommand(

            const std::vector<apollo::external_command::Point>& way_points,

            const apollo::external_command::Pose& end);

    std::shared_ptr<apollo::common::ClientWrapper<

            apollo::external_command::ActionCommand,

            apollo::external_command::CommandStatus>>

            action_command_client_;

    std::shared_ptr<apollo::common::ClientWrapper<

            apollo::external_command::FreeSpaceCommand,

            apollo::external_command::CommandStatus>>

            free_space_command_client_;

    std::shared_ptr<apollo::common::ClientWrapper<

            apollo::external_command::LaneFollowCommand,

            apollo::external_command::CommandStatus>>

            lane_follow_command_client_;

    uint64_t command_id_;

    const std::string module_name_;

};

template <typename T>

void RemoteCotrolCommandDemo::FillCommandHeader(const std::shared_ptr<T>& command) {

    apollo::common::util::FillHeader(module_name_, command.get());

    command->set_command_id(++command_id_);

}

CYBER_REGISTER_COMPONENT(RemoteCotrolCommandDemo);

cyberfile.xml:

代码:

<package format="2">

    <name>external-command-demo</name>

    <version>local</version>

    <description> The package contains temp component for converting routing message to external command. </description>

    <maintainer email="apollo-support@baidu.com">Apollo</maintainer>

    <license>Apache License 2.0</license>

    <url type="website">https://www.apollo.auto/</url>

    <url type="repository">https://github.com/ApolloAuto/apollo</url>

    <url type="bugtracker">https://github.com/ApolloAuto/apollo/issues</url>

    <type>module</type>

    <src_path url="https://github.com/ApolloAuto/apollo">//remote_control_command_demo</src_path>

    <depend repo_name="com_github_gflags_gflags" lib_names="gflags">3rd-gflags</depend>

    <depend type="binary" repo_name="common" lib_names="common">common</depend>

    <depend repo_name="routing" type="binary">routing</depend>

</package>

BUILD:

代码:

load("//tools:cpplint.bzl", "cpplint")

load("//tools:apollo_package.bzl", "apollo_cc_binary", "apollo_cc_library", "apollo_cc_test", "apollo_component", "apollo_package")

package(default_visibility = ["//visibility:public"])

apollo_component(

    name = "libremote_control_command_demo_component.so",

    hdrs = ["remote_control_command_demo.h"],

    srcs = ["remote_control_command_demo.cc"],

    copts = ["-DMODULE_NAME=\\\"external_command_demo\\\""],

    deps = [

        "//cyber",

        "//modules/common/util:message_util",

        "//modules/common_msgs/external_command_msgs:command_status_cc_proto",

        "//modules/common_msgs/external_command_msgs:action_command_cc_proto",

        "//modules/common_msgs/external_command_msgs:chassis_command_cc_proto",

        "//modules/common_msgs/external_command_msgs:free_space_command_cc_proto",

        "//modules/common_msgs/external_command_msgs:lane_follow_command_cc_proto",

        "//modules/common_msgs/external_command_msgs:path_follow_command_cc_proto",

        "//modules/common_msgs/external_command_msgs:speed_command_cc_proto",

        "//modules/common_msgs/external_command_msgs:valet_parking_command_cc_proto",

        "//modules/common_msgs/planning_msgs:planning_cc_proto",

        "//modules/common/service_wrapper:client_wrapper",

    ],

)

filegroup(

    name = "conf",

    srcs = glob([

        "conf/*",

        "dag/*",

        "launch/*"

    ]),

)

cpplint()

apollo_package()

dag/remote control command demo.dag:

代码:

module_config {

  module_library : "remote_control_command_demo/libremote_control_command_demo_component.so"

  timer_components {

    class_name : "RemoteCotrolCommandDemo"

    config {

      name: "remote_control_command_demo_component"

      interval: 200 # milliseconds

    }

  }

}

launch/remote control command demo.launch:

代码:

<cyber>

  <module>

    <name>remote_control_command_demo</name>

    <dag_conf>remote_control_command_demo/dag/remote_control_command_demo.dag</dag_conf>

    <process_name>remote_control_command_demo</process_name>

  </module>

</cyber>

conf/remote control command demo.conf:

代码:

--flagfile=/apollo/modules/common/data/global_flagfile.txt

(4)代码文件拷贝完毕后,点击左上角保存代码文件;

(5)点击上一个网页链接,返回操作终端,

(6)执行下面指令,执行代码编译操作;

buildtool init

buildtool build -p remote_control_command_demo

(7)如下图所示,正常情况会编译成功;如果编译失败,请检查代码的替换内容是否正确(检查完毕后保存后,重新执行5编译操作指令即可);

启动远程控制车辆模块
(1)在终端中,执行下面命令启动远程控制车辆模块,执行成功后,如下图所示。

远程命令模块代码:

mainboard -d remote_control_command_demo/dag/remote_control_command_demo.dag

(2)执行成功后,如下图所示,此进程会被单独的挂起。

在新的终端中启动Dreamview,此步骤略过

发送远程控制指令
(1)点击DV左下角运行按钮,保证车辆沿着当前的轨迹线行驶,切换至远程控制终端,在终端输入"stop"指令,车辆会由“LANE FOLLOW”场景进入"EMERGENCY STOP”场景(如DV所示)车辆会在当前位置缓慢停止;

切换至DV界面,可以发现车辆已经执行急刹指令:

(2)继续在终端输入"start"指令,车辆会再次进入“LANE FOLLOW”场景,车辆会继续沿着当前的的routing线行驶,如下图DV界面所示;

(4)继续在终端输入"start"指令,车辆会由"PULL OVER”场景再次进入“LANE FOLLOW”场景,车辆会继续沿着当前的的routing线行驶;

(5)当我们向终端发送错误的指令时,例如"aaaa",系统无法识别指令,会提醒我们是无效的指令,对当前车辆的运行场景无影响(大胆的操作吧!)

  • 26
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Apollo Docker Quick Start Files是用于在Docker容器中快速启动Apollo配置中心的文件集合。Apollo配置中心是携程框架部门开发的分布式配置管理平台,用于实现配置集中管理和动态配置更新的需求。 使用Docker容器来快速启动Apollo配置中心可以提高开发和部署的效率,方便跨平台和环境的使用。Apollo Docker Quick Start Files包含了配置中心的相关配置文件、Dockerfile和启动脚本等,使用这些文件可以快速构建和启动配置中心的Docker容器。 在启动Docker容器之前,我们需要先配置好Apollo配置中心的相关信息,在配置文件中指定数据库、端口等参数。然后,使用Docker命令构建Docker镜像并生成Docker容器,通过运行启动脚本,让Docker容器启动并运行Apollo配置中心。 通过使用Apollo Docker Quick Start Files,可以方便地在各种环境中部署和启动Apollo配置中心,提高系统的可维护性和可扩展性。同时,通过Docker的特性,我们可以更好地管理和监控配置中心的运行状态,更灵活地进行配置的更新和维护。 总之,Apollo Docker Quick Start Files提供了一种便捷的方式来快速部署和启动Apollo配置中心,使得我们能够更加高效地管理和使用分布式配置,提高系统的稳定性和可靠性。 ### 回答2: Apollo是一个分布式配置中心,用于管理和配置分布式系统中的应用程序的配置信息。Docker是一种容器化平台,可以将应用程序打包成容器,并在不同的环境中快速部署和运行。 Apollo-Docker-Quick-Start-Files是一个用于快速开始使用Apollo和Docker的文件集合。它包含了一系列的配置文件和脚本,可以帮助用户快速搭建Apollo配置中心和使用Docker部署应用程序。 在这个文件集合中,用户可以找到一些配置文件示例,如application.properties和meta-server.properties,这些文件定义了Apollo的配置中心和元数据服务器的相关配置信息。用户可以根据自己的需要进行修改和定制。 此外,还有一些脚本文件,如docker-compose.yaml和Dockerfile。这些文件用于定义Docker容器的构建和部署规则。用户可以使用docker-compose命令,根据docker-compose.yaml文件一键启动Apollo配置中心和应用程序的Docker容器。 使用Apollo-Docker-Quick-Start-Files,用户可以轻松地搭建Apollo配置中心和部署应用程序。它提供了一种快捷的方式,帮助用户快速入门并使用Apollo和Docker进行分布式系统的配置和部署管理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值