Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit 4f4c344

Browse files
committed
Start with LayoutForceTab
1 parent ce73ef3 commit 4f4c344

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

gazebo/gui/JointControlWidget.cc

+28-8
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ void JointControlWidget::SetModelName(const std::string &_modelName)
263263
this->jointPub.reset();
264264

265265
msgs::Model modelMsg;
266+
std::map<std::string, msgs::JointCmd> jointCmds;
266267

267268
this->modelLabel->setText(QString::fromStdString(std::string("Model: ")));
268269

@@ -282,12 +283,29 @@ void JointControlWidget::SetModelName(const std::string &_modelName)
282283
{
283284
modelMsg.ParseFromString(response.serialized_data());
284285
}
286+
287+
int i = 0;
288+
for (; i < modelMsg.joint_size(); ++i)
289+
{
290+
std::string jointName = modelMsg.joint(i).name();
291+
292+
this->requestMsg = msgs::CreateRequest("joint_controller");
293+
this->requestMsg->set_data(joint_name);
294+
295+
response = transport::request("default", *this->requestMsg);
296+
297+
if (response.response() != "error" &&
298+
response.type() == jointCmds.begin()->second.GetTypeName())
299+
{
300+
jointCmd_M[jointName].ParseFromString(response.serialized_data());
301+
}
302+
}
285303
}
286304

287305
this->modelLabel->setText(QString::fromStdString(
288306
std::string("Model: ") + modelMsg.name()));
289307

290-
this->LayoutForceTab(modelMsg);
308+
this->LayoutForceTab(&jointCmds);
291309

292310
this->LayoutPositionTab(modelMsg);
293311

@@ -547,7 +565,8 @@ void JointControlWidget::AddScrollTab(QTabWidget *_tabPane,
547565
}
548566

549567
/////////////////////////////////////////////////
550-
void JointControlWidget::LayoutForceTab(msgs::Model &_modelMsg)
568+
void JointControlWidget::LayoutForceTab(
569+
std::map<std::string, msgs::JointCmd> &_jointCmds);
551570
{
552571
// Remove the old widgets;
553572
QLayoutItem *wItem;
@@ -560,19 +579,19 @@ void JointControlWidget::LayoutForceTab(msgs::Model &_modelMsg)
560579
this->sliders.clear();
561580

562581
// Don't add any widget if there are no joints
563-
if (_modelMsg.joint_size() == 0)
582+
if (_jointCmds->size() == 0)
564583
return;
565584

566585
this->forceGridLayout->addItem(new QSpacerItem(10, 20, QSizePolicy::Expanding,
567586
QSizePolicy::Minimum), 0, 0, 2);
568587
this->forceGridLayout->addWidget(new QLabel("Newton-meter", this), 0, 2);
569588

570589
int i = 0;
571-
for (; i < _modelMsg.joint_size(); ++i)
590+
for (std::map<std::string, msgs::JointCmd>::iterator iter =
591+
_jointCmds->begin(), iter != jointCmds->end(); ++iter)
572592
{
573-
std::string jointName = _modelMsg.joint(i).name();
574-
// Do a request / response right here, make a request handler for
575-
// JointController
593+
std::string jointName = iter->first;
594+
msgs::JointCmd jointCmd = iter->second;
576595

577596
// Get the joint name minus the model name
578597
int modelNameIndex = jointName.find("::") + 2;
@@ -583,12 +602,13 @@ void JointControlWidget::LayoutForceTab(msgs::Model &_modelMsg)
583602
this->forceGridLayout->addItem(new QSpacerItem(10, 20,
584603
QSizePolicy::Expanding, QSizePolicy::Minimum), i+1, 1);
585604

586-
JointForceControl *slider = new JointForceControl(jointName,
605+
JointForceControl *slider = new JointForceControl(&jointCmd,
587606
this->forceGridLayout, this, i+1);
588607

589608
this->sliders[jointName] = slider;
590609
connect(slider, SIGNAL(changed(double, const std::string &)),
591610
this, SLOT(OnForceChanged(double, const std::string &)));
611+
++i;
592612
}
593613

594614
// Add a space at the bottom of the grid layout to consume extra space.

gazebo/gui/JointControlWidget.hh

+4-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,10 @@ namespace gazebo
120120
const QString &_name);
121121

122122
/// \brief Layout the force tab.
123-
/// \param[in] _modelMsg Message used to create the joint controls
124-
private: void LayoutForceTab(msgs::Model &_modelMsg);
123+
/// \param[in] _jointCmds Map of joint messages used to set default
124+
/// values for controls.
125+
private: void LayoutForceTab(std::map<std::string, msgs::JointCmd>
126+
&_jointCmds);
125127

126128
/// \brief Layout the position PID tab.
127129
/// \param[in] _modelMsg Message used to create the joint controls

0 commit comments

Comments
 (0)