|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2006-2023 Istituto Italiano di Tecnologia (IIT) |
| 3 | + * SPDX-License-Identifier: BSD-3-Clause |
| 4 | + */ |
| 5 | + |
| 6 | +#include "fakeJointCoupling.h" |
| 7 | + |
| 8 | +#include <yarp/conf/environment.h> |
| 9 | + |
| 10 | +#include <yarp/os/Bottle.h> |
| 11 | +#include <yarp/os/Time.h> |
| 12 | +#include <yarp/os/LogComponent.h> |
| 13 | +#include <yarp/os/LogStream.h> |
| 14 | +#include <yarp/os/NetType.h> |
| 15 | +#include <yarp/dev/Drivers.h> |
| 16 | + |
| 17 | +#include <sstream> |
| 18 | +#include <cstring> |
| 19 | +#include <algorithm> |
| 20 | + |
| 21 | +using namespace yarp::dev; |
| 22 | +using namespace yarp::os; |
| 23 | +using namespace yarp::os::impl; |
| 24 | + |
| 25 | + |
| 26 | +namespace { |
| 27 | +YARP_LOG_COMPONENT(FAKEJOINTCOUPLING, "yarp.device.fakeJointCoupling") |
| 28 | +} |
| 29 | + |
| 30 | +bool FakeJointCoupling::open(yarp::os::Searchable &par) { |
| 31 | + yarp::sig::VectorOf<size_t> coupled_physical_joints {2,3}; |
| 32 | + yarp::sig::VectorOf<size_t> coupled_actuated_axes {2}; |
| 33 | + std::vector<std::string> physical_joint_names{"phys_joint_0", "phys_joint_1", "phys_joint_2", "phys_joint_3"}; |
| 34 | + std::vector<std::string> actuated_axes_names{"act_axes_0", "act_axes_1", "act_axes_2"}; |
| 35 | + std::vector<std::pair<double, double>> physical_joint_limits{{-30.0, 30.0}, {-10.0, 10.0}, {-32.0, 33.0}, {0.0, 120.0}}; |
| 36 | + initialise(coupled_physical_joints, coupled_actuated_axes, physical_joint_names, actuated_axes_names, physical_joint_limits); |
| 37 | + return true; |
| 38 | +} |
| 39 | +bool FakeJointCoupling::close() { |
| 40 | + return true; |
| 41 | +} |
| 42 | + |
| 43 | +bool FakeJointCoupling::convertFromPhysicalJointsToActuatedAxesPos(const yarp::sig::Vector& physJointsPos, yarp::sig::Vector& actAxesPos) { |
| 44 | + size_t nrOfPhysicalJoints; |
| 45 | + size_t nrOfActuatedAxes; |
| 46 | + auto ok = getNrOfPhysicalJoints(nrOfPhysicalJoints); |
| 47 | + ok = ok && getNrOfActuatedAxes(nrOfActuatedAxes); |
| 48 | + if (!ok || physJointsPos.size() != nrOfPhysicalJoints || actAxesPos.size() != nrOfActuatedAxes) { |
| 49 | + // yCDebug(FAKEJOINTCOUPLING) << ok <<physJointsPos.size()<<nrOfPhysicalJoints<<actAxesPos.size()<<nrOfActuatedAxes; |
| 50 | + yCError(FAKEJOINTCOUPLING) << "convertFromPhysicalJointsToActuatedAxesPos: input or output vectors have wrong size"; |
| 51 | + return false; |
| 52 | + } |
| 53 | + actAxesPos[0] = physJointsPos[0]; |
| 54 | + actAxesPos[1] = physJointsPos[1]; |
| 55 | + actAxesPos[2] = physJointsPos[2] + physJointsPos[3]; |
| 56 | + return true; |
| 57 | +} |
| 58 | +bool FakeJointCoupling::convertFromPhysicalJointsToActuatedAxesVel(const yarp::sig::Vector& physJointsPos, const yarp::sig::Vector& physJointsVel, yarp::sig::Vector& actAxesVel) { |
| 59 | + size_t nrOfPhysicalJoints; |
| 60 | + size_t nrOfActuatedAxes; |
| 61 | + auto ok = getNrOfPhysicalJoints(nrOfPhysicalJoints); |
| 62 | + ok = ok && getNrOfActuatedAxes(nrOfActuatedAxes); |
| 63 | + if (!ok || physJointsPos.size() != nrOfPhysicalJoints || physJointsVel.size() != nrOfPhysicalJoints || actAxesVel.size() != nrOfActuatedAxes) { |
| 64 | + yCError(FAKEJOINTCOUPLING) << "convertFromPhysicalJointsToActuatedAxesPos: input or output vectors have wrong size"; |
| 65 | + return false; |
| 66 | + } |
| 67 | + actAxesVel[0] = physJointsVel[0]; |
| 68 | + actAxesVel[1] = physJointsVel[1]; |
| 69 | + actAxesVel[2] = physJointsPos[2] + physJointsPos[3] + physJointsVel[2] + physJointsVel[3]; |
| 70 | + return true; |
| 71 | +} |
| 72 | +bool FakeJointCoupling::convertFromPhysicalJointsToActuatedAxesAcc(const yarp::sig::Vector& physJointsPos, const yarp::sig::Vector& physJointsVel, |
| 73 | + const yarp::sig::Vector& physJointsAcc, yarp::sig::Vector& actAxesAcc) { |
| 74 | + size_t nrOfPhysicalJoints; |
| 75 | + size_t nrOfActuatedAxes; |
| 76 | + auto ok = getNrOfPhysicalJoints(nrOfPhysicalJoints); |
| 77 | + ok = ok && getNrOfActuatedAxes(nrOfActuatedAxes); |
| 78 | + if(!ok || physJointsPos.size() != nrOfPhysicalJoints || physJointsVel.size() != nrOfPhysicalJoints || physJointsAcc.size() != nrOfPhysicalJoints || actAxesAcc.size() != nrOfActuatedAxes) { |
| 79 | + yCError(FAKEJOINTCOUPLING) << "convertFromPhysicalJointsToActuatedAxesPos: input or output vectors have wrong size"; |
| 80 | + return false; |
| 81 | + } |
| 82 | + actAxesAcc[0] = physJointsAcc[0]; |
| 83 | + actAxesAcc[1] = physJointsAcc[1]; |
| 84 | + actAxesAcc[2] = physJointsPos[2] + physJointsPos[3] + physJointsVel[2] + physJointsVel[3] + physJointsAcc[2] + physJointsAcc[3]; |
| 85 | + return true; |
| 86 | +} |
| 87 | +bool FakeJointCoupling::convertFromPhysicalJointsToActuatedAxesTrq(const yarp::sig::Vector& physJointsPos, const yarp::sig::Vector& physJointsTrq, yarp::sig::Vector& actAxesTrq) { |
| 88 | + yCError(FAKEJOINTCOUPLING) << "convertFromPhysicalJointsToActuatedAxesTrq: not implemented yet"; |
| 89 | + return false; |
| 90 | +} |
| 91 | +bool FakeJointCoupling::convertFromActuatedAxesToPhysicalJointsPos(const yarp::sig::Vector& actAxesPos, yarp::sig::Vector& physJointsPos) { |
| 92 | + size_t nrOfPhysicalJoints; |
| 93 | + size_t nrOfActuatedAxes; |
| 94 | + auto ok = getNrOfPhysicalJoints(nrOfPhysicalJoints); |
| 95 | + ok = ok && getNrOfActuatedAxes(nrOfActuatedAxes); |
| 96 | + if(!ok || actAxesPos.size() != nrOfActuatedAxes || physJointsPos.size() != nrOfPhysicalJoints) { |
| 97 | + yCError(FAKEJOINTCOUPLING) << "convertFromActuatedAxesToPhysicalJointsPos: input or output vectors have wrong size"; |
| 98 | + return false; |
| 99 | + } |
| 100 | + physJointsPos[0] = actAxesPos[0]; |
| 101 | + physJointsPos[1] = actAxesPos[1]; |
| 102 | + physJointsPos[2] = actAxesPos[2] / 2.0; |
| 103 | + physJointsPos[3] = actAxesPos[2] / 2.0; |
| 104 | + return true; |
| 105 | +} |
| 106 | +bool FakeJointCoupling::convertFromActuatedAxesToPhysicalJointsVel(const yarp::sig::Vector& actAxesPos, const yarp::sig::Vector& actAxesVel, yarp::sig::Vector& physJointsVel) { |
| 107 | + size_t nrOfPhysicalJoints; |
| 108 | + size_t nrOfActuatedAxes; |
| 109 | + auto ok = getNrOfPhysicalJoints(nrOfPhysicalJoints); |
| 110 | + ok = ok && getNrOfActuatedAxes(nrOfActuatedAxes); |
| 111 | + if(!ok || actAxesPos.size() != nrOfActuatedAxes || actAxesVel.size() != nrOfActuatedAxes || physJointsVel.size() != nrOfPhysicalJoints) { |
| 112 | + yCError(FAKEJOINTCOUPLING) << "convertFromActuatedAxesToPhysicalJointsVel: input or output vectors have wrong size"; |
| 113 | + return false; |
| 114 | + } |
| 115 | + physJointsVel[0] = actAxesVel[0]; |
| 116 | + physJointsVel[1] = actAxesVel[1]; |
| 117 | + physJointsVel[2] = actAxesPos[2] / 2.0 - actAxesVel[2] / 2.0; |
| 118 | + physJointsVel[3] = actAxesPos[2] / 2.0 + actAxesVel[2] / 2.0; |
| 119 | + return true; |
| 120 | + |
| 121 | +} |
| 122 | +bool FakeJointCoupling::convertFromActuatedAxesToPhysicalJointsAcc(const yarp::sig::Vector& actAxesPos, const yarp::sig::Vector& actAxesVel, const yarp::sig::Vector& actAxesAcc, yarp::sig::Vector& physJointsAcc) { |
| 123 | + size_t nrOfPhysicalJoints; |
| 124 | + size_t nrOfActuatedAxes; |
| 125 | + auto ok = getNrOfPhysicalJoints(nrOfPhysicalJoints); |
| 126 | + ok = ok && getNrOfActuatedAxes(nrOfActuatedAxes); |
| 127 | + if(!ok || actAxesPos.size() != nrOfActuatedAxes || actAxesVel.size() != nrOfActuatedAxes || actAxesAcc.size() != nrOfActuatedAxes || physJointsAcc.size() != nrOfPhysicalJoints) { |
| 128 | + yCError(FAKEJOINTCOUPLING) << "convertFromActuatedAxesToPhysicalJointsAcc: input or output vectors have wrong size"; |
| 129 | + return false; |
| 130 | + } |
| 131 | + physJointsAcc[0] = actAxesAcc[0]; |
| 132 | + physJointsAcc[1] = actAxesAcc[1]; |
| 133 | + physJointsAcc[2] = actAxesPos[2] / 2.0 - actAxesVel[2] / 2.0 - actAxesAcc[2] / 2.0; |
| 134 | + physJointsAcc[3] = actAxesPos[2] / 2.0 + actAxesVel[2] / 2.0 + actAxesAcc[2] / 2.0; |
| 135 | + return true; |
| 136 | +} |
| 137 | +bool FakeJointCoupling::convertFromActuatedAxesToPhysicalJointsTrq(const yarp::sig::Vector& actAxesPos, const yarp::sig::Vector& actAxesTrq, yarp::sig::Vector& physJointsTrq) { |
| 138 | + yCWarning(FAKEJOINTCOUPLING) << "convertFromActuatedAxesToPhysicalJointsTrq: not implemented yet"; |
| 139 | + return false; |
| 140 | +} |
0 commit comments