YARP
Yet Another Robot Platform
ControlBoardWrapperInteractionMode.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 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 
10 
12 
14 
16 {
17  size_t off;
18  try {
19  off = device.lut.at(j).offset;
20  } catch (...) {
21  yCError(CONTROLBOARDWRAPPER, "Joint number %d out of bound [0-%zu] for part %s", j, controlledJoints, partName.c_str());
22  return false;
23  }
24  size_t subIndex = device.lut[j].deviceEntry;
25 
26  SubDevice* s = device.getSubdevice(subIndex);
27  if (!s) {
28  return false;
29  }
30 
31  if (s->iInteract) {
32  return s->iInteract->getInteractionMode(static_cast<int>(off + s->base), mode);
33  }
34  return false;
35 }
36 
38 {
39  bool ret = true;
40 
41  rpcDataMutex.lock();
42  //Reset subdev_jointsVectorLen vector
43  memset(rpcData.subdev_jointsVectorLen, 0x00, sizeof(int) * rpcData.deviceNum);
44 
45  // Create a map of joints for each subDevice
46  size_t subIndex = 0;
47  for (int j = 0; j < n_joints; j++) {
48  subIndex = device.lut[joints[j]].deviceEntry;
49  rpcData.jointNumbers[subIndex][rpcData.subdev_jointsVectorLen[subIndex]] =
50  static_cast<int>(device.lut[joints[j]].offset + rpcData.subdevices_p[subIndex]->base);
51  rpcData.subdev_jointsVectorLen[subIndex]++;
52  }
53 
54  for (subIndex = 0; subIndex < rpcData.deviceNum; subIndex++) {
55  if (rpcData.subdevices_p[subIndex]->iInteract) {
58  rpcData.jointNumbers[subIndex],
59  reinterpret_cast<yarp::dev::InteractionModeEnum*>(rpcData.modes[subIndex]));
60  } else {
61  ret = false;
62  }
63  }
64 
65  if (ret) {
66  // ReMix values by user expectations
67  for (size_t i = 0; i < rpcData.deviceNum; i++) {
68  rpcData.subdev_jointsVectorLen[i] = 0; // reset tmp index
69  }
70 
71  // fill the output vector
72  for (int j = 0; j < n_joints; j++) {
73  subIndex = device.lut[joints[j]].deviceEntry;
74  modes[j] = static_cast<yarp::dev::InteractionModeEnum>(rpcData.modes[subIndex][rpcData.subdev_jointsVectorLen[subIndex]]);
75  rpcData.subdev_jointsVectorLen[subIndex]++;
76  }
77  } else {
78  for (int j = 0; j < n_joints; j++) {
79  modes[j] = VOCAB_IM_UNKNOWN;
80  }
81  }
82  rpcDataMutex.unlock();
83  return ret;
84 }
85 
87 {
88 
90  bool ret = true;
91  for (size_t d = 0; d < device.subdevices.size(); d++) {
93  if (!p) {
94  ret = false;
95  break;
96  }
97 
98  if ((p->iInteract) && (ret = p->iInteract->getInteractionModes(imodes))) {
99  for (size_t juser = p->wbase, jdevice = p->base; juser <= p->wtop; juser++, jdevice++) {
100  modes[juser] = imodes[jdevice];
101  }
102  } else {
103  printError("getInteractionModes", p->id, ret);
104  ret = false;
105  break;
106  }
107  }
108 
109  delete[] imodes;
110  return ret;
111 }
112 
114 {
115  size_t off;
116  try {
117  off = device.lut.at(j).offset;
118  } catch (...) {
119  yCError(CONTROLBOARDWRAPPER, "Joint number %d out of bound [0-%zu] for part %s", j, controlledJoints, partName.c_str());
120  return false;
121  }
122  size_t subIndex = device.lut[j].deviceEntry;
123 
124  SubDevice* s = device.getSubdevice(subIndex);
125  if (!s) {
126  return false;
127  }
128 
129  if (s->iInteract) {
130  return s->iInteract->setInteractionMode(static_cast<int>(off + s->base), mode);
131  }
132  return false;
133 }
134 
136 {
137  bool ret = true;
138 
139  rpcDataMutex.lock();
140  //Reset subdev_jointsVectorLen vector
141  memset(rpcData.subdev_jointsVectorLen, 0x00, sizeof(int) * rpcData.deviceNum);
142 
143  // Create a map of joints for each subDevice
144  size_t subIndex = 0;
145  for (int j = 0; j < n_joints; j++) {
146  subIndex = device.lut[joints[j]].deviceEntry;
147  rpcData.jointNumbers[subIndex][rpcData.subdev_jointsVectorLen[subIndex]] =
148  static_cast<int>(device.lut[joints[j]].offset + rpcData.subdevices_p[subIndex]->base);
149  rpcData.modes[subIndex][rpcData.subdev_jointsVectorLen[subIndex]] = static_cast<int>(modes[j]);
150  rpcData.subdev_jointsVectorLen[subIndex]++;
151  }
152 
153  for (subIndex = 0; subIndex < rpcData.deviceNum; subIndex++) {
154  if (rpcData.subdevices_p[subIndex]->iInteract) {
157  rpcData.jointNumbers[subIndex],
158  reinterpret_cast<yarp::dev::InteractionModeEnum*>(rpcData.modes[subIndex]));
159  } else {
160  ret = false;
161  }
162  }
163  rpcDataMutex.unlock();
164  return ret;
165 }
166 
168 {
169  bool ret = true;
170 
171  for (size_t j = 0; j < controlledJoints; j++) {
172  size_t off;
173  try {
174  off = device.lut.at(j).offset;
175  } catch (...) {
176  yCError(CONTROLBOARDWRAPPER, "Joint number %zu out of bound [0-%zu] for part %s", j, controlledJoints, partName.c_str());
177  return false;
178  }
179  size_t subIndex = device.lut[j].deviceEntry;
180 
181  SubDevice* p = device.getSubdevice(subIndex);
182  if (!p) {
183  return false;
184  }
185 
186  if (p->iInteract) {
187  ret = ret && p->iInteract->setInteractionMode(static_cast<int>(off + p->base), modes[j]);
188  } else {
189  ret = false;
190  }
191  }
192  return ret;
193 }
ControlBoardWrapperCommon::rpcData
MultiJointData rpcData
Definition: ControlBoardWrapperCommon.h:28
ControlBoardWrapperLogComponent.h
MultiJointData::jointNumbers
int ** jointNumbers
Definition: MultiJointData.h:21
ControlBoardWrapperInteractionMode::getInteractionModes
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.
Definition: ControlBoardWrapperInteractionMode.cpp:37
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
MultiJointData::subdev_jointsVectorLen
int * subdev_jointsVectorLen
Definition: MultiJointData.h:20
ControlBoardWrapperInteractionMode::setInteractionMode
bool setInteractionMode(int j, yarp::dev::InteractionModeEnum mode) override
Set the interaction mode of the robot, values can be stiff or compliant.
Definition: ControlBoardWrapperInteractionMode.cpp:113
MultiJointData::subdevices_p
SubDevice ** subdevices_p
Definition: MultiJointData.h:24
CONTROLBOARDWRAPPER
const yarp::os::LogComponent & CONTROLBOARDWRAPPER()
Definition: ControlBoardWrapperLogComponent.cpp:11
ControlBoardWrapperInteractionMode::setInteractionModes
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.
Definition: ControlBoardWrapperInteractionMode.cpp:135
ControlBoardWrapperCommon::partName
std::string partName
Definition: ControlBoardWrapperCommon.h:24
yarp::dev::IInteractionMode::getInteractionMode
virtual bool getInteractionMode(int axis, yarp::dev::InteractionModeEnum *mode)=0
Get the current interaction mode of the robot, values can be stiff or compliant.
ControlBoardWrapperCommon::controlledJoints
size_t controlledJoints
Definition: ControlBoardWrapperCommon.h:23
SubDevice::id
std::string id
Definition: SubDevice.h:57
WrappedDevice::getSubdevice
SubDevice * getSubdevice(size_t i)
Definition: SubDevice.h:129
yarp::dev::InteractionModeEnum
InteractionModeEnum
Definition: IInteractionMode.h:21
WrappedDevice::subdevices
SubDeviceVector subdevices
Definition: SubDevice.h:125
yarp::dev::IInteractionMode::setInteractionModes
virtual bool setInteractionModes(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.
ControlBoardWrapperCommon::device
WrappedDevice device
Definition: ControlBoardWrapperCommon.h:22
yCError
#define yCError(component,...)
Definition: LogComponent.h:157
ControlBoardWrapperInteractionMode.h
SubDevice::base
size_t base
Definition: SubDevice.h:58
ControlBoardWrapperInteractionMode::getInteractionMode
bool getInteractionMode(int j, yarp::dev::InteractionModeEnum *mode) override
Get the current interaction mode of the robot, values can be stiff or compliant.
Definition: ControlBoardWrapperInteractionMode.cpp:15
WrappedDevice::lut
std::vector< DevicesLutEntry > lut
Definition: SubDevice.h:126
SubDevice::iInteract
yarp::dev::IInteractionMode * iInteract
Definition: SubDevice.h:84
yarp::dev::IInteractionMode::getInteractionModes
virtual bool getInteractionModes(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.
MultiJointData::modes
int ** modes
Definition: MultiJointData.h:22
yarp::dev::IInteractionMode::setInteractionMode
virtual bool setInteractionMode(int axis, yarp::dev::InteractionModeEnum mode)=0
Set the interaction mode of the robot, values can be stiff or compliant.
MultiJointData::deviceNum
size_t deviceNum
Definition: MultiJointData.h:17
SubDevice::wbase
size_t wbase
Definition: SubDevice.h:60
SubDevice
Definition: SubDevice.h:55
ControlBoardWrapperCommon::rpcDataMutex
std::mutex rpcDataMutex
Definition: ControlBoardWrapperCommon.h:27
WrappedDevice::maxNumOfJointsInDevices
size_t maxNumOfJointsInDevices
Definition: SubDevice.h:127
yarp::dev::VOCAB_IM_UNKNOWN
@ VOCAB_IM_UNKNOWN
Definition: IInteractionMode.h:24
ControlBoardWrapperCommon::printError
void printError(const std::string &func_name, const std::string &info, bool result)
Definition: ControlBoardWrapperCommon.h:72