NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
data_bagger.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 DATA_BAGGER_DATA_BAGGER_H_
20 #define DATA_BAGGER_DATA_BAGGER_H_
21 
22 #include <boost/date_time/posix_time/posix_time.hpp>
23 
25 
27 
28 #include <errno.h>
29 
30 #include <ff_msgs/DataToDiskState.h>
31 #include <ff_msgs/DataTopicsList.h>
32 #include <ff_msgs/EnableRecording.h>
33 #include <ff_msgs/SetDataToDisk.h>
34 
35 #include <ff_common/ff_names.h>
36 #include <ff_util/ff_nodelet.h>
37 
38 #include <pluginlib/class_list_macros.h>
39 
40 #include <ros/ros.h>
41 #include <ros/package.h>
42 
43 #include <sys/stat.h>
44 #include <sys/types.h>
45 
46 #include <string>
47 #include <vector>
48 
49 
50 namespace data_bagger {
51 
53  public:
54  DataBagger();
55  ~DataBagger();
56 
57  // Service that sets delayed recording settings
58  bool SetDelayedDataToDiskService(ff_msgs::SetDataToDisk::Request &req,
59  ff_msgs::SetDataToDisk::Response &res);
60 
61  // This service enables and disables the delayed recording
62  bool EnableDelayedRecordingService(ff_msgs::EnableRecording::Request &req,
63  ff_msgs::EnableRecording::Response &res);
64 
65  protected:
66  virtual void Initialize(ros::NodeHandle *nh);
67  bool ReadParams(); // Reads data bagger parameters and default profile
68 
69  private:
70  // Reads all topic names published by the robot
71  void GetTopicNames();
72 
73  // Recursively created bag destionation folder
74  bool MakeDir(std::string dir, bool assert_init_fault, std::string &err_msg);
75 
76  // Gets the date for name generation
77  std::string GetDate(bool with_time);
78 
79  // Adds the namespace to topic names
80  void AddTopicNamespace(std::string &topic);
81 
82  // Timer for when the robot finishes startup, starts immediate recording
83  void OnStartupTimer(ros::TimerEvent const& event);
84 
85  // Sets immediate recording settings
86  bool SetImmediateDataToDisk(std::string &err_msg);
87 
88  bool SetDelayedDataToDisk(ff_msgs::DataToDiskState &state,
89  std::string &err_msg);
90 
91  // Start Recordings
92  void StartDelayedRecording();
93  void StartImmediateRecording();
94 
95  // Clear topics, stop recording
96  void ResetRecorders(bool immediate);
97 
98  // Update data bagger profile state
99  void GenerateCombinedState(ff_msgs::DataToDiskState *ground_state);
100 
101  // Publish data bagger state
102  void PublishState();
103 
104  astrobee_rosbag::Recorder *delayed_recorder_, *immediate_recorder_;
105 
106  config_reader::ConfigReader config_params_;
107 
108  ff_msgs::DataToDiskState default_data_state_, combined_data_state_;
109 
110  int pub_queue_size_;
111  unsigned int startup_time_secs_;
112  int64_t bag_size_bytes_;
113 
114  ros::Publisher pub_data_state_, pub_data_topics_;
115  ros::Timer startup_timer_;
116 
117  ros::ServiceServer set_service_, record_service_;
118 
119  rosbag::RecorderOptions recorder_options_delayed_;
120  rosbag::RecorderOptions recorder_options_immediate_;
121 
122  std::thread delayed_thread_, immediate_thread_;
123  std::string save_dir_, robot_name_, delayed_profile_name_;
124 };
125 
126 } // namespace data_bagger
127 
128 #endif // DATA_BAGGER_DATA_BAGGER_H_
data_bagger::DataBagger::DataBagger
DataBagger()
Definition: data_bagger.cc:26
data_bagger::DataBagger
Definition: data_bagger.h:52
data_bagger
Definition: data_bagger.h:50
astrobee_rosbag::Recorder
Definition: astrobee_recorder.h:108
data_bagger::DataBagger::~DataBagger
~DataBagger()
Definition: data_bagger.cc:36
ff_nodelet.h
data_bagger::DataBagger::Initialize
virtual void Initialize(ros::NodeHandle *nh)
Definition: data_bagger.cc:41
data_bagger::DataBagger::ReadParams
bool ReadParams()
Definition: data_bagger.cc:80
ff_util::FreeFlyerNodelet
Definition: ff_nodelet.h:57
ff_names.h
config_reader::ConfigReader
Definition: config_reader.h:48
data_bagger::DataBagger::EnableDelayedRecordingService
bool EnableDelayedRecordingService(ff_msgs::EnableRecording::Request &req, ff_msgs::EnableRecording::Response &res)
Definition: data_bagger.cc:337
config_reader.h
state
uint8_t state
Definition: signal_lights.h:90
astrobee_recorder.h
data_bagger::DataBagger::SetDelayedDataToDiskService
bool SetDelayedDataToDiskService(ff_msgs::SetDataToDisk::Request &req, ff_msgs::SetDataToDisk::Response &res)
Definition: data_bagger.cc:280