motion_planning_param_widget.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012, 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: Robert Haschke */
36 
42 
44 
45 namespace moveit_rviz_plugin
46 {
47 MotionPlanningParamWidget::MotionPlanningParamWidget(QWidget* parent) : rviz::PropertyTreeWidget(parent)
48 {
50 }
51 
53 {
54 }
55 
56 void MotionPlanningParamWidget::setMoveGroup(const mpi::MoveGroupInterfacePtr& mg)
57 {
58  move_group_ = mg;
59  if (mg)
61 }
62 
63 void MotionPlanningParamWidget::setGroupName(const std::string& group_name)
64 {
65  group_name_ = group_name;
66  this->setModel(NULL);
68  delete property_tree_model_;
70 }
71 
72 bool try_lexical_convert(const QString& value, long& lvalue)
73 {
74  bool ok;
75  lvalue = value.toLong(&ok);
76  return ok;
77 }
78 
79 bool try_lexical_convert(const QString& value, double& dvalue)
80 {
81  bool ok;
82  dvalue = value.toDouble(&ok);
83  return ok;
84 }
85 
87 {
88  if (planner_id_.empty())
89  return NULL;
90  const std::map<std::string, std::string>& params = move_group_->getPlannerParams(planner_id_, group_name_);
91 
92  rviz::Property* root = new rviz::Property(QString::fromStdString(planner_id_ + " parameters"));
93  for (std::map<std::string, std::string>::const_iterator it = params.begin(), end = params.end(); it != end; ++it)
94  {
95  const QString key = QString::fromStdString(it->first);
96  const QString value = QString::fromStdString(it->second);
97  long value_long;
98  double value_double;
99 
100  if (try_lexical_convert(value, value_long))
101  {
102  new rviz::IntProperty(key, value_long, QString(), root, SLOT(changedValue()), this);
103  }
104  else if (try_lexical_convert(value, value_double))
105  {
106  new rviz::FloatProperty(key, value_double, QString(), root, SLOT(changedValue()), this);
107  }
108  else
109  new rviz::StringProperty(key, value, QString(), root, SLOT(changedValue()), this);
110  }
111  return root;
112 }
113 
115 {
116  if (!move_group_)
117  return;
118  rviz::Property* source = qobject_cast<rviz::Property*>(QObject::sender());
119  std::map<std::string, std::string> params;
120  params[source->getName().toStdString()] = source->getValue().toString().toStdString();
121  move_group_->setPlannerParams(planner_id_, group_name_, params);
122 }
123 
124 void MotionPlanningParamWidget::setPlannerId(const std::string& planner_id)
125 {
126  planner_id_ = planner_id;
127  if (!move_group_)
128  return;
129 
134  if (old_model)
135  delete old_model;
136 }
137 }
#define NULL
root
void setModel(PropertyTreeModel *model)
moveit::planning_interface::MoveGroupInterfacePtr move_group_
virtual QVariant getValue() const
void setMoveGroup(const moveit::planning_interface::MoveGroupInterfacePtr &mg)
bool try_lexical_convert(const QString &value, long &lvalue)
int value
virtual QString getName() const


visualization
Author(s): Ioan Sucan , Dave Coleman , Sachin Chitta
autogenerated on Sun Oct 18 2020 13:19:09