From e2a683aef0e6462203a0d983efafde45666e0116 Mon Sep 17 00:00:00 2001 From: Mohamed Zaghloul Date: Sun, 9 Mar 2025 13:52:48 +0200 Subject: [PATCH 1/3] Add velocity limits component and method to Joint class (#2664) Signed-off-by: Mohamed Zaghloul --- .vscode/settings.json | 5 ++ include/gz/sim/Joint.hh | 6 ++ .../gz/sim/components/JointVelocityLimits.hh | 55 +++++++++++++++++++ src/Joint.cc | 9 +++ src/systems/physics/Physics.cc | 1 + 5 files changed, 76 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 include/gz/sim/components/JointVelocityLimits.hh diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..f2678ea4c4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "optional": "cpp" + } +} \ No newline at end of file diff --git a/include/gz/sim/Joint.hh b/include/gz/sim/Joint.hh index 9f2c6e0565..47a0341180 100644 --- a/include/gz/sim/Joint.hh +++ b/include/gz/sim/Joint.hh @@ -260,6 +260,12 @@ namespace gz public: std::optional> Position( const EntityComponentManager &_ecm) const; + /// \brief Get the velocity limits of the joint. + /// \param[in] _ecm Entity-component manager. + /// \return Velocity limits (min, max) or nullopt if not available. + public: std::optional> VelocityLimits( + const EntityComponentManager &_ecm) const; + /// \brief Get the transmitted wrench of the joint /// \param[in] _ecm Entity-component manager. /// \return Transmitted wrench of the joint or nullopt if transmitted diff --git a/include/gz/sim/components/JointVelocityLimits.hh b/include/gz/sim/components/JointVelocityLimits.hh new file mode 100644 index 0000000000..8dd9d98970 --- /dev/null +++ b/include/gz/sim/components/JointVelocityLimits.hh @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2021 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef GZ_SIM_COMPONENTS_JOINTVELOCITYLIMITS_HH_ +#define GZ_SIM_COMPONENTS_JOINTVELOCITYLIMITS_HH_ + +#include +#include + +#include +#include +#include +#include +#include + +namespace gz +{ +namespace sim +{ +// Inline bracket to help doxygen filtering. +inline namespace GZ_SIM_VERSION_NAMESPACE { + +namespace components +{ +/// \brief Component for recording the current velocity limits of a joint. +/// Data are a vector with a Vector2 for each DOF. The X() component of the +/// Vector2 specifies the minimum velocity limit, the Y() component stands +/// for maximum limit. +using JointVelocityLimits = Component< + std::vector, + class JointVelocityLimitsTag, + serializers::VectorSerializer +>; + +GZ_SIM_REGISTER_COMPONENT( + "gz_sim_components.JointVelocityLimits", JointVelocityLimits) +} +} +} +} + +#endif \ No newline at end of file diff --git a/src/Joint.cc b/src/Joint.cc index 8147897e4e..078bbb8408 100644 --- a/src/Joint.cc +++ b/src/Joint.cc @@ -28,6 +28,7 @@ #include "gz/sim/components/JointVelocity.hh" #include "gz/sim/components/JointVelocityCmd.hh" #include "gz/sim/components/JointVelocityLimitsCmd.hh" +#include "gz/sim/components/JointVelocityLimits.hh" #include "gz/sim/components/JointVelocityReset.hh" #include "gz/sim/components/Name.hh" #include "gz/sim/components/ParentEntity.hh" @@ -354,6 +355,14 @@ std::optional> Joint::Position( this->dataPtr->id); } +////////////////////////////////////////////////// +std::optional> Joint::VelocityLimits( + const EntityComponentManager &_ecm) const +{ + return _ecm.ComponentData( + this->dataPtr->id); +} + ////////////////////////////////////////////////// std::optional> Joint::TransmittedWrench( const EntityComponentManager &_ecm) const diff --git a/src/systems/physics/Physics.cc b/src/systems/physics/Physics.cc index 1207db6320..c788255e38 100644 --- a/src/systems/physics/Physics.cc +++ b/src/systems/physics/Physics.cc @@ -122,6 +122,7 @@ #include "gz/sim/components/JointVelocity.hh" #include "gz/sim/components/JointVelocityCmd.hh" #include "gz/sim/components/JointVelocityLimitsCmd.hh" +#include "gz/sim/components/JointVelocityLimits.hh" #include "gz/sim/components/JointVelocityReset.hh" #include "gz/sim/components/LinearAcceleration.hh" #include "gz/sim/components/LinearVelocity.hh" From c8a195334f2aff558df74b65bbb5512a9235c7f5 Mon Sep 17 00:00:00 2001 From: Mohamed Zaghloul Date: Mon, 10 Mar 2025 16:15:14 +0200 Subject: [PATCH 2/3] Update copyright year in JointVelocityLimits component Signed-off-by: Mohamed Zaghloul --- include/gz/sim/components/JointVelocityLimits.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/gz/sim/components/JointVelocityLimits.hh b/include/gz/sim/components/JointVelocityLimits.hh index 8dd9d98970..b53c7619ba 100644 --- a/include/gz/sim/components/JointVelocityLimits.hh +++ b/include/gz/sim/components/JointVelocityLimits.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Open Source Robotics Foundation + * Copyright (C) 2025 Open Source Robotics Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 03a0d8a00633c2579833aa177ff42ce85af62b79 Mon Sep 17 00:00:00 2001 From: Mohamed Zaghloul Date: Mon, 10 Mar 2025 17:03:47 +0200 Subject: [PATCH 3/3] Remove vscode config files Signed-off-by: Mohamed Zaghloul --- .vscode/settings.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index f2678ea4c4..0000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "files.associations": { - "optional": "cpp" - } -} \ No newline at end of file