YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ImplementMotor.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;
12
13namespace {
14YARP_LOG_COMPONENT(IMPLEMENT_LAYER_COMPONENT, "yarp.ImplementMotor")
15}
16
18// Encoder Interface Timed Implementation
20 m_iraw(y),
21 m_helper(nullptr)
22{ }
23
28
29bool ImplementMotor:: initialize (int size, const int *amap)
30{
31 if (m_helper != nullptr) {
32 return false;
33 }
34
35 m_helper=(void *)(new ControlBoardHelper(size, amap));
36 yAssert (m_helper != nullptr);
37
38 m_buffer_ints.resize (size);
39 m_buffer_doubles.resize(size);
40
41 return true;
42}
43
49{
50 if (m_helper!=nullptr)
51 {
52 delete castToMapper(m_helper);
53 m_helper=nullptr;
54 }
55
56 return true;
57}
58
60{
61 std::lock_guard lock(m_imp_mutex);
62 POINTERCHECK(IMPLEMENT_LAYER_COMPONENT,num)
63
64 (*num)=castToMapper(m_helper)->axes();
65 return ReturnValue_ok;
66}
67
69{
70 std::lock_guard lock(m_imp_mutex);
71 JOINTIDCHECK(IMPLEMENT_LAYER_COMPONENT,m)
72 POINTERCHECK(IMPLEMENT_LAYER_COMPONENT,value)
73
74 ReturnValue ret;
75 int k=castToMapper(m_helper)->toHw(m);
76
77 ret=m_iraw->getTemperatureRaw(k, value);
78
79 return ret;
80}
81
83{
84 std::lock_guard lock(m_imp_mutex);
85 JOINTIDCHECK(IMPLEMENT_LAYER_COMPONENT,m)
86 POINTERCHECK(IMPLEMENT_LAYER_COMPONENT,value)
87
88 ReturnValue ret;
89 int k=castToMapper(m_helper)->toHw(m);
90
91 ret=m_iraw->getTemperatureLimitRaw(k, value);
92
93 return ret;
94}
95
97{
98 std::lock_guard lock(m_imp_mutex);
99 JOINTIDCHECK(IMPLEMENT_LAYER_COMPONENT,m)
100
101 ReturnValue ret;
102 int k=castToMapper(m_helper)->toHw(m);
103
104 ret=m_iraw->setTemperatureLimitRaw(k, value);
105
106 return ret;
107}
108
110{
111 std::lock_guard lock(m_imp_mutex);
112 JOINTIDCHECK(IMPLEMENT_LAYER_COMPONENT,m)
113 POINTERCHECK(IMPLEMENT_LAYER_COMPONENT,value)
114
115 ReturnValue ret;
116 int k = castToMapper(m_helper)->toHw(m);
117
118 ret = m_iraw->getGearboxRatioRaw(k, value);
119
120 return ret;
121}
122
124{
125 std::lock_guard lock(m_imp_mutex);
126 JOINTIDCHECK(IMPLEMENT_LAYER_COMPONENT,m)
127
128 ReturnValue ret;
129 int k = castToMapper(m_helper)->toHw(m);
130
131 ret = m_iraw->setGearboxRatioRaw(k, value);
132
133 return ret;
134}
135
137{
138 std::lock_guard lock(m_imp_mutex);
139 POINTERCHECK(IMPLEMENT_LAYER_COMPONENT,v)
140
142 for (size_t i=0; i< castToMapper(m_helper)->axes(); i++)
143 {
144 int k = castToMapper(m_helper)->toHw(i);
145 v[i] = m_buffer_doubles[k];
146 }
147 return ret;
148}
yarp::dev::ControlBoardHelper * castToMapper(void *p)
#define yAssert(x)
Definition Log.h:388
#define ReturnValue_ok
Definition ReturnValue.h:82
Control board, encoder interface.
Definition IMotor.h:25
virtual yarp::dev::ReturnValue setGearboxRatioRaw(int m, const double val)=0
Set the gearbox ratio for a specific motor.
virtual yarp::dev::ReturnValue setTemperatureLimitRaw(int m, const double temp)=0
Set the temperature limit for a specific motor.
virtual yarp::dev::ReturnValue getTemperaturesRaw(double *vals)=0
Get temperature of all the motors.
virtual yarp::dev::ReturnValue getTemperatureRaw(int m, double *val)=0
Get temperature of a motor.
virtual yarp::dev::ReturnValue getTemperatureLimitRaw(int m, double *temp)=0
Retrieves the current temperature limit for a specific motor.
virtual yarp::dev::ReturnValue getGearboxRatioRaw(int m, double *val)=0
Get the gearbox ratio for a specific motor.
bool uninitialize()
Clean up internal data and memory.
ImplementMotor(yarp::dev::IMotorRaw *y)
yarp::dev::ReturnValue getNumberOfMotors(int *num) override
Get the number of available motors.
yarp::dev::IMotorRaw * m_iraw
yarp::dev::ReturnValue setTemperatureLimit(int m, const double val) override
Set the temperature limit for a specific motor.
yarp::dev::ReturnValue setGearboxRatio(int m, const double val) override
Set the gearbox ratio for a specific motor.
yarp::dev::ReturnValue getTemperatures(double *vals) override
Get temperature of all the motors.
std::vector< double > m_buffer_doubles
std::vector< int > m_buffer_ints
bool initialize(int size, const int *amap)
Initialize the internal data and alloc memory.
yarp::dev::ReturnValue getTemperature(int m, double *val) override
Get temperature of a motor.
yarp::dev::ReturnValue getTemperatureLimit(int m, double *val) override
Retrieves the current temperature limit for a specific motor.
yarp::dev::ReturnValue getGearboxRatio(int m, double *val) override
Get the gearbox ratio for a specific motor.
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.