recorder/joint_state.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 /*
19 * LOCAL includes
20 */
21 #include "joint_state.hpp"
22 
23 namespace naoqi
24 {
25 namespace recorder
26 {
27 
28 JointStateRecorder::JointStateRecorder( const std::string& topic, float buffer_frequency ):
29  topic_( topic ),
30  buffer_duration_(helpers::recorder::bufferDefaultDuration),
31  is_initialized_( false ),
32  is_subscribed_( false ),
33  buffer_frequency_(buffer_frequency),
34  counter_(1)
35 {}
36 
37 void JointStateRecorder::write( const sensor_msgs::JointState& js_msg,
38  const std::vector<geometry_msgs::TransformStamped>& tf_transforms )
39 {
40  if (!js_msg.header.stamp.isZero()) {
41  gr_->write(topic_, js_msg, js_msg.header.stamp);
42  }
43  else {
44  gr_->write(topic_, js_msg);
45  }
46  gr_->write("/tf", tf_transforms);
47 }
48 
50 {
51  boost::mutex::scoped_lock lock_write_buffer( mutex_ );
52  boost::circular_buffer< std::vector<geometry_msgs::TransformStamped> >::iterator it_tf;
53  for (it_tf = bufferTF_.begin(); it_tf != bufferTF_.end(); it_tf++)
54  {
55  gr_->write("/tf", *it_tf);
56  }
57  for (boost::circular_buffer<sensor_msgs::JointState>::iterator it_js = bufferJoinState_.begin();
58  it_js != bufferJoinState_.end(); it_js++)
59  {
60  if (!it_js->header.stamp.isZero()) {
61  gr_->write(topic_, *it_js, it_js->header.stamp);
62  }
63  else {
64  gr_->write(topic_, *it_js);
65  }
66  }
67 }
68 
70 {
71  gr_ = gr;
72  conv_frequency_ = conv_frequency;
73  if (buffer_frequency_ != 0)
74  {
75  max_counter_ = static_cast<int>(conv_frequency/buffer_frequency_);
76  buffer_size_ = static_cast<size_t>(buffer_duration_*(conv_frequency/max_counter_));
77  }
78  else
79  {
80  max_counter_ = 1;
81  buffer_size_ = static_cast<size_t>(buffer_duration_*conv_frequency);
82  }
84  bufferTF_.resize(buffer_size_);
85  is_initialized_ = true;
86 }
87 
88 void JointStateRecorder::bufferize( const sensor_msgs::JointState& js_msg,
89  const std::vector<geometry_msgs::TransformStamped>& tf_transforms )
90 {
91  boost::mutex::scoped_lock lock_bufferize( mutex_ );
92  if (counter_ < max_counter_)
93  {
94  counter_++;
95  }
96  else
97  {
98  counter_ = 1;
99  bufferJoinState_.push_back(js_msg);
100  bufferTF_.push_back(tf_transforms);
101  }
102 }
103 
105 {
106  boost::mutex::scoped_lock lock_bufferize( mutex_ );
107  buffer_size_ = static_cast<size_t>(duration*(conv_frequency_/max_counter_));
108  buffer_duration_ = duration;
109  bufferJoinState_.set_capacity(buffer_size_);
110  bufferTF_.set_capacity(buffer_size_);
111 }
112 
113 } //publisher
114 } // naoqi
void bufferize(const sensor_msgs::JointState &js_msg, const std::vector< geometry_msgs::TransformStamped > &tf_transforms)
boost::circular_buffer< sensor_msgs::JointState > bufferJoinState_
JointStateRecorder(const std::string &topic, float buffer_frequency=0)
void reset(boost::shared_ptr< naoqi::recorder::GlobalRecorder > gr, float conv_frequency)
static const float bufferDefaultDuration
boost::shared_ptr< naoqi::recorder::GlobalRecorder > gr_
void write(const sensor_msgs::JointState &js_msg, const std::vector< geometry_msgs::TransformStamped > &tf_transforms)
void writeDump(const ros::Time &time)
boost::circular_buffer< std::vector< geometry_msgs::TransformStamped > > bufferTF_


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