YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ImplementVelocityDirect.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025-2025 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
19
24
25bool ImplementVelocityDirect::initialize(int size, const int* axis_map, const double* enc, const double* zeros)
26{
27 if (m_helper != nullptr) {
28 return false;
29 }
30
31 m_helper = (void*)(new ControlBoardHelper(size, axis_map, enc, zeros));
32 yAssert(m_helper != nullptr);
33
34 m_buffer_ints.resize(size);
35 m_buffer_doubles.resize(size);
36
37 return true;
38}
39
41{
42 if (m_helper != nullptr)
43 {
44 delete castToMapper(m_helper);
45 m_helper = nullptr;
46 }
47
48 return true;
49}
50
56
68
70{
71 size_t axes = castToMapper(m_helper)->axes();
72 if (vels.size() != axes) {
73 yError("Input vector size does not match number of axes");
75 }
78 return ret;
79}
80
81yarp::dev::ReturnValue ImplementVelocityDirect::setDesiredVelocity(const std::vector<int>& jnts, const std::vector<double>& vels)
82{
83 if (jnts.size() != vels.size()) {
84 yError("Joints and velocities vectors must have the same size");
86 }
87 if (!castToMapper(m_helper)->checkAxesIds(static_cast<int>(jnts.size()), jnts.data())) {
89 }
90
91 for (size_t idx = 0; idx < jnts.size(); idx++) {
94 }
95
97 return ret;
98}
99
101{
102 if (j >= castToMapper(m_helper)->axes()) {
103 yError("joint id out of bound");
105 }
106 int k = castToMapper(m_helper)->toHw(j);
107 double tmp;
109 vel = castToMapper(m_helper)->velE2A(tmp, k);
110 return ret;
111}
112
114{
115 size_t axes = castToMapper(m_helper)->axes();
117 if (vels.size() != axes) { vels.resize(axes); }
119 return ret;
120}
121
123{
124 if (jnts.size() != vels.size()) {
125 vels.resize(jnts.size());
126 }
127 if (!castToMapper(m_helper)->checkAxesIds(static_cast<int>(jnts.size()), jnts.data())) {
129 }
130 for (size_t idx = 0; idx < jnts.size(); idx++) {
132 }
133
135
136 for (size_t idx = 0; idx < jnts.size(); idx++) {
138 }
139
140 return ret;
141}
yarp::dev::ControlBoardHelper * castToMapper(void *p)
bool ret
#define yError(...)
Definition Log.h:361
#define yAssert(x)
Definition Log.h:388
#define ReturnValue_ok
Definition ReturnValue.h:80
void velE2A(double enc, int j, double &ang, int &k)
void velA2E(double ang, int j, double &enc, int &k)
Interface for control boards implementing direct velocity control.
virtual yarp::dev::ReturnValue getDesiredVelocityRaw(const int jnt, double &vel)=0
Get the last reference velocity set by setDesiredVelocity() for a single joint.
virtual yarp::dev::ReturnValue setDesiredVelocityRaw(int jnt, double vel)=0
Set the velocity of single joint.
yarp::dev::ReturnValue getDesiredVelocity(const int jnt, double &vel) override
Get the last reference velocity set by setDesiredVelocity() for a single joint.
bool uninitialize()
Clean up internal data and memory.
ImplementVelocityDirect(yarp::dev::IVelocityDirectRaw *y)
Constructor.
yarp::dev::ReturnValue setDesiredVelocity(int jnt, double vel) override
Set the velocity of single joint.
bool initialize(int size, const int *amap, const double *enc, const double *zos)
Initialize the internal data and alloc memory.
yarp::dev::ReturnValue getAxes(size_t &axes) override
Get the number of controlled axes.
@ return_value_error_method_failed
Method is deprecated.
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.