NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
wak_ros_interface.h
1 // Walk and kick: ROS interface class
2 // Author: Philipp Allgeuer <pallgeuer@ais.uni-bonn.de>
3 
4  // Ensure header is only included once
5 #ifndef WAK_ROS_INTERFACE_H
6 #define WAK_ROS_INTERFACE_H
7 
8 // Includes
9 #include <walk_and_kick/wak_common.h>
10 #include <walk_and_kick/wak_config.h>
11 #include <walk_and_kick/wak_actuator_vars.h>
12 #include <walk_and_kick/wak_gc_ros.h>
13 #include <walk_and_kick/wak_tc_ros.h>
14 #include <walk_and_kick/wak_vis.h>
15 #include <walk_and_kick/BehaviourState.h>
16 #include <walk_and_kick/TeamCommsData.h>
17 #include <walk_and_kick/VisualiseDBH.h>
18 #include <walk_and_kick/VisualiseDbApp.h>
19 #include <geometry_msgs/PointStamped.h>
20 #include <geometry_msgs/PolygonStamped.h>
21 #include <nimbro_op_interface/LEDCommand.h>
22 #include <nimbro_op_interface/Button.h>
23 #include <vision_module/vision_outputs.h>
24 #include <head_control/LookAtTarget.h>
25 #include <robotcontrol/RobotHeading.h>
26 #include <robotcontrol/Diagnostics.h>
27 #include <robotcontrol/State.h>
28 #include <plot_msgs/plot_manager.h>
29 #include <tf/transform_broadcaster.h>
30 #include <gait_msgs/GaitCommand.h>
31 #include <boost/shared_ptr.hpp>
32 #include <gait/gait_common.h>
33 #include <std_msgs/String.h>
34 #include <std_srvs/Empty.h>
35 #include <std_msgs/Bool.h>
36 #include <ros/ros.h>
37 
38 // Walk and kick namespace
39 namespace walk_and_kick
40 {
41  // Using declaration
42  using nimbro_op_interface::LEDCommand;
43 
44  // Class declarations
45  class WalkAndKick;
46  class WAKGameState;
47  class WAKBehState;
48 
55  {
56  public:
57  // Constructor
58  explicit WAKRosInterface(WalkAndKick* wak);
59  virtual ~WAKRosInterface();
60 
61  // ROS node handle
62  ros::NodeHandle nh;
63 
64  private:
65  // Main walk and kick object (don't use this for anything other than to forward callbacks if necessary, but in general avoid using at all cost)
66  WalkAndKick* wak;
67 
68  public:
69  // Config parameters
70  WAKConfig& config;
71 
72  // Reset function
73  void resetData();
74 
75  // Return whether this robot is a fake one (e.g. xs0)
76  bool isFakeRobot() const { return m_isFakeRobot; }
77 
78  // Update function
79  void update(const ros::Time& now, bool LED4);
80 
81  // Actuator output functions
82  void writeActuators(const ActuatorVars& actVar);
83  void writeNeutralHead();
84  void writeZeroGcv();
85  void writeNeutral() { writeNeutralHead(); writeZeroGcv(); writeRGBLEDState(); }
86 
87  // LED functions
88  void clearLEDState() { writeLEDCommand(0xFF, 0x00); }
89  void writeLEDCommand(int mask, int state);
90  void updateRGBLED(bool blink);
91  void clearRGBLED() const;
92 
93  // Behaviour state
94  void publishBehaviourState(const WAKGameState* gameState, const WAKBehState* behState);
95  void publishTeamCommsPacket(const TeamCommsData& packet) const { m_pub_teamComms.publish(packet); }
96 
97  // Robot state functions
98  bool stateRelaxed() const { return m_relaxed; }
99  bool stateIniting() const { return m_initing; }
100  bool stateStanding() const { return m_standing; }
101  bool stateWalking() const { return m_walking; }
102  bool stateKicking() const { return m_kicking; }
103  bool stateFallen() const { return m_fallen; }
104 
105  // Game controller
106  GCRosInterface GCRI;
107 
108  // Team communications
109  TCRosInterface TCRI;
110 
111  // Button variables
112  ButtonState button;
113 
114  // Ball variables
115  Vec2f ballVec;
116  float ballConf;
117  bool ballDetected;
118  ros::Time ballTime;
119 
120  // Goal post variables
121  GoalPostList goalPostList;
122  ros::Time goalPostTime;
123 
124  // Obstacle variables
125  ObstacleList obstacleList;
126  ros::Time obstacleTime;
127 
128  // Robot pose variables
129  Vec3f robotPoseVec;
130  float robotPoseConf;
131  ros::Time robotPoseTime;
132 
133  // Robot heading variables
134  float robotHeading;
135  ros::Time robotHeadingTime;
136 
137  // Robotcontrol variables
138  bool robotcontrolCommsOk;
139 
140  // Dive variables
141  DiveDirection diveDecision;
142 
143  // TF transforms
144  void sendTransform(const Vec3f& RobotPose);
145 
146  // Plot manager
147  plot_msgs::PlotManagerFS* PM;
148  plot_msgs::PlotManagerFS& getPM() const { return *PM; }
149 
150  // Marker manager
151  WAKMarkerMan* MM;
152  WAKMarkerMan& getMM() const { return *MM; }
153  WAKBagMarkerMan* MMB;
154  WAKBagMarkerMan& getMMB() const { return *MMB; }
155 
156  private:
157  // TF transforms
158  tf::TransformBroadcaster m_tfBroadcaster;
159  tf::StampedTransform m_tfBehField;
160 
161  // Plot manager
162  void callbackPlotData();
163 
164  // Config param callbacks
165  void updateModeStateText() { MM->ModeStateText.setText((config.sListenToGC() ? "Extern " : "Local ") + m_buttonName); }
166  void handleBlockGCPackets() { GCRI.setEnabled(!config.debugBlockGCPackets()); }
167  void handleNoStoppedGCV() { gait::resetGaitCommand(m_stoppedGaitCmd); }
168 
169  // ROS publishers
170  ros::Publisher m_pub_gaitCmd;
171  ros::Publisher m_pub_headCmd;
172  ros::Publisher m_pub_leds;
173  ros::Publisher m_pub_state;
174  ros::Publisher m_pub_teamComms;
175 
176  // ROS subscribers
177  ros::Subscriber m_sub_button;
178  ros::Subscriber m_sub_robotState;
179  ros::Subscriber m_sub_robotHeading;
180  ros::Subscriber m_sub_stoppedGaitCmd;
181  ros::Subscriber m_sub_robotDiagnostics;
182  ros::Subscriber m_sub_visionOutput;
183  ros::Subscriber m_sub_diveDecision;
184 
185  // ROS service servers
186  ros::ServiceServer m_srv_visualiseClear;
187  ros::ServiceServer m_srv_visualiseDBH;
188  ros::ServiceServer m_srv_visualiseDbApp;
189  ros::ServiceServer m_srv_visualiseGcvXY;
190 
191  // ROS data handlers
192  void handleButtonData(const nimbro_op_interface::ButtonConstPtr& msg);
193  void handleRobotStateData(const robotcontrol::StateConstPtr& msg);
194  void handleRobotHeadingData(const robotcontrol::RobotHeadingConstPtr& msg);
195  void handleStoppedGaitCommand(const gait_msgs::GaitCommandConstPtr& msg);
196  void handleRobotDiagnosticsData(const robotcontrol::DiagnosticsConstPtr& msg);
197  void handleVisionOutputData(const vision_module::vision_outputsConstPtr& msg);
198  void handleDiveDecision(const std_msgs::StringConstPtr& msg);
199 
200  // ROS service handlers
201  bool handleVisualiseClear(std_srvs::EmptyRequest& req, std_srvs::EmptyResponse& resp);
202  bool handleVisualiseDBH(walk_and_kick::VisualiseDBHRequest& req, walk_and_kick::VisualiseDBHResponse& resp);
203  bool handleVisualiseDbApp(walk_and_kick::VisualiseDbAppRequest& req, walk_and_kick::VisualiseDbAppResponse& resp);
204  bool handleVisualiseGcvXY(std_srvs::EmptyRequest& req, std_srvs::EmptyResponse& resp);
205 
206  // Robot state variables
207  bool m_relaxed;
208  bool m_initing;
209  bool m_standing;
210  bool m_walking;
211  bool m_kicking;
212  bool m_fallen;
213 
214  // LED functions
215  void writeRGBLEDState() const;
216 
217  // LED variables
218  int m_lastLEDState;
219  int m_lastLEDMask;
220  ros::Time m_lastLEDTime;
221  bool m_blinkRGBLED;
222 
223  // Miscellaneous variables
224  bool m_isFakeRobot;
225  ButtonState m_lastButton;
226  std::string m_buttonName;
227  bool m_btnHeadCmd;
228  head_control::LookAtTarget m_headCmd;
229  gait_msgs::GaitCommand m_stoppedGaitCmd;
230  BehaviourState m_behState;
231  bool m_publishedNeutral; // Note: This must be reset in the constructor and *not* in resetData()!
232  };
233 }
234 
235 #endif
236 // EOF
Configuration struct for the walk and kick node.
Definition: wak_config.h:20
An interface class to the ROS world for getting game controller messages.
Definition: wak_gc_ros.h:21
Visualisation marker manager for the walk and kick node.
Definition: wak_vis.h:21
The main walk and kick behaviour class.
Definition: walk_and_kick.h:34
boost::shared_ptr< State const > StateConstPtr
Used to represent a Boost shared pointer to a constant State object.
Definition: state_controller.h:413
An interface class to the ROS world for team communications.
Definition: wak_tc_ros.h:30
The base class for all walk and kick game states.
Definition: wak_game_state.h:26
The base class for all walk and kick behaviour states.
Definition: wak_beh_state.h:27
Visualisation marker manager for visualisations that are intended for when playing behaviour bags...
Definition: wak_vis.h:98
void resetGaitCommand(gait_msgs::GaitCommand &cmd)
Reset a gait command to zero.
Definition: gait_common.h:115
An interface class between the walk and kick and ROS worlds.
Definition: wak_ros_interface.h:54
An interface class for encapsulating all of the data that the walk and kick behaviour states should c...
Definition: wak_actuator_vars.h:22