YARP
Yet Another Robot Platform
ImplementMotor.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
12 
13 #include <cstdio>
14 using namespace yarp::dev;
15 
16 #define JOINTIDCHECK if (m >= castToMapper(helper)->axes()){yError("motor id out of bound"); return false;}
17 
19 // Encoder Interface Timed Implementation
21  imotor(y),
22  helper(nullptr),
23  doubleBuffManager(nullptr)
24 { }
25 
27 {
28  uninitialize();
29 }
30 
31 bool ImplementMotor:: initialize (int size, const int *amap)
32 {
33  if (helper!=nullptr)
34  return false;
35 
36  helper=(void *)(new ControlBoardHelper(size, amap));
37  yAssert (helper != nullptr);
38 
40  yAssert (doubleBuffManager != nullptr);
41 
42  return true;
43 }
44 
50 {
51  if (helper!=nullptr)
52  {
53  delete castToMapper(helper);
54  helper=nullptr;
55  }
56 
58  {
59  delete doubleBuffManager;
60  doubleBuffManager=nullptr;
61  }
62 
63  return true;
64 }
65 
67 {
68  (*num)=castToMapper(helper)->axes();
69  return true;
70 }
71 
72 bool ImplementMotor::getTemperature(int m, double* value)
73 {
75  bool ret;
76  int k=castToMapper(helper)->toHw(m);
77 
78  ret=imotor->getTemperatureRaw(k, value);
79 
80  return ret;
81 }
82 
83 bool ImplementMotor::getTemperatureLimit(int m, double* value)
84 {
86  bool ret;
87  int k=castToMapper(helper)->toHw(m);
88 
90 
91  return ret;
92 }
93 
94 bool ImplementMotor::setTemperatureLimit(int m, const double value)
95 {
97  bool ret;
98  int k=castToMapper(helper)->toHw(m);
99 
100  ret=imotor->setTemperatureLimitRaw(k, value);
101 
102  return ret;
103 }
104 
105 bool ImplementMotor::getGearboxRatio(int m, double* value)
106 {
108  bool ret;
109  int k = castToMapper(helper)->toHw(m);
110 
111  ret = imotor->getGearboxRatioRaw(k, value);
112 
113  return ret;
114 }
115 
116 bool ImplementMotor::setGearboxRatio(int m, const double value)
117 {
119  bool ret;
120  int k = castToMapper(helper)->toHw(m);
121 
122  ret = imotor->setGearboxRatioRaw(k, value);
123 
124  return ret;
125 }
126 
128 {
130 
131  bool ret = imotor->getTemperaturesRaw(buffValues.getData());
132  for (size_t i=0; i< buffValues.getSize(); i++)
133  {
134  int k = castToMapper(helper)->toHw(i);
135  v[i] = buffValues[k];
136  }
137  return ret;
138 }
yarp::dev::ImplementMotor::getTemperature
bool getTemperature(int m, double *val) override
Get temperature of a motor.
Definition: ImplementMotor.cpp:72
yarp::dev::ControlBoardHelper::toHw
int toHw(int axis)
Definition: ControlBoardHelper.cpp:245
yarp::dev::ImplementMotor::uninitialize
bool uninitialize()
Clean up internal data and memory.
Definition: ImplementMotor.cpp:49
yarp::dev::ImplementMotor::imotor
IMotorRaw * imotor
Definition: ImplementMotor.h:35
yarp::dev::ImplementMotor::setGearboxRatio
bool setGearboxRatio(int m, const double val) override
Set the gearbox ratio for a specific motor.
Definition: ImplementMotor.cpp:116
yarp::dev::ImplementMotor::getTemperatureLimit
bool getTemperatureLimit(int m, double *val) override
Retreives the current temperature limit for a specific motor.
Definition: ImplementMotor.cpp:83
yarp::dev::impl::Buffer::getData
T * getData()
Return the data pointer.
Definition: FixedSizeBuffersManager-inl.h:29
yarp::dev::impl::FixedSizeBuffersManager< double >
JOINTIDCHECK
#define JOINTIDCHECK
Definition: ImplementMotor.cpp:16
yarp::dev::impl::FixedSizeBuffersManager::getBuffer
Buffer< T > getBuffer()
Get a buffer and fill its information in @buffer.
Definition: FixedSizeBuffersManager-inl.h:87
yarp::dev::IMotorRaw
Control board, encoder interface.
Definition: IMotor.h:29
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
yarp::dev
An interface for the device drivers.
Definition: audioBufferSizeData.cpp:17
yarp::dev::ImplementMotor::getNumberOfMotors
bool getNumberOfMotors(int *num) override
Get the number of available motors.
Definition: ImplementMotor.cpp:66
yarp::dev::IMotorRaw::setTemperatureLimitRaw
virtual bool setTemperatureLimitRaw(int m, const double temp)=0
Set the temperature limit for a specific motor.
yarp::dev::impl::Buffer::getSize
uint32_t getSize()
Return the number of element of buffer.
Definition: FixedSizeBuffersManager-inl.h:36
yarp::dev::ImplementMotor::getTemperatures
bool getTemperatures(double *vals) override
Get temperature of all the motors.
Definition: ImplementMotor.cpp:127
FixedSizeBuffersManager.h
yarp::dev::impl::Buffer
Buffer contains info about a buffer of type T and it is used to exchange information with yarp::dev::...
Definition: FixedSizeBuffersManager.h:27
yarp::dev::IMotorRaw::setGearboxRatioRaw
virtual bool setGearboxRatioRaw(int m, const double val)
Set the gearbox ratio for a specific motor.
Definition: IMotor.h:90
ControlBoardHelper.h
yarp::dev::IMotorRaw::getGearboxRatioRaw
virtual bool getGearboxRatioRaw(int m, double *val)
Get the gearbox ratio for a specific motor.
Definition: IMotor.h:82
yarp::dev::IMotorRaw::getTemperatureLimitRaw
virtual bool getTemperatureLimitRaw(int m, double *temp)=0
Retreives the current temperature limit for a specific motor.
yarp::dev::ImplementMotor::ImplementMotor
ImplementMotor(yarp::dev::IMotorRaw *y)
Definition: ImplementMotor.cpp:20
yarp::dev::IMotorRaw::getTemperatureRaw
virtual bool getTemperatureRaw(int m, double *val)=0
Get temperature of a motor.
yarp::dev::ImplementMotor::~ImplementMotor
virtual ~ImplementMotor()
Definition: ImplementMotor.cpp:26
castToMapper
yarp::dev::ControlBoardHelper * castToMapper(void *p)
Definition: ControlBoardHelper.h:180
yarp::dev::ControlBoardHelper
Definition: ControlBoardHelper.h:60
ControlBoardInterfacesImpl.h
yarp::dev::IMotorRaw::getTemperaturesRaw
virtual bool getTemperaturesRaw(double *vals)=0
Get temperature of all the motors.
yarp::dev::ImplementMotor::setTemperatureLimit
bool setTemperatureLimit(int m, const double val) override
Set the temperature limit for a specific motor.
Definition: ImplementMotor.cpp:94
yarp::dev::ControlBoardHelper::axes
int axes()
Definition: ControlBoardHelper.cpp:762
yarp::dev::ImplementMotor::helper
void * helper
Definition: ImplementMotor.h:36
yarp::dev::ImplementMotor::doubleBuffManager
yarp::dev::impl::FixedSizeBuffersManager< double > * doubleBuffManager
Definition: ImplementMotor.h:38
yAssert
#define yAssert(x)
Definition: Log.h:297
yarp::dev::ImplementMotor::initialize
bool initialize(int size, const int *amap)
Initialize the internal data and alloc memory.
Definition: ImplementMotor.cpp:31
yarp::dev::ImplementMotor::getGearboxRatio
bool getGearboxRatio(int m, double *val) override
Get the gearbox ratio for a specific motor.
Definition: ImplementMotor.cpp:105