visual-tracking-control
FwdKinModel.cpp
Go to the documentation of this file.
1 #include <FwdKinModel.h>
2 
3 #include <exception>
4 #include <iostream>
5 #include <functional>
6 
7 #include <iCub/ctrl/math.h>
8 #include <yarp/math/Math.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::math;
18 using namespace yarp::os;
19 using namespace yarp::sig;
20 
21 
23 
24 
26 
27 
28 void FwdKinModel::propagate(const Ref<const MatrixXf>& cur_state, Ref<MatrixXf> prop_state)
29 {
30  prop_state.topRows<3>() = cur_state.topRows<3>().colwise() + delta_hand_pose_.head<3>().cast<float>();
31 
32  prop_state.middleRows<3>(3) = (cur_state.middleRows<3>(3).colwise() + delta_hand_pose_.middleRows<3>(3).cast<float>());
33  prop_state.middleRows<3>(3).colwise().normalize();
34 
35  RowVectorXf ang = cur_state.bottomRows<1>().array() + static_cast<float>(delta_angle_);
36 
37  for (unsigned int i = 0; i < ang.cols(); ++i)
38  {
39  if (ang(i) > M_PI) ang(i) -= 2.0 * M_PI;
40  else if (ang(i) <= -M_PI) ang(i) += 2.0 * M_PI;
41  }
42 
43  prop_state.bottomRows<1>() = ang;
44 }
45 
46 
48 {
49  std::cerr << "ERROR::PFPREDICTION::SETEXOGENOUSMODEL" << std::endl;
50  std::cerr << "ERROR:\n\tCall to unimplemented base class method.";
51 
52  return MatrixXf::Zero(1, 1);
53 }
54 
55 
56 bool FwdKinModel::setProperty(const std::string& property)
57 {
58  if (property == "ICFW_DELTA")
59  return setDeltaMotion();
60 
61  if (property == "ICFW_INIT")
62  {
63  initialize_delta_ = true;
64  return setDeltaMotion();
65  }
66 
67  return false;
68 }
69 
70 
72 {
73  VectorXd ee_pose = readPose();
74 
75  if (!initialize_delta_)
76  {
77  delta_hand_pose_.head<3>() = ee_pose.head<3>() - prev_ee_pose_.head<3>();
78 
79  delta_hand_pose_.middleRows<3>(3) = ee_pose.middleRows<3>(3) - prev_ee_pose_.middleRows<3>(3);
80 
81  delta_angle_ = ee_pose(6) - prev_ee_pose_(6);
82  if (delta_angle_ > M_PI) delta_angle_ -= 2.0 * M_PI;
83  else if (delta_angle_ <= -M_PI) delta_angle_ += 2.0 * M_PI;
84  }
85  else
86  {
87  delta_hand_pose_ = VectorXd::Zero(6);
88  delta_angle_ = 0.0;
89  initialize_delta_ = false;
90  }
91 
92  prev_ee_pose_ = ee_pose;
93 
94  return true;
95 }
void propagate(const Eigen::Ref< const Eigen::MatrixXf > &cur_state, Eigen::Ref< Eigen::MatrixXf > prop_state) override
Definition: FwdKinModel.cpp:28
bool setProperty(const std::string &property) override
Definition: FwdKinModel.cpp:56
Eigen::MatrixXf getExogenousMatrix() override
Definition: FwdKinModel.cpp:47
~FwdKinModel() noexcept
Definition: FwdKinModel.cpp:25
FwdKinModel() noexcept
Definition: FwdKinModel.cpp:22
bool setDeltaMotion()
Definition: FwdKinModel.cpp:71