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

[Citadel] [TPE] Add velocity cmd #169

Merged
merged 45 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
9cee825
add velocity cmd component
claireyywang May 28, 2020
4102788
add doc for model pose update section
claireyywang May 28, 2020
e8bafc3
add velocity update in physics.cc
claireyywang May 28, 2020
c3d988a
Revert "add velocity update in physics.cc"
claireyywang May 28, 2020
e924c79
add velocity update
claireyywang May 28, 2020
faa0af4
refactor, add angularvelocitycmd
claireyywang May 28, 2020
e587340
refactor, add linearvelocitycmd
claireyywang May 28, 2020
73fc112
update physics.cc with new cmd components
claireyywang May 28, 2020
bf2620e
fix typo
claireyywang May 29, 2020
cb10101
move velocity cmd to optional featurelist, add entitycast
claireyywang Jun 1, 2020
a67f260
fix codecheck errors
claireyywang Jun 1, 2020
dde435d
add velocity_demo.sdf
claireyywang Jun 2, 2020
0f9d13e
add velocity_demo to system/plugins
claireyywang Jun 3, 2020
a4e45ca
remove joints from velocity demo
claireyywang Jun 5, 2020
1265e99
remove odometry from velocitydemo
claireyywang Jun 9, 2020
73218a3
fix codecheck
claireyywang Jun 9, 2020
6bb71c8
remove odometry from sdf
claireyywang Jun 9, 2020
a7eb895
correct typo
claireyywang Jun 9, 2020
76c732e
correct typo
claireyywang Jun 9, 2020
a618b3b
add velocity_demo to shared library
claireyywang Jun 9, 2020
f7a2d37
add working velocity demo
claireyywang Jun 11, 2020
802e7fd
comment out unused param
claireyywang Jun 11, 2020
17ddb85
fix codecheck
claireyywang Jun 11, 2020
832f5db
Merge branch 'ign-gazebo3' into claire/add_velocity_cmd
claireyywang Jun 11, 2020
c8e4127
address review comments
claireyywang Jun 12, 2020
b482eb6
Merge branch 'claire/add_velocity_cmd' of github.com:ignitionrobotics…
claireyywang Jun 12, 2020
c059599
alphabetize includes
claireyywang Jun 12, 2020
f921bd2
fix cppcheck
claireyywang Jun 12, 2020
b47e2a5
set velocity in local frame
claireyywang Jun 23, 2020
b371612
add orientation to angular velocity
claireyywang Jun 25, 2020
96e15a2
add velocity control to test worlds
claireyywang Jun 25, 2020
d7b9360
add angular velocity cmd integration test
claireyywang Jun 25, 2020
5885b0f
Revert "add angular velocity cmd integration test"
claireyywang Jun 25, 2020
1eecc59
create velocity_control integration test
claireyywang Jun 25, 2020
dbc5e1a
modift test to check model position
claireyywang Jun 25, 2020
1b551a4
remove unused variables and add test to cmakelist
claireyywang Jun 25, 2020
d6d449f
update velocitycontrol
claireyywang Jun 25, 2020
df8c2c8
remove .vscode
claireyywang Jun 25, 2020
67a8900
pass test
claireyywang Jun 26, 2020
0237c9e
remove vscode
claireyywang Jun 26, 2020
310734c
pass codecheck
claireyywang Jun 26, 2020
814017c
remove speedlimiter
claireyywang Jun 26, 2020
1b88b37
add pose check in test
iche033 Jun 30, 2020
d1f71cd
Merge branch 'ign-gazebo3' into claire/add_velocity_cmd
claireyywang Jun 30, 2020
f9064e9
remove unused command
claireyywang Jun 30, 2020
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
492 changes: 492 additions & 0 deletions examples/worlds/velocity_control.sdf

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions include/ignition/gazebo/components/AngularVelocityCmd.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2020 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_ANGULARVELOCITYCMD_HH_
#define IGNITION_GAZEBO_COMPONENTS_ANGULARVELOCITYCMD_HH_

#include <ignition/math/Vector3.hh>

#include <ignition/gazebo/config.hh>

#include <ignition/gazebo/components/Factory.hh>
#include "ignition/gazebo/components/Component.hh"

namespace ignition
{
namespace gazebo
{
// Inline bracket to help doxygen filtering.
inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
namespace components
{
/// \brief A component type that contains angular velocity cmd of an entity
/// represented by ignition::math::Vector3d.
using AngularVelocityCmd =
Component<math::Vector3d, class AngularVelocityCmdTag>;
IGN_GAZEBO_REGISTER_COMPONENT(
"ign_gazebo_components.AngularVelocityCmd", AngularVelocityCmd)

/// \brief A component type that contains angular velocity cmd
/// of an entity in the world frame represented by ignition::math::Vector3d.
using WorldAngularVelocityCmd =
Component<math::Vector3d, class WorldAngularVelocityCmdTag>;
IGN_GAZEBO_REGISTER_COMPONENT(
"ign_gazebo_components.WorldAngularVelocityCmd", WorldAngularVelocityCmd)
}
}
}
}

#endif
53 changes: 53 additions & 0 deletions include/ignition/gazebo/components/LinearVelocityCmd.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2020 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_LINEARVELOCITYCMD_HH_
#define IGNITION_GAZEBO_COMPONENTS_LINEARVELOCITYCMD_HH_

#include <ignition/math/Vector3.hh>

#include <ignition/gazebo/config.hh>

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

namespace ignition
{
namespace gazebo
{
// Inline bracket to help doxygen filtering.
inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
namespace components
{
/// \brief A component type that contains linear velocity of an entity
/// represented by ignition::math::Vector3d.
using LinearVelocityCmd = Component<
math::Vector3d, class LinearVelocityCmdTag>;
IGN_GAZEBO_REGISTER_COMPONENT(
"ign_gazebo_components.LinearVelocityCmd", LinearVelocityCmd)

/// \brief A component type that contains linear velocity of an entity in the
/// world frame represented by ignition::math::Vector3d.
using WorldLinearVelocityCmd =
Component<math::Vector3d, class WorldLinearVelocityCmdTag>;
IGN_GAZEBO_REGISTER_COMPONENT(
"ign_gazebo_components.WorldLinearVelocityCmd", WorldLinearVelocityCmd)
}
}
}
}

#endif
1 change: 1 addition & 0 deletions src/systems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@ add_subdirectory(thermal)
add_subdirectory(touch_plugin)
add_subdirectory(triggered_publisher)
add_subdirectory(user_commands)
add_subdirectory(velocity_control)
add_subdirectory(wind_effects)
85 changes: 85 additions & 0 deletions src/systems/physics/Physics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <ignition/common/SystemPaths.hh>
#include <ignition/math/AxisAlignedBox.hh>
#include <ignition/math/eigen3/Conversions.hh>
#include <ignition/math/Vector3.hh>
#include <ignition/physics/config.hh>
#include <ignition/physics/FeatureList.hh>
#include <ignition/physics/FeaturePolicy.hh>
Expand Down Expand Up @@ -75,6 +76,7 @@
// Components
#include "ignition/gazebo/components/AngularAcceleration.hh"
#include "ignition/gazebo/components/AngularVelocity.hh"
#include "ignition/gazebo/components/AngularVelocityCmd.hh"
#include "ignition/gazebo/components/AxisAlignedBox.hh"
#include "ignition/gazebo/components/BatterySoC.hh"
#include "ignition/gazebo/components/CanonicalLink.hh"
Expand All @@ -95,6 +97,7 @@
#include "ignition/gazebo/components/JointVelocityReset.hh"
#include "ignition/gazebo/components/LinearAcceleration.hh"
#include "ignition/gazebo/components/LinearVelocity.hh"
#include "ignition/gazebo/components/LinearVelocityCmd.hh"
#include "ignition/gazebo/components/Link.hh"
#include "ignition/gazebo/components/Model.hh"
#include "ignition/gazebo/components/Name.hh"
Expand Down Expand Up @@ -421,6 +424,25 @@ class ignition::gazebo::systems::PhysicsPrivate
public: std::unordered_map<Entity, JointVelocityCommandPtrType>
entityJointVelocityCommandMap;

//////////////////////////////////////////////////
// World velocity command
public: using WorldVelocityCommandFeatureList =
ignition::physics::FeatureList<
ignition::physics::SetFreeGroupWorldVelocity>;

/// \brief Free group type with world velocity command.
public: using FreeGroupVelocityCmdPtrType =
ignition::physics::FreeGroupPtr<
ignition::physics::FeaturePolicy3d,
WorldVelocityCommandFeatureList>;

/// \brief A map between free group entity ids in the ECM
/// to FreeGroup Entities in ign-physics, with velocity command feature.
/// All FreeGroup on this map are casted for
/// `WorldVelocityCommandFeatureList`.
public: std::unordered_map<Entity, FreeGroupVelocityCmdPtrType>
entityWorldVelocityCommandMap;

//////////////////////////////////////////////////
// Meshes

Expand Down Expand Up @@ -1316,6 +1338,7 @@ void PhysicsPrivate::UpdatePhysics(EntityComponentManager &_ecm)
return true;
});

// Update model pose
_ecm.Each<components::Model, components::WorldPoseCmd>(
[&](const Entity &_entity, const components::Model *,
const components::WorldPoseCmd *_poseCmd)
Expand Down Expand Up @@ -1364,6 +1387,68 @@ void PhysicsPrivate::UpdatePhysics(EntityComponentManager &_ecm)
return true;
});

// Update model angular velocity
_ecm.Each<components::Model, components::AngularVelocityCmd>(
[&](const Entity &_entity, const components::Model *,
const components::AngularVelocityCmd *_angularVelocityCmd)
{
auto modelIt = this->entityModelMap.find(_entity);
if (modelIt == this->entityModelMap.end())
return true;

auto freeGroup = modelIt->second->FindFreeGroup();
if (!freeGroup)
return true;

const components::Pose *poseComp =
_ecm.Component<components::Pose>(_entity);
math::Vector3d worldAngularVel = poseComp->Data().Rot() *
_angularVelocityCmd->Data();

auto worldAngularVelFeature = entityCast(_entity, freeGroup,
this->entityWorldVelocityCommandMap);
if (!worldAngularVelFeature)
{
return true;
}

worldAngularVelFeature->SetWorldAngularVelocity(
math::eigen3::convert(worldAngularVel));

return true;
});

// Update model linear velocity
_ecm.Each<components::Model, components::LinearVelocityCmd>(
[&](const Entity &_entity, const components::Model *,
const components::LinearVelocityCmd *_linearVelocityCmd)
{
auto modelIt = this->entityModelMap.find(_entity);
if (modelIt == this->entityModelMap.end())
return true;

auto freeGroup = modelIt->second->FindFreeGroup();
if (!freeGroup)
return true;

const components::Pose *poseComp =
_ecm.Component<components::Pose>(_entity);
math::Vector3d worldLinearVel = poseComp->Data().Rot() *
_linearVelocityCmd->Data();

auto worldLinearVelFeature = entityCast(_entity, freeGroup,
this->entityWorldVelocityCommandMap);
if (!worldLinearVelFeature)
{
return true;
}

worldLinearVelFeature->SetWorldLinearVelocity(
math::eigen3::convert(worldLinearVel));

return true;
});

// Clear pending commands
// Note: Removing components from inside an Each call can be dangerous.
// Instead, we collect all the entities that have the desired components and
Expand Down
6 changes: 6 additions & 0 deletions src/systems/velocity_control/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
gz_add_system(velocity-control
SOURCES
VelocityControl.cc
PUBLIC_LINK_LIBS
ignition-common${IGN_COMMON_VER}::ignition-common${IGN_COMMON_VER}
)
Loading