提交 bb1e3a06 编写于 作者: A Aaron Xiao 提交者: Jiangtao Hu

Monitor: Add system monitor process.

上级 b0e524a6
......@@ -81,7 +81,6 @@ cc_library(
"//modules/common/monitor/proto:monitor_proto",
"//modules/common/proto:gnss_status_proto",
"//modules/control/proto:control_proto",
"//modules/dreamview/proto:hmi_status_proto",
"//modules/drivers/gnss/proto:ins_proto",
"//modules/drivers/proto:sensor_proto",
"//modules/hmi/proto:hmi_message_proto",
......@@ -89,6 +88,7 @@ cc_library(
"//modules/localization/proto:imu_proto",
"//modules/localization/proto:localization_proto",
"//modules/map/proto:map_proto",
"//modules/monitor/proto:system_status_proto",
"//modules/perception/proto:perception_proto",
"//modules/planning/proto:planning_proto",
"//modules/prediction/proto:prediction_proto",
......
......@@ -52,9 +52,10 @@ DEFINE_string(ins_status_topic, "/apollo/sensor/gnss/ins_status",
"ins status topic name");
DEFINE_string(gnss_status_topic, "/apollo/sensor/gnss/gnss_status",
"gnss status topic name");
DEFINE_string(system_status_topic, "/apollo/monitor/system_status",
"System status topic name");
DEFINE_string(hmi_command_topic, "/apollo/hmi_command",
"HMI command topic name");
DEFINE_string(hmi_status_topic, "/apollo/hmi_status", "HMI status topic name");
DEFINE_string(mobileye_topic, "/apollo/sensor/mobileye", "mobileye topic name");
DEFINE_string(delphi_esr_topic, "/apollo/sensor/delphi_esr",
"delphi esr radar topic name");
......
......@@ -40,9 +40,9 @@ DECLARE_string(relative_odometry_topic);
DECLARE_string(ins_stat_topic);
DECLARE_string(ins_status_topic);
DECLARE_string(gnss_status_topic);
DECLARE_string(system_status_topic);
// TODO(xiaoxq): Retire hmi_command topic after integration with dreamview.
DECLARE_string(hmi_command_topic);
DECLARE_string(hmi_status_topic);
DECLARE_string(mobileye_topic);
DECLARE_string(delphi_esr_topic);
DECLARE_string(compressed_image_topic);
......
......@@ -132,12 +132,16 @@ void AdapterManager::Init(const AdapterManagerConfig &configs) {
config.message_history_limit());
break;
case AdapterConfig::INS_STATUS:
EnableInsStat(FLAGS_ins_status_topic, config.mode(),
config.message_history_limit());
EnableInsStatus(FLAGS_ins_status_topic, config.mode(),
config.message_history_limit());
break;
case AdapterConfig::GNSS_STATUS:
EnableInsStat(FLAGS_gnss_status_topic, config.mode(),
config.message_history_limit());
EnableGnssStatus(FLAGS_gnss_status_topic, config.mode(),
config.message_history_limit());
break;
case AdapterConfig::SYSTEM_STATUS:
EnableSystemStatus(FLAGS_system_status_topic, config.mode(),
config.message_history_limit());
break;
case AdapterConfig::HMI_COMMAND:
EnableHMICommand(FLAGS_hmi_command_topic, config.mode(),
......@@ -155,10 +159,6 @@ void AdapterManager::Init(const AdapterManagerConfig &configs) {
EnableCompressedImage(FLAGS_compressed_image_topic, config.mode(),
config.message_history_limit());
break;
case AdapterConfig::HMI_STATUS:
EnableHMIStatus(FLAGS_hmi_status_topic, config.mode(),
config.message_history_limit());
break;
default:
AERROR << "Unknown adapter config type!";
break;
......
......@@ -245,9 +245,9 @@ class AdapterManager {
REGISTER_ADAPTER(InsStat);
REGISTER_ADAPTER(InsStatus);
REGISTER_ADAPTER(GnssStatus);
REGISTER_ADAPTER(SystemStatus);
// TODO(xiaoxq): Retire HMICommand adapter after integration with dreamview.
REGISTER_ADAPTER(HMICommand);
REGISTER_ADAPTER(HMIStatus);
REGISTER_ADAPTER(Mobileye);
REGISTER_ADAPTER(DelphiESR);
REGISTER_ADAPTER(CompressedImage);
......
......@@ -25,7 +25,6 @@
#include "modules/common/proto/gnss_status.pb.h"
#include "modules/control/proto/control_cmd.pb.h"
#include "modules/control/proto/pad_msg.pb.h"
#include "modules/dreamview/proto/hmi_status.pb.h"
#include "modules/drivers/gnss/proto/ins.pb.h"
#include "modules/drivers/proto/delphi_esr.pb.h"
#include "modules/drivers/proto/mobileye.pb.h"
......@@ -33,6 +32,7 @@
#include "modules/localization/proto/gps.pb.h"
#include "modules/localization/proto/imu.pb.h"
#include "modules/localization/proto/localization.pb.h"
#include "modules/monitor/proto/system_status.pb.h"
#include "modules/perception/proto/perception_obstacle.pb.h"
#include "modules/perception/proto/traffic_light_detection.pb.h"
#include "modules/planning/proto/planning.pb.h"
......@@ -71,9 +71,9 @@ using RelativeOdometryAdapter =
using InsStatAdapter = Adapter<drivers::gnss::InsStat>;
using InsStatusAdapter = Adapter<gnss_status::InsStatus>;
using GnssStatusAdapter = Adapter<gnss_status::GnssStatus>;
using SystemStatusAdapter = Adapter<apollo::monitor::SystemStatus>;
// TODO(xiaoxq): Retire HMICommandAdapter after integration with dreamview.
using HMICommandAdapter = Adapter<hmi::HMICommand>;
using HMIStatusAdapter = Adapter<dreamview::HMIStatus>;
using MobileyeAdapter = Adapter<drivers::Mobileye>;
using DelphiESRAdapter = Adapter<drivers::DelphiESR>;
using CompressedImageAdapter = Adapter<sensor_msgs::CompressedImage>;
......
......@@ -29,7 +29,7 @@ message AdapterConfig {
MOBILEYE = 21;
DELPHIESR = 22;
COMPRESSED_IMAGE = 23;
HMI_STATUS = 24;
SYSTEM_STATUS = 24;
INS_STATUS = 25;
GNSS_STATUS = 26;
}
......
load("//tools:cpplint.bzl", "cpplint")
package(default_visibility = ["//visibility:public"])
cc_library(
name = "monitor_lib",
srcs = ["monitor.cc"],
hdrs = ["monitor.h"],
deps = [
"//modules/common:apollo_app",
"//modules/common/adapters:adapter_manager",
"//modules/monitor/common:recurrent_runner",
"//modules/monitor/hardware/can:can_monitor",
"//modules/monitor/hardware/gps:gps_monitor",
"//modules/monitor/proto:system_status_proto",
],
)
cc_binary(
name = "monitor",
srcs = ["main.cc"],
deps = [
":monitor_lib",
],
)
cpplint()
......@@ -14,9 +14,9 @@ cc_library(
)
cc_library(
name = "monitor",
srcs = ["monitor.cc"],
hdrs = ["monitor.h"],
name = "monitor_interface",
srcs = ["monitor_interface.cc"],
hdrs = ["monitor_interface.h"],
deps = [
":recurrent_runner",
"//modules/monitor/proto:system_status_proto",
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*****************************************************************************/
#include "modules/monitor/common/monitor.h"
#include "modules/monitor/common/monitor_interface.h"
namespace apollo {
namespace monitor {
......
......@@ -14,8 +14,8 @@
* limitations under the License.
*****************************************************************************/
#ifndef MODULES_MONITOR_COMMON_MONITOR_H_
#define MODULES_MONITOR_COMMON_MONITOR_H_
#ifndef MODULES_MONITOR_COMMON_MONITOR_INTERFACE_H_
#define MODULES_MONITOR_COMMON_MONITOR_INTERFACE_H_
#include <string>
......@@ -50,4 +50,4 @@ class ModuleMonitor : public RecurrentRunner {
} // namespace monitor
} // namespace apollo
#endif // MODULES_MONITOR_COMMON_MONITOR_H_
#endif // MODULES_MONITOR_COMMON_MONITOR_INTERFACE_H_
......@@ -24,7 +24,7 @@
namespace apollo {
namespace monitor {
namespace time = apollo::common::time;
using apollo::common::time::Clock;
RecurrentRunner::RecurrentRunner(const std::string &name,
const double interval)
......@@ -50,6 +50,7 @@ void RecurrentRunnerThread::RegisterRunner(
}
void RecurrentRunnerThread::Start() {
CHECK(!thread_) << "Thread has already started.";
thread_.reset(new std::thread([this]() {
while (true) {
{
......@@ -61,7 +62,7 @@ void RecurrentRunnerThread::Start() {
}
// Tick runners.
const double current_time = time::ToSecond(time::Clock::Now());
const double current_time = Clock::NowInSecond();
for (auto &runner : runners_) {
runner->Tick(current_time);
}
......@@ -72,6 +73,7 @@ void RecurrentRunnerThread::Start() {
}
void RecurrentRunnerThread::Stop() {
CHECK(thread_) << "Thread has already stopped.";
{
std::lock_guard<std::mutex> guard(stop_mutex_);
stop_ = true;
......
......@@ -36,8 +36,12 @@ class RecurrentRunner {
public:
RecurrentRunner(const std::string &name, const double interval);
virtual ~RecurrentRunner() = default;
// Tick once, which may or may not execute the RunOnce() function, based on
// the interval setting.
void Tick(const double current_time);
// Do the actual work.
virtual void RunOnce(const double current_time) = 0;
protected:
......@@ -53,13 +57,16 @@ class RecurrentRunnerThread {
explicit RecurrentRunnerThread(const double interval);
void RegisterRunner(std::unique_ptr<RecurrentRunner> runner);
// Start the thread of ticking all registered runners.
void Start();
// Stop the ticking thread.
void Stop();
private:
int64_t interval_ms_;
std::vector<std::unique_ptr<RecurrentRunner>> runners_;
std::unique_ptr<std::thread> thread_;
std::unique_ptr<std::thread> thread_ = nullptr;
bool stop_ = false;
std::mutex stop_mutex_;
......
package(default_visibility = ["//visibility:public"])
filegroup(
name = "monitor_adapter_manager_config",
srcs = ["adapter.conf"],
)
config {
type: GNSS_STATUS
mode: RECEIVE_ONLY
message_history_limit: 1
}
config {
type: INS_STATUS
mode: RECEIVE_ONLY
message_history_limit: 1
}
config {
type: SYSTEM_STATUS
mode: PUBLISH_ONLY
message_history_limit: 1
}
is_ros: true
......@@ -30,7 +30,7 @@ cc_library(
"//modules/canbus/proto:canbus_proto",
"//modules/canbus/common:canbus_common",
"//modules/common/util:util",
"//modules/monitor/common:monitor",
"//modules/monitor/common:monitor_interface",
],
)
......
......@@ -22,11 +22,19 @@
#include "modules/common/util/file.h"
#include "modules/monitor/hardware/can/can_checker_factory.h"
DEFINE_string(can_monitor_name, "CAN", "Name of the CAN monitor.");
DEFINE_double(can_monitor_interval, 3, "CAN status checking interval (s).");
namespace apollo {
namespace monitor {
using apollo::canbus::CanbusConf;
CanMonitor::CanMonitor(SystemStatus *system_status)
: HardwareMonitor(FLAGS_can_monitor_name, FLAGS_can_monitor_interval,
system_status) {
}
void CanMonitor::RunOnce(const double current_time) {
CanbusConf canbus_conf;
......
......@@ -16,15 +16,17 @@
#ifndef MODULES_MONITOR_HARDWARE_CAN_CAN_MONITOR_H_
#define MODULES_MONITOR_HARDWARE_CAN_CAN_MONITOR_H_
#include <string>
#include <vector>
#include "modules/monitor/common/monitor.h"
#include "modules/monitor/common/monitor_interface.h"
namespace apollo {
namespace monitor {
class CanMonitor : public HardwareMonitor {
public:
explicit CanMonitor(SystemStatus *system_status);
void RunOnce(const double current_time) override;
};
......
......@@ -9,7 +9,7 @@ cc_library(
deps = [
"//modules/common:log",
"//modules/common/adapters:adapter_manager",
"//modules/monitor/common:monitor",
"//modules/monitor/common:monitor_interface",
],
)
......
......@@ -19,12 +19,20 @@
#include "modules/common/adapters/adapter_manager.h"
#include "modules/common/log.h"
DEFINE_string(gps_monitor_name, "GPS", "Name of the GPS monitor.");
DEFINE_double(gps_monitor_interval, 3, "GPS status checking interval (s).");
namespace apollo {
namespace monitor {
using apollo::common::adapter::AdapterManager;
using apollo::common::gnss_status::InsStatus;
GpsMonitor::GpsMonitor(SystemStatus *system_status)
: HardwareMonitor(FLAGS_gps_monitor_name, FLAGS_gps_monitor_interval,
system_status) {
}
void GpsMonitor::RunOnce(const double current_time) {
// Check Gnss status.
auto *gnss_status_adapter = CHECK_NOTNULL(AdapterManager::GetGnssStatus());
......
......@@ -16,9 +16,10 @@
#ifndef MODULES_MONITOR_HARDWARE_GPS_GPS_MONITOR_H_
#define MODULES_MONITOR_HARDWARE_GPS_GPS_MONITOR_H_
#include <string>
#include <vector>
#include "modules/monitor/common/monitor.h"
#include "modules/monitor/common/monitor_interface.h"
namespace apollo {
namespace monitor {
......@@ -26,6 +27,7 @@ namespace monitor {
// AdapterManager is required to listen to ins_status and gnss_status.
class GpsMonitor : public HardwareMonitor {
public:
explicit GpsMonitor(SystemStatus *system_status);
void RunOnce(const double current_time) override;
};
......
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/monitor/monitor.h"
APOLLO_MAIN(apollo::monitor::Monitor);
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/common/adapters/adapter_manager.h"
#include "modules/monitor/hardware/can/can_monitor.h"
#include "modules/monitor/hardware/gps/gps_monitor.h"
#include "modules/monitor/monitor.h"
DEFINE_string(monitor_adapter_config_filename,
"modules/monitor/conf/adapter.conf",
"Directory which contains a group of related maps.");
DEFINE_double(monitor_running_interval, 0.5, "Monitor running interval.");
namespace apollo {
namespace monitor {
namespace {
using apollo::common::Status;
using apollo::common::adapter::AdapterManager;
using apollo::common::util::make_unique;
// A runner which monitors if the system status has changed.
class StatusChangeMonitor : public RecurrentRunner {
public:
// Set internal to 0, so it runs every time when ticking.
explicit StatusChangeMonitor(SystemStatus *system_status)
: RecurrentRunner("SystemStatusMonitor", 0)
, system_status_(system_status) {
}
// Publish the new system status if it changed.
void RunOnce(const double current_time) override {
static std::hash<std::string> hash_fn;
const size_t new_fp = hash_fn(system_status_->ShortDebugString());
if (system_status_fp_ != new_fp) {
AdapterManager::FillSystemStatusHeader(name_, system_status_);
AdapterManager::PublishSystemStatus(*system_status_);
system_status_fp_ = new_fp;
ADEBUG << "Published system status: " << system_status_->DebugString();
}
}
private:
SystemStatus *system_status_;
size_t system_status_fp_ = 0;
};
} // namespace
Monitor::Monitor()
: monitor_thread_(FLAGS_monitor_running_interval) {
}
Status Monitor::Init() {
AdapterManager::Init(FLAGS_monitor_adapter_config_filename);
// Check the expected adapters are initialized.
CHECK(AdapterManager::GetGnssStatus()) <<
"GnssStatusAdapter is not initialized.";
CHECK(AdapterManager::GetInsStatus()) <<
"InsStatusAdapter is not initialized.";
CHECK(AdapterManager::GetSystemStatus()) <<
"SystemStatusAdapter is not initialized.";
monitor_thread_.RegisterRunner(make_unique<CanMonitor>(&system_status_));
monitor_thread_.RegisterRunner(make_unique<GpsMonitor>(&system_status_));
// Register the StatusChangeMonitor as last runner, so it will monitor all
// changes made by the previous runners.
monitor_thread_.RegisterRunner(
make_unique<StatusChangeMonitor>(&system_status_));
return Status::OK();
}
Status Monitor::Start() {
monitor_thread_.Start();
return Status::OK();
}
void Monitor::Stop() {
monitor_thread_.Stop();
}
} // namespace monitor
} // namespace apollo
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#ifndef MODULES_MONITOR_MONITOR_H_
#define MODULES_MONITOR_MONITOR_H_
#include <memory>
#include <string>
#include "modules/common/apollo_app.h"
#include "modules/monitor/common/recurrent_runner.h"
#include "modules/monitor/proto/system_status.pb.h"
/**
* @namespace apollo::monitor
* @brief apollo::monitor
*/
namespace apollo {
namespace monitor {
class Monitor : public apollo::common::ApolloApp {
public:
Monitor();
std::string Name() const override { return "SystemMonitor"; }
apollo::common::Status Init() override;
apollo::common::Status Start() override;
void Stop() override;
private:
RecurrentRunnerThread monitor_thread_;
SystemStatus system_status_;
};
} // namespace monitor
} // namespace apollo
#endif // MODULES_MONITOR_MONITOR_H_
......@@ -12,6 +12,9 @@ cc_proto_library(
proto_library(
name = "system_status_proto_lib",
srcs = ["system_status.proto"],
deps = [
"//modules/common/proto:header_proto_lib",
],
)
cpplint()
......@@ -2,6 +2,8 @@ syntax = "proto2";
package apollo.monitor;
import "modules/common/proto/header.proto";
message HardwareStatus {
enum Status {
OK = 0;
......@@ -32,6 +34,7 @@ message ModuleStatus {
}
message SystemStatus {
map<string, ModuleStatus> modules = 1;
map<string, HardwareStatus> hardware = 2;
optional apollo.common.Header header = 1;
map<string, ModuleStatus> modules = 2;
map<string, HardwareStatus> hardware = 3;
}
#!/usr/bin/env bash
###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "${DIR}/apollo_base.sh"
# run function from apollo_base.sh
# run command_name module_name
run monitor "$@"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册