From be037d5cb5c6e72ad23b943840443b6ff50e69a5 Mon Sep 17 00:00:00 2001 From: Florent Lamiraux Date: Fri, 22 May 2026 13:50:42 +0000 Subject: [PATCH 1/2] Add utility function formerly provided by hpp-corbaserver. --- src/CMakeLists.txt | 1 + src/pyhpp/pinocchio/utils.py | 57 ++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/pyhpp/pinocchio/utils.py diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 816a444..7664b04 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -84,6 +84,7 @@ endmacro() python_install_on_site(pyhpp __init__.py) +python_install_on_site(pyhpp/pinocchio utils.py) python_install_on_site(pyhpp/manipulation constraint_graph_factory.py) python_install_on_site(pyhpp/core static_stability_constraint_factory.py) python_install_on_site(pyhpp/manipulation security_margins.py) diff --git a/src/pyhpp/pinocchio/utils.py b/src/pyhpp/pinocchio/utils.py new file mode 100644 index 0000000..0c96618 --- /dev/null +++ b/src/pyhpp/pinocchio/utils.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# +# Copyright (c) 2025 CNRS +# Author: Florent Lamiraux +# + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH +# DAMAGE. + +def shrinkJointRange(robot, joints, ratio): + """ + Reduce the range of selected joints for security + + Input + - robot: an instance of Robot class, + - joints the list of joint names, + - ratio: the range of the joint is shrunk around the middle of its + bounds by this ratio. + """ + model = robot.model() + for j in joints: + rank = model.getJointId(j) + iq = model.joints[rank].idx_q + assert model.joints[rank].nq == 1 + bounds = [model.lowerPositionLimit[iq], model.upperPositionLimit[iq]] + width = bounds[1] - bounds[0] + if width < 0: + raise ValueError( + "Cannot shrink range of joint " + j + ". The joint is not bounded." + ) + mean = 0.5 * (bounds[1] + bounds[0]) + m = mean - 0.5 * ratio * width + M = mean + 0.5 * ratio * width + model.lowerPositionLimit[iq] = m + model.upperPositionLimit[iq] = M + From 2a619f3f19356e8e3f595a67b78ce8133ddb7fdf Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 22 May 2026 13:52:18 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pyhpp/pinocchio/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pyhpp/pinocchio/utils.py b/src/pyhpp/pinocchio/utils.py index 0c96618..e90b7eb 100644 --- a/src/pyhpp/pinocchio/utils.py +++ b/src/pyhpp/pinocchio/utils.py @@ -28,6 +28,7 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. + def shrinkJointRange(robot, joints, ratio): """ Reduce the range of selected joints for security @@ -54,4 +55,3 @@ def shrinkJointRange(robot, joints, ratio): M = mean + 0.5 * ratio * width model.lowerPositionLimit[iq] = m model.upperPositionLimit[iq] = M -