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 "gazebo/physics/Model.hh"
25 #include "gazebo/common/Time.hh"
27 #include "gazebo/util/system.hh"
28 
29 namespace gazebo
30 {
31  namespace common
32  {
33  class Mesh;
34  class Color;
35  class Skeleton;
36  }
37 
38  namespace physics
39  {
42  class GZ_PHYSICS_VISIBLE TrajectoryInfo
43  {
45  public: TrajectoryInfo();
46 
48  public: unsigned int id;
49 
52  public: std::string type;
53 
55  public: double duration;
56 
58  public: double startTime;
59 
61  public: double endTime;
62 
64  public: bool translated;
65  };
66 
69 
73  class GZ_PHYSICS_VISIBLE Actor : public Model
74  {
76  public: typedef std::map<std::string, common::SkeletonAnimation *>
78 
81  public: explicit Actor(BasePtr _parent);
82 
84  public: virtual ~Actor();
85 
88  public: void Load(sdf::ElementPtr _sdf);
89 
91  public: virtual void Init();
92 
94  public: virtual void Play();
95 
97  public: virtual void Stop();
98 
101  public: virtual bool IsActive() const;
102 
104  public: void Update();
105 
107  public: virtual void Fini();
108 
111  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
112 
115  public: virtual const sdf::ElementPtr GetSDF();
116 
121  public: void SetScriptTime(const double _time);
122 
127  public: double ScriptTime() const;
128 
132  public: const SkeletonAnimation_M &SkeletonAnimations() const;
133 
140  public: void SetCustomTrajectory(TrajectoryInfoPtr &_trajInfo);
141 
146  public: TrajectoryInfoPtr CustomTrajectory() const;
147 
150  public: void ResetCustomTrajectory();
151 
156  public: virtual bool GetSelfCollide() const;
157 
163  public: virtual void SetSelfCollide(bool _selfCollide);
164 
169  public: virtual bool WindMode() const;
170 
176  public: virtual void SetWindMode(const bool _enabled);
177 
183  private: void AddSphereInertia(const sdf::ElementPtr &_linkSdf,
184  const ignition::math::Pose3d &_pose,
185  const double _mass, const double _radius);
186 
193  private: void AddSphereCollision(const sdf::ElementPtr &_linkSdf,
194  const std::string &_name,
195  const ignition::math::Pose3d &_pose,
196  const double _radius);
197 
204  private: void AddBoxCollision(const sdf::ElementPtr &_linkSdf,
205  const std::string &_name,
206  const ignition::math::Pose3d &_pose,
207  const ignition::math::Vector3d &_size);
208 
216  private: void AddSphereVisual(const sdf::ElementPtr &_linkSdf,
217  const std::string &_name,
218  const ignition::math::Pose3d &_pose, const double _radius,
219  const std::string &_material, const common::Color &_ambient);
220 
228  private: void AddBoxVisual(const sdf::ElementPtr &_linkSdf,
229  const std::string &_name,
230  const ignition::math::Pose3d &_pose,
231  const ignition::math::Vector3d &_size,
232  const std::string &_material,
233  const common::Color &_ambient);
234 
239  private: void AddActorVisual(const sdf::ElementPtr &_linkSdf,
240  const std::string &_name,
241  const ignition::math::Pose3d &_pose);
242 
247  private: bool LoadSkin(sdf::ElementPtr _sdf);
248 
254  private: void LoadAnimation(sdf::ElementPtr _sdf);
255 
258  private: void LoadScript(sdf::ElementPtr _sdf);
259 
265  private: void SetPose(
266  std::map<std::string, ignition::math::Matrix4d> _frame,
267  std::map<std::string, std::string> _skelMap,
268  const double _time);
269 
271  protected: const common::Mesh *mesh = nullptr;
272 
274  protected: common::Skeleton *skeleton = nullptr;
275 
277  protected: std::string skinFile;
278 
280  protected: double skinScale;
281 
284  protected: double startDelay;
285 
287  protected: double scriptLength;
288 
290  protected: bool loop;
291 
293  protected: bool active;
294 
297  protected: bool autoStart;
298 
300  protected: LinkPtr mainLink;
301 
304 
307 
311  protected: std::map<unsigned int, common::PoseAnimation *> trajectories;
312 
317  protected: std::vector<TrajectoryInfo> trajInfo;
318 
324 
333  protected: std::map<std::string, std::map<std::string, std::string> >
335 
338  // direction.
341  protected: std::map<std::string, bool> interpolateX;
342 
344  protected: ignition::math::Vector3d lastPos;
345 
347  protected: double pathLength;
348 
350  protected: unsigned int lastTraj;
351 
353  protected: std::string visualName;
354 
356  protected: uint32_t visualId;
357 
360 
363  private: double scriptTime;
364 
367  private: TrajectoryInfoPtr customTrajectoryInfo;
368  };
370  }
371 }
372 #endif
373 
transport::PublisherPtr bonePosePub
Publisher to send bone info.
Definition: Actor.hh:359
A 3D mesh.
Definition: Mesh.hh:42
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:109
A skeleton.
Definition: Skeleton.hh:52
Forward declarations for the common classes.
Definition: Animation.hh:33
double startTime
Start time of this keyframe within the trajectory, in seconds.
Definition: Actor.hh:58
ignition::math::Vector3d lastPos
Last position of the actor.
Definition: Actor.hh:344
bool loop
True if the animation should loop.
Definition: Actor.hh:290
std::vector< TrajectoryInfo > trajInfo
A vector of trajectory information, which contains information such as their durations, uniquely identifiable by their IDs.
Definition: Actor.hh:317
Actor class enables GPU based mesh model / skeleton scriptable animation.
Definition: Actor.hh:73
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
unsigned int id
ID of the trajectory.
Definition: Actor.hh:48
std::shared_ptr< TrajectoryInfo > TrajectoryInfoPtr
Definition: PhysicsTypes.hh:101
double scriptLength
Total time length of the script, in seconds.
Definition: Actor.hh:287
std::string skinFile
Filename for the skin.
Definition: Actor.hh:277
std::map< unsigned int, common::PoseAnimation * > trajectories
Map of all the trajectories (pose animations) and their indices.
Definition: Actor.hh:311
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:323
uint32_t visualId
ID for the visual representing the skin.
Definition: Actor.hh:356
Information about a trajectory for an Actor.
Definition: Actor.hh:42
double endTime
End time of this keyframe within the trajectory, in seconds.
Definition: Actor.hh:61
double duration
Duration of this keyframe in seconds.
Definition: Actor.hh:55
std::string visualName
Name of the visual representing the skin.
Definition: Actor.hh:353
bool translated
True if the trajectory is translated.
Definition: Actor.hh:64
std::map< std::string, std::map< std::string, std::string > > skelNodesMap
Skeleton to node map:
Definition: Actor.hh:334
Defines a color.
Definition: Color.hh:36
bool autoStart
True if the actor should start running automatically, otherwise it will only start once Play is calle...
Definition: Actor.hh:297
std::map< std::string, common::SkeletonAnimation * > SkeletonAnimation_M
Typedef the skeleton animation map, indexed by their names.
Definition: Actor.hh:77
LinkPtr mainLink
Pointer to the actor&#39;s canonical link.
Definition: Actor.hh:300
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:280
double pathLength
Length of the actor&#39;s path.
Definition: Actor.hh:347
bool active
True if the actor is being updated.
Definition: Actor.hh:293
unsigned int lastTraj
Id of the last trajectory.
Definition: Actor.hh:350
common::Time prevFrameTime
Time of the previous frame.
Definition: Actor.hh:303
common::Time playStartTime
Time when the animation was started.
Definition: Actor.hh:306
double startDelay
Time to wait before starting the script.
Definition: Actor.hh:284
std::string type
Type of trajectory.
Definition: Actor.hh:52
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:341
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