Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added components to dynamically set joint limits #847

Merged
merged 8 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ ign_find_package (Qt5

#--------------------------------------
# Find ignition-physics
ign_find_package(ignition-physics2 VERSION 2.3
ign_find_package(ignition-physics2 VERSION 2.5
COMPONENTS
mesh
sdf
Expand Down
60 changes: 60 additions & 0 deletions include/ignition/gazebo/components/JointEffortLimitsCmd.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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 IGNITION_GAZEBO_COMPONENTS_JOINTEFFORTLIMITSCMD_HH_
#define IGNITION_GAZEBO_COMPONENTS_JOINTEFFORTLIMITSCMD_HH_

#include <vector>
#include <ignition/math/Vector2.hh>

#include <ignition/gazebo/components/Component.hh>
#include <ignition/gazebo/components/Factory.hh>
#include <ignition/gazebo/components/Serialization.hh>
#include <ignition/gazebo/config.hh>
#include <ignition/gazebo/Export.hh>

namespace ignition
{
namespace gazebo
{
// Inline bracket to help doxygen filtering.
inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {

namespace components
{

/// \brief Command for setting effort limits of a joint. Data are a vector
/// with a Vector2 for each DOF. The X() component of the Vector2 specifies
/// the minimum effort limit, the Y() component stands for maximum limit.
/// Set to +-infinity to disable the limits.
/// \note It is expected that the physics plugin reads this component and
/// sets the limit to the dynamics engine. After setting it, the data of this
/// component will be cleared (i.e. the vector will have length zero).
using JointEffortLimitsCmd = Component<
std::vector<ignition::math::Vector2d>,
class JointEffortLimitsCmdTag,
serializers::VectorSerializer<ignition::math::Vector2d>
>;

IGN_GAZEBO_REGISTER_COMPONENT(
"ign_gazebo_components.JointEffortLimitsCmd", JointEffortLimitsCmd)
}

}
}
}

#endif
58 changes: 58 additions & 0 deletions include/ignition/gazebo/components/JointPositionLimitsCmd.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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 IGNITION_GAZEBO_COMPONENTS_JOINTPOSITIONLIMITSCMD_HH_
#define IGNITION_GAZEBO_COMPONENTS_JOINTPOSITIONLIMITSCMD_HH_

#include <vector>
#include <ignition/math/Vector2.hh>

#include <ignition/gazebo/components/Component.hh>
#include <ignition/gazebo/components/Factory.hh>
#include <ignition/gazebo/components/Serialization.hh>
#include <ignition/gazebo/config.hh>
#include <ignition/gazebo/Export.hh>

namespace ignition
{
namespace gazebo
{
// Inline bracket to help doxygen filtering.
inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {

namespace components
{
/// \brief Command for setting position limits of a joint. Data are a vector
/// with a Vector2 for each DOF. The X() component of the Vector2 specifies
/// the minimum positional limit, the Y() component stands for maximum limit.
/// Set to +-infinity to disable the limits.
/// \note It is expected that the physics plugin reads this component and
/// sets the limit to the dynamics engine. After setting it, the data of this
/// component will be cleared (i.e. the vector will have length zero).
using JointPositionLimitsCmd = Component<
std::vector<ignition::math::Vector2d>,
class JointPositionLimitsCmdTag,
serializers::VectorSerializer<ignition::math::Vector2d>
>;

IGN_GAZEBO_REGISTER_COMPONENT(
"ign_gazebo_components.JointPositionLimitsCmd", JointPositionLimitsCmd)
}
}
}
}

#endif
58 changes: 58 additions & 0 deletions include/ignition/gazebo/components/JointVelocityLimitsCmd.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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 IGNITION_GAZEBO_COMPONENTS_JOINTVELOCITYLIMITSCMD_HH_
#define IGNITION_GAZEBO_COMPONENTS_JOINTVELOCITYLIMITSCMD_HH_

#include <vector>
#include <ignition/math/Vector2.hh>

#include <ignition/gazebo/components/Component.hh>
#include <ignition/gazebo/components/Factory.hh>
#include <ignition/gazebo/components/Serialization.hh>
#include <ignition/gazebo/config.hh>
#include <ignition/gazebo/Export.hh>

namespace ignition
{
namespace gazebo
{
// Inline bracket to help doxygen filtering.
inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {

namespace components
{
/// \brief Command for setting 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.
/// Set to +-infinity to disable the limits.
/// \note It is expected that the physics plugin reads this component and
/// sets the limit to the dynamics engine. After setting it, the data of this
/// component will be cleared (i.e. the vector will have length zero).
using JointVelocityLimitsCmd = Component<
std::vector<ignition::math::Vector2d>,
class JointVelocityLimitsCmdTag,
serializers::VectorSerializer<ignition::math::Vector2d>
>;

IGN_GAZEBO_REGISTER_COMPONENT(
"ign_gazebo_components.JointVelocityLimitsCmd", JointVelocityLimitsCmd)
}
}
}
}

#endif
34 changes: 34 additions & 0 deletions include/ignition/gazebo/components/Serialization.hh
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,40 @@ namespace serializers
return _in;
}
};

template <typename T>
class VectorSerializer
{
/// \brief Serialization for `std::vector<T>` with serializable T.
/// \param[in] _out Output stream.
/// \param[in] _data The data to stream.
/// \return The stream.
public: static std::ostream &Serialize(std::ostream &_out,
const std::vector<T> &_data)
{
_out << _data.size();
peci1 marked this conversation as resolved.
Show resolved Hide resolved
for (const auto& datum : _data)
_out << " " << datum;
return _out;
}

/// \brief Deserialization for `std::vector<T>` with serializable T.
/// \param[in] _in Input stream.
/// \param[out] _data The data to populate.
/// \return The stream.
public: static std::istream &Deserialize(std::istream &_in,
std::vector<T> &_data)
{
size_t size;
_in >> size;
_data.resize(size);
for (size_t i = 0; i < size; ++i)
{
_in >> _data[i];
}
return _in;
}
};
}
}
}
Expand Down
Loading