visual-tracking-control
InitiCubArm.cpp
Go to the documentation of this file.
1 #include <InitiCubArm.h>
2 
3 #include <iCub/ctrl/math.h>
4 
5 using namespace Eigen;
6 using namespace iCub::iKin;
7 using namespace iCub::ctrl;
8 using namespace yarp::math;
9 using namespace yarp::sig;
10 using namespace yarp::os;
11 
12 
13 InitiCubArm::InitiCubArm(const ConstString& port_prefix, const ConstString& cam_sel, const ConstString& laterality) noexcept :
14  icub_kin_arm_(iCubArm(laterality + "_v2")), icub_kin_finger_{iCubFinger(laterality + "_thumb"), iCubFinger(laterality + "_index"), iCubFinger(laterality + "_middle")}
15 {
16  icub_kin_arm_.setAllConstraints(false);
17  icub_kin_arm_.releaseLink(0);
18  icub_kin_arm_.releaseLink(1);
19  icub_kin_arm_.releaseLink(2);
20 
21  icub_kin_finger_[0].setAllConstraints(false);
22  icub_kin_finger_[1].setAllConstraints(false);
23  icub_kin_finger_[2].setAllConstraints(false);
24 
25  port_arm_enc_.open ("/" + port_prefix + "/cam/" + cam_sel + "/" + laterality + "_arm:i");
26  port_torso_enc_.open("/" + port_prefix + "/cam/" + cam_sel + "/torso:i");
27 }
28 
29 
30 InitiCubArm::InitiCubArm(const ConstString& cam_sel, const ConstString& laterality) noexcept :
31  InitiCubArm("InitiCubArm", cam_sel, laterality) { }
32 
33 
35 {
36  port_arm_enc_.close();
37  port_torso_enc_.close();
38 }
39 
40 
41 void InitiCubArm::initialize(Eigen::Ref<Eigen::MatrixXf> state, Eigen::Ref<Eigen::VectorXf> weight)
42 {
43  Vector ee_pose = icub_kin_arm_.EndEffPose(CTRL_DEG2RAD * readRootToEE());
44 
45  Map<VectorXd> init_hand_pose(ee_pose.data(), 7, 1);
46 
47  for (int i = 0; i < state.cols(); ++i)
48  state.col(i) = init_hand_pose.cast<float>();
49 
50  weight.fill(1.0 / state.cols());
51 }
52 
53 
55 {
56  Bottle* b = port_torso_enc_.read(true);
57  if (!b) return Vector(3, 0.0);
58 
59  Vector torso_enc(3);
60  torso_enc(0) = b->get(2).asDouble();
61  torso_enc(1) = b->get(1).asDouble();
62  torso_enc(2) = b->get(0).asDouble();
63 
64  return torso_enc;
65 }
66 
67 
69 {
70  Bottle* b = port_arm_enc_.read(true);
71  if (!b) return Vector(10, 0.0);
72 
73  Vector root_ee_enc(10);
74 
75  root_ee_enc.setSubvector(0, readTorso());
76 
77  for (size_t i = 0; i < 7; ++i)
78  root_ee_enc(i + 3) = b->get(i).asDouble();
79 
80  return root_ee_enc;
81 }
yarp::sig::Vector readRootToEE()
Definition: InitiCubArm.cpp:68
InitiCubArm(const yarp::os::ConstString &port_prefix, const yarp::os::ConstString &cam_sel, const yarp::os::ConstString &laterality) noexcept
yarp::sig::Vector readTorso()
Definition: InitiCubArm.cpp:54
void initialize(Eigen::Ref< Eigen::MatrixXf > state, Eigen::Ref< Eigen::VectorXf > weight) override
Definition: InitiCubArm.cpp:41
~InitiCubArm() noexcept
Definition: InitiCubArm.cpp:34