-
Notifications
You must be signed in to change notification settings - Fork 41
/
SimulationFeatures.hh
151 lines (119 loc) · 4.33 KB
/
SimulationFeatures.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* Copyright (C) 2018 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_PHYSICS_DARTSIM_SRC_SIMULATIONFEATURES_HH_
#define GZ_PHYSICS_DARTSIM_SRC_SIMULATIONFEATURES_HH_
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include <dart/config.hpp>
#ifdef DART_HAS_CONTACT_SURFACE
#include <dart/constraint/ContactSurface.hpp>
#endif
#include <gz/math/Pose3.hh>
#include <gz/physics/CanWriteData.hh>
#include <gz/physics/ForwardStep.hh>
#include <gz/physics/GetContacts.hh>
#include <gz/physics/GetRayIntersection.hh>
#include <gz/physics/ContactProperties.hh>
#include <gz/physics/SpecifyData.hh>
#include "Base.hh"
namespace dart
{
namespace collision
{
class Contact;
}
}
namespace gz {
namespace physics {
namespace dartsim {
struct SimulationFeatureList : FeatureList<
ForwardStep,
#ifdef DART_HAS_CONTACT_SURFACE
SetContactPropertiesCallbackFeature,
#endif
GetContactsFromLastStepFeature,
GetRayIntersectionFromLastStepFeature
> { };
#ifdef DART_HAS_CONTACT_SURFACE
class GzContactSurfaceHandler : public dart::constraint::ContactSurfaceHandler
{
public: dart::constraint::ContactSurfaceParams createParams(
const dart::collision::Contact& _contact,
size_t _numContactsOnCollisionObject) const override;
public: dart::constraint::ContactConstraintPtr createConstraint(
dart::collision::Contact& _contact,
size_t _numContactsOnCollisionObject,
double _timeStep) const override;
public: typedef SetContactPropertiesCallbackFeature Feature;
public: typedef Feature::Implementation<FeaturePolicy3d> Impl;
public: Impl::SurfaceParamsCallback surfaceParamsCallback;
public: std::function<
std::optional<Impl::ContactImpl>(const dart::collision::Contact&)
> convertContact;
public: mutable typename Feature::ContactSurfaceParams<FeaturePolicy3d>
lastGzParams;
};
using GzContactSurfaceHandlerPtr = std::shared_ptr<GzContactSurfaceHandler>;
#endif
class SimulationFeatures :
public CanWriteRequiredData<SimulationFeatures, RequireData<WorldPoses>>,
public CanWriteExpectedData<SimulationFeatures,
ExpectData<ChangedWorldPoses>>,
public virtual Base,
public virtual Implements3d<SimulationFeatureList>
{
public: using GetContactsFromLastStepFeature::Implementation<FeaturePolicy3d>
::ContactInternal;
public: using GetRayIntersectionFromLastStepFeature::Implementation<
FeaturePolicy3d>::RayIntersection;
public: SimulationFeatures() = default;
public: ~SimulationFeatures() override = default;
public: void WorldForwardStep(
const Identity &_worldID,
ForwardStep::Output &_h,
ForwardStep::State &_x,
const ForwardStep::Input &_u) override;
public: void Write(WorldPoses &_worldPoses) const;
public: void Write(ChangedWorldPoses &_changedPoses) const;
public: std::vector<ContactInternal> GetContactsFromLastStep(
const Identity &_worldID) const override;
public: RayIntersection GetRayIntersectionFromLastStep(
const Identity &_worldID,
const LinearVector3d &_from,
const LinearVector3d &_end) const override;
/// \brief link poses from the most recent pose change/update.
/// The key is the link's ID, and the value is the link's pose
private: mutable std::unordered_map<std::size_t, math::Pose3d> prevLinkPoses;
private: std::optional<ContactInternal> convertContact(
const dart::collision::Contact& _contact) const;
#ifdef DART_HAS_CONTACT_SURFACE
public: void AddContactPropertiesCallback(
const Identity &_worldID,
const std::string &_callbackID,
SurfaceParamsCallback _callback) override;
public: bool RemoveContactPropertiesCallback(
const Identity &_worldID, const std::string &_callbackID) override;
private: std::unordered_map<
std::string, GzContactSurfaceHandlerPtr> contactSurfaceHandlers;
#endif
};
}
}
}
#endif