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


moveit_setup_assistant
Author(s): Dave Coleman
autogenerated on Sat May 3 2025 02:28:04