iCub-main
Loading...
Searching...
No Matches
CouplingICubEye.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2006-2024 Istituto Italiano di Tecnologia (IIT)
3 * All rights reserved.
4 *
5 * This software may be modified and distributed under the terms of the
6 * BSD-3-Clause license. See the accompanying LICENSE file for details.
7 */
8
9#include "CouplingICubEye.h"
10#include <yarp/os/LogStream.h>
11#include <cmath>
12#include <array>
13#include <numeric>
14
15
16YARP_LOG_COMPONENT(COUPLINGICUBEYE, "yarp.device.couplingICubEye")
17
18
19bool CouplingICubEye::populateCouplingParameters() {
20 yarp::sig::VectorOf<size_t> coupled_physical_joints{1, 2};
21 yarp::sig::VectorOf<size_t> coupled_actuated_axes{1, 2};
22 std::vector<std::pair<double, double>> physical_joint_limits;
23
24 physical_joint_limits.resize(m_jointNames.size());
25 for (int i = 0; i< m_jointNames.size(); i++)
26 {
27 physical_joint_limits[i] = std::make_pair(m_LIMITS_jntPosMin[i], m_LIMITS_jntPosMax[i]);
28 }
29 initialise(coupled_physical_joints, coupled_actuated_axes, m_jointNames, m_COUPLING_actuatedAxesNames, physical_joint_limits);
30 return true;
31}
32
33bool CouplingICubEye::open(yarp::os::Searchable& config) {
34
35 if(!parseParams(config)) {
36 yCError(COUPLINGICUBEYE) << "Error parsing parameters";
37 return false;
38 }
39
40 if(!populateCouplingParameters()) {
41 yCError(COUPLINGICUBEYE) << "Error populating coupling parameters";
42 return false;
43 }
44
45 yCDebug(COUPLINGICUBEYE) << "Opening couplingICubEye" << config.toString();
46 return true;
47}
48
49bool CouplingICubEye::convertFromPhysicalJointsToActuatedAxesPos(const yarp::sig::Vector& physJointsPos, yarp::sig::Vector& actAxesPos) {
50 size_t nrOfPhysicalJoints;
51 size_t nrOfActuatedAxes;
52 auto ok = getNrOfPhysicalJoints(nrOfPhysicalJoints);
53 ok = ok && getNrOfActuatedAxes(nrOfActuatedAxes);
54 if (!ok || physJointsPos.size() != nrOfPhysicalJoints || actAxesPos.size() != nrOfActuatedAxes) {
55 yCError(COUPLINGICUBEYE) << "convertFromPhysicalJointsToActuatedAxesPos: input or output vectors have wrong size";
56 return false;
57 }
58
59 // eyes_tilt
60 actAxesPos[0] = physJointsPos[0];
61 // eyes_version
62 actAxesPos[1] = (physJointsPos[1] + physJointsPos[2])/2;
63 // eyes_vergence
64 actAxesPos[2] = (physJointsPos[1] - physJointsPos[2]);
65
66 return true;
67}
68
69bool CouplingICubEye::convertFromPhysicalJointsToActuatedAxesVel(const yarp::sig::Vector& physJointsPos, const yarp::sig::Vector& physJointsVel, yarp::sig::Vector& actAxesVel) {
70 size_t nrOfPhysicalJoints;
71 size_t nrOfActuatedAxes;
72 auto ok = getNrOfPhysicalJoints(nrOfPhysicalJoints);
73 ok = ok && getNrOfActuatedAxes(nrOfActuatedAxes);
74 if (!ok || physJointsVel.size() != nrOfPhysicalJoints || actAxesVel.size() != nrOfActuatedAxes) {
75 yCError(COUPLINGICUBEYE) << "convertFromPhysicalJointsToActuatedAxesVel: input or output vectors have wrong size";
76 return false;
77 }
78 // eyes_tilt
79 actAxesVel[0] = physJointsVel[0];
80 // eyes_version
81 actAxesVel[1] = (physJointsVel[1] + physJointsVel[2])/2;
82 // eyes_vergence
83 actAxesVel[2] = (physJointsVel[1] - physJointsVel[2]);
84
85 return true;
86}
87
88bool CouplingICubEye::convertFromPhysicalJointsToActuatedAxesAcc(const yarp::sig::Vector& physJointsPos, const yarp::sig::Vector& physJointsVel, const yarp::sig::Vector& physJointsAcc, yarp::sig::Vector& actAxesAcc) {
89 size_t nrOfPhysicalJoints;
90 size_t nrOfActuatedAxes;
91 auto ok = getNrOfPhysicalJoints(nrOfPhysicalJoints);
92 ok = ok && getNrOfActuatedAxes(nrOfActuatedAxes);
93 if (!ok || physJointsAcc.size() != nrOfPhysicalJoints || actAxesAcc.size() != nrOfActuatedAxes) {
94 yCError(COUPLINGICUBEYE) << "convertFromPhysicalJointsToActuatedAxesAcc: input or output vectors have wrong size";
95 return false;
96 }
97
98 // eyes_tilt
99 actAxesAcc[0] = physJointsAcc[0];
100 // eyes_version
101 actAxesAcc[1] = (physJointsAcc[1] + physJointsAcc[2])/2;
102 // eyes_vergence
103 actAxesAcc[2] = (physJointsAcc[1] - physJointsAcc[2]);
104
105 return true;
106}
107
108bool CouplingICubEye::convertFromPhysicalJointsToActuatedAxesTrq(const yarp::sig::Vector& physJointsPos, const yarp::sig::Vector& physJointsTrq, yarp::sig::Vector& actAxesTrq) {
109 return false;
110}
111
112bool CouplingICubEye::convertFromActuatedAxesToPhysicalJointsPos(const yarp::sig::Vector& actAxesPos, yarp::sig::Vector& physJointsPos) {
113 size_t nrOfPhysicalJoints;
114 size_t nrOfActuatedAxes;
115 auto ok = getNrOfPhysicalJoints(nrOfPhysicalJoints);
116 ok = ok && getNrOfActuatedAxes(nrOfActuatedAxes);
117 if (!ok || physJointsPos.size() != nrOfPhysicalJoints || actAxesPos.size() != nrOfActuatedAxes) {
118 yCError(COUPLINGICUBEYE) << "convertFromActuatedAxesToPhysicalJointsPos: input or output vectors have wrong size";
119 return false;
120 }
121
122 // eyes_tilt
123 physJointsPos[0] = actAxesPos[0];
124 // l_eye_pan_joint
125 physJointsPos[1] = actAxesPos[1] + actAxesPos[2]/2;
126 // r_eye_pan_joint
127 physJointsPos[2] = actAxesPos[1] - actAxesPos[2]/2;
128
129 return true;
130}
131
132bool CouplingICubEye::convertFromActuatedAxesToPhysicalJointsVel(const yarp::sig::Vector& actAxesPos, const yarp::sig::Vector& actAxesVel, yarp::sig::Vector& physJointsVel) {
133 size_t nrOfPhysicalJoints;
134 size_t nrOfActuatedAxes;
135 auto ok = getNrOfPhysicalJoints(nrOfPhysicalJoints);
136 ok = ok && getNrOfActuatedAxes(nrOfActuatedAxes);
137 if (!ok || actAxesPos.size() != nrOfActuatedAxes || physJointsVel.size() != nrOfPhysicalJoints || actAxesVel.size() != nrOfActuatedAxes) {
138 yCError(COUPLINGICUBEYE) << "convertFromPhysicalJointsToActuatedAxesVel: input or output vectors have wrong size";
139 return false;
140 }
141
142 // eyes_tilt
143 physJointsVel[0] = actAxesVel[0];
144 // l_eye_pan_joint
145 physJointsVel[1] = actAxesVel[1] + actAxesVel[2]/2;
146 // r_eye_pan_joint
147 physJointsVel[2] = actAxesVel[1] - actAxesVel[2]/2;
148
149 return true;
150}
151
152bool CouplingICubEye::convertFromActuatedAxesToPhysicalJointsAcc(const yarp::sig::Vector& actAxesPos, const yarp::sig::Vector& actAxesVel, const yarp::sig::Vector& actAxesAcc, yarp::sig::Vector& physJointsAcc) {
153 size_t nrOfPhysicalJoints;
154 size_t nrOfActuatedAxes;
155 auto ok = getNrOfPhysicalJoints(nrOfPhysicalJoints);
156 ok = ok && getNrOfActuatedAxes(nrOfActuatedAxes);
157 if (!ok || actAxesPos.size() != nrOfActuatedAxes || physJointsAcc.size() != nrOfPhysicalJoints || actAxesAcc.size() != nrOfActuatedAxes) {
158 yCError(COUPLINGICUBEYE) << "convertFromPhysicalJointsToActuatedAxesAcc: input or output vectors have wrong size";
159 return false;
160 }
161
162 // eyes_tilt
163 physJointsAcc[0] = actAxesAcc[0];
164 // l_eye_pan_joint
165 physJointsAcc[1] = actAxesAcc[1] + actAxesAcc[2]/2;
166 // r_eye_pan_joint
167 physJointsAcc[2] = actAxesAcc[1] - actAxesAcc[2]/2;
168
169 return true;
170}
171
172bool CouplingICubEye::convertFromActuatedAxesToPhysicalJointsTrq(const yarp::sig::Vector& actAxesPos, const yarp::sig::Vector& actAxesTrq, yarp::sig::Vector& physJointsTrq) {
173 return false;
174}
bool parseParams(const yarp::os::Searchable &config) override
Coupling law from https://icub-tech-iit.github.io/documentation/icub_kinematics/icub-vergence-version...
bool open(yarp::os::Searchable &config) override
Configure with a set of options.
bool convertFromActuatedAxesToPhysicalJointsTrq(const yarp::sig::Vector &actAxesPos, const yarp::sig::Vector &actAxesTrq, yarp::sig::Vector &physJointsTrq) override
bool convertFromPhysicalJointsToActuatedAxesTrq(const yarp::sig::Vector &physJointsPos, const yarp::sig::Vector &physJointsTrq, yarp::sig::Vector &actAxesTrq) override
bool convertFromActuatedAxesToPhysicalJointsVel(const yarp::sig::Vector &actAxesPos, const yarp::sig::Vector &actAxesVel, yarp::sig::Vector &physJointsVel) override
bool convertFromPhysicalJointsToActuatedAxesPos(const yarp::sig::Vector &physJointsPos, yarp::sig::Vector &actAxesPos) override
bool convertFromActuatedAxesToPhysicalJointsPos(const yarp::sig::Vector &actAxesPos, yarp::sig::Vector &physJointsPos) override
bool convertFromPhysicalJointsToActuatedAxesVel(const yarp::sig::Vector &physJointsPos, const yarp::sig::Vector &physJointsVel, yarp::sig::Vector &actAxesVel) override
bool convertFromActuatedAxesToPhysicalJointsAcc(const yarp::sig::Vector &actAxesPos, const yarp::sig::Vector &actAxesVel, const yarp::sig::Vector &actAxesAcc, yarp::sig::Vector &physJointsAcc) override
bool convertFromPhysicalJointsToActuatedAxesAcc(const yarp::sig::Vector &physJointsPos, const yarp::sig::Vector &physJointsVel, const yarp::sig::Vector &physJointsAcc, yarp::sig::Vector &actAxesAcc) override