Skip to content

Commit b7ee491

Browse files
Add isSetPointSetAtLeastOnce flag to IK and TSID task classes for set-point validation (#939)
1 parent c95003f commit b7ee491

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+336
-101
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ All notable changes to this project are documented in this file.
99
- Add `getCurrentTime` to the `FixedFootDetector` (https://github.com/ami-iit/bipedal-locomotion-framework/pull/928)
1010
- Add the possibility to easily disable/enable the rt logging in `YarpRobotLoggerDevice` (https://github.com/ami-iit/bipedal-locomotion-framework/pull/932)
1111
- Enable Programmatic Creation of `VariableRegularizationTask` (https://github.com/ami-iit/bipedal-locomotion-framework/pull/934)
12+
- Check if the setpoint has been set at least once in TSID and IK (https://github.com/ami-iit/bipedal-locomotion-framework/pull/939)
1213

1314
### Changed
1415
- Some improvements on the YarpRobotLoggerDevice (https://github.com/ami-iit/bipedal-locomotion-framework/pull/910)
1516
- Removed ROS1 device publisher and the corresponding example (https://github.com/ami-iit/bipedal-locomotion-framework/pull/910)
17+
- Remove the possibility of setting the desired gravity direction and desired forward velocity separately in the `IK::GravityTrask` (https://github.com/ami-iit/bipedal-locomotion-framework/pull/939)
1618

1719
### Fixed
1820
- Fix outputs of `UnicycleTrajectoryGenerator` (https://github.com/ami-iit/bipedal-locomotion-framework/pull/916)

bindings/python/IK/src/GravityTask.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ void CreateGravityTask(pybind11::module& module)
2929

3030
py::class_<GravityTask, std::shared_ptr<GravityTask>, IKLinearTask>(module, "GravityTask")
3131
.def(py::init())
32-
.def("set_desired_gravity_direction_in_target_frame",
33-
&GravityTask::setDesiredGravityDirectionInTargetFrame,
34-
py::arg("desired_gravity_direction"))
35-
.def("set_feedforward_velocity_in_target_frame",
36-
&GravityTask::setFeedForwardVelocityInTargetFrame,
37-
py::arg("feedforward_velocity"))
3832
.def("set_set_point",
3933
&GravityTask::setSetPoint,
4034
py::arg("desired_gravity_direction"),

bindings/python/IK/tests/test_QP_inverse_kinematics.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,7 @@ def test_gravity_task():
256256
assert gravity_task.set_variables_handler(variables_handler=gravity_task_var_handler)
257257

258258
# Set desired distance
259-
assert gravity_task.set_desired_gravity_direction_in_target_frame(desired_gravity_direction=[np.random.uniform(-0.5,0.5) for _ in range(3)])
260-
assert gravity_task.set_feedforward_velocity_in_target_frame(feedforward_velocity=[np.random.uniform(-0.5,0.5) for _ in range(3)])
261-
assert gravity_task.set_set_point(desired_gravity_direction=[np.random.uniform(-0.5,0.5) for _ in range(3)])
259+
assert gravity_task.set_set_point(desired_gravity_direction=[np.random.uniform(-0.5,0.5) for _ in range(3)], feedforward_velocity=[np.random.uniform(-0.5,0.5) for _ in range(3)])
262260

263261
def test_joint_velocity_limits_task():
264262

src/IK/include/BipedalLocomotion/IK/AngularMomentumTask.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class AngularMomentumTask : public IKLinearTask
5353

5454
Eigen::MatrixXd m_centroidalMomentumMatrix;
5555
std::size_t m_angularMomentumTaskSize{m_angularVelocitySize}; /**< DoFs associated to the linear task */
56-
std::array<bool, m_angularVelocitySize> m_mask{true, true, true};
56+
std::array<bool, m_angularVelocitySize> m_mask{true, true, true}; /**< Mask representing the angular momentum coordinates controlled. */
57+
bool m_isSetPointSetAtLeastOnce{false}; /**< True if the set point has been set at least once. */
5758
public:
5859

5960
/**

src/IK/include/BipedalLocomotion/IK/CoMTask.h

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class CoMTask : public IKLinearTask
7272
std::size_t m_DoFs{m_linearVelocitySize}; /**< DoFs associated to the task */
7373

7474
Eigen::MatrixXd m_jacobian; /**< CoM Jacobian matrix in MIXED representation */
75+
bool m_isSetPointSetAtLeastOnce{false}; /**< True if the set-point has been set at least once */
76+
7577
public:
7678
/**
7779
* Initialize the task.

src/IK/include/BipedalLocomotion/IK/DistanceTask.h

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class DistanceTask : public IKLinearTask
6464
double m_computedDistance{0.0}; /**< Computed distance. */
6565
double m_distanceNumericThreshold{0.001}; /**< Numeric threshold when inverting the computed
6666
distance in the Jacobian computation. */
67+
bool m_isSetPointSetAtLeastOnce{false}; /**< True if the set point has been set at least once. */
6768

6869
public:
6970
// clang-format off

src/IK/include/BipedalLocomotion/IK/GravityTask.h

+22-19
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class GravityTask : public IKLinearTask
125125
Eigen::MatrixXd m_bm; /**< Matrix filtering acceleration. */
126126

127127
iDynTree::FrameIndex m_targetFrameIndex; /**< Index of the target frame. */
128+
bool m_isSetPointSetAtLeastOnce{false}; /**< True if the set-point has been set at least once */
128129

129130
public:
130131
// clang-format off
@@ -169,25 +170,6 @@ class GravityTask : public IKLinearTask
169170
*/
170171
bool update() override;
171172

172-
/**
173-
* @brief Set the desired gravity direction expressed the target frame.
174-
* @param desiredGravityDirection The desired gravity direction.
175-
* @return True in case of success, false otherwise.
176-
*
177-
* The input is normalized, unless the norm is too small.
178-
*/
179-
bool setDesiredGravityDirectionInTargetFrame(
180-
const Eigen::Ref<const Eigen::Vector3d> desiredGravityDirection);
181-
182-
/**
183-
* @brief Set the feedforward angular velocity expressed in the target frame.
184-
* @param feedforwardVelocity The desired feedforward velocity in rad/s.
185-
* @return True in case of success, false otherwise.
186-
* Only the first two components are used.
187-
*/
188-
bool
189-
setFeedForwardVelocityInTargetFrame(const Eigen::Ref<const Eigen::Vector3d> feedforwardVelocity);
190-
191173
/**
192174
* @brief Set the desired gravity direction expressed the target frame and the feedforward
193175
* velocity.
@@ -205,6 +187,27 @@ class GravityTask : public IKLinearTask
205187
const Eigen::Ref<const Eigen::Vector3d> feedforwardVelocity
206188
= Eigen::Vector3d::Zero());
207189

190+
/**
191+
* @brief Set the desired gravity direction expressed the target frame.
192+
* @param desiredGravityDirection The desired gravity direction.
193+
* @return True in case of success, false otherwise.
194+
*
195+
* The input is normalized, unless the norm is too small.
196+
*/
197+
[[deprecated("Use setSetPoint instead")]]
198+
bool setDesiredGravityDirectionInTargetFrame(
199+
const Eigen::Ref<const Eigen::Vector3d> desiredGravityDirection);
200+
201+
/**
202+
* @brief Set the feedforward angular velocity expressed in the target frame.
203+
* @param feedforwardVelocity The desired feedforward velocity in rad/s.
204+
* @return True in case of success, false otherwise.
205+
* Only the first two components are used.
206+
*/
207+
[[deprecated("Use setSetPoint instead")]]
208+
bool setFeedForwardVelocityInTargetFrame( //
209+
const Eigen::Ref<const Eigen::Vector3d> feedforwardVelocity);
210+
208211
/**
209212
* Get the size of the task. (I.e the number of rows of the vector b)
210213
* @return the size of the task.

src/IK/include/BipedalLocomotion/IK/JointTrackingTask.h

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class JointTrackingTask : public IKLinearTask
4848
std::shared_ptr<iDynTree::KinDynComputations> m_kinDyn; /**< Pointer to a KinDynComputations
4949
object */
5050

51+
bool m_isSetPointSetAtLeastOnce{false}; /**< True if the set point has been set at least once. */
5152
public:
5253
/**
5354
* Initialize the task.

src/IK/include/BipedalLocomotion/IK/R3Task.h

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class R3Task : public IKLinearTask, public BipedalLocomotion::System::ITaskContr
7474
/** State of the proportional controller implemented in the task */
7575
Mode m_controllerMode{Mode::Enable};
7676

77+
bool m_isSetPointSetAtLeastOnce{false}; /**< True if the set point has been set at least once */
7778
public:
7879
/**
7980
* Initialize the task.

src/IK/include/BipedalLocomotion/IK/SE3Task.h

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class SE3Task : public IKLinearTask, public BipedalLocomotion::System::ITaskCont
8888
/** State of the proportional controller implemented in the task */
8989
Mode m_controllerMode{Mode::Enable};
9090

91+
bool m_isSetPointSetAtLeastOnce{false}; /**< True if the set-point has been set at least once */
9192
public:
9293
/**
9394
* Initialize the task.

src/IK/include/BipedalLocomotion/IK/SO3Task.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ class SO3Task : public IKLinearTask
5959
std::shared_ptr<iDynTree::KinDynComputations> m_kinDyn; /**< Pointer to a KinDynComputations
6060
object */
6161

62-
Eigen::MatrixXd m_jacobian;
62+
Eigen::MatrixXd m_jacobian; /**< Internal buffer to store the jacobian. */
6363

64+
bool m_isSetPointSetAtLeastOnce{false}; /**< True if the set point has been set at least once. */
6465
public:
6566

6667
/**

src/IK/src/AngularMomentumTask.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@ bool AngularMomentumTask::update()
140140

141141
m_isValid = false;
142142

143+
if (!m_isInitialized)
144+
{
145+
log()->error("[AngularMomentumTask::update] The task is not initialized. Please call "
146+
"initialize method.");
147+
return m_isValid;
148+
}
149+
150+
if (!m_isSetPointSetAtLeastOnce)
151+
{
152+
log()->error("[AngularMomentumTask::update] The set point has not been set at least once.");
153+
return m_isValid;
154+
}
155+
143156
if (!m_kinDyn->getCentroidalTotalMomentumJacobian(m_centroidalMomentumMatrix))
144157
{
145158
log()->error("[AngularMomentumTask::update] Unable to get the centroidal momentum matrix.");
@@ -190,6 +203,8 @@ bool AngularMomentumTask::setSetPoint(Eigen::Ref<const Eigen::Vector3d> desiredA
190203
}
191204
}
192205
}
206+
207+
m_isSetPointSetAtLeastOnce = true;
193208
return true;
194209
}
195210

src/IK/src/CoMTask.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,19 @@ bool CoMTask::update()
175175

176176
m_isValid = false;
177177

178+
if (!m_isInitialized)
179+
{
180+
log()->error("[CoMTask::update] The task is not initialized. Please call initialize "
181+
"method.");
182+
return m_isValid;
183+
}
184+
185+
if (!m_isSetPointSetAtLeastOnce)
186+
{
187+
log()->error("[CoMTask::update] The set point has not been set at least once.");
188+
return m_isValid;
189+
}
190+
178191
// set the state
179192
if (!m_useExogenousFeedback)
180193
{
@@ -228,6 +241,8 @@ bool CoMTask::setSetPoint(Eigen::Ref<const Eigen::Vector3d> position,
228241
ok = ok && m_R3Controller.setDesiredState(position);
229242
ok = ok && m_R3Controller.setFeedForward(velocity);
230243

244+
m_isSetPointSetAtLeastOnce = ok;
245+
231246
return ok;
232247
}
233248

src/IK/src/DistanceTask.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,19 @@ bool DistanceTask::update()
182182

183183
m_isValid = false;
184184

185+
if (!m_isInitialized)
186+
{
187+
log()->error("[DistanceTask::update] The task is not initialized. Please call initialize "
188+
"method.");
189+
return m_isValid;
190+
}
191+
192+
if (!m_isSetPointSetAtLeastOnce)
193+
{
194+
log()->error("[DistanceTask::update] The set point has not been set at least once.");
195+
return m_isValid;
196+
}
197+
185198
if (m_referenceName == "")
186199
{
187200
m_framePosition = toEigen(m_kinDyn->getWorldTransform(m_targetFrameIndex).getPosition());
@@ -222,6 +235,7 @@ bool DistanceTask::update()
222235
bool DistanceTask::setDesiredDistance(double desiredDistance)
223236
{
224237
m_desiredDistance = std::abs(desiredDistance);
238+
m_isSetPointSetAtLeastOnce = true;
225239
return true;
226240
}
227241

src/IK/src/GravityTask.cpp

+19-2
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,19 @@ bool GravityTask::update()
152152

153153
m_isValid = false;
154154

155+
if (!m_isInitialized)
156+
{
157+
log()->error("[GravityTask::update] The task is not initialized. Please call initialize "
158+
"method.");
159+
return m_isValid;
160+
}
161+
162+
if (!m_isSetPointSetAtLeastOnce)
163+
{
164+
log()->error("[GravityTask::update] The set point has not been set at least once.");
165+
return m_isValid;
166+
}
167+
155168
auto targetRotation = toEigen(m_kinDyn->getWorldTransform(m_targetFrameIndex).getRotation());
156169

157170
Eigen::Vector3d desiredZDirectionAbsolute = targetRotation * m_desiredZDirectionBody;
@@ -176,21 +189,25 @@ bool GravityTask::setDesiredGravityDirectionInTargetFrame(
176189
{
177190
m_desiredZDirectionBody = desiredGravityDirection;
178191
m_desiredZDirectionBody.normalize();
192+
m_isSetPointSetAtLeastOnce = true;
179193
return true;
180194
}
181195

182196
bool GravityTask::setFeedForwardVelocityInTargetFrame(
183197
const Eigen::Ref<const Eigen::Vector3d> feedforwardVelocity)
184198
{
185199
m_feedForwardBody = feedforwardVelocity;
200+
m_isSetPointSetAtLeastOnce = true;
186201
return true;
187202
}
188203

189204
bool GravityTask::setSetPoint(const Eigen::Ref<const Eigen::Vector3d> desiredGravityDirection,
190205
const Eigen::Ref<const Eigen::Vector3d> feedforwardVelocity)
191206
{
192-
return setDesiredGravityDirectionInTargetFrame(desiredGravityDirection)
193-
&& setFeedForwardVelocityInTargetFrame(feedforwardVelocity);
207+
m_isSetPointSetAtLeastOnce = setDesiredGravityDirectionInTargetFrame(desiredGravityDirection)
208+
&& setFeedForwardVelocityInTargetFrame(feedforwardVelocity);
209+
210+
return m_isSetPointSetAtLeastOnce;
194211
}
195212

196213
std::size_t GravityTask::size() const

src/IK/src/JointTrackingTask.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ bool JointTrackingTask::setVariablesHandler(const System::VariablesHandler& vari
3838
return false;
3939
}
4040

41-
4241
if (!variablesHandler.getVariable(m_robotVelocityVariableName, robotVelocityVariable))
4342
{
4443
log()->error("{} Error while retrieving the robot velocity variable.", errorPrefix);
@@ -55,7 +54,6 @@ bool JointTrackingTask::setVariablesHandler(const System::VariablesHandler& vari
5554
return false;
5655
}
5756

58-
5957
// resize the matrices
6058
m_A.resize(m_kinDyn->getNrOfDegreesOfFreedom(), variablesHandler.getNumberOfVariables());
6159
m_A.setZero();
@@ -71,7 +69,8 @@ bool JointTrackingTask::setVariablesHandler(const System::VariablesHandler& vari
7169
return true;
7270
}
7371

74-
bool JointTrackingTask::initialize(std::weak_ptr<const ParametersHandler::IParametersHandler> paramHandler)
72+
bool JointTrackingTask::initialize(
73+
std::weak_ptr<const ParametersHandler::IParametersHandler> paramHandler)
7574
{
7675
constexpr auto errorPrefix = "[JointTrackingTask::initialize] ";
7776

@@ -131,6 +130,18 @@ bool JointTrackingTask::update()
131130

132131
m_isValid = false;
133132

133+
if (!m_isInitialized)
134+
{
135+
log()->error("{} The task is not initialized. Please call initialize method.", errorPrefix);
136+
return m_isValid;
137+
}
138+
139+
if (!m_isSetPointSetAtLeastOnce)
140+
{
141+
log()->error("{} The set point has not been set at least once.", errorPrefix);
142+
return m_isValid;
143+
}
144+
134145
if (!m_kinDyn->getJointPos(m_jointPosition))
135146
{
136147
log()->error("{} Unable to get the joint position.", errorPrefix);
@@ -168,6 +179,8 @@ bool JointTrackingTask::setSetPoint(Eigen::Ref<const Eigen::VectorXd> jointPosit
168179
m_desiredJointPosition = jointPosition;
169180
m_desiredJointVelocity = jointVelocity;
170181

182+
m_isSetPointSetAtLeastOnce = true;
183+
171184
return true;
172185
}
173186

0 commit comments

Comments
 (0)