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

Commit 2c9a1df

Browse files
florent-lamirauxOlivier Stasse
authored andcommitted
Add a command to get the joint names of the robot.
1 parent 8c0f6b2 commit 2c9a1df

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/dynamic-command.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,31 @@ class GetDimension : public Command {
6060
}
6161
}; // class GetDimension
6262

63+
// Command getJointNames
64+
class GetJointNames : public Command {
65+
public:
66+
/// Create command and store it in Entity
67+
/// \param entity instance of Entity owning this command
68+
/// \param docstring documentation of the command
69+
GetJointNames(DynamicPinocchio& entity, const std::string& docstring)
70+
: Command(entity, std::vector<Value::Type>(), docstring){}
71+
virtual Value doExecute() {
72+
DynamicPinocchio& robot = static_cast<DynamicPinocchio&>(owner());
73+
if (robot.m_model == 0x0){
74+
SOT_THROW ExceptionDynamic(ExceptionDynamic::GENERIC,
75+
"model has not been initialized.");
76+
}
77+
const std::vector<std::string>& jointNames = robot.m_model->names;
78+
// Remove first joint names 'universe'
79+
std::size_t n (jointNames.size());
80+
assert(n >= 1);
81+
std::vector<Value> res;
82+
for (std::size_t i=1; i<jointNames.size(); ++i) {
83+
res.push_back(Value(jointNames[i]));
84+
}
85+
return Value(res);
86+
}
87+
};
6388
} // namespace command
6489
} /* namespace sot */
6590
} /* namespace dynamicgraph */

src/sot-dynamic-pinocchio.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ DynamicPinocchio::DynamicPinocchio(const std::string& name)
202202
"string (joint name)");
203203
addCommand("createAcceleration",
204204
makeCommandVoid2(*this, &DynamicPinocchio::cmd_createAccelerationSignal, docstring));
205+
docstring="\n"
206+
" Return robot joint names.\n\n";
207+
addCommand("getJointNames", new command::GetJointNames(*this, docstring));
205208
}
206209

207210
sphericalJoints.clear();

0 commit comments

Comments
 (0)