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::ImplementInteractionMode::helper
void * helper
Definition: ImplementInteractionMode.h:44
yarp::dev::ImplementInteractionMode::iInteraction
yarp::dev::IInteractionModeRaw * iInteraction
Definition: ImplementInteractionMode.h:43
yarp::dev::ControlBoardHelper::toHw
int toHw(int axis)
Definition: ControlBoardHelper.cpp:245
yarp::dev::ControlBoardHelper::toUser
int toUser(int axis)
Definition: ControlBoardHelper.cpp:248
yarp::dev::ImplementInteractionMode::imodeBuffManager
yarp::dev::impl::FixedSizeBuffersManager< yarp::dev::InteractionModeEnum > * imodeBuffManager
Definition: ImplementInteractionMode.h:46
yarp::dev::ImplementInteractionMode::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: ImplementInteractionMode.cpp:133
yarp::dev::ImplementInteractionMode::getInteractionMode
bool getInteractionMode(int axis, yarp::dev::InteractionModeEnum *mode) override
Get the current interaction mode of the robot, values can be stiff or compliant.
Definition: ImplementInteractionMode.cpp:87
yarp::dev::ImplementInteractionMode::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: ImplementInteractionMode.cpp:93
yarp::dev::impl::Buffer::getData
T * getData()
Return the data pointer.
Definition: FixedSizeBuffersManager-inl.h:29
yarp::dev::impl::FixedSizeBuffersManager< int >
yarp::dev::impl::FixedSizeBuffersManager::getBuffer
Buffer< T > getBuffer()
Get a buffer and fill its information in @buffer.
Definition: FixedSizeBuffersManager-inl.h:87
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
yarp::dev::ImplementInteractionMode::intBuffManager
yarp::dev::impl::FixedSizeBuffersManager< int > * intBuffManager
Definition: ImplementInteractionMode.h:47
yarp::dev
An interface for the device drivers.
Definition: audioBufferSizeData.cpp:17
yarp::dev::ImplementInteractionMode::setInteractionMode
bool setInteractionMode(int axis, yarp::dev::InteractionModeEnum mode) override
Set the interaction mode of the robot, values can be stiff or compliant.
Definition: ImplementInteractionMode.cpp:127
yarp::dev::IInteractionModeRaw::getInteractionModesRaw
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.
yarp::dev::IInteractionModeRaw
Interface settings the way the robot interacts with the environment: basic interaction types are Stif...
Definition: IInteractionMode.h:122
yarp::dev::ImplementInteractionMode::uninitialize
bool uninitialize()
Clean up internal data and memory.
Definition: ImplementInteractionMode.cpp:65
yarp::dev::IInteractionModeRaw::setInteractionModeRaw
virtual bool setInteractionModeRaw(int axis, yarp::dev::InteractionModeEnum mode)=0
Set the interaction mode of the robot, values can be stiff or compliant.
FixedSizeBuffersManager.h
yarp::dev::impl::Buffer
Buffer contains info about a buffer of type T and it is used to exchange information with yarp::dev::...
Definition: FixedSizeBuffersManager.h:27
yarp::dev::InteractionModeEnum
InteractionModeEnum
Definition: IInteractionMode.h:21
ControlBoardHelper.h
yarp::dev::impl::FixedSizeBuffersManager::releaseBuffer
void releaseBuffer(Buffer< T > &buffer)
Release a buffer.
Definition: FixedSizeBuffersManager-inl.h:156
yarp::dev::ImplementInteractionMode::ImplementInteractionMode
ImplementInteractionMode(yarp::dev::IInteractionModeRaw *Class_p)
Constructor.
Definition: ImplementInteractionMode.cpp:20
ImplementInteractionMode.h
yarp::os
An interface to the operating system, including Port based communication.
Definition: AbstractCarrier.h:17
castToMapper
yarp::dev::ControlBoardHelper * castToMapper(void *p)
Definition: ControlBoardHelper.h:180
yarp::dev::ControlBoardHelper
Definition: ControlBoardHelper.h:60
ControlBoardInterfacesImpl.h
yarp::dev::IInteractionModeRaw::getInteractionModeRaw
virtual bool getInteractionModeRaw(int axis, yarp::dev::InteractionModeEnum *mode)=0
Get the current interaction mode of the robot, values can be stiff or compliant.
yarp::dev::ControlBoardHelper::axes
int axes()
Definition: ControlBoardHelper.cpp:762
yAssert
#define yAssert(x)
Definition: Log.h:297
yarp::dev::IInteractionModeRaw::setInteractionModesRaw
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.
yarp::dev::ImplementInteractionMode::~ImplementInteractionMode
virtual ~ImplementInteractionMode()
Destructor.
Definition: ImplementInteractionMode.cpp:28
yarp::dev::ImplementInteractionMode::initialize
bool initialize(int size, const int *amap)
Initialize the internal data and alloc memory, smaller version.
Definition: ImplementInteractionMode.cpp:39