YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ImplementPositionControl.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#define JOINTIDCHECK if (j >= castToMapper(helper)->axes()){yError("joint id out of bound"); return false;}
16
18 iPosition(y),
19 helper(nullptr),
20 intBuffManager(nullptr),
21 doubleBuffManager(nullptr),
22 boolBuffManager(nullptr)
23{;}
24
25
30
39bool ImplementPositionControl::initialize(int size, const int *amap, const double *enc, const double *zos)
40{
41 if (helper != nullptr) {
42 return false;
43 }
44
45 helper=(void *)(new ControlBoardHelper(size, amap, enc, zos));
46 yAssert(helper != nullptr);
47
49 yAssert (intBuffManager != nullptr);
50
52 yAssert (doubleBuffManager != nullptr);
53
55 yAssert (boolBuffManager != nullptr);
56 return true;
57}
58
64{
65 if(helper != nullptr)
66 {
67 delete castToMapper(helper);
68 helper = nullptr;
69 }
70
72 {
73 delete intBuffManager;
74 intBuffManager=nullptr;
75 }
76
78 {
79 delete doubleBuffManager;
80 doubleBuffManager=nullptr;
81 }
82
84 {
85 delete boolBuffManager;
86 boolBuffManager=nullptr;
87 }
88
89 return true;
90}
91
93{
95 int k;
96 double enc;
99}
100
121
131
133{
135 int k;
136 double enc;
138
140}
141
160
169
177
179{
180 if (!castToMapper(helper)->checkAxesIds(n_joint, joints)) {
181 return false;
182 }
183
185 for(int idx=0; idx<n_joint; idx++)
186 {
188 }
191 return ret;
192}
193
198
200{
202 int k;
203 double enc;
205 return iPosition->setRefSpeedRaw(k, enc);
206}
207
224
233
235{
237 int k;
238 double enc;
239
242}
243
262
272
274{
276 int k;
277 double enc;
279
280 bool ret = iPosition->getRefSpeedRaw(k, &enc);
281
283
284 return ret;
285}
286
287bool ImplementPositionControl::getRefSpeeds(const int n_joint, const int *joints, double *spds)
288{
289 if (!castToMapper(helper)->checkAxesIds(n_joint, joints)) {
290 return false;
291 }
292
294 for(int idx=0; idx<n_joint; idx++)
295 {
297 }
298
300 bool ret = iPosition->getRefSpeedsRaw(n_joint, buffJoints.getData(), buffValues.getData());
301
302 for(int idx=0; idx<n_joint; idx++)
303 {
305 }
308 return ret;
309}
310
319
328
352
354{
356 int k;
357 double enc;
360
362
363 return ret;
364}
365
367{
369 int k;
371
372 return iPosition->stopRaw(k);
373}
374
376{
378 for(int idx=0; idx<n_joint; idx++)
379 {
381 }
382
383 bool ret = iPosition->stopRaw(n_joint, buffValues.getData());
385 return ret;
386}
387
389{
390 return iPosition->stopRaw();
391}
392
394{
395 (*axis)=castToMapper(helper)->axes();
396
397 return true;
398}
399
400
402{
403 if (!castToMapper(helper)->checkAxisId(joint)) {
404 return false;
405 }
406 int k;
407 double enc;
410
411 *ref=castToMapper(helper)->posE2A(enc, k);
412
413 return ret;
414}
415
424
448
449
450
451// Stub interface
452
453bool StubImplPositionControlRaw::NOT_YET_IMPLEMENTED(const char *func)
454{
455 if (func) {
456 yError("%s: not yet implemented\n", func);
457 } else {
458 yError("Function not yet implemented\n");
459 }
460
461 return false;
462}
yarp::dev::ControlBoardHelper * castToMapper(void *p)
bool ret
#define JOINTIDCHECK
#define yError(...)
Definition Log.h:361
#define yAssert(x)
Definition Log.h:388
void velE2A_abs(double enc, int j, double &ang, int &k)
void velA2E(double ang, int j, double &enc, int &k)
void posE2A(double enc, int j, double &ang, int &k)
void accA2E_abs(double ang, int j, double &enc, int &k)
void accE2A_abs(double enc, int j, double &ang, int &k)
void velA2E_abs(double ang, int j, double &enc, 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 getRefAccelerationRaw(int j, double *acc)=0
Get reference acceleration for a joint.
virtual bool stopRaw(int j)=0
Stop motion, single joint.
virtual bool getRefSpeedsRaw(double *spds)=0
Get reference speed of all joints.
virtual bool relativeMoveRaw(int j, double delta)=0
Set relative position.
virtual bool getTargetPositionsRaw(double *refs)
Get the last position reference for all axes.
virtual bool setRefAccelerationRaw(int j, double acc)=0
Set reference acceleration for a joint.
virtual bool checkMotionDoneRaw(int j, bool *flag)=0
Check if the current trajectory is terminated.
virtual bool getRefSpeedRaw(int j, double *ref)=0
Get reference speed for a joint.
virtual bool setRefAccelerationsRaw(const double *accs)=0
Set reference acceleration on all joints.
virtual bool positionMoveRaw(int j, double ref)=0
Set new reference point for a single axis.
virtual bool getTargetPositionRaw(const int joint, double *ref)
Get the last position reference for the specified axis.
virtual bool setRefSpeedsRaw(const double *spds)=0
Set reference speed on all joints.
virtual bool getRefAccelerationsRaw(double *accs)=0
Get reference acceleration of all joints.
virtual bool setRefSpeedRaw(int j, double sp)=0
Set reference speed for a joint, this is the speed used during the interpolation of the trajectory.
bool positionMove(int j, double ref) override
Set new reference point for a single axis.
bool getRefSpeeds(const int n_joint, const int *joints, double *spds) override
Get reference speed of all joints.
bool getRefSpeed(int j, double *ref) override
Get reference speed for a joint.
bool getTargetPositions(double *refs) override
Get the last position reference for all axes.
bool setRefAccelerations(const int n_joint, const int *joints, const double *accs) override
Set reference acceleration on all joints.
bool getRefAccelerations(const int n_joint, const int *joints, double *accs) override
Get reference acceleration for a joint.
bool relativeMove(int j, double delta) override
Set relative position.
bool getTargetPosition(const int joint, double *ref) override
Get the last position reference for the specified axis.
bool checkMotionDone(bool *flag) override
Check if the current trajectory is terminated.
bool setRefSpeed(int j, double sp) override
Set reference speed for a joint, this is the speed used during the interpolation of the trajectory.
yarp::dev::impl::FixedSizeBuffersManager< bool > * boolBuffManager
bool setRefAcceleration(int j, double acc) override
Set reference acceleration for a joint.
ImplementPositionControl(yarp::dev::IPositionControlRaw *y)
Constructor.
yarp::dev::impl::FixedSizeBuffersManager< int > * intBuffManager
yarp::dev::impl::FixedSizeBuffersManager< double > * doubleBuffManager
bool getAxes(int *axis) override
Get the number of controlled axes.
bool stop() override
Stop motion, multiple joints.
bool getRefAcceleration(int j, double *acc) override
Get reference acceleration for a joint.
bool setRefSpeeds(const int n_joint, const int *joints, const double *spds) override
Set reference speed on all joints.
bool uninitialize()
Clean up internal data and memory.
bool initialize(int size, const int *amap, const double *enc, const double *zos)
Initialize the internal data and alloc memory.
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.