display.cpp
Go to the documentation of this file.
1 
9 #include <gui/display.hpp>
10 #include <QVBoxLayout>
11 #include <QGroupBox>
12 #include <QPushButton>
13 
14 
15 // Labels shown before the values, and headers in the ouput file.
16 // Since 0.2.3
17 const char *DataWidget::names[] =
18  {"t", "x", "y", "theta", "v", "omega", "v", "omega"}; // -----------
19 
20 /* The constructor needs the ROS node whose data will be displayed.
21  *
22  * Parameter parent The main window containing this widget,
23  * node the ROS node whose data will be displayed.
24  */
25 DataWidget::DataWidget(QWidget& parent)
26  : QWidget(&parent), output(NULL), motion_GUI() {
27  // the widget is split vertically in two group boxes
28  QVBoxLayout *layout = new QVBoxLayout(this);
29  QGroupBox *odom_box = new QGroupBox( tr("Odometry"), this),
30  *cmd_box = new QGroupBox( tr("Commands"), this), *a_box;
31  layout->addWidget(odom_box);
32  layout->addWidget(cmd_box);
33  QGridLayout *odom_layout = new QGridLayout(odom_box),
34  *cmd_layout = new QGridLayout(cmd_box), *a_layout;
35  static const char *init_val = "----.--";
36  int idx; // for each label
37  for(idx = 0, a_layout = odom_layout; idx < nbLabels; idx++) {
38  // update the pointers when needed
39  if (idx == nbOdoms) a_layout = cmd_layout;
40  // Boxes contains lines of 3 columns with 2 labels
41  const int nbCols = 3, dId = (idx == tOdom ? nbOdoms - 1 :
42  idx < nbOdoms ? idx - 1 : idx),
43  // dId = display index, index are displayed with tOdom
44  // as last odometry data
45  line = dId / nbCols, col = (2 * dId) % (2 * nbCols);
46  // Additions to the basic labels
47  const bool isGreek =
48  (idx == thOdom) || (idx == omOdom) || (idx == omCmd);
49  char name[25];
50  sprintf(name, "%s%s%s", isGreek ? "<span>&" : "<em>",
51  names[idx], isGreek ? ";</span>:" : "</em>:");
52  a_layout->addWidget(new QLabel( tr(name) ), line, col);
53  labels[idx].setText(init_val);
54  a_layout->addWidget(&(labels[idx]), line, col + 1);
55  } // end of for (each label)
56  QPushButton *motionBtn = new QPushButton("Historic"); // History
57  layout->addWidget(motionBtn); // button is added at the bottom
58  connect( motionBtn, SIGNAL( clicked() ), // and connected to
59  &motion_GUI, SLOT( showHide() ) ); // motion's GUI showHide
60 } // end of DataWidget::DataWidget(QtCtrlGUI&, ROSnode&) -------------
61 
62 /* Transfer data into the labels. See labels.
63  * This is the common part of updateOdometry and updateCommands.
64  *
65  * Parameters offset The initial index in the label array,
66  * nbData the number of data to transfer,
67  * data the array of data to display.
68  */
69 void DataWidget::setLabels(const Labels& offset, const Labels& nbData,
70  const double *data) {
71  static const QString val("%1");
72  int idx;
73  const double *data_prt = data;
74  QLabel *label_prt = &(labels[offset]);
75  for(idx = 0; idx < nbData; idx++, data_prt++, label_prt++)
76  // show the angle in degree, and rotation velocities in degree/s
77  label_prt->setText
78  ( (idx == thOdom) || (idx == omOdom) || (idx == omCmd)
79  ? val.arg(iSeeML::Object::rad2deg(*data_prt), 0, 'f', 0)
80  : val.arg(*data_prt, 0, 'f', 2) );
81 } // end of DataWidget::setLabels(const Labels&, ..., const double*) -
82 
83 // Update the display of the odometry.
84 // Parameters odom The odometry data. Since 0.2.2.
85 void DataWidget::updateState(const State& state) {
86  const iSeeML::rob::OrPtConfig& q = state.configuration();
87  const iSeeML::geom::Point& P = q.position();
88  const double data[] =
89  {state.date(), P.xCoord(), P.yCoord(), q.orientation(),
90  state.translationVelocity(), state.rotationVelocity()};
91  setLabels(tOdom, nbOdoms, data);
92  motion_GUI.addState(state);
93  if ( outputOK() ) {
94  int idx;
95  for(idx = 0; idx < nbOdoms; idx++)
96  *output << data[idx] << '\t';
97  *output << last_vel.x() << '\t' << last_vel.y() << std::endl;
98  } // end of if (ouput OK)
99 } // end of void DataWidget::updateOdometry(const Odometry::ConstPtr&)
100 
101 // Update the display of the controller's commands.
102 // Parameters trans_vel the translation velocity sent to ROS,
103 // rot_vel the rotation velocity sent to ROS.
104 // Since 0.3.1
105 void DataWidget::updateCommands(const double& trans_vel,
106  const double& rot_vel) {
107  const double data[] = {trans_vel, rot_vel};
108  last_vel.setX(data[0]);
109  last_vel.setY(data[1]);
110  setLabels(vCmd, nbCmds, data);
111 } // end of void DataWidget::updateCommands(const Twist&) ------------
void updateState(const State &state)
Update the display of the state.
Definition: display.cpp:85
Number of commands indexes.
Definition: display.hpp:44
Index of the odometry&#39;s time.
Definition: display.hpp:34
QPointF last_vel
The last command published.
Definition: display.hpp:28
std::ofstream * output
The output stream, if any.
Definition: display.hpp:29
const double & rotationVelocity() const
Gives the rotation velocity of the state.
Definition: state.hpp:81
const iSeeML::rob::OrPtConfig & configuration() const
Gives the configuration of the state.
Definition: state.hpp:67
DataWidget(QWidget &parent)
The constructor needs the ROS node whose data will be displayed.
Definition: display.cpp:25
Index of the commands&#39; rotation velocity.
Definition: display.hpp:41
Number of labels in the array.
Definition: display.hpp:42
bool outputOK() const
Is the output stream OK for writting?
Definition: display.hpp:74
Labels
These are the indexes of the array of labels.
Definition: display.hpp:33
const double & translationVelocity() const
Gives the translation velocity of the state.
Definition: state.hpp:74
const double & date() const
Gives the configuration of the state.
Definition: state.hpp:61
Qt widget displaying data for qt_ctrl.
Index of the odometry&#39;s orientation.
Definition: display.hpp:37
This class defines a state, i.e. a configuration and its (translation and rotation) velocities...
Definition: state.hpp:22
QLabel labels[nbLabels]
Array of labels displaying controller&#39;s data.
Definition: display.hpp:53
void addState(const State &state, const Qt::GlobalColor motion_color=Qt::blue)
Definition: overview.cpp:39
void setLabels(const Labels &offset, const Labels &nbData, const double *data)
Transfer data into the labels.
Definition: display.cpp:69
static const char * names[]
Labels shown before the values, and headers in the ouput file.
Definition: display.hpp:49
QtMotionGUI motion_GUI
Window showing the motion&#39;s path and velocities.
Definition: display.hpp:57
Index of the commands&#39; translation velocity.
Definition: display.hpp:40
void updateCommands(const double &trans_vel, const double &rot_vel)
Update the display of the controller&#39;s commands.
Definition: display.cpp:105
Index of the odometry&#39;s rotation velocity.
Definition: display.hpp:39
Number of odometry indexes.
Definition: display.hpp:43


qt_ctrl
Author(s): Alexis Scheuer
autogenerated on Wed Dec 16 2020 15:51:32