Skip to content

Commit 6c4f18e

Browse files
GiulioRomualdiergocub
authored andcommitted
Enable the temperature reading in RobotInterface::Helper
1 parent ce0289e commit 6c4f18e

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

src/RobotInterface/include/WalkingControllers/RobotInterface/Helper.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <yarp/dev/IPositionDirect.h>
1717
#include <yarp/dev/IVelocityControl.h>
1818
#include <yarp/dev/IInteractionMode.h>
19+
#include <yarp/dev/IMotor.h>
20+
1921
#include <yarp/sig/Vector.h>
2022
#include <yarp/os/Timer.h>
2123

@@ -48,6 +50,7 @@ namespace WalkingControllers
4850
yarp::dev::IControlMode *m_controlModeInterface{nullptr}; /**< Control mode interface. */
4951
yarp::dev::IControlLimits *m_limitsInterface{nullptr}; /**< Encorders interface. */
5052
yarp::dev::IInteractionMode *m_interactionInterface{nullptr}; /**< Stiff/compliant mode interface. */
53+
yarp::dev::IMotor *m_motorInterface{nullptr}; /**< Motor interface. */
5154

5255
std::unique_ptr<WalkingPIDHandler> m_PIDHandler; /**< Pointer to the PID handler object. */
5356

@@ -66,6 +69,13 @@ namespace WalkingControllers
6669
iDynTree::VectorDynSize m_jointVelocitiesBounds; /**< Joint Velocity bounds [rad/s]. */
6770
iDynTree::VectorDynSize m_jointPositionsUpperBounds; /**< Joint Position upper bound [rad]. */
6871
iDynTree::VectorDynSize m_jointPositionsLowerBounds; /**< Joint Position lower bound [rad]. */
72+
73+
iDynTree::VectorDynSize m_motorTemperatures; /**< Motor temperature [Celsius]. */
74+
mutable std::mutex m_motorTemperatureMutex; /**< Mutex for the motor temperature. */
75+
std::atomic_bool m_motorTemperatureTreadIsRunning; /**< True if the motor temperature is updated. */
76+
double m_motorTemperatureDt{0.5};
77+
std::thread m_motorTemperatureThread; /**< Thread for the motor temperature. */
78+
6979
// yarp::sig::Vector m_positionFeedbackDegFiltered;
7080
yarp::sig::Vector m_velocityFeedbackDegFiltered; /**< Vector containing the filtered joint velocity [deg/s]. */
7181
std::unique_ptr<iCub::ctrl::FirstOrderLowPassFilter> m_positionFilter; /**< Joint position low pass filter .*/
@@ -127,6 +137,8 @@ namespace WalkingControllers
127137
bool useWrenchFilter,
128138
double cutFrequency,
129139
MeasuredWrench& measuredWrench);
140+
141+
void readMotorTemperature();
130142
public:
131143

132144
/**
@@ -205,6 +217,9 @@ namespace WalkingControllers
205217
*/
206218
const iDynTree::VectorDynSize& getJointVelocity() const;
207219

220+
221+
iDynTree::VectorDynSize getMotorTemperature() const;
222+
208223
/**
209224
* Get the joint upper limit
210225
* @return the joint upper bound in radiants

src/RobotInterface/src/Helper.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ bool RobotInterface::configureRobot(const yarp::os::Searchable& config)
313313
}
314314
}
315315

316+
m_motorTemperatures.resize(m_actuatedDOFs);
317+
316318
// open the device
317319
if(!m_robotDevice.open(options))
318320
{
@@ -363,6 +365,12 @@ bool RobotInterface::configureRobot(const yarp::os::Searchable& config)
363365
return false;
364366
}
365367

368+
if (!m_robotDevice.view(m_motorInterface) || !m_motorInterface)
369+
{
370+
yError() << "[configureRobot] Cannot obtain IMotor interface";
371+
return false;
372+
}
373+
366374
// resize the buffers
367375
m_positionFeedbackDeg.resize(m_actuatedDOFs, 0.0);
368376
m_velocityFeedbackDeg.resize(m_actuatedDOFs, 0.0);
@@ -482,9 +490,31 @@ bool RobotInterface::configureRobot(const yarp::os::Searchable& config)
482490
return false;
483491
}
484492

493+
m_motorTemperatureThread = std::thread(&RobotInterface::readMotorTemperature, this);
494+
485495
return true;
486496
}
487497

498+
void RobotInterface::readMotorTemperature()
499+
{
500+
m_motorTemperatureTreadIsRunning = true;
501+
502+
while(m_motorTemperatureTreadIsRunning)
503+
{
504+
{
505+
std::lock_guard<std::mutex> lock(m_motorTemperatureMutex);
506+
507+
if(!m_motorInterface->getTemperatures(m_motorTemperatures.data()))
508+
{
509+
yError() << "[RobotInterface::readMotorTemperature] Unable to get the motor temperatures.";
510+
}
511+
}
512+
513+
// TODO GR you should load the time required for the read and close it
514+
yarp::os::Time::delay(m_motorTemperatureDt);
515+
}
516+
}
517+
488518
bool RobotInterface::configureForceTorqueSensor(const std::string& portPrefix,
489519
const std::string& portInputName,
490520
const std::string& wholeBodyDynamicsPortName,
@@ -1096,6 +1126,12 @@ bool RobotInterface::setVelocityReferences(const iDynTree::VectorDynSize& desire
10961126

10971127
bool RobotInterface::close()
10981128
{
1129+
m_motorTemperatureTreadIsRunning = false;
1130+
if (m_motorTemperatureThread.joinable())
1131+
{
1132+
m_motorTemperatureThread.join();
1133+
}
1134+
10991135
// close all the ports
11001136
for(auto& wrench : m_leftFootMeasuredWrench)
11011137
wrench.port->close();
@@ -1119,11 +1155,18 @@ const iDynTree::VectorDynSize& RobotInterface::getJointPosition() const
11191155
{
11201156
return m_positionFeedbackRad;
11211157
}
1158+
11221159
const iDynTree::VectorDynSize& RobotInterface::getJointVelocity() const
11231160
{
11241161
return m_velocityFeedbackRad;
11251162
}
11261163

1164+
iDynTree::VectorDynSize RobotInterface::getMotorTemperature() const
1165+
{
1166+
std::lock_guard lock(m_motorTemperatureMutex);
1167+
return m_motorTemperatures;
1168+
}
1169+
11271170
const iDynTree::Wrench& RobotInterface::getLeftWrench() const
11281171
{
11291172
return m_leftWrench;

0 commit comments

Comments
 (0)