Skip to content

Commit 43c771f

Browse files
committed
Add velocity limits component and method to Joint class (#2664)
Signed-off-by: Mohamed Zaghloul <[email protected]>
1 parent f8dac72 commit 43c771f

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.associations": {
3+
"optional": "cpp"
4+
}
5+
}

include/gz/sim/Joint.hh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ namespace gz
260260
public: std::optional<std::vector<double>> Position(
261261
const EntityComponentManager &_ecm) const;
262262

263+
/// \brief Get the velocity limits of the joint.
264+
/// \param[in] _ecm Entity-component manager.
265+
/// \return Velocity limits (min, max) or nullopt if not available.
266+
public: std::optional<std::vector<gz::math::Vector2d>> VelocityLimits(
267+
const EntityComponentManager &_ecm) const;
268+
263269
/// \brief Get the transmitted wrench of the joint
264270
/// \param[in] _ecm Entity-component manager.
265271
/// \return Transmitted wrench of the joint or nullopt if transmitted
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (C) 2021 Open Source Robotics Foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
#ifndef GZ_SIM_COMPONENTS_JOINTVELOCITYLIMITS_HH_
18+
#define GZ_SIM_COMPONENTS_JOINTVELOCITYLIMITS_HH_
19+
20+
#include <vector>
21+
#include <gz/math/Vector2.hh>
22+
23+
#include <gz/sim/components/Component.hh>
24+
#include <gz/sim/components/Factory.hh>
25+
#include <gz/sim/components/Serialization.hh>
26+
#include <gz/sim/config.hh>
27+
#include <gz/sim/Export.hh>
28+
29+
namespace gz
30+
{
31+
namespace sim
32+
{
33+
// Inline bracket to help doxygen filtering.
34+
inline namespace GZ_SIM_VERSION_NAMESPACE {
35+
36+
namespace components
37+
{
38+
/// \brief Component for recording the current velocity limits of a joint.
39+
/// Data are a vector with a Vector2 for each DOF. The X() component of the
40+
/// Vector2 specifies the minimum velocity limit, the Y() component stands
41+
/// for maximum limit.
42+
using JointVelocityLimits = Component<
43+
std::vector<gz::math::Vector2d>,
44+
class JointVelocityLimitsTag,
45+
serializers::VectorSerializer<gz::math::Vector2d>
46+
>;
47+
48+
GZ_SIM_REGISTER_COMPONENT(
49+
"gz_sim_components.JointVelocityLimits", JointVelocityLimits)
50+
}
51+
}
52+
}
53+
}
54+
55+
#endif

src/Joint.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "gz/sim/components/JointVelocity.hh"
2929
#include "gz/sim/components/JointVelocityCmd.hh"
3030
#include "gz/sim/components/JointVelocityLimitsCmd.hh"
31+
#include "gz/sim/components/JointVelocityLimits.hh"
3132
#include "gz/sim/components/JointVelocityReset.hh"
3233
#include "gz/sim/components/Name.hh"
3334
#include "gz/sim/components/ParentEntity.hh"
@@ -354,6 +355,14 @@ std::optional<std::vector<double>> Joint::Position(
354355
this->dataPtr->id);
355356
}
356357

358+
//////////////////////////////////////////////////
359+
std::optional<std::vector<gz::math::Vector2d>> Joint::VelocityLimits(
360+
const EntityComponentManager &_ecm) const
361+
{
362+
return _ecm.ComponentData<components::JointVelocityLimits>(
363+
this->dataPtr->id);
364+
}
365+
357366
//////////////////////////////////////////////////
358367
std::optional<std::vector<msgs::Wrench>> Joint::TransmittedWrench(
359368
const EntityComponentManager &_ecm) const

src/systems/physics/Physics.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
#include "gz/sim/components/JointVelocity.hh"
123123
#include "gz/sim/components/JointVelocityCmd.hh"
124124
#include "gz/sim/components/JointVelocityLimitsCmd.hh"
125+
#include "gz/sim/components/JointVelocityLimits.hh"
125126
#include "gz/sim/components/JointVelocityReset.hh"
126127
#include "gz/sim/components/LinearAcceleration.hh"
127128
#include "gz/sim/components/LinearVelocity.hh"

0 commit comments

Comments
 (0)