Actor.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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 GAZEBO_PHYSICS_ACTOR_HH_
18 #define GAZEBO_PHYSICS_ACTOR_HH_
19 
20 #include <string>
21 #include <map>
22 #include <vector>
23 
24 #include <ignition/math/Color.hh>
25 
26 #include "gazebo/physics/Model.hh"
27 #include "gazebo/common/Time.hh"
29 #include "gazebo/util/system.hh"
30 
31 namespace gazebo
32 {
33  namespace common
34  {
35  class Mesh;
36  class Skeleton;
37  }
38 
39  namespace physics
40  {
43  class GZ_PHYSICS_VISIBLE TrajectoryInfo
44  {
46  public: TrajectoryInfo();
47 
49  public: unsigned int id;
50 
53  public: std::string type;
54 
56  public: double duration;
57 
59  public: double startTime;
60 
62  public: double endTime;
63 
65  public: bool translated;
66  };
67 
70 
74  class GZ_PHYSICS_VISIBLE Actor : public Model
75  {
77  public: typedef std::map<std::string, common::SkeletonAnimation *>
79 
82  public: explicit Actor(BasePtr _parent);
83 
85  public: virtual ~Actor();
86 
89  public: void Load(sdf::ElementPtr _sdf);
90 
92  public: virtual void Init();
93 
95  public: virtual void Play();
96 
98  public: virtual void Stop();
99 
102  public: virtual bool IsActive() const;
103 
105  public: void Update();
106 
108  public: virtual void Fini();
109 
112  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
113 
116  public: virtual const sdf::ElementPtr GetSDF();
117 
119  public: void Reset();
120  using Model::Reset;
121 
126  public: void SetScriptTime(const double _time);
127 
132  public: double ScriptTime() const;
133 
137  public: const SkeletonAnimation_M &SkeletonAnimations() const;
138 
145  public: void SetCustomTrajectory(TrajectoryInfoPtr &_trajInfo);
146 
149  public: void ResetCustomTrajectory();
150 
155  public: virtual bool GetSelfCollide() const;
156 
162  public: virtual void SetSelfCollide(bool _selfCollide);
163 
168  public: virtual bool WindMode() const;
169 
175  public: virtual void SetWindMode(const bool _enabled);
176 
182  private: void AddSphereInertia(const sdf::ElementPtr &_linkSdf,
183  const ignition::math::Pose3d &_pose,
184  const double _mass, const double _radius);
185 
191  private: void AddSphereCollision(const sdf::ElementPtr &_linkSdf,
192  const std::string &_name,
193  const ignition::math::Pose3d &_pose,
194  const double _radius);
195 
203  private: void AddSphereVisual(const sdf::ElementPtr &_linkSdf,
204  const std::string &_name,
205  const ignition::math::Pose3d &_pose, const double _radius,
206  const std::string &_material,
207  const ignition::math::Color &_ambient);
208 
216  private: void AddBoxVisual(const sdf::ElementPtr &_linkSdf,
217  const std::string &_name,
218  const ignition::math::Pose3d &_pose,
219  const ignition::math::Vector3d &_size,
220  const std::string &_material,
221  const ignition::math::Color &_ambient);
222 
227  private: void AddActorVisual(const sdf::ElementPtr &_linkSdf,
228  const std::string &_name,
229  const ignition::math::Pose3d &_pose);
230 
235  private: bool LoadSkin(sdf::ElementPtr _sdf);
236 
242  private: void LoadAnimation(sdf::ElementPtr _sdf);
243 
246  private: void LoadScript(sdf::ElementPtr _sdf);
247 
253  private: void SetPose(
254  std::map<std::string, ignition::math::Matrix4d> _frame,
255  std::map<std::string, std::string> _skelMap,
256  const double _time);
257 
259  protected: const common::Mesh *mesh = nullptr;
260 
262  protected: common::Skeleton *skeleton = nullptr;
263 
265  protected: std::string skinFile;
266 
268  protected: double skinScale;
269 
272  protected: double startDelay;
273 
275  protected: double scriptLength;
276 
278  protected: bool loop;
279 
281  protected: bool active;
282 
285  protected: bool autoStart;
286 
288  protected: LinkPtr mainLink;
289 
292 
295 
299  protected: std::map<unsigned int, common::PoseAnimation *> trajectories;
300 
305  protected: std::vector<TrajectoryInfo> trajInfo;
306 
312 
321  protected: std::map<std::string, std::map<std::string, std::string> >
323 
326  // direction.
329  protected: std::map<std::string, bool> interpolateX;
330 
332  protected: ignition::math::Vector3d lastPos;
333 
335  protected: double pathLength;
336 
338  protected: unsigned int lastTraj;
339 
341  protected: std::string visualName;
342 
344  protected: uint32_t visualId;
345 
348 
351  private: double scriptTime;
352 
355  private: TrajectoryInfoPtr customTrajectoryInfo;
356  };
358  }
359 }
360 #endif
361 
transport::PublisherPtr bonePosePub
Publisher to send bone info.
Definition: Actor.hh:347
A 3D mesh.
Definition: Mesh.hh:42
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:109
A skeleton.
Definition: Skeleton.hh:52
void Reset()
Reset the model.
double startTime
Start time of this keyframe within the trajectory, in seconds.
Definition: Actor.hh:59
ignition::math::Vector3d lastPos
Last position of the actor.
Definition: Actor.hh:332
bool loop
True if the animation should loop.
Definition: Actor.hh:278
std::vector< TrajectoryInfo > trajInfo
A vector of trajectory information, which contains information such as their durations, uniquely identifiable by their IDs.
Definition: Actor.hh:305
Actor class enables GPU based mesh model / skeleton scriptable animation.
Definition: Actor.hh:74
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
unsigned int id
ID of the trajectory.
Definition: Actor.hh:49
std::shared_ptr< TrajectoryInfo > TrajectoryInfoPtr
Definition: PhysicsTypes.hh:101
double scriptLength
Total time length of the script, in seconds.
Definition: Actor.hh:275
std::string skinFile
Filename for the skin.
Definition: Actor.hh:265
std::map< unsigned int, common::PoseAnimation * > trajectories
Map of all the trajectories (pose animations) and their indices.
Definition: Actor.hh:299
A model is a collection of links, joints, and plugins.
Definition: Model.hh:59
SkeletonAnimation_M skelAnimation
Map of skeleton animations, indexed by their names.
Definition: Actor.hh:311
uint32_t visualId
ID for the visual representing the skin.
Definition: Actor.hh:344
Information about a trajectory for an Actor.
Definition: Actor.hh:43
double endTime
End time of this keyframe within the trajectory, in seconds.
Definition: Actor.hh:62
double duration
Duration of this keyframe in seconds.
Definition: Actor.hh:56
std::string visualName
Name of the visual representing the skin.
Definition: Actor.hh:341
bool translated
True if the trajectory is translated.
Definition: Actor.hh:65
std::map< std::string, std::map< std::string, std::string > > skelNodesMap
Skeleton to node map:
Definition: Actor.hh:322
bool autoStart
True if the actor should start running automatically, otherwise it will only start once Play is calle...
Definition: Actor.hh:285
std::map< std::string, common::SkeletonAnimation * > SkeletonAnimation_M
Typedef the skeleton animation map, indexed by their names.
Definition: Actor.hh:78
LinkPtr mainLink
Pointer to the actor's canonical link.
Definition: Actor.hh:288
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
double skinScale
Scaling factor to apply to the skin.
Definition: Actor.hh:268
double pathLength
Length of the actor's path.
Definition: Actor.hh:335
bool active
True if the actor is being updated.
Definition: Actor.hh:281
unsigned int lastTraj
Id of the last trajectory.
Definition: Actor.hh:338
common::Time prevFrameTime
Time of the previous frame.
Definition: Actor.hh:291
common::Time playStartTime
Time when the animation was started.
Definition: Actor.hh:294
double startDelay
Time to wait before starting the script.
Definition: Actor.hh:272
std::string type
Type of trajectory.
Definition: Actor.hh:53
std::map< std::string, bool > interpolateX
Map of animation types (the same name as in skelAnimation and skelNodesMap) and whether they should b...
Definition: Actor.hh:329
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:77
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44