10 #include <QGridLayout> 11 #include <QToolButton> 27 vel_drawing(*this, control, motion_model), mapper(this) {
28 setTitle( tr(
"Teleoperation") );
31 static const int nb_buttons = 7, nb_dir_btns = 4, nb_shortcuts = 2;
33 static const Qt::Key shortcuts[nb_buttons][nb_shortcuts] =
34 { {Qt::Key_8, Qt::Key_Up}, {Qt::Key_Period, Qt::Key_PageDown},
35 {Qt::Key_2, Qt::Key_Down}, {Qt::Key_0, Qt::Key_End},
36 {Qt::Key_4, Qt::Key_Left}, {Qt::Key_5, Qt::Key_Home},
37 {Qt::Key_6, Qt::Key_Right} };
39 static const char *tips[nb_buttons] =
40 {
"Accelerate motion",
"Stop motion",
"Decelerate motion",
41 "Stop all",
"Accelerate rotation toward left",
42 "Stop rotation",
"Accelerate rotation toward right" };
44 static const Qt::ArrowType arrows[nb_dir_btns] =
45 { Qt::UpArrow, Qt::DownArrow, Qt::LeftArrow, Qt::RightArrow };
47 static const QString file(
":/files/%1.svg");
49 static const char *names[] = {
"pause",
"stop",
"eject"};
51 static const int disp_size = 3;
53 setMinimumSize(200, 200);
55 QGridLayout *layout =
new QGridLayout(
this);
57 for(
int id = 0;
id < nb_buttons;
id++) {
58 QToolButton *button =
new QToolButton(
this);
60 button->setArrowType(arrows[
id / 2]);
62 button->setIcon( QIcon( file.arg(names[
id / 2]) ) );
64 layout->addWidget(button,
id < disp_size ?
id : disp_size,
65 id < disp_size ? 0 :
id - disp_size);
67 for(
int short_id = 0; short_id < nb_shortcuts; short_id++)
68 button->setShortcut(shortcuts[
id][short_id]);
70 button->setToolTip(tips[
id]);
72 mapper.setMapping(button, shortcuts[
id][0]);
73 connect( button, SIGNAL( pressed() ), &
mapper, SLOT( map() ) );
75 connect( button, SIGNAL( released() ),
this, SLOT(
stopAcc() ) );
78 connect( &
mapper, SIGNAL( mapped(
const int&) ),
79 this, SLOT(
react(
const int&) ) );
82 0, 1, disp_size, disp_size);
114 case Qt::Key_0 :
case Qt::Key_End : kbd_ctrl.
stopMotion();
break;
115 case Qt::Key_1 : kbd_ctrl.
acc(-1,1);
break;
116 case Qt::Key_2 :
case Qt::Key_Down : kbd_ctrl.
acc(-1,0);
break;
117 case Qt::Key_3 : kbd_ctrl.
acc(-1,-1);
break;
118 case Qt::Key_4 :
case Qt::Key_Left : kbd_ctrl.
acc(0,1);
break;
119 case Qt::Key_5:
case Qt::Key_Home: kbd_ctrl.
stopRotation();
break;
120 case Qt::Key_6 :
case Qt::Key_Right : kbd_ctrl.
acc(0,-1);
break;
121 case Qt::Key_7 : kbd_ctrl.
acc(1,1);
break;
122 case Qt::Key_8 :
case Qt::Key_Up : kbd_ctrl.
acc(1,0);
break;
123 case Qt::Key_9 : kbd_ctrl.
acc(1,-1);
break;
124 case Qt::Key_Period:
case Qt::Key_PageDown:
void stopMotion()
Stops the robot (i.e. sets both velocities to zero).
KbdCtrl allows to control the robot with the keyboard.
void stopTranslation()
Stops the robot's translation.
void acc(const int transFact, const int rotFact)
Changes both velocities (translation and rotation) by adding or removing the related increment (accel...
QWidget & widget()
Returns the widget used to display the behaviour.
Qt based teleoperation widget for qt_ctrl.
This class defines a motion model, with the motion limits.
void stopRotation()
Stops the robot's rotation.