visual-tracking-control
PlayFwdKinModel.cpp
Go to the documentation of this file.
1 #include <PlayFwdKinModel.h>
2 
3 #include <exception>
4 #include <functional>
5 
6 #include <iCub/ctrl/math.h>
7 #include <yarp/math/Math.h>
8 #include <yarp/eigen/Eigen.h>
9 #include <yarp/os/Bottle.h>
10 #include <yarp/os/Property.h>
11 #include <yarp/os/LogStream.h>
12 
13 using namespace bfl;
14 using namespace Eigen;
15 using namespace iCub::ctrl;
16 using namespace iCub::iKin;
17 using namespace yarp::eigen;
18 using namespace yarp::math;
19 using namespace yarp::os;
20 using namespace yarp::sig;
21 
22 
23 PlayFwdKinModel::PlayFwdKinModel(const ConstString& robot, const ConstString& laterality, const ConstString& port_prefix) noexcept :
24  icub_kin_arm_(iCubArm(laterality+"_v2")),
25  robot_(robot), laterality_(laterality), port_prefix_(port_prefix)
26 {
27  port_arm_enc_.open ("/hand-tracking/" + ID_ + "/" + port_prefix_ + "/" + laterality_ + "_arm:i");
28  port_torso_enc_.open("/hand-tracking/" + ID_ + "/" + port_prefix_ + "/torso:i");
29 
30  icub_kin_arm_.setAllConstraints(false);
31  icub_kin_arm_.releaseLink(0);
32  icub_kin_arm_.releaseLink(1);
33  icub_kin_arm_.releaseLink(2);
34 
35  yInfo() << log_ID_ << "Succesfully initialized.";
36 }
37 
39 {
40  port_torso_enc_.interrupt();
41  port_torso_enc_.close();
42 
43  port_arm_enc_.interrupt();
44  port_arm_enc_.close();
45 }
46 
47 
48 bool PlayFwdKinModel::setProperty(const std::string& property)
49 {
50  return FwdKinModel::setProperty(property);
51 }
52 
53 
55 {
56  Vector ee_pose = icub_kin_arm_.EndEffPose(CTRL_DEG2RAD * readRootToEE());
57  return toEigen(ee_pose);
58 }
59 
60 
62 {
63  Bottle* b = port_torso_enc_.read(true);
64  if (!b) return Vector(3, 0.0);
65 
66  Vector torso_enc(3);
67  torso_enc(0) = b->get(2).asDouble();
68  torso_enc(1) = b->get(1).asDouble();
69  torso_enc(2) = b->get(0).asDouble();
70 
71  return torso_enc;
72 }
73 
74 
76 {
77  Bottle* b = port_arm_enc_.read(true);
78  if (!b) return Vector(10, 0.0);
79 
80  Vector root_ee_enc(10);
81  root_ee_enc.setSubvector(0, readTorso());
82  for (size_t i = 0; i < 7; ++i)
83  root_ee_enc(i + 3) = b->get(i).asDouble();
84 
85  return root_ee_enc;
86 }
Eigen::VectorXd readPose() override
yarp::sig::Vector readRootToEE()
bool setProperty(const std::string &property) override
~PlayFwdKinModel() noexcept
PlayFwdKinModel(const yarp::os::ConstString &robot, const yarp::os::ConstString &laterality, const yarp::os::ConstString &port_prefix) noexcept
bool setProperty(const std::string &property) override
Definition: FwdKinModel.cpp:56
yarp::sig::Vector readTorso()