NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
wak_gc_ros.h
1 // Walk and kick: Game controller ROS interface
2 // Author: Philipp Allgeuer <pallgeuer@ais.uni-bonn.de>
3 
4 // Ensure header is only included once
5 #ifndef WAK_GC_ROS_H
6 #define WAK_GC_ROS_H
7 
8 // Includes
9 #include <walk_and_kick/wak_common.h>
10 #include <rcup_game_controller/GCData.h>
11 #include <ros/ros.h>
12 
13 // Walk and kick namespace
14 namespace walk_and_kick
15 {
22  {
23  public:
24  // Constructor
25  GCRosInterface() : m_nh("~"), m_enabled(true) { resetData(); }
26  explicit GCRosInterface(ros::NodeHandle& nh) : m_nh(nh), m_enabled(true) { resetData(); }
27  virtual ~GCRosInterface() { stopListening(); }
28 
29  // Reset function
30  void resetData() { m_data = rcup_game_controller::GCData(); }
31 
32  // Start/stop listening functions
33  void startListening() { stopListening(); m_subscriber = m_nh.subscribe("/game_controller/data", 1, &GCRosInterface::handleGameControllerData, this); }
34  void stopListening() { m_subscriber.shutdown(); }
35 
36  // Enable/disable game controller data (without unsubscribing to the topic)
37  bool getEnabled() const { return m_enabled; }
38  void setEnabled(bool enabled) { m_enabled = enabled; }
39 
40  // Get functions
41  const rcup_game_controller::GCData& data() const { return m_data; }
42 
43  private:
44  // ROS node handle
45  ros::NodeHandle m_nh;
46 
47  // Enabled state of class
48  bool m_enabled;
49 
50  // Last received game controller data
51  rcup_game_controller::GCData m_data;
52 
53  // ROS subscriber
54  ros::Subscriber m_subscriber;
55  void handleGameControllerData(const rcup_game_controller::GCDataConstPtr& msg) { if(m_enabled) m_data = *msg; } // Note: Any game controller packet that is received here definitely concerns us as it has already been preprocessed into 'ownTeam' and 'oppTeam' by the rcup_game_controller node
56  };
57 }
58 
59 #endif
60 // EOF
An interface class to the ROS world for getting game controller messages.
Definition: wak_gc_ros.h:21