YARP
Yet Another Robot Platform
ImplementInteractionMode.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include <cstdio>
7
12
13using namespace yarp::dev;
14using namespace yarp::os;
15#define JOINTIDCHECK if (j >= castToMapper(helper)->axes()){yError("joint id out of bound"); return false;}
16
17ImplementInteractionMode::ImplementInteractionMode(yarp::dev::IInteractionModeRaw *class_p) :
18 iInteraction(class_p),
19 helper(nullptr),
20 imodeBuffManager(nullptr),
21 intBuffManager(nullptr)
22{;}
23
24
26{
28}
29
36bool ImplementInteractionMode::initialize(int size, const int *amap)
37{
38 return initialize(size, amap, nullptr, nullptr);
39}
40
41bool ImplementInteractionMode::initialize(int size, const int *amap, const double *enc, const double *zos)
42{
43 if (helper != nullptr) {
44 return false;
45 }
46
47 helper=(void *)(new ControlBoardHelper(size, amap, enc, zos));
48 yAssert(helper != nullptr);
49
51 yAssert (intBuffManager != nullptr);
52
54 yAssert (imodeBuffManager != nullptr);
55
56 return true;
57}
58
64{
65 if(helper != nullptr)
66 {
67 delete castToMapper(helper);
68 helper = nullptr;
69 }
70
72 {
73 delete intBuffManager;
74 intBuffManager=nullptr;
75 }
76
78 {
79 delete imodeBuffManager;
80 imodeBuffManager=nullptr;
81 }
82 return true;
83}
84
86{
87 int j = castToMapper(helper)->toHw(axis);
88 return iInteraction->getInteractionModeRaw(j, mode);
89}
90
92{
93 if (!castToMapper(helper)->checkAxesIds(n_joints, joints)) {
94 return false;
95 }
96
98
99 for (int i = 0; i < n_joints; i++)
100 {
101 buffJoints[i] = castToMapper(helper)->toHw(joints[i]);
102 }
103 bool ret = iInteraction->getInteractionModesRaw(n_joints, buffJoints.getData(), modes);
104
105 intBuffManager->releaseBuffer(buffJoints);
106 return ret;
107}
108
110{
112 if(!iInteraction->getInteractionModesRaw(buffValues.getData()) )
113 {
114 imodeBuffManager->releaseBuffer(buffValues);
115 return false;
116 }
117 for(int idx=0; idx<castToMapper(helper)->axes(); idx++)
118 {
119 int j = castToMapper(helper)->toUser(idx);
120 modes[j] = buffValues[idx];
121 }
122 imodeBuffManager->releaseBuffer(buffValues);
123 return true;
124}
125
127{
128 int j = castToMapper(helper)->toHw(axis);
129 return iInteraction->setInteractionModeRaw(j, mode);
130}
131
133{
134 if (!castToMapper(helper)->checkAxesIds(n_joints, joints)) {
135 return false;
136 }
137
139
140 for(int idx=0; idx<n_joints; idx++)
141 {
142 buffJoints[idx] = castToMapper(helper)->toHw(joints[idx]);
143 }
144 bool ret = iInteraction->setInteractionModesRaw(n_joints, buffJoints.getData(), modes);
145 intBuffManager->releaseBuffer(buffJoints);
146 return ret;
147}
148
150{
152 for(int idx=0; idx< castToMapper(helper)->axes(); idx++)
153 {
154 int j = castToMapper(helper)->toHw(idx);
155 buffValues[j] = modes[idx];
156 }
157
158 bool ret = iInteraction->setInteractionModesRaw(buffValues.getData());
159 imodeBuffManager->releaseBuffer(buffValues);
160 return ret;
161}
yarp::dev::ControlBoardHelper * castToMapper(void *p)
bool ret
#define yAssert(x)
Definition: Log.h:383
Interface settings the way the robot interacts with the environment: basic interaction types are Stif...
virtual bool getInteractionModesRaw(int n_joints, int *joints, yarp::dev::InteractionModeEnum *modes)=0
Get the current interaction mode of the robot for a set of joints, values can be stiff or compliant.
virtual bool setInteractionModeRaw(int axis, yarp::dev::InteractionModeEnum mode)=0
Set the interaction mode of the robot, values can be stiff or compliant.
virtual bool setInteractionModesRaw(int n_joints, int *joints, yarp::dev::InteractionModeEnum *modes)=0
Set the interaction mode of the robot for a set of joints, values can be stiff or compliant.
virtual bool getInteractionModeRaw(int axis, yarp::dev::InteractionModeEnum *mode)=0
Get the current interaction mode of the robot, values can be stiff or compliant.
bool setInteractionMode(int axis, yarp::dev::InteractionModeEnum mode) override
Set the interaction mode of the robot, values can be stiff or compliant.
bool getInteractionMode(int axis, yarp::dev::InteractionModeEnum *mode) override
Get the current interaction mode of the robot, values can be stiff or compliant.
yarp::dev::IInteractionModeRaw * iInteraction
bool setInteractionModes(int n_joints, int *joints, yarp::dev::InteractionModeEnum *modes) override
Set the interaction mode of the robot for a set of joints, values can be stiff or compliant.
yarp::dev::impl::FixedSizeBuffersManager< int > * intBuffManager
bool getInteractionModes(int n_joints, int *joints, yarp::dev::InteractionModeEnum *modes) override
Get the current interaction mode of the robot for a set of joints, values can be stiff or compliant.
bool uninitialize()
Clean up internal data and memory.
yarp::dev::impl::FixedSizeBuffersManager< yarp::dev::InteractionModeEnum > * imodeBuffManager
bool initialize(int size, const int *amap)
Initialize the internal data and alloc memory, smaller version.
Buffer contains info about a buffer of type T and it is used to exchange information with yarp::dev::...
T * getData()
Return the data pointer.
Buffer< T > getBuffer()
Get a buffer and fill its information in @buffer.
void releaseBuffer(Buffer< T > &buffer)
Release a buffer.
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.