YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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
13
14using namespace yarp::dev;
15using namespace yarp::os;
16
17namespace {
18YARP_LOG_COMPONENT(IMPLEMENT_LAYER_COMPONENT, "yarp.ImplementInteractionMode")
19}
20
25
26
31
39{
40 return initialize(size, amap, nullptr, nullptr);
41}
42
43bool ImplementInteractionMode::initialize(int size, const int *amap, const double *enc, const double *zos)
44{
45 if (m_helper != nullptr) {
46 return false;
47 }
48
49 m_helper=(void *)(new ControlBoardHelper(size, amap, enc, zos));
50 yAssert(m_helper != nullptr);
51
52 m_buffer_ints.resize (size);
53 m_buffer_doubles.resize(size);
54 m_buffer_enums.resize(size);
55
56 return true;
57}
58
64{
65 if(m_helper != nullptr)
66 {
67 delete castToMapper(m_helper);
68 m_helper = nullptr;
69 }
70
71 return true;
72}
73
75{
76 std::lock_guard lock(m_imp_mutex);
77
78 int j = castToMapper(m_helper)->toHw(axis);
79 return m_iraw->getInteractionModeRaw(j, mode);
80}
81
82ReturnValue ImplementInteractionMode::getInteractionModes(const std::vector<int>& joints, std::vector<yarp::dev::InteractionModeEnum>& modes)
83{
84 std::lock_guard lock(m_imp_mutex);
86
87 std::vector<int> vectorInt_tmp(joints.size());
88 for (int i = 0; i < joints.size(); i++)
89 {
90 vectorInt_tmp[i] = castToMapper(m_helper)->toHw(joints[i]);
91 }
93
94 return ret;
95}
96
97ReturnValue ImplementInteractionMode::getInteractionModes(std::vector < yarp::dev::InteractionModeEnum>& modes)
98{
99 std::lock_guard lock(m_imp_mutex);
101
103 if(!ret)
104 {
105 return ret;
106 }
107 for(int idx=0; idx<castToMapper(m_helper)->axes(); idx++)
108 {
109 int j = castToMapper(m_helper)->toUser(idx);
110 modes[j] = m_buffer_enums[idx];
111 }
112
113 return ReturnValue_ok;
114}
115
117{
118 std::lock_guard lock(m_imp_mutex);
119
120 int j = castToMapper(m_helper)->toHw(axis);
121 return m_iraw->setInteractionModeRaw(j, mode);
122}
123
124ReturnValue ImplementInteractionMode::setInteractionModes(const std::vector<int>& joints, const std::vector<yarp::dev::InteractionModeEnum>& modes)
125{
126 std::lock_guard lock(m_imp_mutex);
128
129 std::vector<int> vectorInt_tmp(joints.size());
130 for(int idx=0; idx<joints.size(); idx++)
131 {
133 }
135
136 return ret;
137}
138
139ReturnValue ImplementInteractionMode::setInteractionModes(const std::vector<yarp::dev::InteractionModeEnum>& modes)
140{
141 std::lock_guard lock(m_imp_mutex);
143
144 for(int idx=0; idx< castToMapper(m_helper)->axes(); idx++)
145 {
146 int j = castToMapper(m_helper)->toHw(idx);
147 m_buffer_enums[j] = modes[idx];
148 }
149
151
152 return ret;
153}
yarp::dev::ControlBoardHelper * castToMapper(void *p)
#define yAssert(x)
Definition Log.h:388
#define ReturnValue_ok
Definition ReturnValue.h:82
Interface settings the way the robot interacts with the environment: basic interaction types are Stif...
virtual yarp::dev::ReturnValue setInteractionModesRaw(const std::vector< int > &joints, const std::vector< yarp::dev::InteractionModeEnum > &modes)=0
Set the interaction mode of the robot for a set of joints, values can be stiff or compliant.
virtual yarp::dev::ReturnValue getInteractionModesRaw(const std::vector< int > &joints, std::vector< 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 yarp::dev::ReturnValue setInteractionModeRaw(int axis, yarp::dev::InteractionModeEnum mode)=0
Set the interaction mode of the robot, values can be stiff or compliant.
virtual yarp::dev::ReturnValue getInteractionModeRaw(int axis, yarp::dev::InteractionModeEnum &mode)=0
Get the current interaction mode of the robot, values can be stiff or compliant.
yarp::dev::ReturnValue setInteractionModes(const std::vector< int > &joints, const std::vector< yarp::dev::InteractionModeEnum > &modes) override
Set the 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::ReturnValue setInteractionMode(int axis, yarp::dev::InteractionModeEnum mode) override
Set the interaction mode of the robot, values can be stiff or compliant.
std::vector< yarp::dev::InteractionModeEnum > m_buffer_enums
yarp::dev::IInteractionModeRaw * m_iraw
ImplementInteractionMode(yarp::dev::IInteractionModeRaw *Class_p)
Constructor.
yarp::dev::ReturnValue getInteractionMode(int axis, yarp::dev::InteractionModeEnum &mode) override
Get the current interaction mode of the robot, values can be stiff or compliant.
yarp::dev::ReturnValue getInteractionModes(const std::vector< int > &joints, std::vector< 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 initialize(int size, const int *amap)
Initialize the internal data and alloc memory, smaller version.
A mini-server for performing network communication in the background.
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.
Definition OSTestMsg.cpp:13