Skip to content
6 changes: 6 additions & 0 deletions include/gz/sim/Joint.hh
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ namespace gz
public: std::optional<std::vector<double>> 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<std::vector<gz::math::Vector2d>> 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
Expand Down
55 changes: 55 additions & 0 deletions include/gz/sim/components/JointVelocityLimits.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.
* 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 <vector>
#include <gz/math/Vector2.hh>

#include <gz/sim/components/Component.hh>
#include <gz/sim/components/Factory.hh>
#include <gz/sim/components/Serialization.hh>
#include <gz/sim/config.hh>
#include <gz/sim/Export.hh>

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<gz::math::Vector2d>,
class JointVelocityLimitsTag,
serializers::VectorSerializer<gz::math::Vector2d>
>;

GZ_SIM_REGISTER_COMPONENT(
"gz_sim_components.JointVelocityLimits", JointVelocityLimits)
}
}
}
}

#endif
14 changes: 14 additions & 0 deletions src/Joint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -354,6 +355,19 @@ std::optional<std::vector<double>> Joint::Position(
this->dataPtr->id);
}

//////////////////////////////////////////////////
std::optional<gz::math::Vector2d> Joint::VelocityLimits(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a compile error here. The declaration in the header is std::optional<std::vector<gz::math::Vector2d> but it is std::optional<gz::math::Vector2d> here.

I think it should be std::optional<std::vector<gz::math::Vector2d> so that it is consistent with the JointVelocityLimitsCmd component.

On the other hand, the function returns jointAxis->Data().MaxVelocity() which is just a double. So we'll need to change it to return a vector of gz::math::Vector2d, something like (untested):

return {gz::math::Vector2d(-jointAxis->Data().MaxVelocity(), 
        jointAxis->Data().MaxVelocity())};

const EntityComponentManager &_ecm) const
{
auto jointAxis = _ecm.Component<components::JointAxis>(this->dataPtr->id);
if (jointAxis)
{
return jointAxis->Data().MaxVelocity();
}

return std::nullopt;
}

//////////////////////////////////////////////////
std::optional<std::vector<msgs::Wrench>> Joint::TransmittedWrench(
const EntityComponentManager &_ecm) const
Expand Down
1 change: 1 addition & 0 deletions src/systems/physics/Physics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down