YARP
Yet Another Robot Platform
ImplementInteractionMode.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 
9 #include <cstdio>
10 
15 
16 using namespace yarp::dev;
17 using namespace yarp::os;
18 #define JOINTIDCHECK if (j >= castToMapper(helper)->axes()){yError("joint id out of bound"); return false;}
19 
21  iInteraction(class_p),
22  helper(nullptr),
23  imodeBuffManager(nullptr),
24  intBuffManager(nullptr)
25 {;}
26 
27 
29 {
30  uninitialize();
31 }
32 
39 bool ImplementInteractionMode::initialize(int size, const int *amap)
40 {
41  return initialize(size, amap, nullptr, nullptr);
42 }
43 
44 bool ImplementInteractionMode::initialize(int size, const int *amap, const double *enc, const double *zos)
45 {
46  if(helper != nullptr)
47  return false;
48 
49  helper=(void *)(new ControlBoardHelper(size, amap, enc, zos));
50  yAssert(helper != nullptr);
51 
53  yAssert (intBuffManager != nullptr);
54 
56  yAssert (imodeBuffManager != nullptr);
57 
58  return true;
59 }
60 
66 {
67  if(helper != nullptr)
68  {
69  delete castToMapper(helper);
70  helper = nullptr;
71  }
72 
73  if(intBuffManager)
74  {
75  delete intBuffManager;
76  intBuffManager=nullptr;
77  }
78 
80  {
81  delete imodeBuffManager;
82  imodeBuffManager=nullptr;
83  }
84  return true;
85 }
86 
88 {
89  int j = castToMapper(helper)->toHw(axis);
90  return iInteraction->getInteractionModeRaw(j, mode);
91 }
92 
94 {
95  if(!castToMapper(helper)->checkAxesIds(n_joints, joints))
96  return false;
97 
99 
100  for (int i = 0; i < n_joints; i++)
101  {
102  buffJoints[i] = castToMapper(helper)->toHw(joints[i]);
103  }
104  bool ret = iInteraction->getInteractionModesRaw(n_joints, buffJoints.getData(), modes);
105 
106  intBuffManager->releaseBuffer(buffJoints);
107  return ret;
108 }
109 
111 {
113  if(!iInteraction->getInteractionModesRaw(buffValues.getData()) )
114  {
115  imodeBuffManager->releaseBuffer(buffValues);
116  return false;
117  }
118  for(int idx=0; idx<castToMapper(helper)->axes(); idx++)
119  {
120  int j = castToMapper(helper)->toUser(idx);
121  modes[j] = buffValues[idx];
122  }
123  imodeBuffManager->releaseBuffer(buffValues);
124  return true;
125 }
126 
128 {
129  int j = castToMapper(helper)->toHw(axis);
130  return iInteraction->setInteractionModeRaw(j, mode);
131 }
132 
134 {
135  if(!castToMapper(helper)->checkAxesIds(n_joints, joints))
136  return false;
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:297
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
ImplementInteractionMode(yarp::dev::IInteractionModeRaw *Class_p)
Constructor.
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.
An interface for the device drivers.
An interface to the operating system, including Port based communication.