locked_robot_state.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012-2013, Willow Garage, Inc.
5  * Copyright (c) 2013, Ioan A. Sucan
6  * Copyright (c) 2014, SRI International
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *********************************************************************/
36 
37 /* Author: Ioan Sucan, Acorn Pooley */
38 
40 
41 robot_interaction::LockedRobotState::LockedRobotState(const robot_state::RobotState& state)
42  : state_(new robot_state::RobotState(state))
43 {
44  state_->update();
45 }
46 
47 robot_interaction::LockedRobotState::LockedRobotState(const robot_model::RobotModelPtr& model)
48  : state_(new robot_state::RobotState(model))
49 {
50  state_->setToDefaultValues();
51  state_->update();
52 }
53 
55 {
56 }
57 
58 robot_state::RobotStateConstPtr robot_interaction::LockedRobotState::getState() const
59 {
60  boost::mutex::scoped_lock lock(state_lock_);
61  return state_;
62 }
63 
64 void robot_interaction::LockedRobotState::setState(const robot_state::RobotState& state)
65 {
66  {
67  boost::mutex::scoped_lock lock(state_lock_);
68 
69  // If someone else has a reference to the state, then make a new copy.
70  // The old state is orphaned (does not change, but is now out of date).
71  if (state_.unique())
72  *state_ = state;
73  else
74  state_.reset(new robot_state::RobotState(state));
75 
76  state_->update();
77  }
79 }
80 
82 {
83  {
84  boost::mutex::scoped_lock lock(state_lock_);
85 
86  // If someone else has a reference to the state, then make a copy.
87  // The old state is orphaned (does not change, but is now out of date).
88  if (!state_.unique())
89  state_.reset(new robot_state::RobotState(*state_));
90 
91  modify(state_.get());
92  state_->update();
93  }
95 }
96 
98 {
99 }
robot_state::RobotStateConstPtr getState() const
get read-only access to the state.
void setState(const robot_state::RobotState &state)
Set the state to the new value.
LockedRobotState(const robot_state::RobotState &state)
void modifyState(const ModifyStateFunction &modify)
robot_state::RobotStatePtr state_
boost::function< void(robot_state::RobotState *)> ModifyStateFunction


robot_interaction
Author(s): Ioan Sucan
autogenerated on Sun Oct 18 2020 13:18:32