20 #include <yarp/os/Network.h>
21 #include <yarp/os/Log.h>
22 #include <yarp/os/LogStream.h>
23 #include <yarp/os/Stamp.h>
26 using namespace yarp::os;
32 Bottle &conf_group = rf.findGroup(
"GENERAL");
33 Bottle* jointsBottle =
nullptr;
34 if (conf_group.isNull())
36 yWarning() <<
"Missing GENERAL group! The module uses the default values";
40 if(conf_group.check(
"portprefix")) { m_portPrefix = conf_group.find(
"portprefix").asString(); }
41 if(conf_group.check(
"period")) { _updatePeriod = conf_group.find(
"period").asFloat64(); }
42 if(conf_group.check(
"robotname")) { _robotName = conf_group.find(
"robotname").asString(); }
43 if (conf_group.check(
"listofjoints"))
45 jointsBottle = conf_group.find(
"listofjoints").asList();
46 _nEnabledMotors = jointsBottle->size();
47 for(
int i=0; i < _nEnabledMotors; i++) _listOfJoints.push_back(jointsBottle->get(i).asInt32());
54 options.put(
"device",
"remote_controlboard");
55 options.put(
"remote",
"/"+ _robotName + m_portPrefix);
56 options.put(
"local", m_portPrefix +
"/mc");
59 yDebug() <<
"++++ config:\n"
60 <<
"\t portprefix: " << m_portPrefix <<
"\n"
61 <<
"\t period: " << _updatePeriod <<
"\n"
62 <<
"\t robotname: " << _robotName <<
"\n"
63 <<
"\t listofjoints: " << jointsBottle->toString() <<
"\n";
65 _motionControlDevice.open(options);
67 if (!_motionControlDevice.isValid())
69 yError() <<
"Unable to open device driver. Aborting...";
73 if (!_motionControlDevice.view(_imot) || _imot==
nullptr)
75 yError() <<
"Unable to open motor raw interface. Aborting...";
79 if (!_imot->getNumberOfMotors(&_nmotors))
81 yError() <<
"Unable to retrieve the number of motors";
86 yDebug() <<
"Working with" << _nmotors <<
"motors";
87 yDebug() <<
"Enabling" << _nEnabledMotors <<
"motors of the subpart";
91 if (!alloc(_nEnabledMotors))
93 yError() <<
"Error allocating memory for pointers. Aborting...";
99 if(!_outputPort.open(m_portPrefix +
"/motor_temperatures:o"))
101 yError() <<
"Error opening output port for motor control";
105 for (uint8_t i = 0; i < _listOfJoints.size(); i++)
107 if (!_imot->getTemperatureLimit(i, &_motorTemperatureLimits[i]))
109 yError() <<
"Unable to get motor temperature Limits. Aborting...";
114 yDebug() <<
"Limit for motor#" << i <<
"value:" << _motorTemperatureLimits[i];
125 yInfo() <<
"Calling close functionality\n";
130 yError() <<
"Error deallocating memory for pointer. Failing...";
139 return _updatePeriod;
145 for (
int i = 0; i < _listOfJoints.size(); i++)
147 _motorTemperatures[i]= 0;
148 int jointNib = (int)_listOfJoints[i];
149 if (!_imot->getTemperature(jointNib, &_motorTemperatures[jointNib]))
151 yError() <<
"Unable to get motor " << jointNib <<
" temperature.\n";
155 sendData2OutputPort(_motorTemperatures);
168 bool MotorTemperaturePublisher::sendData2OutputPort(
double * temperatures)
170 static yarp::os::Stamp stamp;
174 Bottle &b = _outputPort.prepare();
175 _outputPort.setEnvelope(stamp);
179 b.addFloat64(stamp.getTime());
180 for (
size_t i = 0; i < _nEnabledMotors; i++)
182 b.addFloat64(temperatures[i]);
184 if(temperatures[i] >= _motorTemperatureLimits[i])
194 bool MotorTemperaturePublisher::alloc(
int nm)
196 _motorTemperatures = allocAndCheck<double>(nm);
197 _motorTemperatureLimits = allocAndCheck<double>(nm);
203 bool MotorTemperaturePublisher::dealloc()
205 checkAndDestroy(_motorTemperatures);
206 checkAndDestroy(_motorTemperatureLimits);
~MotorTemperaturePublisher() override
bool configure(yarp::os::ResourceFinder &rf)
MotorTemperaturePublisher()