Actor.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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 _ACTOR_HH_
18 #define _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"
28 #include "gazebo/util/system.hh"
29 
30 namespace gazebo
31 {
32  namespace common
33  {
34  class Mesh;
35  class Color;
36  }
37 
38  namespace physics
39  {
41  class GZ_PHYSICS_VISIBLE TrajectoryInfo
42  {
44  public: TrajectoryInfo();
45 
47  public: unsigned int id;
48 
50  public: std::string type;
51 
53  public: double duration;
54 
56  public: double startTime;
57 
59  public: double endTime;
60 
62  public: bool translated;
63  };
64 
67 
71  class GZ_PHYSICS_VISIBLE Actor : public Model
72  {
74  public: typedef std::map<std::string, common::SkeletonAnimation*>
76 
79  public: explicit Actor(BasePtr _parent);
80 
82  public: virtual ~Actor();
83 
86  public: void Load(sdf::ElementPtr _sdf);
87 
89  public: virtual void Init();
90 
92  public: virtual void Play();
93 
95  public: virtual void Stop();
96 
98  public: virtual bool IsActive();
99 
101  public: void Update();
102 
104  public: virtual void Fini();
105 
108  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
109 
112  public: virtual const sdf::ElementPtr GetSDF();
113 
116  public: void SetScriptTime(const double _time);
117 
120  public: double ScriptTime() const;
121 
125  public: const SkeletonAnimation_M &SkeletonAnimations() const;
126 
129  public: void SetCustomTrajectory(TrajectoryInfoPtr &_trajInfo);
130 
132  public: void ResetCustomTrajectory();
133 
134  // Documentation inherited
135  public: virtual bool GetSelfCollide() const;
136 
137  // Documentation inherited
138  public: virtual void SetSelfCollide(bool _self_collide);
139 
145  private: void AddSphereInertia(const sdf::ElementPtr &_linkSdf,
146  const ignition::math::Pose3d &_pose,
147  const double _mass, const double _radius);
148 
154  private: void AddSphereCollision(const sdf::ElementPtr &_linkSdf,
155  const std::string &_name,
156  const ignition::math::Pose3d &_pose,
157  const double _radius);
158 
166  private: void AddSphereVisual(const sdf::ElementPtr &_linkSdf,
167  const std::string &_name,
168  const ignition::math::Pose3d &_pose, const double _radius,
169  const std::string &_material, const common::Color &_ambient);
170 
178  private: void AddBoxVisual(const sdf::ElementPtr &_linkSdf,
179  const std::string &_name,
180  const ignition::math::Pose3d &_pose,
181  const ignition::math::Vector3d &_size,
182  const std::string &_material,
183  const common::Color &_ambient);
184 
189  private: void AddActorVisual(const sdf::ElementPtr &_linkSdf,
190  const std::string &_name,
191  const ignition::math::Pose3d &_pose);
192 
195  private: void LoadAnimation(sdf::ElementPtr _sdf);
196 
199  private: void LoadScript(sdf::ElementPtr _sdf);
200 
205  private: void SetPose(
206  std::map<std::string, ignition::math::Matrix4d> _frame,
207  std::map<std::string, std::string> _skelMap, double _time);
208 
210  protected: const common::Mesh *mesh;
211 
214 
216  protected: std::string skinFile;
217 
219  protected: double skinScale;
220 
222  protected: double startDelay;
223 
225  protected: double scriptLength;
226 
228  protected: bool loop;
229 
231  protected: bool active;
232 
234  protected: bool autoStart;
235 
237  protected: LinkPtr mainLink;
238 
241 
244 
246  protected: std::map<unsigned int, common::PoseAnimation*> trajectories;
247 
249  protected: std::vector<TrajectoryInfo> trajInfo;
250 
253 
255  protected: std::map<std::string, std::map<std::string, std::string> >
257 
259  protected: std::map<std::string, bool> interpolateX;
260 
262  protected: ignition::math::Vector3d lastPos;
263 
265  protected: double pathLength;
266 
268  protected: unsigned int lastTraj;
269 
271  protected: std::string visualName;
272 
274  protected: uint32_t visualId;
275 
278 
280  private: double scriptTime;
281 
284  private: TrajectoryInfoPtr customTrajectoryInfo;
285  };
287  }
288 }
289 #endif
transport::PublisherPtr bonePosePub
Where to send bone info.
Definition: Actor.hh:277
A 3D mesh.
Definition: Mesh.hh:44
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:109
A skeleton.
Definition: Skeleton.hh:53
double startTime
Start time of the trajectory.
Definition: Actor.hh:56
ignition::math::Vector3d lastPos
Last position of the actor.
Definition: Actor.hh:262
bool loop
True if the animation should loop.
Definition: Actor.hh:228
std::vector< TrajectoryInfo > trajInfo
Trajectory information.
Definition: Actor.hh:249
Actor class enables GPU based mesh model / skeleton scriptable animation.
Definition: Actor.hh:71
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
unsigned int id
ID of the trajectory.
Definition: Actor.hh:47
std::shared_ptr< TrajectoryInfo > TrajectoryInfoPtr
Definition: PhysicsTypes.hh:101
double scriptLength
Time length of a scipt.
Definition: Actor.hh:225
std::string skinFile
Filename for the skin.
Definition: Actor.hh:216
const common::Mesh * mesh
Pointer to the actor's mesh.
Definition: Actor.hh:210
A model is a collection of links, joints, and plugins.
Definition: Model.hh:53
SkeletonAnimation_M skelAnimation
Skeleton animations.
Definition: Actor.hh:252
uint32_t visualId
ID for this visual.
Definition: Actor.hh:274
Information about a trajectory for an Actor.
Definition: Actor.hh:41
double endTime
End time of the trajectory.
Definition: Actor.hh:59
double duration
Duration of the trajectory.
Definition: Actor.hh:53
std::string visualName
Name of the visual.
Definition: Actor.hh:271
std::map< unsigned int, common::PoseAnimation * > trajectories
All the trajectories.
Definition: Actor.hh:246
bool translated
True if the trajectory is tranlated.
Definition: Actor.hh:62
std::map< std::string, std::map< std::string, std::string > > skelNodesMap
Skeleton to node map.
Definition: Actor.hh:256
Defines a color.
Definition: Color.hh:36
bool autoStart
True if the actor should start running automatically.
Definition: Actor.hh:234
LinkPtr mainLink
Base link.
Definition: Actor.hh:237
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:219
double pathLength
Length of the actor's path.
Definition: Actor.hh:265
bool active
True if the actor is being updated.
Definition: Actor.hh:231
common::Skeleton * skeleton
The actor's skeleton.
Definition: Actor.hh:213
unsigned int lastTraj
THe last trajectory.
Definition: Actor.hh:268
common::Time prevFrameTime
Time of the previous frame.
Definition: Actor.hh:240
common::Time playStartTime
Time when the animation was started.
Definition: Actor.hh:243
double startDelay
Amount of time to delay start by.
Definition: Actor.hh:222
std::string type
Type of trajectory.
Definition: Actor.hh:50
std::map< std::string, bool > interpolateX
True to interpolate along x direction.
Definition: Actor.hh:259
std::map< std::string, common::SkeletonAnimation * > SkeletonAnimation_M
Typedef the skeleton animation map.
Definition: Actor.hh:75
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