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 <memory>
23 #include <vector>
24 
25 #include <ignition/math/Color.hh>
26 
27 #include "gazebo/physics/Model.hh"
28 #include "gazebo/common/Time.hh"
30 #include "gazebo/util/system.hh"
31 
32 namespace gazebo
33 {
34  namespace common
35  {
36  class Mesh;
37  class Skeleton;
38  }
39 
40  namespace physics
41  {
42  class ActorPrivate;
43 
46  class GZ_PHYSICS_VISIBLE TrajectoryInfo
47  {
49  public: TrajectoryInfo();
50 
52  public: unsigned int id;
53 
56  public: std::string type;
57 
59  public: double duration;
60 
62  public: double startTime;
63 
65  public: double endTime;
66 
68  public: bool translated;
69  };
70 
73 
77  class GZ_PHYSICS_VISIBLE Actor : public Model
78  {
80  public: typedef std::map<std::string, common::SkeletonAnimation *>
82 
85  public: explicit Actor(BasePtr _parent);
86 
88  public: virtual ~Actor();
89 
92  public: void Load(sdf::ElementPtr _sdf);
93 
95  public: virtual void Init();
96 
98  public: virtual void Play();
99 
101  public: virtual void Stop();
102 
105  public: virtual bool IsActive() const;
106 
108  public: void Update();
109 
111  public: virtual void Fini();
112 
115  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
116 
119  public: virtual const sdf::ElementPtr GetSDF();
120 
122  public: void Reset();
123  using Model::Reset;
124 
129  public: void SetScriptTime(const double _time);
130 
135  public: double ScriptTime() const;
136 
140  public: const SkeletonAnimation_M &SkeletonAnimations() const;
141 
148  public: void SetCustomTrajectory(TrajectoryInfoPtr &_trajInfo);
149 
152  public: const common::Mesh *Mesh() const;
153 
158  public: TrajectoryInfoPtr CustomTrajectory() const;
159 
162  public: void ResetCustomTrajectory();
163 
168  public: virtual bool GetSelfCollide() const;
169 
175  public: virtual void SetSelfCollide(bool _selfCollide);
176 
181  public: virtual bool WindMode() const;
182 
188  public: virtual void SetWindMode(const bool _enabled);
189 
195  private: void AddSphereInertia(const sdf::ElementPtr &_linkSdf,
196  const ignition::math::Pose3d &_pose,
197  const double _mass, const double _radius);
198 
205  private: void AddSphereCollision(const sdf::ElementPtr &_linkSdf,
206  const std::string &_name,
207  const ignition::math::Pose3d &_pose,
208  const double _radius);
209 
216  private: void AddBoxCollision(const sdf::ElementPtr &_linkSdf,
217  const std::string &_name,
218  const ignition::math::Pose3d &_pose,
219  const ignition::math::Vector3d &_size);
220 
228  private: void AddSphereVisual(const sdf::ElementPtr &_linkSdf,
229  const std::string &_name,
230  const ignition::math::Pose3d &_pose, const double _radius,
231  const std::string &_material,
232  const ignition::math::Color &_ambient);
233 
241  private: void AddBoxVisual(const sdf::ElementPtr &_linkSdf,
242  const std::string &_name,
243  const ignition::math::Pose3d &_pose,
244  const ignition::math::Vector3d &_size,
245  const std::string &_material,
246  const ignition::math::Color &_ambient);
247 
252  private: void AddActorVisual(const sdf::ElementPtr &_linkSdf,
253  const std::string &_name,
254  const ignition::math::Pose3d &_pose);
255 
260  private: bool LoadSkin(sdf::ElementPtr _sdf);
261 
267  private: void LoadAnimation(sdf::ElementPtr _sdf);
268 
271  private: void LoadScript(sdf::ElementPtr _sdf);
272 
278  private: void SetPose(
279  std::map<std::string, ignition::math::Matrix4d> _frame,
280  std::map<std::string, std::string> _skelMap,
281  const double _time);
282 
284  protected: const common::Mesh *mesh = nullptr;
285 
287  protected: common::Skeleton *skeleton = nullptr;
288 
290  protected: std::string skinFile;
291 
293  protected: double skinScale;
294 
297  protected: double startDelay;
298 
300  protected: double scriptLength;
301 
303  protected: bool loop;
304 
306  protected: bool active;
307 
310  protected: bool autoStart;
311 
313  protected: LinkPtr mainLink;
314 
317 
320 
324  protected: std::map<unsigned int, common::PoseAnimation *> trajectories;
325 
330  protected: std::vector<TrajectoryInfo> trajInfo;
331 
337 
346  protected: std::map<std::string, std::map<std::string, std::string> >
348 
351  // direction.
354  protected: std::map<std::string, bool> interpolateX;
355 
357  protected: ignition::math::Vector3d lastPos;
358 
360  protected: double pathLength;
361 
363  protected: unsigned int lastTraj;
364 
366  protected: std::string visualName;
367 
369  protected: uint32_t visualId;
370 
373 
376  private: double scriptTime;
377 
380  private: TrajectoryInfoPtr customTrajectoryInfo;
381 
383  private: std::unique_ptr<ActorPrivate> dataPtr;
384  };
386  }
387 }
388 #endif
389 
unsigned int lastTraj
Id of the last trajectory.
Definition: Actor.hh:363
double startTime
Start time of this keyframe within the trajectory, in seconds.
Definition: Actor.hh:62
std::vector< TrajectoryInfo > trajInfo
A vector of trajectory information, which contains information such as their durations,...
Definition: Actor.hh:330
virtual void SetWindMode(const bool _enabled)
Override set wind mode method to make it impossible to set it to true for actors.
virtual void Fini()
Finalize the actor.
Forward declarations for the common classes.
Definition: Animation.hh:26
double scriptLength
Total time length of the script, in seconds.
Definition: Actor.hh:300
A Time class, can be used to hold wall- or sim-time. stored as sec and nano-sec.
Definition: Time.hh:47
std::map< std::string, std::map< std::string, std::string > > skelNodesMap
Skeleton to node map:
Definition: Actor.hh:347
void SetScriptTime(const double _time)
Set the current script time.
common::Skeleton * skeleton
The actor's skeleton.
Definition: Actor.hh:287
ignition::math::Vector3d lastPos
Last position of the actor.
Definition: Actor.hh:357
std::string visualName
Name of the visual representing the skin.
Definition: Actor.hh:366
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
const common::Mesh * mesh
Pointer to the actor's mesh.
Definition: Actor.hh:284
common
Definition: FuelModelDatabase.hh:37
virtual bool GetSelfCollide() const
Get whether the links in the actor can collide with each other.
TrajectoryInfoPtr CustomTrajectory() const
Get the custom trajectory.
const SkeletonAnimation_M & SkeletonAnimations() const
Returns a dictionary of all the skeleton animations associated with the actor.
const common::Mesh * Mesh() const
Returns the actor's mesh.
virtual void Stop()
Stop playing the script.
uint32_t visualId
ID for the visual representing the skin.
Definition: Actor.hh:369
unsigned int id
ID of the trajectory.
Definition: Actor.hh:52
void SetCustomTrajectory(TrajectoryInfoPtr &_trajInfo)
Set a custom trajectory for the actor, using one of the existing animations.
virtual void Play()
Start playing the script.
double endTime
End time of this keyframe within the trajectory, in seconds.
Definition: Actor.hh:65
double pathLength
Length of the actor's path.
Definition: Actor.hh:360
double duration
Duration of this keyframe in seconds.
Definition: Actor.hh:59
SkeletonAnimation_M skelAnimation
Map of skeleton animations, indexed by their names.
Definition: Actor.hh:336
TrajectoryInfo()
Constructor.
A skeleton.
Definition: Skeleton.hh:52
double ScriptTime() const
Get the current script time.
virtual ~Actor()
Destructor.
void Update()
Update the actor.
LinkPtr mainLink
Pointer to the actor's canonical link.
Definition: Actor.hh:313
void Reset()
Reset the model.
std::string skinFile
Filename for the skin.
Definition: Actor.hh:290
void Load(sdf::ElementPtr _sdf)
Load the actor.
double skinScale
Scaling factor to apply to the skin.
Definition: Actor.hh:293
virtual void SetSelfCollide(bool _selfCollide)
Override set self collide method to make it impossible to set it to true for actors.
bool autoStart
True if the actor should start running automatically, otherwise it will only start once Play is calle...
Definition: Actor.hh:310
std::shared_ptr< TrajectoryInfo > TrajectoryInfoPtr
Definition: PhysicsTypes.hh:101
A model is a collection of links, joints, and plugins.
Definition: Model.hh:59
virtual void UpdateParameters(sdf::ElementPtr _sdf)
Update the parameters using new sdf values.
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:77
Information about a trajectory for an Actor.
Definition: Actor.hh:46
common::Time prevFrameTime
Time of the previous frame.
Definition: Actor.hh:316
virtual bool IsActive() const
Returns true when actor is playing animation.
virtual bool WindMode() const
Get whether the links in the actor are affected by wind.
common::Time playStartTime
Time when the animation was started.
Definition: Actor.hh:319
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:109
double startDelay
Time to wait before starting the script.
Definition: Actor.hh:297
Actor(BasePtr _parent)
Constructor.
virtual const sdf::ElementPtr GetSDF()
Get the SDF values for the actor.
A 3D mesh.
Definition: Mesh.hh:42
bool translated
True if the trajectory is translated.
Definition: Actor.hh:68
void Reset()
Reset the actor.
std::string type
Type of trajectory.
Definition: Actor.hh:56
std::map< std::string, common::SkeletonAnimation * > SkeletonAnimation_M
Typedef the skeleton animation map, indexed by their names.
Definition: Actor.hh:81
bool active
True if the actor is being updated.
Definition: Actor.hh:306
void ResetCustomTrajectory()
Reset custom trajectory of the actor.
bool loop
True if the animation should loop.
Definition: Actor.hh:303
Actor class enables GPU based mesh model / skeleton scriptable animation.
Definition: Actor.hh:77
std::map< unsigned int, common::PoseAnimation * > trajectories
Map of all the trajectories (pose animations) and their indices.
Definition: Actor.hh:324
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:354
transport::PublisherPtr bonePosePub
Publisher to send bone info.
Definition: Actor.hh:372
virtual void Init()
Initialize the actor.