NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
generic_ros_sub_rapid_pub.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, United States Government, as represented by the
2  * Administrator of the National Aeronautics and Space Administration.
3  *
4  * All rights reserved.
5  *
6  * The Astrobee platform is licensed under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations
16  * under the License.
17  */
18 
19 #ifndef COMMS_BRIDGE_GENERIC_ROS_SUB_RAPID_PUB_H_
20 #define COMMS_BRIDGE_GENERIC_ROS_SUB_RAPID_PUB_H_
21 
22 /* This is a specialization of ROSBridgeSubscriber using a DDS conduit
23 */
24 
27 
28 #include <ff_msgs/GenericCommsAdvertisementInfo.h>
29 #include <ff_msgs/GenericCommsContent.h>
30 #include <ff_msgs/GenericCommsReset.h>
31 
32 #include <map>
33 #include <string>
34 #include <utility>
35 #include <vector>
36 
37 #include "dds_msgs/GenericCommsRequestSupport.h"
38 
39 namespace ff {
40 
41 class TopicEntry {
42  public:
44  out_topic_(""),
45  rate_seconds_(0),
46  last_time_pub_(0),
47  seq_num_(0),
48  type_md5_sum_(""),
49  data_size_(0),
50  data_(NULL) {}
51  TopicEntry(std::string robot_in, std::string topic_in, double rate_in) :
52  connecting_robot_(robot_in),
53  out_topic_(topic_in),
54  rate_seconds_(rate_in),
55  last_time_pub_(0),
56  seq_num_(0),
57  type_md5_sum_(""),
58  data_size_(0),
59  data_(NULL) {}
60 
61  void SetDataToSend(const int seq_num,
62  std::string const& md5_sum,
63  const size_t data_size,
64  uint8_t const* data) {
65  seq_num_ = seq_num;
66  type_md5_sum_ = md5_sum;
67  data_size_ = data_size;
68  data_ = data;
69  }
70 
71  std::string connecting_robot_;
72  std::string out_topic_;
73  double rate_seconds_;
74 
75  // Info only needed for rate messages. A little wasted space but quicker
76  // program execution
78  int seq_num_;
79  std::string type_md5_sum_;
80  size_t data_size_;
81  uint8_t const* data_;
82 };
83 
85  public:
86  explicit GenericROSSubRapidPub(ros::NodeHandle const* nh);
88 
89  void AddTopics(std::map<std::string,
90  std::vector<std::shared_ptr<TopicEntry>>> const& link_entries);
91 
92  float FloatMod(float x, float y);
93 
94  void InitializeDDS(std::vector<std::string> const& connections);
95 
96  // Called with the mutex held
97  virtual void subscribeTopic(std::string const& in_topic,
98  const RelayTopicInfo& info);
99 
100  // Called with the mutex held
101  virtual void advertiseTopic(const RelayTopicInfo& info);
102 
103  // Called with the mutex held
104  virtual void relayMessage(const RelayTopicInfo& topic_info,
105  ContentInfo const& content_info);
106 
107  void ConvertRequest(rapid::ext::astrobee::GenericCommsRequest const* data,
108  std::string const& connecting_robot);
109 
110  void CheckPubMsg(const ros::TimerEvent& event);
111 
112  private:
113  bool dds_initialized_, pub_rate_msgs_;
114 
115  ros::Timer rate_msg_pub_timer_;
116 
117  std::map<std::string, std::vector<std::shared_ptr<TopicEntry>>> topic_mapping_;
118  std::map<std::string, GenericRapidPubPtr> robot_connections_;
119  std::vector<std::shared_ptr<TopicEntry>> rate_topic_entries_;
120 };
121 
122 } // end namespace ff
123 
124 #endif // COMMS_BRIDGE_GENERIC_ROS_SUB_RAPID_PUB_H_
ff::GenericROSSubRapidPub
Definition: generic_ros_sub_rapid_pub.h:84
ff::TopicEntry::seq_num_
int seq_num_
Definition: generic_ros_sub_rapid_pub.h:78
BridgeSubscriber::RelayTopicInfo
Definition: bridge_subscriber.h:71
ff::GenericROSSubRapidPub::GenericROSSubRapidPub
GenericROSSubRapidPub(ros::NodeHandle const *nh)
Definition: generic_ros_sub_rapid_pub.cpp:28
ff::GenericROSSubRapidPub::advertiseTopic
virtual void advertiseTopic(const RelayTopicInfo &info)
Definition: generic_ros_sub_rapid_pub.cpp:106
ff::TopicEntry::SetDataToSend
void SetDataToSend(const int seq_num, std::string const &md5_sum, const size_t data_size, uint8_t const *data)
Definition: generic_ros_sub_rapid_pub.h:61
ff::TopicEntry::out_topic_
std::string out_topic_
Definition: generic_ros_sub_rapid_pub.h:72
ff::TopicEntry::data_
uint8_t const * data_
Definition: generic_ros_sub_rapid_pub.h:81
ff::TopicEntry::type_md5_sum_
std::string type_md5_sum_
Definition: generic_ros_sub_rapid_pub.h:79
ff::GenericROSSubRapidPub::FloatMod
float FloatMod(float x, float y)
Definition: generic_ros_sub_rapid_pub.cpp:81
ff::GenericROSSubRapidPub::InitializeDDS
void InitializeDDS(std::vector< std::string > const &connections)
Definition: generic_ros_sub_rapid_pub.cpp:87
BridgeSubscriber::ContentInfo
Definition: bridge_subscriber.h:84
ff::GenericROSSubRapidPub::subscribeTopic
virtual void subscribeTopic(std::string const &in_topic, const RelayTopicInfo &info)
Definition: generic_ros_sub_rapid_pub.cpp:99
ff
Definition: generic_rapid_msg_ros_pub.h:36
ff::GenericROSSubRapidPub::~GenericROSSubRapidPub
~GenericROSSubRapidPub()
Definition: generic_ros_sub_rapid_pub.cpp:39
ff::TopicEntry::connecting_robot_
std::string connecting_robot_
Definition: generic_ros_sub_rapid_pub.h:71
ff::GenericROSSubRapidPub::CheckPubMsg
void CheckPubMsg(const ros::TimerEvent &event)
Definition: generic_ros_sub_rapid_pub.cpp:249
ff::TopicEntry::TopicEntry
TopicEntry(std::string robot_in, std::string topic_in, double rate_in)
Definition: generic_ros_sub_rapid_pub.h:51
ff::TopicEntry::data_size_
size_t data_size_
Definition: generic_ros_sub_rapid_pub.h:80
ff::TopicEntry
Definition: generic_ros_sub_rapid_pub.h:41
ff::GenericROSSubRapidPub::relayMessage
virtual void relayMessage(const RelayTopicInfo &topic_info, ContentInfo const &content_info)
Definition: generic_ros_sub_rapid_pub.cpp:142
ff::GenericROSSubRapidPub::AddTopics
void AddTopics(std::map< std::string, std::vector< std::shared_ptr< TopicEntry >>> const &link_entries)
Definition: generic_ros_sub_rapid_pub.cpp:41
ff::TopicEntry::rate_seconds_
double rate_seconds_
Definition: generic_ros_sub_rapid_pub.h:73
ff::GenericROSSubRapidPub::ConvertRequest
void ConvertRequest(rapid::ext::astrobee::GenericCommsRequest const *data, std::string const &connecting_robot)
Definition: generic_ros_sub_rapid_pub.cpp:186
generic_rapid_pub.h
BridgeSubscriber
Definition: bridge_subscriber.h:40
ff::TopicEntry::last_time_pub_
double last_time_pub_
Definition: generic_ros_sub_rapid_pub.h:77
ff::TopicEntry::TopicEntry
TopicEntry()
Definition: generic_ros_sub_rapid_pub.h:43
bridge_subscriber.h