28#include <yarp/os/Network.h>
29#include <yarp/os/PeriodicThread.h>
30#include <yarp/os/RFModule.h>
31#include <yarp/os/BufferedPort.h>
32#include <yarp/os/Time.h>
33#include <yarp/sig/Vector.h>
34#include <yarp/math/Math.h>
41using namespace yarp::os;
42using namespace yarp::sig;
43using namespace yarp::math;
52class inPort :
public BufferedPort<Bottle>
61 lock_guard<mutex> lg(
mtx);
62 if (
vect.length()!=b.size())
63 vect.resize(b.size());
65 for (
size_t i=0; i<
vect.length(); i++)
66 vect[i]=b.get(i).asFloat64();
73 lock_guard<mutex> lg(
mtx);
80 lock_guard<mutex> lg(
mtx);
101 lock_guard<mutex> lg(
mtx);
109 lock_guard<mutex> lg(
mtx);
120class Solver :
public PeriodicThread
148 fprintf(stdout,
"Starting Solver at %g ms\n",1000.0*getPeriod());
150 string name=
rf.find(
"name").asString();
153 Property linksOptions;
154 linksOptions.fromConfigFile(
rf.findFile(
"config"));
161 fprintf(stdout,
"Error: invalid links parameters!\n");
186 port_xd.open(
"/"+name+
"/xd:i");
190 port_qd.open(
"/"+name+
"/qd:o");
199 fprintf(stdout,
"Solver started successfully\n");
201 fprintf(stdout,
"Solver did not start\n");
222 Vector qdhat=
slv->
solve(q0,xd,0.0,dummyVect,dummyVect,0.01,q0,w_3rd);
282 fprintf(stdout,
"Starting Controller at %g ms\n",1000.0*getPeriod());
284 string name=
rf.find(
"name").asString();
287 Property linksOptions;
288 linksOptions.fromConfigFile(
rf.findFile(
"config"));
295 fprintf(stdout,
"Error: invalid links parameters!\n");
310 port_v.open(
"/"+name+
"/v:o");
311 port_x.open(
"/"+name+
"/x:o");
320 fprintf(stdout,
"Controller started successfully\n");
322 fprintf(stdout,
"Controller did not start\n");
377 string name=rf.find(
"name").asString();
399 port_q.open(
"/"+name+
"/q:i");
435int main(
int argc,
char *argv[])
438 rf.setDefault(
"name",
"ctrl");
439 rf.setDefault(
"config",
"config.ini");
440 rf.configure(argc,argv);
442 if (rf.check(
"help"))
444 fprintf(stdout,
"Options:\n\n");
445 fprintf(stdout,
"\t--name name: controller name (default: \"ctrl\")\n");
446 fprintf(stdout,
"\t--config file: specify the file containing the DH parameters of the links (default: \"config.ini\")\n");
447 fprintf(stdout,
"\t--T time: specify the task execution time in seconds (default: 2.0)\n");
448 fprintf(stdout,
"\t--onlyXYZ : disable orientation control\n");
454 if (!
yarp.checkNetwork())
458 return mod.runModule(rf);
virtual void threadRelease()
virtual bool threadInit()
Controller(ResourceFinder &_rf, inPort *_port_q, exchangeData *_commData, unsigned int period)
MultiRefMinJerkCtrl * ctrl
virtual void afterStart(bool s)
BufferedPort< Vector > port_q
BufferedPort< Vector > port_x
virtual bool configure(ResourceFinder &rf)
virtual double getPeriod()
virtual bool updateModule()
virtual void threadRelease()
virtual void afterStart(bool s)
virtual bool threadInit()
Solver(ResourceFinder &_rf, inPort *_port_q, exchangeData *_commData, unsigned int period)
void getDesired(Vector &_xd, Vector &_qd)
void setDesired(const Vector &_xd, const Vector &_qd)
A class derived from iKinCtrl implementing the multi-referential approach.
virtual yarp::sig::Vector iterate(yarp::sig::Vector &xd, yarp::sig::Vector &qd, yarp::sig::Vector *xdot_set, const unsigned int verbose)
double set_execTime(const double _execTime, const bool warn=false)
Sets the task execution time in seconds.
yarp::sig::Vector get_qdot() const
Returns the actual derivative of joint angles.
virtual void set_q(const yarp::sig::Vector &q0)
Sets the joint angles values.
A Base class for defining a Serial Link Chain.
yarp::sig::Vector EndEffPose(const bool axisRep=true)
Returns the coordinates of end-effector.
yarp::sig::Vector getAng()
Returns the current free joint angles values.
yarp::sig::Vector setAng(const yarp::sig::Vector &q)
Sets the free joint angles to values of q[i].
unsigned int getDOF() const
Returns the current number of Chain's DOF.
virtual yarp::sig::Vector get_x() const
Returns the actual cartesian position of the End-Effector.
Class for inverting chain's kinematics based on IpOpt lib.
void setUserScaling(const bool useUserScaling, const double _obj_scaling, const double _x_scaling, const double _g_scaling)
Enables/disables user scaling factors.
virtual yarp::sig::Vector solve(const yarp::sig::Vector &q0, yarp::sig::Vector &xd, double weight2ndTask, yarp::sig::Vector &xd_2nd, yarp::sig::Vector &w_2nd, double weight3rdTask, yarp::sig::Vector &qd_3rd, yarp::sig::Vector &w_3rd, int *exit_code=NULL, bool *exhalt=NULL, iKinIterateCallback *iterate=NULL)
Executes the IpOpt algorithm trying to converge on target.
A class for defining generic Limb.
iKinChain * asChain()
Returns a pointer to the Limb seen as Chain object.
bool isValid() const
Checks if the limb has been properly configured.
virtual void onRead(Bottle &b)
void set_vect(const Vector &_vect)
#define IKINCTRL_POSE_FULL
#define IKINCTRL_POSE_XYZ
constexpr double CTRL_RAD2DEG
180/PI.
constexpr double CTRL_DEG2RAD
PI/180.
Copyright (C) 2008 RobotCub Consortium.