YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeJointCoupling.cpp
Go to the documentation of this file.
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
9
10#include <yarp/os/Bottle.h>
11#include <yarp/os/Time.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
21using namespace yarp::dev;
22using namespace yarp::os;
23using namespace yarp::os::impl;
24
25
26namespace {
27YARP_LOG_COMPONENT(FAKEJOINTCOUPLING, "yarp.device.fakeJointCoupling")
28}
29
31{
32 if (!this->parseParams(config)) {return false;}
33
36 std::vector<std::string> physical_joint_names{"phys_joint_0", "phys_joint_1", "phys_joint_2", "phys_joint_3"};
37 std::vector<std::string> actuated_axes_names{"act_axes_0", "act_axes_1", "act_axes_2"};
38 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}};
40 return true;
41}
43 return true;
44}
45
47 size_t nrOfPhysicalJoints;
48 size_t nrOfActuatedAxes;
51 if (!ok || physJointsPos.size() != nrOfPhysicalJoints || actAxesPos.size() != nrOfActuatedAxes) {
52 // yCDebug(FAKEJOINTCOUPLING) << ok <<physJointsPos.size()<<nrOfPhysicalJoints<<actAxesPos.size()<<nrOfActuatedAxes;
53 yCError(FAKEJOINTCOUPLING) << "convertFromPhysicalJointsToActuatedAxesPos: input or output vectors have wrong size";
54 return false;
55 }
56 actAxesPos[0] = physJointsPos[0];
57 actAxesPos[1] = physJointsPos[1];
58 actAxesPos[2] = physJointsPos[2] + physJointsPos[3];
59 return true;
60}
62 size_t nrOfPhysicalJoints;
63 size_t nrOfActuatedAxes;
66 if (!ok || physJointsPos.size() != nrOfPhysicalJoints || physJointsVel.size() != nrOfPhysicalJoints || actAxesVel.size() != nrOfActuatedAxes) {
67 yCError(FAKEJOINTCOUPLING) << "convertFromPhysicalJointsToActuatedAxesPos: input or output vectors have wrong size";
68 return false;
69 }
70 actAxesVel[0] = physJointsVel[0];
71 actAxesVel[1] = physJointsVel[1];
72 actAxesVel[2] = physJointsPos[2] + physJointsPos[3] + physJointsVel[2] + physJointsVel[3];
73 return true;
74}
76 const yarp::sig::Vector& physJointsAcc, yarp::sig::Vector& actAxesAcc) {
77 size_t nrOfPhysicalJoints;
78 size_t nrOfActuatedAxes;
81 if(!ok || physJointsPos.size() != nrOfPhysicalJoints || physJointsVel.size() != nrOfPhysicalJoints || physJointsAcc.size() != nrOfPhysicalJoints || actAxesAcc.size() != nrOfActuatedAxes) {
82 yCError(FAKEJOINTCOUPLING) << "convertFromPhysicalJointsToActuatedAxesPos: input or output vectors have wrong size";
83 return false;
84 }
85 actAxesAcc[0] = physJointsAcc[0];
86 actAxesAcc[1] = physJointsAcc[1];
87 actAxesAcc[2] = physJointsPos[2] + physJointsPos[3] + physJointsVel[2] + physJointsVel[3] + physJointsAcc[2] + physJointsAcc[3];
88 return true;
89}
91 yCError(FAKEJOINTCOUPLING) << "convertFromPhysicalJointsToActuatedAxesTrq: not implemented yet";
92 return false;
93}
95 size_t nrOfPhysicalJoints;
96 size_t nrOfActuatedAxes;
99 if(!ok || actAxesPos.size() != nrOfActuatedAxes || physJointsPos.size() != nrOfPhysicalJoints) {
100 yCError(FAKEJOINTCOUPLING) << "convertFromActuatedAxesToPhysicalJointsPos: input or output vectors have wrong size";
101 return false;
102 }
103 physJointsPos[0] = actAxesPos[0];
104 physJointsPos[1] = actAxesPos[1];
105 physJointsPos[2] = actAxesPos[2] / 2.0;
106 physJointsPos[3] = actAxesPos[2] / 2.0;
107 return true;
108}
110 size_t nrOfPhysicalJoints;
111 size_t nrOfActuatedAxes;
114 if(!ok || actAxesPos.size() != nrOfActuatedAxes || actAxesVel.size() != nrOfActuatedAxes || physJointsVel.size() != nrOfPhysicalJoints) {
115 yCError(FAKEJOINTCOUPLING) << "convertFromActuatedAxesToPhysicalJointsVel: input or output vectors have wrong size";
116 return false;
117 }
118 physJointsVel[0] = actAxesVel[0];
119 physJointsVel[1] = actAxesVel[1];
120 physJointsVel[2] = actAxesPos[2] / 2.0 - actAxesVel[2] / 2.0;
121 physJointsVel[3] = actAxesPos[2] / 2.0 + actAxesVel[2] / 2.0;
122 return true;
123
124}
126 size_t nrOfPhysicalJoints;
127 size_t nrOfActuatedAxes;
130 if(!ok || actAxesPos.size() != nrOfActuatedAxes || actAxesVel.size() != nrOfActuatedAxes || actAxesAcc.size() != nrOfActuatedAxes || physJointsAcc.size() != nrOfPhysicalJoints) {
131 yCError(FAKEJOINTCOUPLING) << "convertFromActuatedAxesToPhysicalJointsAcc: input or output vectors have wrong size";
132 return false;
133 }
134 physJointsAcc[0] = actAxesAcc[0];
135 physJointsAcc[1] = actAxesAcc[1];
136 physJointsAcc[2] = actAxesPos[2] / 2.0 - actAxesVel[2] / 2.0 - actAxesAcc[2] / 2.0;
137 physJointsAcc[3] = actAxesPos[2] / 2.0 + actAxesVel[2] / 2.0 + actAxesAcc[2] / 2.0;
138 return true;
139}
141 yCWarning(FAKEJOINTCOUPLING) << "convertFromActuatedAxesToPhysicalJointsTrq: not implemented yet";
142 return false;
143}
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
bool convertFromActuatedAxesToPhysicalJointsTrq(const yarp::sig::Vector &actAxesPos, const yarp::sig::Vector &actAxesTrq, yarp::sig::Vector &physJointsTrq) override
bool open(yarp::os::Searchable &par) override
Open the DeviceDriver.
bool convertFromActuatedAxesToPhysicalJointsVel(const yarp::sig::Vector &actAxesPos, const yarp::sig::Vector &actAxesVel, yarp::sig::Vector &physJointsVel) override
bool convertFromPhysicalJointsToActuatedAxesVel(const yarp::sig::Vector &physJointsPos, const yarp::sig::Vector &physJointsVel, yarp::sig::Vector &actAxesVel) override
bool convertFromActuatedAxesToPhysicalJointsPos(const yarp::sig::Vector &actAxesPos, yarp::sig::Vector &physJointsPos) override
bool convertFromPhysicalJointsToActuatedAxesPos(const yarp::sig::Vector &physJointsPos, yarp::sig::Vector &actAxesPos) override
bool convertFromPhysicalJointsToActuatedAxesTrq(const yarp::sig::Vector &physJointsPos, const yarp::sig::Vector &physJointsTrq, yarp::sig::Vector &actAxesTrq) override
bool convertFromPhysicalJointsToActuatedAxesAcc(const yarp::sig::Vector &physJointsPos, const yarp::sig::Vector &physJointsVel, const yarp::sig::Vector &physJointsAcc, yarp::sig::Vector &actAxesAcc) override
bool close() override
Close the DeviceDriver.
bool convertFromActuatedAxesToPhysicalJointsAcc(const yarp::sig::Vector &actAxesPos, const yarp::sig::Vector &actAxesVel, const yarp::sig::Vector &actAxesAcc, yarp::sig::Vector &physJointsAcc) override
bool getNrOfActuatedAxes(size_t &nrOfActuatedAxes) override final
bool getNrOfPhysicalJoints(size_t &nrOfPhysicalJoints) override final
void initialise(yarp::sig::VectorOf< size_t > coupled_physical_joints, yarp::sig::VectorOf< size_t > coupled_actuated_axes, std::vector< std::string > physical_joint_names, std::vector< std::string > actuated_axes_names, std::vector< std::pair< double, double > > coupled_physical_joint_limits)
A mini-server for performing network communication in the background.
A base class for nested structures that can be searched.
Definition Searchable.h:31
size_t size() const
Definition Vector.h:341
#define yCError(component,...)
#define yCWarning(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.