fill_trajectory.cpp
Go to the documentation of this file.
2 
3 namespace ram_qt_guis
4 {
6  rviz::Panel(parent)
7 {
8  setObjectName("Fill trajectory");
9  setName(objectName());
10 
12 
13  movement_type_ = new QComboBox;
14  movement_type_->addItem("Joint");
15  movement_type_->addItem("Linear");
16  QHBoxLayout *movement_type_layout = new QHBoxLayout;
17  movement_type_layout->addWidget(new QLabel("Movement type:"));
18  movement_type_layout->addWidget(movement_type_);
19  connect(movement_type_, SIGNAL(currentIndexChanged(int)), this, SLOT(movementTypeChanged()));
20 
21  approach_type_ = new QComboBox;
22  approach_type_->addItem("Stop/go");
23  approach_type_->addItem("Blend radius");
24  QHBoxLayout *approach_type_layout = new QHBoxLayout;
25  approach_type_layout->addWidget(new QLabel("Approach type:"));
26  approach_type_layout->addWidget(approach_type_);
27  connect(approach_type_, SIGNAL(currentIndexChanged(int)), this, SLOT(approachTypeChanged()));
28 
29  blend_radius_ = new QSpinBox;
30  blend_radius_->setRange(0, 100);
31  blend_radius_->setSingleStep(5);
32  blend_radius_->setSuffix(" %");
33  QHBoxLayout *blend_radius_layout = new QHBoxLayout;
34  blend_radius_layout->addWidget(new QLabel("Blend radius:"));
35  blend_radius_layout->addWidget(blend_radius_);
36 
37  speed_ = new QDoubleSpinBox;
38  speed_->setRange(0.001, 100);
39  speed_->setSingleStep(0.1);
40  QHBoxLayout *speed_layout = new QHBoxLayout;
41  speed_layout->addWidget(new QLabel("Speed:"));
42  speed_layout->addWidget(speed_);
43 
44  laser_power_ = new QSpinBox;
45  laser_power_->setRange(0, 32000);
46  laser_power_->setSingleStep(100);
47  laser_power_->setSuffix(" W");
48  QHBoxLayout *laser_power_layout = new QHBoxLayout;
49  laser_power_layout->addWidget(new QLabel("Laser power:"));
50  laser_power_layout->addWidget(laser_power_);
51 
52  feed_rate_ = new QDoubleSpinBox;
53  feed_rate_->setRange(0, 10);
54  feed_rate_->setSingleStep(0.1);
55  feed_rate_->setSuffix(" meters/min");
56  QHBoxLayout *feed_rate_layout = new QHBoxLayout;
57  feed_rate_layout->addWidget(new QLabel("Feed rate:"));
58  feed_rate_layout->addWidget(feed_rate_);
59 
60  send_button_ = new QPushButton("Send");
61 
62  QVBoxLayout *scroll_widget_layout = new QVBoxLayout();
63  QWidget *scroll_widget = new QWidget;
64  scroll_widget->setLayout(scroll_widget_layout);
65  QScrollArea *scroll_area = new QScrollArea;
66  scroll_area->setWidget(scroll_widget);
67  scroll_area->setWidgetResizable(true);
68  scroll_area->setFrameShape(QFrame::NoFrame);
69  QVBoxLayout* main_layout = new QVBoxLayout(this);
70  main_layout->addWidget(scroll_area);
71 
72  scroll_widget_layout->addLayout(movement_type_layout);
73  scroll_widget_layout->addLayout(approach_type_layout);
74  scroll_widget_layout->addLayout(blend_radius_layout);
75  scroll_widget_layout->addLayout(speed_layout);
76  scroll_widget_layout->addLayout(laser_power_layout);
77  scroll_widget_layout->addLayout(feed_rate_layout);
78  scroll_widget_layout->addStretch(1);
79 
80  main_layout->addWidget(send_button_);
81 
82  connect(send_button_, SIGNAL(clicked()), this, SLOT(sendInformationButtonHandler()));
83  connect(this, SIGNAL(displayErrorMessageBox(const QString, const QString, const QString)), this,
84  SLOT(displayErrorBoxHandler(const QString, const QString, const QString)));
85 
86  // connect with configChanged signal
87  connect(movement_type_, SIGNAL(currentIndexChanged(int)), this, SIGNAL(configChanged()));
88  connect(approach_type_, SIGNAL(currentIndexChanged(int)), this, SIGNAL(configChanged()));
89  connect(blend_radius_, SIGNAL(valueChanged(int)), this, SIGNAL(configChanged()));
90  connect(speed_, SIGNAL(valueChanged(double)), this, SIGNAL(configChanged()));
91  connect(laser_power_, SIGNAL(valueChanged(int)), this, SIGNAL(configChanged()));
92  connect(feed_rate_, SIGNAL(valueChanged(double)), this, SIGNAL(configChanged()));
93 
94  pub_ = nh_.advertise<ram_msgs::AdditiveManufacturingParams>("ram/fill_trajectory/parameters", 1);
95 }
96 
98 {
99 }
100 
102 {
103  params_.movement_type = movement_type_->currentIndex();
104  params_.approach_type = approach_type_->currentIndex();
105  params_.blend_radius = blend_radius_->value();
106  params_.speed = speed_->value() * conversion_factor_;
107  params_.laser_power = laser_power_->value();
108  params_.feed_rate = feed_rate_->value() / 60.0; // meters/min > meters / sec
109 }
110 
112 {
113  Q_EMIT setEnabled(false);
114  // Change speed
115  switch (movement_type_->currentIndex())
116  {
117  case 0: //Joint
118  speed_->setSuffix("");
119  conversion_factor_ = 1;
120  break;
121  case 1: //Linear
122  speed_->setSuffix(" meters/min");
123  conversion_factor_ = 1 / 60.0; // meters/min > meters / sec
124  break;
125  }
127  Q_EMIT setEnabled(true);
128 }
129 
131 {
132  Q_EMIT setEnabled(false);
133  switch (approach_type_->currentIndex())
134  {
135  case 0: // Stop-go
136  blend_radius_->setEnabled(false);
137  break;
138  case 1: // Blend radius
139  blend_radius_->setEnabled(true);
140  break;
141  }
142  Q_EMIT setEnabled(true);
143 }
144 
146 {
147  Q_EMIT configChanged();
148  Q_EMIT setEnabled(false);
150  // Run in a separate thread
151  QtConcurrent::run(this, &FillTrajectory::sendInformation);
152 }
153 
155 {
156  if (pub_.getNumSubscribers() == 0)
157  {
158  Q_EMIT displayErrorMessageBox(
159  "Published message will be lost: ",
160  QString::fromStdString(pub_.getTopic() + " has no subscriber"), "");
161  }
162 
164  ros::spinOnce();
165  Q_EMIT setEnabled(true);
166 }
167 
169 {
170  rviz::Panel::load(config);
171 
172  int tmp_int(0);
173  float tmp_float(0.01);
174 
175  if (config.mapGetInt("movement_type", &tmp_int))
176  movement_type_->setCurrentIndex(tmp_int);
177 
178  if (config.mapGetInt("approach_type", &tmp_int))
179  approach_type_->setCurrentIndex(tmp_int);
180 
181  if (config.mapGetFloat("blend_radius", &tmp_float))
182  blend_radius_->setValue(tmp_float);
183 
184  if (config.mapGetFloat("speed", &tmp_float))
185  speed_->setValue(tmp_float);
186 
187  if (config.mapGetFloat("laser_power", &tmp_float))
188  laser_power_->setValue(tmp_float);
189 
190  if (config.mapGetFloat("feed_rate", &tmp_float))
191  feed_rate_->setValue(tmp_float);
192 
193 
194  Q_EMIT approachTypeChanged();
195  QtConcurrent::run(this, &FillTrajectory::sendLoadedInformation);
196 }
197 
199 {
201 
202  // Try to send parameters
203  unsigned count(0);
204  while (1)
205  {
206  if (pub_.getNumSubscribers() != 0)
207  {
208  Q_EMIT setEnabled(false);
210  ros::spinOnce();
211  Q_EMIT setEnabled(true);
212  break;
213  }
214  ros::Duration(0.5).sleep();
215 
216  if (++count > 5)
217  break;
218  }
219 }
220 
222  {
223  config.mapSetValue("movement_type", movement_type_->currentIndex());
224  config.mapSetValue("approach_type", approach_type_->currentIndex());
225  config.mapSetValue("blend_radius", blend_radius_->value());
226  config.mapSetValue("speed", speed_->value());
227  config.mapSetValue("laser_power", laser_power_->value());
228  config.mapSetValue("feed_rate", feed_rate_->value());
229  rviz::Panel::save(config);
230 }
231 
232 void FillTrajectory::displayErrorBoxHandler(const QString title,
233  const QString message,
234  const QString info_msg)
235 {
236  bool old_state(isEnabled());
237  Q_EMIT setEnabled(false);
238  QMessageBox msg_box;
239  msg_box.setWindowTitle(title);
240  msg_box.setText(message);
241  msg_box.setInformativeText(info_msg);
242  msg_box.setIcon(QMessageBox::Critical);
243  msg_box.setStandardButtons(QMessageBox::Ok);
244  msg_box.exec();
245  Q_EMIT setEnabled(old_state);
246 }
247 
248 }
249 
void publish(const boost::shared_ptr< M > &message) const
bool sleep() const
void load(const rviz::Config &config)
bool mapGetFloat(const QString &key, float *value_out) const
void configChanged()
FillTrajectory(QWidget *parent=NULL)
void mapSetValue(const QString &key, QVariant value)
virtual void setName(const QString &name)
void displayErrorMessageBox(const QString, const QString, const QString)
void displayErrorBoxHandler(const QString title, const QString message, const QString info_msg)
ram_msgs::AdditiveManufacturingParams params_
void save(rviz::Config config) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool mapGetInt(const QString &key, int *value_out) const
uint32_t getNumSubscribers() const
virtual void save(Config config) const
std::string getTopic() const
virtual void load(const Config &config)
ROSCPP_DECL void spinOnce()
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)


ram_qt_guis
Author(s): Victor Lamoine - Institut Maupertuis
autogenerated on Mon Jun 10 2019 14:50:11