passive_joints_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: Dave Coleman */
36 
37 // SA
38 #include "passive_joints_widget.h"
39 // Qt
40 #include <QFormLayout>
41 #include <QMessageBox>
42 
43 namespace moveit_setup_assistant
44 {
45 // ******************************************************************************************
46 // Constructor
47 // ******************************************************************************************
48 PassiveJointsWidget::PassiveJointsWidget(QWidget* parent, moveit_setup_assistant::MoveItConfigDataPtr config_data)
49  : SetupScreenWidget(parent), config_data_(config_data)
50 {
51  // Basic widget container
52  QVBoxLayout* layout = new QVBoxLayout();
53 
54  // Top Header Area ------------------------------------------------
55 
56  HeaderWidget* header =
57  new HeaderWidget("Define Passive Joints", "Specify the set of passive joints (not actuated). Joint "
58  "state is not expected to be published for these joints.",
59  this);
60  layout->addWidget(header);
61 
62  // Joints edit widget
63  joints_widget_ = new DoubleListWidget(this, config_data_, "Joint Collection", "Joint", false);
64  connect(joints_widget_, SIGNAL(selectionUpdated()), this, SLOT(selectionUpdated()));
65  connect(joints_widget_, SIGNAL(previewSelected(std::vector<std::string>)), this,
66  SLOT(previewSelectedJoints(std::vector<std::string>)));
67 
68  // Set the title
69  joints_widget_->title_->setText("");
70 
71  joints_widget_->setColumnNames("Active Joints", "Passive Joints");
72 
73  layout->addWidget(joints_widget_);
74 
75  // Finish Layout --------------------------------------------------
76  this->setLayout(layout);
77 }
78 
79 // ******************************************************************************************
80 //
81 // ******************************************************************************************
83 {
85 
86  // Retrieve pointer to the shared kinematic model
87  const robot_model::RobotModelConstPtr& model = config_data_->getRobotModel();
88 
89  // Get the names of the all joints
90  const std::vector<std::string>& joints = model->getJointModelNames();
91 
92  if (joints.size() == 0)
93  {
94  QMessageBox::critical(this, "Error Loading", "No joints found for robot model");
95  return;
96  }
97  std::vector<std::string> active_joints;
98  for (std::size_t i = 0; i < joints.size(); ++i)
99  if (model->getJointModel(joints[i])->getVariableCount() > 0)
100  active_joints.push_back(joints[i]);
101 
102  // Set the available joints (left box)
103  joints_widget_->setAvailable(active_joints);
104 
105  std::vector<std::string> passive_joints;
106  for (std::size_t i = 0; i < config_data_->srdf_->passive_joints_.size(); ++i)
107  passive_joints.push_back(config_data_->srdf_->passive_joints_[i].name_);
108  joints_widget_->setSelected(passive_joints);
109 }
110 
111 // ******************************************************************************************
112 //
113 // ******************************************************************************************
115 {
116  config_data_->srdf_->passive_joints_.clear();
117  for (int i = 0; i < joints_widget_->selected_data_table_->rowCount(); ++i)
118  {
120  pj.name_ = joints_widget_->selected_data_table_->item(i, 0)->text().toStdString();
121  config_data_->srdf_->passive_joints_.push_back(pj);
122  }
124 }
125 
126 // ******************************************************************************************
127 // Called from Double List widget to highlight joints
128 // ******************************************************************************************
129 void PassiveJointsWidget::previewSelectedJoints(std::vector<std::string> joints)
130 {
131  // Unhighlight all links
132  Q_EMIT unhighlightAll();
133 
134  for (std::size_t i = 0; i < joints.size(); ++i)
135  {
136  const robot_model::JointModel* joint_model = config_data_->getRobotModel()->getJointModel(joints[i]);
137 
138  // Check that a joint model was found
139  if (!joint_model)
140  {
141  continue;
142  }
143 
144  // Get the name of the link
145  const std::string link = joint_model->getChildLinkModel()->getName();
146 
147  if (link.empty())
148  {
149  continue;
150  }
151 
152  // Highlight link
153  Q_EMIT highlightLink(link, QColor(255, 0, 0));
154  }
155 }
156 
157 } // namespace
void setSelected(const std::vector< std::string > &items)
Set the right box.
moveit_setup_assistant::MoveItConfigDataPtr config_data_
Contains all the configuration data for the setup assistant.
void highlightLink(const std::string &name, const QColor &)
Event for telling rviz to highlight a link of the robot.
void unhighlightAll()
Event for telling rviz to unhighlight all links of the robot.
virtual void focusGiven()
Received when this widget is chosen from the navigation menu.
void setAvailable(const std::vector< std::string > &items)
Loads the availble data list.
void previewSelectedJoints(std::vector< std::string > joints)
Called from Double List widget to highlight joints.
PassiveJointsWidget(QWidget *parent, moveit_setup_assistant::MoveItConfigDataPtr config_data)
void setColumnNames(const QString &col1, const QString &col2)
Set the names of the two columns in the widget.


moveit_setup_assistant
Author(s): Dave Coleman
autogenerated on Sun Oct 18 2020 13:19:28