Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <moveit/robot_interaction/kinematic_options_map.h>
00038 #include <ros/console.h>
00039 #include <algorithm>
00040
00041
00042 const std::string robot_interaction::KinematicOptionsMap::DEFAULT = "";
00043 const std::string robot_interaction::KinematicOptionsMap::ALL = "";
00044
00045 robot_interaction::KinematicOptionsMap::KinematicOptionsMap()
00046 {}
00047
00048
00049
00050 robot_interaction::KinematicOptions
00051 robot_interaction::KinematicOptionsMap::getOptions(
00052 const std::string& key) const
00053 {
00054 boost::mutex::scoped_lock lock(lock_);
00055
00056 if (&key == &DEFAULT)
00057 return defaults_;
00058
00059 M_options::const_iterator it = options_.find(key);
00060 if (it == options_.end())
00061 return defaults_;
00062 return it->second;
00063 }
00064
00065 void robot_interaction::KinematicOptionsMap::setOptions(
00066 const std::string& key,
00067 const KinematicOptions& options_delta,
00068 KinematicOptions::OptionBitmask fields)
00069 {
00070 boost::mutex::scoped_lock lock(lock_);
00071
00072 if (&key == &ALL)
00073 {
00074 if (fields == KinematicOptions::ALL)
00075 {
00076
00077
00078 defaults_ = options_delta;
00079 options_.clear();
00080 return;
00081 }
00082
00083 defaults_.setOptions(options_delta, fields);
00084 for (M_options::iterator it = options_.begin() ;
00085 it != options_.end() ;
00086 ++it)
00087 {
00088 it->second.setOptions(options_delta, fields);
00089 }
00090 return;
00091 }
00092
00093 if (&key == &DEFAULT)
00094 {
00095 defaults_.setOptions(options_delta, fields);
00096 return;
00097 }
00098
00099 M_options::iterator it = options_.find(key);
00100 KinematicOptions* opts;
00101 if (it == options_.end())
00102 {
00103
00104 opts = &options_[key];
00105 *opts = defaults_;
00106 }
00107 else
00108 {
00109 opts = &it->second;
00110 }
00111
00112 opts->setOptions(options_delta, fields);
00113 }
00114
00115
00116 void robot_interaction::KinematicOptionsMap::merge(
00117 const KinematicOptionsMap& other)
00118 {
00119 if (&other == this)
00120 return;
00121
00122
00123
00124 boost::mutex *m1 = &lock_;
00125 boost::mutex *m2 = &other.lock_;
00126 if (m2 < m1)
00127 std::swap(m1, m2);
00128 boost::mutex::scoped_lock lock1(*m1);
00129 boost::mutex::scoped_lock lock2(*m2);
00130
00131 defaults_ = other.defaults_;
00132 for (M_options::const_iterator it = other.options_.begin() ;
00133 it != other.options_.end() ;
00134 ++it)
00135 {
00136 options_[it->first] = it->second;
00137 }
00138 }
00139
00140
00141
00142 bool robot_interaction::KinematicOptionsMap::setStateFromIK(
00143 robot_state::RobotState& state,
00144 const std::string& key,
00145 const std::string& group,
00146 const std::string& tip,
00147 const geometry_msgs::Pose& pose) const
00148 {
00149
00150 KinematicOptions options = getOptions(key);
00151 return options.setStateFromIK(state, group, tip, pose);
00152 }
00153