Example #1
0
// BEGIN_TUTORIAL
// Here is the implementation of the TeleopPanel class.  TeleopPanel
// has these responsibilities:
//
// - Act as a container for GUI elements DriveWidget and QLineEdit.
// - Publish command velocities 10 times per second (whether 0 or not).
// - Saving and restoring internal state from a config file.
//
// We start with the constructor, doing the standard Qt thing of
// passing the optional *parent* argument on to the superclass
// constructor, and also zero-ing the velocities we will be
// publishing.
  TeleopPanel::TeleopPanel( QWidget* parent )
  : rviz::Panel( parent )
  , linear_velocity_( 0 )
  , angular_velocity_( 0 )
{
  // Next we lay out the "output topic" text entry field using a
  // QLabel and a QLineEdit in a QHBoxLayout.
  QHBoxLayout* topic_layout = new QHBoxLayout;
  topic_layout->addWidget( new QLabel( "Output Topic:" ));
  output_topic_editor_ = new QLineEdit;
  topic_layout->addWidget( output_topic_editor_ );

  // Then create the control widget.
  drive_widget_ = new DriveWidget;

  // Lay out the topic field above the control widget.
  QVBoxLayout* layout = new QVBoxLayout;
  layout->addLayout( topic_layout );
  layout->addWidget( drive_widget_ );
  setLayout( layout );

  // Create a timer for sending the output.  Motor controllers want to
  // be reassured frequently that they are doing the right thing, so
  // we keep re-sending velocities even when they aren't changing.
  // 
  // Here we take advantage of QObject's memory management behavior:
  // since "this" is passed to the new QTimer as its parent, the
  // QTimer is deleted by the QObject destructor when this TeleopPanel
  // object is destroyed.  Therefore we don't need to keep a pointer
  // to the timer.
  QTimer* output_timer = new QTimer( this );

  // Next we make signal/slot connections.
  connect( drive_widget_, SIGNAL( outputVelocity( float, float )), this, SLOT( setVel( float, float )));
  connect( output_topic_editor_, SIGNAL( editingFinished() ), this, SLOT( updateTopic() ));
  connect( output_timer, SIGNAL( timeout() ), this, SLOT( sendVel() ));

  // Start the timer.
  output_timer->start( 100 );

  // Make the control widget start disabled, since we don't start with an output topic.
  drive_widget_->setEnabled( false );
}
//********************************************************
// Initializes the QT user interface, buttons etc
void TeleopPanel::initGUI()
{

    QHBoxLayout* hboxStatus = new QHBoxLayout;              // Status fields on top
    hboxStatus->addWidget( new QLabel( "Status: " ));
    labelStatus = new QLabel;
    labelStatus->setText("not connected");
    hboxStatus->addWidget(labelStatus);


    buttonConnect = new QPushButton;                        // buttons to connect. ..
    buttonConnect -> setText("Connect");
    buttonReset = new QPushButton;
    buttonReset -> setText("Reset");
    buttonEnable = new QPushButton;
    buttonEnable -> setText("Enable");

    labelOverride = new QLabel;
    labelOverride->setText(QString::number(override_value));
    buttonOverridePlus = new QPushButton;
    buttonOverridePlus -> setText("Override Plus");
    buttonOverrideMinus = new QPushButton;
    buttonOverrideMinus -> setText("Override Minus");


    buttonGripperOpen = new QPushButton;
    buttonGripperOpen -> setText("Open Gripper");
    buttonGripperClose = new QPushButton;
    buttonGripperClose -> setText("Close Gripper");

    buttonJog0Plus = new QPushButton;                        // Jog Buttons
    buttonJog0Plus -> setText("J1 Plus");
    buttonJog0Minus = new QPushButton;
    buttonJog0Minus -> setText("J1 Minus");
    labelJ0 = new QLabel;
    labelJ0 -> setText("0.0");

    buttonJog1Plus = new QPushButton;
    buttonJog1Plus -> setText("J2 Plus");
    buttonJog1Minus = new QPushButton;
    buttonJog1Minus -> setText("J2 Minus");
    labelJ1 = new QLabel;
    labelJ1 -> setText("0.0");

    buttonJog2Plus = new QPushButton;
    buttonJog2Plus -> setText("J3 Plus");
    buttonJog2Minus = new QPushButton;
    buttonJog2Minus -> setText("J3 Minus");
    labelJ2 = new QLabel;
    labelJ2 -> setText("0.0");

    buttonJog3Plus = new QPushButton;
    buttonJog3Plus -> setText("J4 Plus");
    buttonJog3Minus = new QPushButton;
    buttonJog3Minus -> setText("J4 Minus");
    labelJ3 = new QLabel;
    labelJ3 -> setText("0.0");

    if(flagMover6){         // if mover6 is defined add two joint buttons
        buttonJog4Plus = new QPushButton;
        buttonJog4Plus -> setText("J5 Plus");
        buttonJog4Minus = new QPushButton;
        buttonJog4Minus -> setText("J5 Minus");
        labelJ4 = new QLabel;
        labelJ4 -> setText("0.0");
        buttonJog5Plus = new QPushButton;
        buttonJog5Plus -> setText("J6 Plus");
        buttonJog5Minus = new QPushButton;
        buttonJog5Minus -> setText("J6 Minus");
        labelJ5 = new QLabel;
        labelJ5 -> setText("0.0");
    }


    QVBoxLayout* layout = new QVBoxLayout;                  // the main container

    QHBoxLayout * hbox1 = new QHBoxLayout;                  // Compile a simple layout
    hbox1->addWidget(buttonConnect);
    hbox1->addWidget(buttonReset);
    hbox1->addWidget(buttonEnable);

    QHBoxLayout * hboxGripper = new QHBoxLayout;
    hboxGripper->addWidget(buttonGripperClose);
    hboxGripper->addWidget(buttonGripperOpen);

    QHBoxLayout * hboxOverride = new QHBoxLayout;
    hboxOverride->addWidget(buttonOverrideMinus);
    hboxOverride->addWidget(labelOverride);
    hboxOverride->addWidget(buttonOverridePlus);

    layout->addLayout(hboxStatus);
    layout->addLayout(hbox1);
    layout->addLayout(hboxGripper);
    layout->addLayout(hboxOverride);

    QHBoxLayout * hboxJ0 = new QHBoxLayout;
    hboxJ0->addWidget(buttonJog0Minus);
    hboxJ0->addWidget(labelJ0);
    hboxJ0->addWidget(buttonJog0Plus);
    layout->addLayout(hboxJ0);

    QHBoxLayout * hboxJ1 = new QHBoxLayout;
    hboxJ1->addWidget(buttonJog1Minus);
    hboxJ1->addWidget(labelJ1);
    hboxJ1->addWidget(buttonJog1Plus);
    layout->addLayout(hboxJ1);

    QHBoxLayout * hboxJ2 = new QHBoxLayout;
    hboxJ2->addWidget(buttonJog2Minus);
    hboxJ2->addWidget(labelJ2);
    hboxJ2->addWidget(buttonJog2Plus);
    layout->addLayout(hboxJ2);

    QHBoxLayout * hboxJ3 = new QHBoxLayout;
    hboxJ3->addWidget(buttonJog3Minus);
    hboxJ3->addWidget(labelJ3);
    hboxJ3->addWidget(buttonJog3Plus);
    layout->addLayout(hboxJ3);

    if(flagMover6){         // if mover6 is defined add two joint buttons
        QHBoxLayout * hboxJ4 = new QHBoxLayout;
        hboxJ4->addWidget(buttonJog4Minus);
        hboxJ4->addWidget(labelJ4);
        hboxJ4->addWidget(buttonJog4Plus);
        layout->addLayout(hboxJ4);

        QHBoxLayout * hboxJ5 = new QHBoxLayout;
        hboxJ5->addWidget(buttonJog5Minus);
        hboxJ5->addWidget(labelJ5);
        hboxJ5->addWidget(buttonJog5Plus);
        layout->addLayout(hboxJ5);
    }

    setLayout( layout );

    // Create a timer for sending the output.
    output_timer = new QTimer( this );

    connect( buttonConnect, SIGNAL( clicked() ), this, SLOT( btPressedConnect() ));
    connect( buttonReset, SIGNAL( clicked() ), this, SLOT( btPressedReset() ));
    connect( buttonEnable, SIGNAL( clicked() ), this, SLOT( btPressedEnable() ));
    connect( buttonGripperClose, SIGNAL( clicked() ), this, SLOT( btPressedGripperClose() ));
    connect( buttonGripperOpen, SIGNAL( clicked() ), this, SLOT( btPressedGripperOpen() ));
    connect( buttonOverrideMinus, SIGNAL( clicked() ), this, SLOT( btPressedOverrideMinus() ));
    connect( buttonOverridePlus, SIGNAL( clicked() ), this, SLOT( btPressedOverridePlus() ));
    connect( output_timer, SIGNAL( timeout() ), this, SLOT( sendVel() ));

}