YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ImplementCurrentControl.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
10
11#include <cstdio>
12using namespace yarp::dev;
13using namespace yarp::os;
14
15namespace {
16YARP_LOG_COMPONENT(IMPLEMENT_LAYER_COMPONENT, "yarp.ImplementCurrentControl")
17}
18
23
28
29bool ImplementCurrentControl::initialize(int size, const int *amap, const double* ampsToSens)
30{
31 if (m_helper != nullptr) {
32 return false;
33 }
34
35 m_helper = (void *)(new ControlBoardHelper(size, amap, nullptr, nullptr, nullptr, ampsToSens, nullptr, nullptr));
36 yAssert (m_helper != nullptr);
37
38 m_buffer_doubles.resize(size);
39 m_buffer_doubles2.resize(size);
40 m_buffer_ints.resize(size);
41
42 return true;
43}
44
46{
47 if (m_helper!=nullptr)
48 {
49 delete castToMapper(m_helper);
50 m_helper=nullptr;
51 }
52
53 return true;
54}
55
63
65{
66 std::lock_guard lock(m_imp_mutex);
69
70 int k;
71 ReturnValue ret;
72 double current;
74 ret = m_iraw->getRefCurrentRaw(k, &current);
75 *r = castToMapper(m_helper)->ampereS2A(current, k);
76 return ret;
77}
78
89
100
102{
103 std::lock_guard lock(m_imp_mutex);
105
106 int k;
107 double sens;
109 return m_iraw->setRefCurrentRaw(k, sens);
110}
111
113{
114 std::lock_guard lock(m_imp_mutex);
116
119
120 return ret;
121}
122
123ReturnValue ImplementCurrentControl::setRefCurrents(const int n_joints, const int *joints, const double *t)
124{
125 std::lock_guard lock(m_imp_mutex);
129
130 for(int idx=0; idx<n_joints; idx++)
131 {
134 }
135
136 ReturnValue ret = m_iraw->setRefCurrentsRaw(n_joints, m_buffer_ints.data(), m_buffer_doubles.data());
137
138 return ret;
139}
140
142{
143 std::lock_guard lock(m_imp_mutex);
146
147 int k;
148 ReturnValue ret;
149 double current;
151 ret = m_iraw->getCurrentRaw(k, &current);
152 *t = castToMapper(m_helper)->ampereS2A(current, k);
153 return ret;
154}
155
168
170{
171 std::lock_guard lock(m_imp_mutex);
175
176 int k;
178 double min_t, max_t;
182 return ret;
183}
yarp::dev::ControlBoardHelper * castToMapper(void *p)
#define yAssert(x)
Definition Log.h:388
void ampereA2S(double ampere, int j, double &sens, int &k)
void ampereS2A(const double *sens, double *ampere)
Interface for control boards implementing current control.
virtual yarp::dev::ReturnValue getRefCurrentRaw(int m, double *curr)=0
Get the reference value of the current for a single motor.
virtual yarp::dev::ReturnValue setRefCurrentsRaw(const double *currs)=0
Set the reference value of the currents for all motors.
virtual yarp::dev::ReturnValue getRefCurrentsRaw(double *currs)=0
Get the reference value of the currents for all motors.
virtual yarp::dev::ReturnValue getCurrentRangesRaw(double *min, double *max)=0
Get the full scale of the current measurements for all motors motor (e.g.
virtual yarp::dev::ReturnValue getNumberOfMotorsRaw(int *number)=0
Retrieves the number of controlled motors from the current physical interface.
virtual yarp::dev::ReturnValue getCurrentRaw(int m, double *curr)=0
Get the instantaneous current measurement for a single motor.
virtual yarp::dev::ReturnValue getCurrentRangeRaw(int m, double *min, double *max)=0
Get the full scale of the current measurement for a given motor (e.g.
virtual yarp::dev::ReturnValue setRefCurrentRaw(int m, double curr)=0
Set the reference value of the current for a single motor.
virtual yarp::dev::ReturnValue getCurrentsRaw(double *currs)=0
Get the instantaneous current measurement for all motors.
ImplementCurrentControl(yarp::dev::ICurrentControlRaw *y)
bool uninitialize()
Clean up internal data and memory.
yarp::dev::ReturnValue getCurrents(double *t) override
Get the instantaneous current measurement for all motors.
yarp::dev::ICurrentControlRaw * m_iraw
yarp::dev::ReturnValue getCurrentRange(int j, double *min, double *max) override
Get the full scale of the current measurement for a given motor (e.g.
yarp::dev::ReturnValue getCurrent(int j, double *t) override
Get the instantaneous current measurement for a single motor.
yarp::dev::ReturnValue getRefCurrents(double *t) override
Get the reference value of the currents for all motors.
bool initialize(int size, const int *amap, const double *ampsToSens)
Initialize the internal data and alloc memory.
yarp::dev::ReturnValue getCurrentRanges(double *min, double *max) override
Get the full scale of the current measurements for all motors motor (e.g.
yarp::dev::ReturnValue getNumberOfMotors(int *ax) override
Retrieves the number of controlled axes from the current physical interface.
yarp::dev::ReturnValue setRefCurrent(int j, double t) override
Set the reference value of the current for a single motor.
yarp::dev::ReturnValue setRefCurrents(const double *t) override
Set the reference value of the currents for all motors.
yarp::dev::ReturnValue getRefCurrent(int j, double *) override
Get the reference value of the current for a single motor.
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.