Skip to content

Commit 69aaa5e

Browse files
GiulioRomualdiergocub
authored andcommitted
Implement the MotorsTemperatureChecker and the logic to prevent the robot to walk when the temperature is greather then a value
1 parent 6c4f18e commit 69aaa5e

5 files changed

Lines changed: 185 additions & 3 deletions

File tree

src/RobotInterface/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
add_walking_controllers_library(
66
NAME RobotInterface
7-
SOURCES src/Helper.cpp src/PIDHandler.cpp
8-
PUBLIC_HEADERS include/WalkingControllers/RobotInterface/Helper.h include/WalkingControllers/RobotInterface/PIDHandler.h
7+
SOURCES src/Helper.cpp src/PIDHandler.cpp src/MotorTemperatureChecker.cpp
8+
PUBLIC_HEADERS include/WalkingControllers/RobotInterface/Helper.h include/WalkingControllers/RobotInterface/PIDHandler.h include/WalkingControllers/RobotInterface/MotorTemperatureChecker.h
99
PUBLIC_LINK_LIBRARIES WalkingControllers::YarpUtilities WalkingControllers::iDynTreeUtilities ctrlLib
1010
PRIVATE_LINK_LIBRARIES Eigen3::Eigen)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-FileCopyrightText: Fondazione Istituto Italiano di Tecnologia (IIT)
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
4+
#ifndef WALKING_CONTROLLERS_MOTOR_TEMPERATURE_CHECKER
5+
#define WALKING_CONTROLLERS_MOTOR_TEMPERATURE_CHECKER
6+
7+
// std
8+
#include <vector>
9+
10+
#include <iDynTree/VectorDynSize.h>
11+
12+
#include <yarp/os/Searchable.h>
13+
14+
namespace WalkingControllers
15+
{
16+
class MotorsTemperatureChecker
17+
{
18+
private:
19+
std::vector<double> m_maxTemperature;
20+
std::vector<unsigned int> m_samplesAboveTheLimit;
21+
iDynTree::VectorDynSize m_limits;
22+
int m_maxNumberOfSampleAboveTheLimits;
23+
24+
public:
25+
26+
const std::vector<double>& getMaxTemperature() const;
27+
std::vector<unsigned int> getMotorsOverLimit() const;
28+
bool isThereAMotorOverLimit() const;
29+
bool setMotorTemperatures(const iDynTree::VectorDynSize& temperature);
30+
bool configure(const yarp::os::Searchable& config, int dofs);
31+
};
32+
};
33+
#endif
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// SPDX-FileCopyrightText: Fondazione Istituto Italiano di Tecnologia (IIT)
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
4+
#include <yarp/os/LogStream.h>
5+
6+
#include <WalkingControllers/RobotInterface/MotorTemperatureChecker.h>
7+
#include <WalkingControllers/YarpUtilities/Helper.h>
8+
9+
using namespace WalkingControllers;
10+
11+
bool MotorsTemperatureChecker::configure(const yarp::os::Searchable& config, int dofs)
12+
{
13+
m_limits.resize(dofs);
14+
if(!YarpUtilities::getVectorFromSearchable(config, "temperature_limits", m_limits))
15+
{
16+
yError() << "[MotorsTemperatureChecker::configure] Unable to get the parameter temperature limits";
17+
return false;
18+
}
19+
20+
m_samplesAboveTheLimit = std::vector<unsigned int>(dofs, 0);
21+
22+
if(!YarpUtilities::getNumberFromSearchable(config, "max_samples_above_the_limits", m_maxNumberOfSampleAboveTheLimits))
23+
{
24+
yError() << "[MotorsTemperatureChecker::configure] Unable to get the parameter 'max_samples_above_the_limits'";
25+
return false;
26+
}
27+
28+
m_maxTemperature.resize(dofs);
29+
for (int i = 0; i < dofs; i++)
30+
{
31+
m_maxTemperature[i] = 0;
32+
}
33+
34+
return true;
35+
}
36+
37+
bool MotorsTemperatureChecker::isThereAMotorOverLimit() const
38+
{
39+
if (m_maxNumberOfSampleAboveTheLimits < 0)
40+
{
41+
return false;
42+
}
43+
44+
for (const auto sample : m_samplesAboveTheLimit)
45+
{
46+
if (sample > m_maxNumberOfSampleAboveTheLimits)
47+
{
48+
return true;
49+
}
50+
}
51+
return false;
52+
}
53+
54+
std::vector<unsigned int> MotorsTemperatureChecker::getMotorsOverLimit() const
55+
{
56+
std::vector<unsigned int> indeces;
57+
58+
if (m_maxNumberOfSampleAboveTheLimits < 0)
59+
{
60+
return indeces;
61+
}
62+
63+
for (int i =0; i < m_samplesAboveTheLimit.size(); i++)
64+
{
65+
if (m_samplesAboveTheLimit[i] > m_maxNumberOfSampleAboveTheLimits)
66+
{
67+
indeces.push_back(i);
68+
}
69+
}
70+
return indeces;
71+
}
72+
73+
bool MotorsTemperatureChecker::setMotorTemperatures(const iDynTree::VectorDynSize& temperature)
74+
{
75+
if (temperature.size() != m_limits.size())
76+
{
77+
yError() << "[MotorsTemperatureChecker::setMotorTemperatures] Unexpected size of the temperature vector"
78+
<< "provided: " << temperature.size() << " expected: " << m_limits.size();
79+
return false;
80+
}
81+
82+
if (m_maxNumberOfSampleAboveTheLimits < 0)
83+
{
84+
return true;
85+
}
86+
87+
for (int i = 0; i < temperature.size(); i++)
88+
{
89+
90+
if (temperature(i) > m_limits(i))
91+
{
92+
m_samplesAboveTheLimit[i]++;
93+
}
94+
else
95+
{
96+
m_samplesAboveTheLimit[i] = 0;
97+
}
98+
99+
if (temperature(i) > m_maxTemperature[i])
100+
{
101+
m_maxTemperature[i] = temperature(i);
102+
}
103+
}
104+
105+
return true;
106+
}
107+
108+
const std::vector<double>& MotorsTemperatureChecker::getMaxTemperature() const
109+
{
110+
return m_maxTemperature;
111+
}

src/WalkingModule/include/WalkingControllers/WalkingModule/Module.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
// WalkingControllers library
3030
#include <WalkingControllers/RobotInterface/Helper.h>
3131
#include <WalkingControllers/RobotInterface/PIDHandler.h>
32+
#include <WalkingControllers/RobotInterface/MotorTemperatureChecker.h>
33+
3234
#include <WalkingControllers/TrajectoryPlanner/TrajectoryGenerator.h>
3335
#include <WalkingControllers/TrajectoryPlanner/StableDCMModel.h>
3436
#include <WalkingControllers/TrajectoryPlanner/FreeSpaceEllipseManager.h>
@@ -75,6 +77,7 @@ namespace WalkingControllers
7577
iDynTree::Position m_zmpOffsetLocal; /** < Offset in the local frame*/
7678

7779
std::unique_ptr<RobotInterface> m_robotControlHelper; /**< Robot control helper. */
80+
std::unique_ptr<MotorsTemperatureChecker> m_motorTemperatureChecker; /**< Robot control helper. */
7881
std::unique_ptr<TrajectoryGenerator> m_trajectoryGenerator; /**< Pointer to the trajectory generator object. */
7982
std::unique_ptr<FreeSpaceEllipseManager> m_freeSpaceEllipseManager; /**< Pointer to the free space ellipse manager. */
8083
std::unique_ptr<WalkingController> m_walkingController; /**< Pointer to the walking DCM MPC object. */
@@ -118,6 +121,7 @@ namespace WalkingControllers
118121

119122
iDynTree::VectorDynSize m_qDesired; /**< Vector containing the results of the IK algorithm [rad]. */
120123
iDynTree::VectorDynSize m_dqDesired; /**< Vector containing the results of the IK algorithm [rad]. */
124+
iDynTree::VectorDynSize m_motorTemperature; /**< Vector containing the results of the IK algorithm [rad]. */
121125

122126
iDynTree::Rotation m_inertial_R_worldFrame; /**< Rotation between the inertial and the world frame. */
123127

src/WalkingModule/src/Module.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ bool WalkingModule::configure(yarp::os::ResourceFinder &rf)
182182
return false;
183183
}
184184

185+
m_motorTemperatureChecker = std::make_unique<MotorsTemperatureChecker>();
186+
if (!m_motorTemperatureChecker->configure(robotControlHelperOptions, m_robotControlHelper->getActuatedDoFs()))
187+
{
188+
yError() << "[WalkingModule::configure] Unable to configure the motor temperature helper.";
189+
return false;
190+
}
191+
185192
yarp::os::Bottle &forceTorqueSensorsOptions = rf.findGroup("FT_SENSORS");
186193
forceTorqueSensorsOptions.append(generalOptions);
187194
if (!m_robotControlHelper->configureForceTorqueSensors(forceTorqueSensorsOptions))
@@ -442,6 +449,7 @@ bool WalkingModule::configure(yarp::os::ResourceFinder &rf)
442449
// resize variables
443450
m_qDesired.resize(m_robotControlHelper->getActuatedDoFs());
444451
m_dqDesired.resize(m_robotControlHelper->getActuatedDoFs());
452+
m_motorTemperature.resize(m_robotControlHelper->getActuatedDoFs());
445453

446454
yInfo() << "[WalkingModule::configure] Ready to play! Please prepare the robot.";
447455

@@ -732,6 +740,14 @@ bool WalkingModule::updateModule()
732740
return false;
733741
}
734742

743+
m_motorTemperature = m_robotControlHelper->getMotorTemperature();
744+
745+
if (!m_motorTemperatureChecker->setMotorTemperatures(m_motorTemperature))
746+
{
747+
yError() << "[WalkingModule::updateModule] Unable to set the motor temperature to the helper.";
748+
return false;
749+
}
750+
735751
m_profiler->setEndTime("Feedback");
736752

737753
auto retargetingPhase = m_isStancePhase.front() ? RetargetingClient::Phase::Stance : RetargetingClient::Phase::Walking;
@@ -1497,8 +1513,26 @@ bool WalkingModule::startWalking()
14971513

14981514
bool WalkingModule::setPlannerInput(const yarp::sig::Vector &plannerInput)
14991515
{
1500-
m_plannerInput = plannerInput;
1516+
if (m_motorTemperatureChecker->isThereAMotorOverLimit())
1517+
{
1518+
yWarning() << "[WalkingModule::setPlannerInput] The motor temperature is over the limit.";
1519+
std::vector<unsigned int> indeces = m_motorTemperatureChecker->getMotorsOverLimit();
1520+
std::string msg = "The following motors temperature are over the limits: ";
1521+
for (auto index : indeces)
1522+
{
1523+
msg += m_robotControlHelper->getAxesList()[index]
1524+
+ ": Max temperature: "
1525+
+ std::to_string(m_motorTemperatureChecker->getMaxTemperature()[index]) + " celsius.";
1526+
}
1527+
msg += "The trajectory will be set to zero.";
1528+
yWarning() << msg;
15011529

1530+
m_plannerInput.zero();
1531+
}
1532+
else
1533+
{
1534+
m_plannerInput = plannerInput;
1535+
}
15021536
// the trajectory was already finished the new trajectory will be attached as soon as possible
15031537
if (m_mergePoints.empty())
15041538
{

0 commit comments

Comments
 (0)