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::ControlBoardHelper * castToMapper(void *p)
bool ret
#define JOINTIDCHECK
#define yAssert(x)
Definition: Log.h:297
Control board, encoder interface.
Definition: IMotor.h:29
virtual bool getTemperatureRaw(int m, double *val)=0
Get temperature of a motor.
virtual bool getTemperatureLimitRaw(int m, double *temp)=0
Retreives the current temperature limit for a specific motor.
virtual bool setGearboxRatioRaw(int m, const double val)
Set the gearbox ratio for a specific motor.
Definition: IMotor.h:90
virtual bool getGearboxRatioRaw(int m, double *val)
Get the gearbox ratio for a specific motor.
Definition: IMotor.h:82
virtual bool setTemperatureLimitRaw(int m, const double temp)=0
Set the temperature limit for a specific motor.
virtual bool getTemperaturesRaw(double *vals)=0
Get temperature of all the motors.
bool uninitialize()
Clean up internal data and memory.
ImplementMotor(yarp::dev::IMotorRaw *y)
yarp::dev::impl::FixedSizeBuffersManager< double > * doubleBuffManager
bool getTemperatureLimit(int m, double *val) override
Retreives the current temperature limit for a specific motor.
bool setTemperatureLimit(int m, const double val) override
Set the temperature limit for a specific motor.
bool getGearboxRatio(int m, double *val) override
Get the gearbox ratio for a specific motor.
bool getTemperatures(double *vals) override
Get temperature of all the motors.
bool initialize(int size, const int *amap)
Initialize the internal data and alloc memory.
bool setGearboxRatio(int m, const double val) override
Set the gearbox ratio for a specific motor.
bool getTemperature(int m, double *val) override
Get temperature of a motor.
bool getNumberOfMotors(int *num) override
Get the number of available motors.
Buffer contains info about a buffer of type T and it is used to exchange information with yarp::dev::...
T * getData()
Return the data pointer.
uint32_t getSize()
Return the number of element of buffer.
Buffer< T > getBuffer()
Get a buffer and fill its information in @buffer.
An interface for the device drivers.