ASCO Aerial Autonomy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
state_machine_gui_connector.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <geometry_msgs/PoseStamped.h>
4 #include <glog/logging.h>
5 #include <ros/ros.h>
6 #include <std_msgs/String.h>
7 #include <tf_conversions/tf_eigen.h>
8 
10 
19 template <class EventManagerT, class LogicStateMachineT>
21 public:
30  StateMachineGUIConnector(ros::NodeHandle &nh, EventManagerT &event_manager,
31  LogicStateMachineT &logic_state_machine)
32  : event_manager_(event_manager),
33  logic_state_machine_(logic_state_machine) {
34  event_manager_sub_ = nh.subscribe(
35  "event_manager", 1, &StateMachineGUIConnector::eventCallback, this);
36  pose_command_sub_ =
37  nh.subscribe("goal_pose_command", 1,
38  &StateMachineGUIConnector::poseCommandCallback, this);
39  }
40 
46  return event_manager_sub_.getNumPublishers() > 0;
47  }
48 
55  return pose_command_sub_.getNumPublishers() > 0;
56  }
57 
58 private:
64  void eventCallback(const std_msgs::StringConstPtr &event_data) {
65  VLOG(1) << "Triggering event: " << event_data;
66  event_manager_.triggerEvent(event_data->data, logic_state_machine_);
67  }
68 
74  void poseCommandCallback(const geometry_msgs::PoseStamped &pose) {
75  PositionYaw pose_command;
76  pose_command.x = pose.pose.position.x;
77  pose_command.y = pose.pose.position.y;
78  pose_command.z = pose.pose.position.z;
79  pose_command.yaw = tf::getYaw(pose.pose.orientation);
80  VLOG(1) << "Received Pose command: " << pose_command.x << "\t"
81  << pose_command.y << "\t" << pose_command.z << "\t"
82  << pose_command.yaw;
83  logic_state_machine_.process_event(pose_command);
84  }
85 
89  ros::Subscriber pose_command_sub_;
93  ros::Subscriber event_manager_sub_;
97  EventManagerT &event_manager_;
101  LogicStateMachineT &logic_state_machine_;
102 };
bool isPoseCommandConnected()
Returns whether the GUI connector is connected to an pose command publisher.
Definition: state_machine_gui_connector.h:54
double y
y component in m
Definition: position.h:23
double x
x component in m
Definition: position.h:22
Stores Position, yaw. PositionYaw is used as the goal for UAV systems.
Definition: position_yaw.h:10
StateMachineGUIConnector(ros::NodeHandle &nh, EventManagerT &event_manager, LogicStateMachineT &logic_state_machine)
Constructor Creates subscriber to event callbacks to connect GUI to state machine.
Definition: state_machine_gui_connector.h:30
double yaw
Orientation about body axis rad.
Definition: position_yaw.h:51
double z
z component in m
Definition: position.h:24
bool isEventManagerConnected()
Returns whether the GUI connector is connected to an event publisher.
Definition: state_machine_gui_connector.h:45
Connects a logic state machine to the GUI over a ROS interface.
Definition: state_machine_gui_connector.h:20