YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ImplementPositionDirect.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
10#include <yarp/os/Log.h>
12
13using namespace yarp::dev;
14using namespace yarp::os;
15
16#define JOINTIDCHECK if (j >= castToMapper(helper)->axes()){yError("joint id out of bound"); return false;}
17
19 iPDirect(y),
20 helper(nullptr),
21 intBuffManager(nullptr),
22 doubleBuffManager(nullptr)
23{;}
24
25
30
31bool ImplementPositionDirect::initialize(int size, const int *amap, const double *enc, const double *zos)
32{
33 if (helper != nullptr) {
34 return false;
35 }
36
37 helper=(void *)(new ControlBoardHelper(size, amap, enc, zos));
38 yAssert(helper != nullptr);
39
41 yAssert (intBuffManager != nullptr);
42
44 yAssert (doubleBuffManager != nullptr);
45
46 return true;
47}
48
50{
51 if(helper!=nullptr)
52 {
53 delete castToMapper(helper);
54 helper=nullptr;
55 }
56
58 {
59 delete intBuffManager;
60 intBuffManager=nullptr;
61 }
62
64 {
65 delete doubleBuffManager;
66 doubleBuffManager=nullptr;
67 }
68
69 return true;
70}
71
73{
74 (*axes)=castToMapper(helper)->axes();
75 return true;
76}
77
79{
81 int k;
82 double enc;
83 castToMapper(helper)->posA2E(ref, j, enc, k);
84 return iPDirect->setPositionRaw(k, enc);
85}
86
87bool ImplementPositionDirect::setPositions(const int n_joint, const int *joints, const double *refs)
88{
89 if (!castToMapper(helper)->checkAxesIds(n_joint, joints)) {
90 return false;
91 }
92
95
96 if (n_joint > (int)intBuffManager->getBufferSize()) {
97 return false;
98 }
99
100 for(int idx=0; idx<n_joint; idx++)
101 {
102 buffJoints.setValue(idx, castToMapper(helper)->toHw(joints[idx]));
103 buffValues.setValue(idx, castToMapper(helper)->posA2E(refs[idx], joints[idx]));
104 }
105
106 bool ret = iPDirect->setPositionsRaw(n_joint, buffJoints.getData(), buffValues.getData());
107
110
111 return ret;
112}
113
122
123bool ImplementPositionDirect::getRefPosition(const int j, double* ref)
124{
126 int k;
127 double tmp;
129
131
132 *ref=(castToMapper(helper)->posE2A(tmp, k));
133 return ret;
134}
135
137{
138 if (!castToMapper(helper)->checkAxesIds(n_joint, joints)) {
139 return false;
140 }
141
143
144 for(int idx=0; idx<n_joint; idx++)
145 {
147 }
148
150 bool ret = iPDirect->getRefPositionsRaw(n_joint, buffJoints.getData(), buffValues.getData());
151
152 for(int idx=0; idx<n_joint; idx++)
153 {
155 }
156
159
160 return ret;
161}
162
171
172
173// Stub impl
174
175bool StubImplPositionDirectRaw::NOT_YET_IMPLEMENTED(const char *func)
176{
177 if (func) {
178 yError("%s: not yet implemented\n", func);
179 } else {
180 yError("Function not yet implemented\n");
181 }
182
183 return false;
184}
yarp::dev::ControlBoardHelper * castToMapper(void *p)
bool ret
#define JOINTIDCHECK
#define yError(...)
Definition Log.h:361
#define yAssert(x)
Definition Log.h:388
void posE2A(double enc, int j, double &ang, int &k)
void posA2E(double ang, int j, double &enc, int &k)
Interface for a generic control board device implementing position control in encoder coordinates.
virtual bool setPositionsRaw(const int n_joint, const int *joints, const double *refs)=0
Set new reference point for all axes.
virtual bool setPositionRaw(int j, double ref)=0
Set new position for a single axis.
virtual bool getRefPositionsRaw(double *refs)
Get the last position reference for all axes.
virtual bool getRefPositionRaw(const int joint, double *ref)
Get the last position reference for the specified axis.
bool getRefPositions(double *refs) override
Get the last position reference for all axes.
ImplementPositionDirect(yarp::dev::IPositionDirectRaw *y)
Constructor.
bool setPositions(const int n_joint, const int *joints, const double *refs) override
Set new reference point for all axes.
bool getAxes(int *axes) override
Get the number of controlled axes.
bool uninitialize()
Clean up internal data and memory.
yarp::dev::impl::FixedSizeBuffersManager< double > * doubleBuffManager
bool setPosition(int j, double ref) override
Set new position for a single axis.
bool getRefPosition(const int joint, double *ref) override
Get the last position reference for the specified axis.
bool initialize(int size, const int *amap, const double *enc, const double *zos)
Initialize the internal data and alloc memory.
yarp::dev::impl::FixedSizeBuffersManager< int > * intBuffManager
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.
std::size_t getBufferSize()
Get the number of elements of a buffer.
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.
Definition jointData.cpp:13
An interface to the operating system, including Port based communication.