YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ImplementControlMode.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
9
10#include <cstdio>
11using namespace yarp::dev;
12using namespace yarp::os;
13
14#define JOINTIDCHECK if (j >= castToMapper(helper)->axes()){yError("joint id out of bound"); return false;}
15
17 helper(nullptr),
18 raw(r),
19 buffManager(nullptr)
20{;}
21
22bool ImplementControlMode::initialize(int size, const int *amap)
23{
24 if (helper != nullptr) {
25 return false;
26 }
27
28 helper=(void *)(new ControlBoardHelper(size, amap));
29 yAssert (helper != nullptr);
30
31 buffManager = new yarp::dev::impl::FixedSizeBuffersManager<int> (size);
32 yAssert (buffManager != nullptr);
33 return true;
34}
35
40
42{
43 if (helper!=nullptr)
44 {
45 delete castToMapper(helper);
46 helper=nullptr;
47 }
48
49 if (buffManager!=nullptr)
50 {
51 delete buffManager;
52 buffManager=nullptr;
53 }
54 return true;
55}
56
58{
60 int k=castToMapper(helper)->toHw(j);
61 return raw->getControlModeRaw(k, f);
62}
63
65{
67
68 bool ret=raw->getControlModesRaw(buffValues.getData());
69 castToMapper(helper)->toUser(buffValues.getData(), modes);
70
71 buffManager->releaseBuffer(buffValues);
72 return ret;
73}
74
76{
77 if (!castToMapper(helper)->checkAxesIds(n_joint, joints)) {
78 return false;
79 }
80
82
83 for(int idx=0; idx<n_joint; idx++)
84 {
86 }
87 bool ret = raw->getControlModesRaw(n_joint, buffValues.getData(), modes);
88
89 buffManager->releaseBuffer(buffValues);
90 return ret;
91}
92
93bool ImplementControlMode::setControlMode(const int j, const int mode)
94{
96 int k=castToMapper(helper)->toHw(j);
97 return raw->setControlModeRaw(k, mode);
98}
99
101{
102 if (!castToMapper(helper)->checkAxesIds(n_joint, joints)) {
103 return false;
104 }
105
107
108 for(int idx=0; idx<n_joint; idx++)
109 {
111 }
112 bool ret = raw->setControlModesRaw(n_joint, buffValues.getData(), modes);
113
114 buffManager->releaseBuffer(buffValues);
115 return ret;
116}
117
119{
121 for(int idx=0; idx<castToMapper(helper)->axes(); idx++)
122 {
123 buffValues[castToMapper(helper)->toHw(idx)] = modes[idx];
124 }
125 bool ret = raw->setControlModesRaw(buffValues.getData());
126 buffManager->releaseBuffer(buffValues);
127 return ret;
128}
yarp::dev::ControlBoardHelper * castToMapper(void *p)
bool ret
#define JOINTIDCHECK
#define yAssert(x)
Definition Log.h:388
Interface for setting control mode in control board.
virtual bool getControlModeRaw(int j, int *mode)=0
virtual bool setControlModeRaw(const int j, const int mode)=0
virtual bool setControlModesRaw(const int n_joint, const int *joints, int *modes)=0
virtual bool getControlModesRaw(int *modes)=0
bool setControlModes(const int n_joint, const int *joints, int *modes) override
Set the current control mode for a subset of axes.
bool initialize(int k, const int *amap)
bool getControlModes(int *modes) override
Get the current control mode (multiple joints).
bool setControlMode(const int j, const int mode) override
Set the current control mode.
bool getControlMode(int j, int *f) override
Get the current control mode.
Buffer contains info about a buffer of type T and it is used to exchange information with yarp::dev::...
A manager of fixed size buffers in multi-thread environment.
Buffer< T > getBuffer()
Get a buffer and fill its information in @buffer.
void releaseBuffer(Buffer< T > &buffer)
Release a buffer.
A mini-server for performing network communication in the background.
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.