141 #include <yarp/os/LogStream.h>
142 #include <yarp/os/Searchable.h>
143 #include <yarp/os/Property.h>
144 #include <yarp/os/Value.h>
145 #include <yarp/os/Bottle.h>
146 #include <yarp/os/Network.h>
147 #include <yarp/os/ResourceFinder.h>
148 #include <yarp/os/RFModule.h>
149 #include <yarp/sig/Vector.h>
150 #include <yarp/sig/Matrix.h>
151 #include <yarp/math/Math.h>
156 using namespace yarp::os;
157 using namespace yarp::sig;
158 using namespace yarp::math;
167 bool configured{
false};
175 iKinLinIneqConstr::clone(obj);
180 C_orig = ptr->C_orig;
181 lB_orig = ptr->lB_orig;
182 uB_orig = ptr->uB_orig;
189 if (options.check(
"LIC_num")) {
190 auto LIC_num = options.find(
"LIC_num").asInt32();
192 for (
auto i = 0; i < LIC_num; i++) {
195 Bottle& group = options.findGroup(tag.str());
196 if (group.isNull()) {
197 yError() <<
"Unable to find group \"" << tag.str() <<
"\"";
200 Bottle* row = group.find(
"C").asList();
201 if (row ==
nullptr) {
202 yError() <<
"Unable to find option \"C\" for group \"" << tag.str() <<
"\"";
205 if (row->size() != chain->getN()) {
206 yError() <<
"Option \"C\" of group \"" << tag.str() <<
"\" has wrong size";
209 C_orig = pile(C_orig,
zeros(chain->getN()));
210 for (
auto i = 0; i < row->size(); i++) {
211 C_orig(C_orig.rows() - 1, i) = row->get(i).asFloat64();
213 lB_orig = cat(lB_orig, group.check(
"lB", Value(lowerBoundInf)).asFloat64());
214 uB_orig = cat(uB_orig, group.check(
"uB", Value(upperBoundInf)).asFloat64());
217 yInfo() <<
"Detected generic linear inequalities constraints";
228 getC().resize(C_orig.rows(), 0);
231 for (
auto i = 0U; i < chain->getN(); i++) {
232 if (chain->isLinkBlocked(i)) {
233 auto v = chain->getAng(i) * C_orig.getCol(i);
237 getC() = cat(getC(), C_orig.getCol(i));
248 shared_ptr<iKinLimb> limb{
nullptr};
249 shared_ptr<GenericLinIneqConstr> cns{
nullptr};
250 shared_ptr<PartDescriptor> desc{
nullptr};
255 if (!options.check(
"robot")) {
256 yError() <<
"\"robot\" option is missing!";
260 if (!options.check(
"NumberOfDrivers")) {
261 yError() <<
"\"NumberOfDrivers\" option is missing!";
265 string robot = options.find(
"robot").asString();
266 yInfo() <<
"Configuring solver for " << robot <<
" ...";
268 Property linksOptions;
270 limb = shared_ptr<iKinLimb>(
new iKinLimb(linksOptions));
271 if (!limb->isValid()) {
272 yError() <<
"invalid links parameters!";
278 desc->lmb = limb.get();
279 desc->chn = limb->asChain();
280 desc->cns = cns.get();
282 bool failure =
false;
283 desc->num = options.find(
"NumberOfDrivers").asInt32();
284 for (
int cnt = 0; cnt < desc->num; cnt++) {
286 str <<
"driver_" << cnt;
287 Bottle& driver = options.findGroup(str.str());
288 if (driver.isNull()) {
289 yError() <<
"\"" << str.str() <<
"\" option is missing!";
294 if (!driver.check(
"Key")) {
295 yError() <<
"\"Key\" option is missing!";
300 if (!driver.check(
"JointsOrder")) {
301 yError() <<
"\"JointsOrder\" option is missing!";
306 string part = driver.find(
"Key").asString();
307 bool directOrder = (driver.find(
"JointsOrder").asString() ==
"direct");
310 optPart.put(
"device",
"remote_controlboard");
311 optPart.put(
"remote",
"/" + robot +
"/" + part);
312 optPart.put(
"local",
"/" + slvName +
"/" + part);
313 optPart.put(
"robot", robot);
314 optPart.put(
"part", part);
315 desc->prp.push_back(optPart);
316 desc->rvs.push_back(!directOrder);
319 return (failure ?
nullptr : desc.get());
332 shared_ptr<CartesianSolver> slv{
nullptr};
337 string part, slvName;
338 if (rf.check(
"part")) {
339 part = rf.find(
"part").asString();
341 yError() <<
"part option is not specified";
345 Bottle& group = rf.findGroup(part);
346 if (group.isNull()) {
347 yError() <<
"unable to locate " << part <<
" definition";
351 if (group.check(
"name")) {
352 slvName = group.find(
"name").asString();
354 yError() <<
"name option is missing";
358 if (group.check(
"CustomKinFile")) {
359 yInfo() <<
"Custom Cartesian Solver detected!";
361 ResourceFinder rf_kin;
362 rf_kin.setDefaultContext(rf.getContext());
363 rf_kin.configure(0,
nullptr);
367 }
else if ((part ==
"left_arm") || (part ==
"right_arm")) {
369 }
else if ((part ==
"left_leg") || (part ==
"right_leg")) {
372 yError() << part <<
" is invalid";
376 return slv->open(group);
395 if (slv->isClosed()) {
399 if (slv->getTimeoutFlag()) {
400 slv->getTimeoutFlag() =
false;
412 if (!
yarp.checkNetwork()) {
413 yError() <<
"YARP server not available!";
418 rf.setDefaultContext(
"cartesianSolver");
419 rf.setDefaultConfigFile(
"cartesianSolver.ini");
420 rf.configure(
argc, argv);
423 return mod.runModule(rf);
PartDescriptor * getPartDesc(Searchable &options)
CustomCartesianSolver(const string &name)
void clone(const iKinLinIneqConstr *obj) override
void update(void *) override
Updates internal state.
GenericLinIneqConstr(iKinChain *chain_, Searchable &options)
bool configure(ResourceFinder &rf)
Abstract class defining the core of on-line solvers.
Derived class which implements the on-line solver for the chain torso+arm.
Derived class which implements the on-line solver for the leg chain.
A Base class for defining a Serial Link Chain.
A class for defining generic Limb.
Class for defining Linear Inequality Constraints of the form lB <= C*q <= uB for the nonlinear proble...
int main(int argc, char *argv[])
static string pathToCustomKinFile
Copyright (C) 2008 RobotCub Consortium.