ASCO Aerial Autonomy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
system_status_publisher.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <ros/ros.h>
4 
5 // Html utils
7 // Base Robot system
9 
14 template <class LogicStateMachineT> class SystemStatusPublisher {
15 public:
22  SystemStatusPublisher(ros::NodeHandle &nh,
23  const BaseRobotSystem &robot_system,
24  LogicStateMachineT &logic_state_machine)
25  : nh_(nh),
26  system_status_pub_(nh.advertise<std_msgs::String>("system_status", 1)),
27  robot_system_(robot_system), logic_state_machine_(logic_state_machine) {
28  }
29 
36  // Get active controller status
37  ControllerStatus uav_controller_status =
39  ControllerStatus arm_controller_status =
41  std::string robot_system_status = robot_system_.getSystemStatus();
42  std::string current_state_name = pstate(logic_state_machine_);
43  std::string no_transition_event_name =
44  logic_state_machine_.get_no_transition_event_index().name();
45  std::type_index last_transition_event_index =
46  logic_state_machine_.lastProcessedEventIndex();
47  HtmlDivisionWriter division_writer;
48  division_writer.addHeader("Robot System Status");
49  division_writer.addText(robot_system_status);
50  // Add subheader for uav controller status
51  division_writer.addHeader("UAV Controller Status", 4);
52  division_writer.addText(uav_controller_status.getHtmlStatusString());
53  // Add subheader for arm controller status
54  division_writer.addHeader("Arm Controller Status", 4);
55  division_writer.addText(arm_controller_status.getHtmlStatusString());
56  // add table for logic state machine
57  HtmlTableWriter logic_state_machine_table(190);
58  logic_state_machine_table.beginRow();
59  logic_state_machine_table.addHeader("Logic State Machine Status",
60  Colors::blue, 2);
61  logic_state_machine_table.beginRow();
62  logic_state_machine_table.addCell("Current state: ");
63  logic_state_machine_table.addCell(current_state_name);
64  logic_state_machine_table.beginRow();
65  logic_state_machine_table.addCell("Last Event without transition: ");
66  logic_state_machine_table.addCell(no_transition_event_name);
67  logic_state_machine_table.beginRow();
68  logic_state_machine_table.addCell("Last Event: ");
69  if (last_transition_event_index == typeid(be::Abort)) {
70  logic_state_machine_table.addCell(last_transition_event_index.name(), "",
71  Colors::red);
72  } else if (last_transition_event_index == typeid(Completed)) {
73  logic_state_machine_table.addCell(last_transition_event_index.name(), "",
75  } else {
76  logic_state_machine_table.addCell(last_transition_event_index.name());
77  }
78  // Add table to division
79  division_writer.addText(logic_state_machine_table.getTableString());
80  std_msgs::String status;
81  status.data = division_writer.getDivisionText();
82  system_status_pub_.publish(status);
83  }
84 
85 private:
86  ros::NodeHandle &nh_;
87  ros::Publisher system_status_pub_;
88  const BaseRobotSystem
89  &robot_system_;
90  const LogicStateMachineT
91  &logic_state_machine_;
92 };
Responsible for publishing system status message.
Definition: system_status_publisher.h:14
virtual std::string getSystemStatus() const =0
Provide the current state of robot system.
static constexpr const char * green
Green color hex code.
Definition: html_utils.h:18
std::string getTableString()
Get the html table in string format.
Definition: html_utils.h:170
Only aerial vehicle.
void addText(std::string text)
Add text to the division.
Definition: html_utils.h:71
Completed Event for transition from for example Landing to Landed etc.
Definition: completed_event.h:6
Add a division to html.
Definition: html_utils.h:44
Status of the controller.
Definition: controller_status.h:10
SystemStatusPublisher(ros::NodeHandle &nh, const BaseRobotSystem &robot_system, LogicStateMachineT &logic_state_machine)
Constructor.
Definition: system_status_publisher.h:22
void publishSystemStatus()
Publish system status and state machine status.
Definition: system_status_publisher.h:35
Provides functions to switch between active controllers and get goals.
Definition: base_robot_system.h:16
static constexpr const char * blue
Blue color hex code.
Definition: html_utils.h:22
void addCell(const DataT &data, std::string header="", std::string bg_color=Colors::white, int colspan=1)
Add a cell to the table. Should be called after beginning a row. Otherwise will throw an exception...
Definition: html_utils.h:116
void addHeader(std::string header, int level=1)
Add a header inside division.
Definition: html_utils.h:60
const char * pstate(PickPlaceStateMachine const &p)
Get current state name.
Definition: pick_place_state_machine.h:211
void beginRow()
Begin a new row in the table.
Definition: html_utils.h:135
std::string getDivisionText()
Create a divsion html in string format.
Definition: html_utils.h:80
void addHeader(std::string header, std::string text_color=Colors::black, int colspan=1)
Add a table header. Should be called after beginning a row.
Definition: html_utils.h:152
Helper class to write html tables to text format.
Definition: html_utils.h:91
ControllerStatus getActiveControllerStatus(HardwareType hardware_type) const
Get the status of the active controller.
Definition: base_robot_system.h:110
static constexpr const char * red
Red color hex code.
Definition: html_utils.h:14
std::string getHtmlStatusString()
Get a Html text describing the controller status.
Definition: controller_status.cpp:12