recorder/log.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Aldebaran
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #include "log.hpp"
19 
20 namespace naoqi
21 {
22 namespace recorder
23 {
24 
25 LogRecorder::LogRecorder(const std::string& topic , float buffer_frequency):
26  topic_( topic ),
27  buffer_duration_(helpers::recorder::bufferDefaultDuration),
28  buffer_frequency_(buffer_frequency),
29  counter_(1)
30 {}
31 
32 void LogRecorder::write(std::list<rosgraph_msgs::Log>& log_msgs)
33 {
34  while ( !log_msgs.empty() )
35  {
36  if (!log_msgs.front().header.stamp.isZero()) {
37  gr_->write(topic_, log_msgs.front(), log_msgs.front().header.stamp);
38  }
39  else {
40  gr_->write(topic_, log_msgs.front());
41  }
42  {
43  log_msgs.pop_front();
44  }
45  }
46 }
47 
49 {
50  boost::mutex::scoped_lock lock_write_buffer( mutex_ );
51  boost::circular_buffer< std::list<rosgraph_msgs::Log> >::iterator it;
52  for (it = buffer_.begin(); it != buffer_.end(); it++)
53  {
54  write(*it);
55  }
56 }
57 
59 {
60  gr_ = gr;
61  conv_frequency_ = conv_frequency;
62  if (buffer_frequency_ != 0)
63  {
64  max_counter_ = static_cast<int>(conv_frequency/buffer_frequency_);
65  buffer_size_ = static_cast<size_t>(buffer_duration_*(conv_frequency/max_counter_));
66  }
67  else
68  {
69  max_counter_ = 1;
70  buffer_size_ = static_cast<size_t>(buffer_duration_*conv_frequency);
71  }
72  buffer_.resize(buffer_size_);
73  is_initialized_ = true;
74 }
75 
76 void LogRecorder::bufferize( std::list<rosgraph_msgs::Log>& log_msgs )
77 {
78  boost::mutex::scoped_lock lock_bufferize( mutex_ );
79  if (counter_ < max_counter_)
80  {
81  counter_++;
82  }
83  else
84  {
85  counter_ = 1;
86  buffer_.push_back(log_msgs);
87  }
88 }
89 
90 void LogRecorder::setBufferDuration(float duration)
91 {
92  boost::mutex::scoped_lock lock_bufferize( mutex_ );
93  buffer_size_ = static_cast<size_t>(duration*(conv_frequency_/max_counter_));
94  buffer_duration_ = duration;
95  buffer_.set_capacity(buffer_size_);
96 }
97 
98 } //publisher
99 } // naoqi
boost::shared_ptr< naoqi::recorder::GlobalRecorder > gr_
void reset(boost::shared_ptr< naoqi::recorder::GlobalRecorder > gr, float conv_frequency)
void bufferize(std::list< rosgraph_msgs::Log > &log_msgs)
void writeDump(const ros::Time &time)
void setBufferDuration(float duration)
LogRecorder(const std::string &topic, float buffer_frequency=0)
void write(std::list< rosgraph_msgs::Log > &log_msgs)
static const float bufferDefaultDuration
boost::circular_buffer< std::list< rosgraph_msgs::Log > > buffer_


naoqi_driver
Author(s): Karsten Knese
autogenerated on Sat Feb 15 2020 03:24:26