moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
trajectory_panel.cpp
Go to the documentation of this file.
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2017, Yannick Jonetzko
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: Yannick Jonetzko */
36
38#include <QHBoxLayout>
39
40namespace moveit_rviz_plugin
41{
42TrajectoryPanel::TrajectoryPanel(QWidget* parent) : Panel(parent)
43{
44}
45
47
49{
50 slider_ = new QSlider(Qt::Horizontal);
51 slider_->setTickInterval(1);
52 slider_->setMinimum(0);
53 slider_->setMaximum(0);
54 slider_->setTickPosition(QSlider::TicksBelow);
55 slider_->setPageStep(1);
56 slider_->setEnabled(false);
57 connect(slider_, SIGNAL(valueChanged(int)), this, SLOT(sliderValueChanged(int)));
58
59 maximum_label_ = new QLabel(QString::number(slider_->maximum()));
60 minimum_label_ = new QLabel(QString::number(slider_->minimum()));
61 minimum_label_->setFixedWidth(20);
62
63 button_ = new QPushButton();
64 button_->setText("Pause");
65 button_->setEnabled(false);
66 connect(button_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
67
68 QHBoxLayout* layout = new QHBoxLayout;
69 layout->addWidget(new QLabel("Waypoint:"));
70 layout->addWidget(minimum_label_);
71 layout->addWidget(slider_);
72 layout->addWidget(maximum_label_);
73 layout->addWidget(button_);
74 setLayout(layout);
75
76 paused_ = false;
77 parentWidget()->setVisible(false);
78}
79
81{
82 show();
83 parentWidget()->show();
84}
85
87{
88 hide();
89 parentWidget()->hide();
90}
91
92void TrajectoryPanel::update(int way_point_count)
93{
94 last_way_point_ = std::max(0, way_point_count - 1);
95
96 slider_->setEnabled(way_point_count != 0);
97 button_->setEnabled(way_point_count != 0);
98
99 slider_->setSliderPosition(0);
100 slider_->setMaximum(last_way_point_);
101 maximum_label_->setText(QString::number(last_way_point_));
102 pauseButton(false);
103}
104
106{
107 if (pause)
108 {
109 button_->setText("Play");
110 paused_ = true;
111 }
112 else
113 {
114 button_->setText("Pause");
115 paused_ = false;
116 if (slider_->sliderPosition() == last_way_point_)
117 slider_->setSliderPosition(0);
118 }
119}
120
122{
123 slider_->setSliderPosition(position);
124}
125
126void TrajectoryPanel::sliderValueChanged(int value)
127{
128 minimum_label_->setText(QString::number(value));
129}
130
131void TrajectoryPanel::buttonClicked()
132{
133 if (paused_)
134 {
135 pauseButton(false);
136 }
137 else
138 {
139 pauseButton(true);
140 }
141}
142
143} // namespace moveit_rviz_plugin
TrajectoryPanel(QWidget *parent=nullptr)