trajectory_monitor.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
39 #include <ros/rate.h>
40 #include <limits>
41 #include <memory>
42 
43 planning_scene_monitor::TrajectoryMonitor::TrajectoryMonitor(const CurrentStateMonitorConstPtr& state_monitor,
44  double sampling_frequency)
45  : current_state_monitor_(state_monitor)
46  , sampling_frequency_(5.0)
47  , trajectory_(current_state_monitor_->getRobotModel(), "")
48 {
49  setSamplingFrequency(sampling_frequency);
50 }
51 
53 {
55 }
56 
58 {
59  if (sampling_frequency <= std::numeric_limits<double>::epsilon())
60  ROS_ERROR("The sampling frequency for trajectory states should be positive");
61  else
62  sampling_frequency_ = sampling_frequency;
63 }
64 
66 {
67  return static_cast<bool>(record_states_thread_);
68 }
69 
71 {
73  {
74  record_states_thread_.reset(new boost::thread(boost::bind(&TrajectoryMonitor::recordStates, this)));
75  ROS_DEBUG("Started trajectory monitor");
76  }
77 }
78 
80 {
82  {
83  std::unique_ptr<boost::thread> copy;
84  copy.swap(record_states_thread_);
85  copy->join();
86  ROS_DEBUG("Stopped trajectory monitor");
87  }
88 }
89 
91 {
92  bool restart = isActive();
93  if (restart)
96  if (restart)
98 }
99 
101 {
103  return;
104 
106 
107  while (record_states_thread_)
108  {
109  rate.sleep();
110  std::pair<robot_state::RobotStatePtr, ros::Time> state = current_state_monitor_->getCurrentStateAndTime();
111  if (trajectory_.empty())
112  {
113  trajectory_.addSuffixWayPoint(state.first, 0.0);
114  trajectory_start_time_ = state.second;
115  last_recorded_state_time_ = state.second;
116  }
117  else
118  {
119  trajectory_.addSuffixWayPoint(state.first, (state.second - last_recorded_state_time_).toSec());
120  last_recorded_state_time_ = state.second;
121  }
123  state_add_callback_(state.first, state.second);
124  }
125 }
std::unique_ptr< boost::thread > record_states_thread_
robot_trajectory::RobotTrajectory trajectory_
TrajectoryStateAddedCallback state_add_callback_
CurrentStateMonitorConstPtr current_state_monitor_
bool sleep()
TrajectoryMonitor(const CurrentStateMonitorConstPtr &state_monitor, double sampling_frequency=5.0)
Constructor.
void setSamplingFrequency(double sampling_frequency)
void addSuffixWayPoint(const robot_state::RobotState &state, double dt)
#define ROS_ERROR(...)
#define ROS_DEBUG(...)


planning
Author(s): Ioan Sucan , Sachin Chitta
autogenerated on Sat Apr 21 2018 02:55:20