Commit 76f9e3a7 authored by Joseph Mirabel's avatar Joseph Mirabel Committed by GitHub

Merge pull request #3 from jmirabel/multithread

Use HPP thread safe API
parents 10d019bc 940a9d32
[plugins]
hppcorbaserverplugin.so=false
hppmanipulationplugin.so=false
# Plugin for hpp-manipulation-server
hppmanipulationwidgetsplugin.so=true
hppmonitoringplugin.so=true
# Plugin for hppcorbaserver
hppwidgetsplugin.so=false
libhppmanipulationplugin.so=false
libhppmonitoringplugin.so=false
......@@ -67,7 +67,6 @@ namespace hpp {
toolBar_->addAction (autoBuildGraph);
connect(autoBuildGraph, SIGNAL(triggered()), SLOT(autoBuildGraph()));
connect(&main->worker(), SIGNAL(done(int)), SLOT(handleWorkerDone(int)));
main->registerSlot("autoBuildGraph", this);
main->registerSlot("drawRobotContacts", this);
main->registerSlot("drawEnvironmentsContacts", this);
......@@ -81,16 +80,17 @@ namespace hpp {
void HppManipulationWidgetsPlugin::loadRobotModel(gepetto::gui::DialogLoadRobot::RobotDefinition rd)
{
try {
client ()->robot ()->getCurrentConfig();
hpp::floatSeq_var q = client ()->robot ()->getCurrentConfig();
(void)q;
} catch (hpp::Error const& e) {
client ()->robot ()->createRobot (gepetto::gui::Traits<QString>::to_corba("composite").in());
client ()->robot ()->createRobot (to_corba("composite").in());
}
hpp_->robot ()->insertRobotModel (gepetto::gui::Traits<QString>::to_corba(rd.robotName_).in(),
gepetto::gui::Traits<QString>::to_corba(rd.rootJointType_).in(),
gepetto::gui::Traits<QString>::to_corba(rd.package_).in(),
gepetto::gui::Traits<QString>::to_corba(rd.modelName_).in(),
gepetto::gui::Traits<QString>::to_corba(rd.urdfSuf_).in(),
gepetto::gui::Traits<QString>::to_corba(rd.srdfSuf_).in());
hpp_->robot ()->insertRobotModel (to_corba(rd.robotName_).in(),
to_corba(rd.rootJointType_).in(),
to_corba(rd.package_).in(),
to_corba(rd.modelName_).in(),
to_corba(rd.urdfSuf_).in(),
to_corba(rd.srdfSuf_).in());
// This is already done in requestRefresh
// jointTreeWidget_->reload();
gepetto::gui::MainWindow::instance()->requestRefresh();
......@@ -101,15 +101,16 @@ namespace hpp {
void HppManipulationWidgetsPlugin::loadEnvironmentModel(gepetto::gui::DialogLoadEnvironment::EnvironmentDefinition ed)
{
try {
client ()->robot ()->getCurrentConfig();
hpp::floatSeq_var q = client ()->robot ()->getCurrentConfig();
(void)q;
} catch (hpp::Error const& e) {
client ()->robot ()->createRobot (gepetto::gui::Traits<QString>::to_corba("composite").in());
client ()->robot ()->createRobot (to_corba("composite").in());
}
hpp_->robot ()-> loadEnvironmentModel(gepetto::gui::Traits<QString>::to_corba(ed.package_).in(),
gepetto::gui::Traits<QString>::to_corba(ed.urdfFilename_).in(),
gepetto::gui::Traits<QString>::to_corba(ed.urdfSuf_).in(),
gepetto::gui::Traits<QString>::to_corba(ed.srdfSuf_).in(),
gepetto::gui::Traits<QString>::to_corba(ed.name_ + "/").in());
hpp_->robot ()-> loadEnvironmentModel(to_corba(ed.package_).in(),
to_corba(ed.urdfFilename_).in(),
to_corba(ed.urdfSuf_).in(),
to_corba(ed.srdfSuf_).in(),
to_corba(ed.name_ + "/").in());
HppWidgetsPlugin::computeObjectPosition();
gepetto::gui::MainWindow::instance()->requestRefresh();
emit logSuccess ("Environment " + ed.name_ + " loaded");
......@@ -506,13 +507,6 @@ namespace hpp {
graphBuilder_->show();
}
void HppManipulationWidgetsPlugin::handleWorkerDone(int id)
{
if (id == lastId_) {
gepetto::gui::MainWindow::instance()->logJobDone(id, "Graph is build");
}
}
void HppManipulationWidgetsPlugin::loadConstraintWidget()
{
gepetto::gui::MainWindow* main = gepetto::gui::MainWindow::instance();
......
......@@ -99,7 +99,6 @@ namespace hpp {
private slots:
/// Construct all the corba vars and create the graph.
void buildGraph();
void handleWorkerDone(int id);
protected:
virtual void loadConstraintWidget();
......@@ -135,8 +134,6 @@ namespace hpp {
QToolBar *toolBar_;
QTabWidget *tw_;
QDialog* graphBuilder_;
int lastId_;
};
} // namespace gui
} // namespace hpp
......
......@@ -75,8 +75,8 @@ namespace hpp {
void ConfigurationListWidget::onSaveClicked ()
{
hpp::floatSeq_var c = plugin_->client()->robot()->getCurrentConfig ();
list()->addItem(makeItem(name()->text(), c.in()));
hpp::floatSeq const* c = plugin_->getCurrentConfig ();
list()->addItem(makeItem(name()->text(), *c));
name()->setText(basename_ + QString::number(count_));
count_++;
}
......@@ -85,8 +85,7 @@ namespace hpp {
{
if (current != 0) {
const hpp::floatSeq& c = getConfig(current);
plugin_->client()->robot()->setCurrentConfig (c);
main_->requestApplyCurrentConfiguration();
plugin_->setCurrentConfig (c);
if (previous_ &&
previous_ != current->listWidget()) {
previous_->clearSelection();
......
......@@ -9,7 +9,6 @@
#include <QDockWidget>
#include <omniORB4/CORBA.h>
#include "gepetto/gui/meta.hh"
#include "gepetto/gui/mainwindow.hh"
#include "hppwidgetsplugin/hppwidgetsplugin.hh"
......
......@@ -30,7 +30,6 @@
#include "hppwidgetsplugin/joint-action.hh"
#include "hppwidgetsplugin/roadmap.hh"
#include <gepetto/gui/meta.hh>
using CORBA::ULong;
......@@ -151,8 +150,16 @@ namespace hpp {
main->registerSlot("getCurrentPath", pathPlayer_);
main->registerSlot("getHppIIOPurl", this);
main->registerSlot("getHppContext", this);
main->registerSlot("getCurrentConfig", this);
main->registerSlot("setCurrentConfig", this);
main->registerSlot("getSelectedJoint", jointTreeWidget_);
main->registerSignal(SIGNAL(appliedConfigAtParam(int,double)), pathPlayer_);
QAction* action = main->findChild<QAction*>("actionFetch_configuration");
if (action != NULL) connect (action, SIGNAL(triggered()), SLOT(fetchConfiguration()));
else qDebug () << "Action actionFetch_configuration not found";
action = main->findChild<QAction*>("actionSend_configuration");
if (action != NULL) connect (action, SIGNAL(triggered()), SLOT(sendConfiguration()));
else qDebug () << "Action actionSend_configuration not found";
ActionSearchBar* asb = main->actionSearchBar();
JointAction* a;
......@@ -174,12 +181,12 @@ namespace hpp {
void HppWidgetsPlugin::loadRobotModel(gepetto::gui::DialogLoadRobot::RobotDefinition rd)
{
client()->robot()->loadRobotModel(
gepetto::gui::Traits<QString>::to_corba(rd.robotName_ ).in(),
gepetto::gui::Traits<QString>::to_corba(rd.rootJointType_).in(),
gepetto::gui::Traits<QString>::to_corba(rd.package_ ).in(),
gepetto::gui::Traits<QString>::to_corba(rd.modelName_ ).in(),
gepetto::gui::Traits<QString>::to_corba(rd.urdfSuf_ ).in(),
gepetto::gui::Traits<QString>::to_corba(rd.srdfSuf_ ).in());
to_corba(rd.robotName_ ).in(),
to_corba(rd.rootJointType_).in(),
to_corba(rd.package_ ).in(),
to_corba(rd.modelName_ ).in(),
to_corba(rd.urdfSuf_ ).in(),
to_corba(rd.srdfSuf_ ).in());
// This is already done in requestRefresh
// jointTreeWidget_->reload();
gepetto::gui::MainWindow::instance()->requestRefresh();
......@@ -191,9 +198,9 @@ namespace hpp {
{
QString prefix = ed.envName_ + "/";
client()->obstacle()->loadObstacleModel(
gepetto::gui::Traits<QString>::to_corba(ed.package_ ).in(),
gepetto::gui::Traits<QString>::to_corba(ed.urdfFilename_).in(),
gepetto::gui::Traits<QString>::to_corba(prefix ).in());
to_corba(ed.package_ ).in(),
to_corba(ed.urdfFilename_).in(),
to_corba(prefix ).in());
computeObjectPosition ();
gepetto::gui::MainWindow::instance()->requestRefresh();
emit logSuccess ("Environment " + ed.name_ + " loaded");
......@@ -206,14 +213,36 @@ namespace hpp {
return itj->prefix + itj->bodyNames[0];
}
void HppWidgetsPlugin::fetchConfiguration ()
{
hpp::floatSeq_var c = client()->robot ()->getCurrentConfig ();
setCurrentConfig (c.in());
}
void HppWidgetsPlugin::sendConfiguration ()
{
client()->robot ()->setCurrentConfig (config_);
}
void HppWidgetsPlugin::setCurrentConfig (const hpp::floatSeq& q)
{
config_ = q;
MainWindow::instance()->requestApplyCurrentConfiguration();
}
hpp::floatSeq const* HppWidgetsPlugin::getCurrentConfig () const
{
return &config_;
}
bool HppWidgetsPlugin::corbaException(int jobId, const CORBA::Exception &excep) const
{
try {
const hpp::Error& error = dynamic_cast <const hpp::Error&> (excep);
emit logJobFailed(jobId, QString (error.msg));
return true;
} catch (const std::exception& exp) {
qDebug () << exp.what();
} catch (const std::bad_cast&) {
// dynamic_cast failed.
}
return false;
}
......@@ -259,6 +288,8 @@ namespace hpp {
void HppWidgetsPlugin::prepareApplyConfiguration()
{
bodyNames_.clear();
config_ .length (client()->robot()->getConfigSize());
velocity_.length (client()->robot()->getNumberDof ());
gepetto::gui::MainWindow * main = gepetto::gui::MainWindow::instance ();
CORBA::ULong size = 0; const CORBA::ULong sall = 100;
linkNames_.length(sall);
......@@ -298,54 +329,54 @@ namespace hpp {
"interface) and you did not refresh this GUI. "
"Use the refresh button \"Tools\" menu.");
}
// Something smarter could be done here.
// For instance, the joint tree item could know the NodePtr_t of their bodies.
hpp::TransformSeq_var Ts = client()->robot ()->getLinksPosition (linkNames_);
hpp::TransformSeq_var Ts = client()->robot ()->getLinksPosition (config_, linkNames_);
fromHPP (Ts, bodyConfs_);
main->osg()->applyConfigurations (bodyNames_, bodyConfs_);
hpp::floatSeq_var c = client()->robot ()->getCurrentConfig ();
for (JointMap::iterator ite = jointMap_.begin ();
ite != jointMap_.end (); ite++) {
if (!ite->item) continue;
if (ite->item->config().length() > 0) {
ite->item->updateFromRobotConfig (c.in());
ite->item->updateFromRobotConfig (config_);
}
}
OsgConfiguration_t T;
for (std::list<std::string>::const_iterator it = jointFrames_.begin ();
it != jointFrames_.end (); ++it) {
std::string n = escapeJointName(*it);
hpp::Transform__var t = client()->robot()->getJointPosition(it->c_str());
fromHPP(t, T);
main->osg()->applyConfiguration (n, T);
}
T.quat.set(0,0,0,1);
for (std::list<std::string>::const_iterator it = comFrames_.begin ();
it != comFrames_.end (); ++it) {
std::string n = "com_" + escapeJointName(*it);
hpp::floatSeq_var t = client()->robot()->getPartialCom(it->c_str());
fromHPP (t, T.position);
main->osg()->applyConfiguration (n, T);
Ts = client()->robot()->getJointsPosition(config_, jointFrames_);
fromHPP (Ts, bodyConfs_);
main->osg()->applyConfigurations (jointGroupNames_, bodyConfs_);
if (comFrames_.size() > 0) {
static bool firstTime = true;
if (firstTime) {
main->log ("COM frames is not thread safe. Use with care.");
firstTime = false;
}
OsgConfiguration_t T;
T.quat.set(0,0,0,1);
client()->robot()->setCurrentConfig (config_);
for (std::list<std::string>::const_iterator it = comFrames_.begin ();
it != comFrames_.end (); ++it) {
std::string n = "com_" + escapeJointName(*it);
hpp::floatSeq_var t = client()->robot()->getPartialCom(it->c_str());
fromHPP (t, T.position);
main->osg()->applyConfiguration (n, T);
}
}
main->osg()->refresh();
}
void HppWidgetsPlugin::configurationValidation()
{
hpp::floatSeq_var q = client()->robot()->getCurrentConfig ();
bool bb = false;
CORBA::Boolean_out b = bb;
bool valid = false;
CORBA::String_var report;
try {
client()->robot()->isConfigValid (q.in(), b, report);
client()->robot()->isConfigValid (config_, valid, report);
} catch (const hpp::Error& e) {
emit logFailure(QString (e.msg));
return;
}
static QRegExp collision ("Collision between object (.*) and (.*)");
QStringList col;
if (!bb) {
if (!valid) {
if (collision.exactMatch(QString::fromLocal8Bit(report))) {
CORBA::String_var robotName = client ()->robot()->getRobotName();
size_t pos = strlen(robotName) + 1;
......@@ -391,8 +422,7 @@ namespace hpp {
if (type == "node") {
try {
hpp::floatSeq_var q = hpp_->problem()->node(n);
hpp_->robot()->setCurrentConfig(q.in());
gepetto::gui::MainWindow::instance()->requestApplyCurrentConfiguration();
setCurrentConfig(q.in());
} catch (const hpp::Error& e) {
emit logFailure(QString::fromLocal8Bit(e.msg));
}
......@@ -406,8 +436,7 @@ namespace hpp {
hpp::floatSeq_var times;
hpp::floatSeqSeq_var waypoints = hpp_->problem()->getWaypoints((CORBA::UShort)pid, times.out());
if (n < waypoints->length()) {
hpp_->robot()->setCurrentConfig(waypoints[n]);
MainWindow::instance()->requestApplyCurrentConfiguration();
setCurrentConfig(waypoints[n]);
}
}
}
......@@ -569,7 +598,9 @@ namespace hpp {
hpp::Transform__var t = client()->robot()->getJointPosition (jn.c_str());
OsgConfiguration_t p;
fromHPP(t, p);
jointFrames_.push_back(jn);
jointFrames_.length(jointFrames_.length()+1);
jointFrames_[jointFrames_.length() -1] = jn.c_str();
jointGroupNames_.push_back(target);
main->osg()->applyConfiguration (target, p);
main->osg()->refresh();
}
......
......@@ -22,6 +22,9 @@ namespace hpp {
class Roadmap;
class ConstraintWidget;
inline CORBA::String_var to_corba(const QString& s)
{ return (const char*)s.toLocal8Bit().data(); }
/// Plugin that add a lot of features to work with hpp.
class HppWidgetsPlugin : public QObject, public gepetto::gui::PluginInterface,
public gepetto::gui::ModelInterface, public gepetto::gui::CorbaInterface
......@@ -85,6 +88,27 @@ namespace hpp {
/// \todo this should be changed because there can be several body per
/// joints now.
std::string getBodyFromJoint (const std::string& jointName) const;
const hpp::floatSeq& currentConfig () const
{
return config_;
}
hpp::floatSeq& currentConfig ()
{
return config_;
}
const hpp::floatSeq& currentVelocity () const
{
return velocity_;
}
hpp::floatSeq& currentVelocity ()
{
return velocity_;
}
signals:
void configurationValidationStatus (bool valid);
void configurationValidationStatus (QStringList collision);
......@@ -106,6 +130,16 @@ signals:
/// Apply the current configuration of the robot.
void applyCurrentConfiguration ();
void setCurrentConfig (const hpp::floatSeq& q);
hpp::floatSeq const* getCurrentConfig () const;
/// Set internal configuration from HPP current config.
void fetchConfiguration ();
/// Set HPP configuration to internal current configuration
void sendConfiguration ();
/// Build a list of bodies in collision.
void configurationValidation ();
......@@ -193,13 +227,16 @@ signals:
JointTreeWidget* jointTreeWidget_;
ConstraintWidget* constraintWidget_;
JointMap jointMap_;
std::list <std::string> jointFrames_;
hpp::Names_t jointFrames_;
std::list <std::string> comFrames_;
hpp::floatSeq config_, velocity_;
// Cache variables
hpp::Names_t linkNames_;
std::vector<std::string> bodyNames_;
std::vector<graphics::Configuration> bodyConfs_;
std::vector<std::string> jointGroupNames_;
};
} // namespace gui
} // namespace hpp
......
......@@ -26,23 +26,27 @@ using CORBA::ULong;
namespace hpp {
namespace gui {
using CORBA::ULong;
const int JointTreeItem::IndexRole = Qt::UserRole + 1;
const int JointTreeItem::LowerBoundRole = Qt::UserRole + 2;
const int JointTreeItem::UpperBoundRole = Qt::UserRole + 3;
const int JointTreeItem::NumberDofRole = Qt::UserRole + 4;
const int JointTreeItem::TypeRole = Qt::UserRole + 10;
JointTreeItem::JointTreeItem(const char* name,
const std::size_t& idxQ,
const ULong& idxQ,
const ULong& idxV,
const hpp::floatSeq &q,
const hpp::floatSeq &b,
const unsigned int nbDof, const NodesPtr_t& nodes)
: QStandardItem (QString (name)), name_ (name), idxQ_ (idxQ), nodes_ (nodes), value_ ()
const ULong& nbDof, const NodesPtr_t& nodes)
: QStandardItem (QString (name)), name_ (name)
, idxQ_ (idxQ), idxV_ (idxV)
, nq_ (q.length()), nv_ (nbDof)
, nodes_ (nodes), value_ ()
{
setData((int)-1, IndexRole);
setData(nbDof, NumberDofRole);
setData(SkipType, TypeRole);
for (size_t i = 0; i < q.length(); ++i) {
for (size_t i = 0; i < nq_; ++i) {
QStandardItem *joint = new QStandardItem;
QStandardItem *upper = new QStandardItem;
QStandardItem *lower = new QStandardItem;
......@@ -72,7 +76,7 @@ namespace hpp {
b[2*(ULong) i] = value_[(ULong) i][0]->data(LowerBoundRole).toFloat();
b[2*(ULong) i+1] = value_[(ULong) i][0]->data(UpperBoundRole).toFloat();
}
return new JointTreeItem (name_.c_str(), idxQ_, q, b, data (NumberDofRole).toInt(), nodes_);
return new JointTreeItem (name_.c_str(), idxQ_, idxV_, q, b, nv_, nodes_);
}
hpp::floatSeq JointTreeItem::config() const
......@@ -128,9 +132,9 @@ namespace hpp {
// planar and freeflyer joints
int threshold = value_.size();
// TODO SO3 joint fall in that case too whereas threshold should be 0 for them.
if (data(NumberDofRole).toInt() == 3 && value_.size() == 4 )
if (nv_ == 3 && nq_ == 4 )
threshold = 2;
else if (data(NumberDofRole).toInt() == 6 && value_.size() == 7 )
else if (nv_ == 6 && nq_ == 7 )
threshold = 3;
for (int i = 0; i < value_.size(); ++i) {
float lo = value_[i][1]->data (Qt::EditRole).toFloat();
......@@ -205,33 +209,16 @@ namespace hpp {
switch (type) {
case JointTreeItem::SkipType:
return 0;
case JointTreeItem::IntegratorType: {
assert (ji);
IntegratorWheel* wheel =
new IntegratorWheel (Qt::Horizontal, plugin_, parent, main_,
ji->name(),
ji->data(JointTreeItem::NumberDofRole).toInt(),
std::min (
index.data(JointTreeItem::IndexRole).toInt(),
ji->data(JointTreeItem::NumberDofRole).toInt()-1));
return wheel;
}
case JointTreeItem::BoundedValueType: {
assert (ji);
hpp::floatSeq* q = new hpp::floatSeq;
hpp::floatSeq cfg = ji->config();
q->length(cfg.length());
*q = cfg;
const QModelIndex& lower = index.sibling(index.row(), 1);
const QModelIndex& upper = index.sibling(index.row(), 2);
float lo = lower.data(Qt::EditRole).toFloat(),
up = upper.data(Qt::EditRole).toFloat();
SliderBoundedJoint* slider =
new SliderBoundedJoint (Qt::Horizontal, plugin_, parent,
main_, ji->name(), q, index.data(JointTreeItem::IndexRole).toInt(),
lo, up);
return slider;
}
case JointTreeItem::IntegratorType:
assert (ji);
return new IntegratorWheel (Qt::Horizontal, plugin_, parent, main_,
ji, std::min ( (ULong)index.data(JointTreeItem::IndexRole).toInt(),
ji->numberDof()-1)
);
case JointTreeItem::BoundedValueType:
assert (ji);
return new SliderBoundedJoint (Qt::Horizontal, plugin_, parent,
main_, ji, index.data(JointTreeItem::IndexRole).toInt());
case JointTreeItem::UnboundedValueType:
case JointTreeItem::BoundType: {
QDoubleSpinBox* spinbox = new QDoubleSpinBox (parent);
......@@ -323,17 +310,19 @@ namespace hpp {
}
IntegratorWheel::IntegratorWheel(Qt::Orientation o, HppWidgetsPlugin *plugin, QWidget *parent,
gepetto::gui::MainWindow *main, std::string jointName,
int nbDof, int index)
: QSlider (o, parent), rate_ (100), main_ (main), plugin_ (plugin), jointName_ (jointName),
bound_ (100), maxVelocity_ (0.1),
currentValue_ (0), dq_ (new hpp::floatSeq), nbDof_ (nbDof), index_ (index)
gepetto::gui::MainWindow *main, JointTreeItem const* item, int index)
: QSlider (o, parent), rate_ (100), main_ (main), plugin_ (plugin),
item_ (item), bound_ (100), maxVelocity_ (0.1),
index_ (index)
{
setMinimum(-bound_);
setMaximum(bound_);
q_.length (item_->configSize());
dq_.length (item_->numberDof());
for (ULong i = 0; i < q_.length(); ++i)
q_ [ i] = plugin_->currentConfig()[item_->rankInConfig()+i];
for (ULong i = 0; i < dq_.length(); ++i) dq_[ i] = 0;
setValue (0);
dq_->length (nbDof_);
for (size_t i = 0; i < dq_->length(); ++i) dq_[(ULong) i] = 0;
connect(this, SIGNAL (sliderReleased()), this, SLOT (reset()));
connect(this, SIGNAL (sliderMoved(int)), this, SLOT (updateIntegrator(int)));
timerId_ = startTimer(rate_);
......@@ -342,9 +331,11 @@ namespace hpp {
void IntegratorWheel::timerEvent(QTimerEvent *)
{
killTimer(timerId_);
if (currentValue_ != 0) {
dq_[index_] = currentValue_;
plugin_->client()->robot ()->jointIntegrate (jointName_.c_str(), dq_.in());
if (dq_[index_] != 0) {
hpp::floatSeq_var q = plugin_->client()->robot ()->jointIntegrate (q_, item_->name().c_str(), dq_, true);
q_ = q.in();
for (ULong i = 0; i < q_.length(); ++i)
plugin_->currentConfig()[item_->rankInConfig()+i] = q_ [ i];
main_->requestApplyCurrentConfiguration();
}
timerId_ = startTimer(rate_);
......@@ -352,36 +343,40 @@ namespace hpp {
void IntegratorWheel::reset()
{
currentValue_ = 0;
dq_[index_] = 0;
setValue(0);
}
void IntegratorWheel::updateIntegrator(int value)
{
currentValue_ = maxVelocity_ * (double)value / (double)bound_;
dq_[index_] = maxVelocity_ * (double)value / (double)bound_;
}
SliderBoundedJoint::SliderBoundedJoint(Qt::Orientation orientation, HppWidgetsPlugin *plugin, QWidget *parent,
gepetto::gui::MainWindow *main, std::string jointName,
hpp::floatSeq *q, int index, double min, double max)
: QSlider (orientation, parent), main_ (main), plugin_ (plugin), jointName_ (jointName),
q_ (q), index_ (index), m_ (min), M_ (max)
gepetto::gui::MainWindow *main, JointTreeItem const* item, int index)
: QSlider (orientation, parent), main_ (main), plugin_ (plugin),
item_ (item), index_ (index)
{
value_ = item_->config()[index];
hpp::floatSeq bounds = item_->bounds();
m_ = bounds[2*index ];
M_ = bounds[2*index+1];
setMinimum(0);
setMaximum(100);
setValue ((int)(100*(q_[index_] - m_)/(M_ - m_)));
setValue ((int)(100*(value_ - m_)/(M_ - m_)));
connect (this, SIGNAL (sliderMoved(int)), this, SLOT (updateConfig(int)));
}
double SliderBoundedJoint::getValue()
{
return q_[index_];
return value_;
}
void SliderBoundedJoint::updateConfig(int value)
{
q_[index_] = m_ + (double)(value - 0) * (M_ - m_) / (double)100;
plugin_->client()->robot()->setJointConfig (jointName_.c_str(), q_.in());
value_ = m_ + (double)(value - 0) * (M_ - m_) / (double)100;
plugin_->currentConfig()[item_->rankInConfig()+index_] = value_;
main_->requestApplyCurrentConfiguration();
}
} // namespace gui
......
......@@ -22,67 +22,14 @@ class QPushButton;
namespace hpp {
namespace gui {
class IntegratorWheel : public QSlider
{
Q_OBJECT
public:
IntegratorWheel (Qt::Orientation o, HppWidgetsPlugin* plugin, QWidget *parent,
gepetto::gui::MainWindow *main, std::string jointName,
int nbDof, int index);
protected:
void timerEvent(QTimerEvent *);
protected slots:
void reset ();
void updateIntegrator (int value);
private:
int rate_; // in millisecond
int timerId_;
gepetto::gui::MainWindow* main_;
HppWidgetsPlugin* plugin_;
std::string jointName_;
const int bound_;
const double maxVelocity_;
double currentValue_;
hpp::floatSeq_var dq_;
int nbDof_, index_;
};
class SliderBoundedJoint : public QSlider
{
Q_OBJECT
public:
SliderBoundedJoint (Qt::Orientation orientation, HppWidgetsPlugin* plugin, QWidget* parent,
gepetto::gui::MainWindow *main, std::string jointName,
hpp::floatSeq* q, int index, double min, double max);
double getValue ();
private slots:
void updateConfig (int value);
private:
gepetto::gui::MainWindow* main_;
HppWidgetsPlugin* plugin_;
std::string jointName_;
hpp::floatSeq_var q_;
int index_;
double m_, M_;
};
class JointTreeItem : public QStandardItem
{
public:
typedef CORBA::ULong ULong;
typedef graphics::NodePtr_t NodePtr_t;
typedef std::vector<NodePtr_t> NodesPtr_t;