All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Actor.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 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  {
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 GAZEBO_VISIBLE Actor : public Model
72  {
75  public: explicit Actor(BasePtr _parent);
76 
78  public: virtual ~Actor();
79 
82  public: void Load(sdf::ElementPtr _sdf);
83 
85  public: virtual void Init();
86 
88  public: virtual void Play();
89 
91  public: virtual void Stop();
92 
94  public: virtual bool IsActive();
95 
97  public: void Update();
98 
100  public: virtual void Fini();
101 
104  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
105 
108  public: virtual const sdf::ElementPtr GetSDF();
109 
115  private: void AddSphereInertia(sdf::ElementPtr _linkSdf,
116  const math::Pose &_pose,
117  double _mass, double _radius);
118 
124  private: void AddSphereCollision(sdf::ElementPtr _linkSdf,
125  const std::string &_name,
126  const math::Pose &_pose,
127  double _radius);
128 
136  private: void AddSphereVisual(sdf::ElementPtr _linkSdf,
137  const std::string &_name,
138  const math::Pose &_pose,
139  double _radius,
140  const std::string &_material,
141  const common::Color &_ambient);
142 
150  private: void AddBoxVisual(sdf::ElementPtr _linkSdf,
151  const std::string &_name,
152  const math::Pose &_pose,
153  const math::Vector3 &_size,
154  const std::string &_material,
155  const common::Color &_ambient);
156 
161  private: void AddActorVisual(sdf::ElementPtr _linkSdf,
162  const std::string &_name,
163  const math::Pose &_pose);
164 
167  private: void LoadAnimation(sdf::ElementPtr _sdf);
168 
171  private: void LoadScript(sdf::ElementPtr _sdf);
172 
177  private: void SetPose(std::map<std::string, math::Matrix4> _frame,
178  std::map<std::string, std::string> _skelMap, double _time);
179 
181  protected: const common::Mesh *mesh;
182 
185 
187  protected: std::string skinFile;
188 
190  protected: double skinScale;
191 
193  protected: double startDelay;
194 
196  protected: double scriptLength;
197 
199  protected: double lastScriptTime;
200 
202  protected: bool loop;
203 
205  protected: bool active;
206 
208  protected: bool autoStart;
209 
211  protected: LinkPtr mainLink;
212 
215 
218 
220  protected: std::map<unsigned int, common::PoseAnimation*> trajectories;
221 
223  protected: std::vector<TrajectoryInfo> trajInfo;
224 
226  protected: std::map<std::string, common::SkeletonAnimation*>
228 
230  protected: std::map<std::string, std::map<std::string, std::string> >
232 
234  protected: std::map<std::string, bool> interpolateX;
235 
237  protected: math::Vector3 lastPos;
238 
240  protected: double pathLength;
241 
243  protected: unsigned int lastTraj;
244 
246  protected: std::string visualName;
247 
249  protected: uint32_t visualId;
250 
253 
255  protected: std::string oldAction;
256  };
258  }
259 }
260 #endif
A 3D mesh.
Definition: Mesh.hh:40
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:66
bool autoStart
True if the actor should start running automatically.
Definition: Actor.hh:208
double endTime
End time of the trajectory.
Definition: Actor.hh:59
A skeleton.
Definition: Skeleton.hh:50
Encapsulates a position and rotation in three space.
Definition: Pose.hh:40
LinkPtr mainLink
Base link.
Definition: Actor.hh:211
std::string oldAction
THe old action.
Definition: Actor.hh:255
double pathLength
Length of the actor's path.
Definition: Actor.hh:240
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:43
unsigned int id
ID of the trajectory.
Definition: Actor.hh:47
std::map< std::string, common::SkeletonAnimation * > skelAnimation
Skeleton animations.
Definition: Actor.hh:227
double skinScale
Scaling factor to apply to the skin.
Definition: Actor.hh:190
Actor class enables GPU based mesh model / skeleton scriptable animation.
Definition: Actor.hh:71
const common::Mesh * mesh
Pointer to the actor's mesh.
Definition: Actor.hh:181
double lastScriptTime
Time the scipt was last updated.
Definition: Actor.hh:199
common::Skeleton * skeleton
The actor's skeleton.
Definition: Actor.hh:184
A model is a collection of links, joints, and plugins.
Definition: Model.hh:52
uint32_t visualId
ID for this visual.
Definition: Actor.hh:249
std::string visualName
Name of the visual.
Definition: Actor.hh:246
bool active
True if the actor is being updated.
Definition: Actor.hh:205
Information about a trajectory for an Actor.
Definition: Actor.hh:41
double startTime
Start time of the trajectory.
Definition: Actor.hh:56
std::string type
Type of trajectory.
Definition: Actor.hh:50
double scriptLength
Time length of a scipt.
Definition: Actor.hh:196
bool translated
True if the trajectory is tranlated.
Definition: Actor.hh:62
unsigned int lastTraj
THe last trajectory.
Definition: Actor.hh:243
double duration
Duration of the trajectory.
Definition: Actor.hh:53
Defines a color.
Definition: Color.hh:39
bool loop
True if the animation should loop.
Definition: Actor.hh:202
std::vector< TrajectoryInfo > trajInfo
Trajectory information.
Definition: Actor.hh:223
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
math::Vector3 lastPos
Last position of the actor.
Definition: Actor.hh:237
std::map< std::string, bool > interpolateX
True to interpolate along x direction.
Definition: Actor.hh:234
std::map< unsigned int, common::PoseAnimation * > trajectories
All the trajectories.
Definition: Actor.hh:220
std::map< std::string, std::map< std::string, std::string > > skelNodesMap
Skeleton to naode map.
Definition: Actor.hh:231
transport::PublisherPtr bonePosePub
Where to send bone info.
Definition: Actor.hh:252
common::Time playStartTime
Time when the animation was started.
Definition: Actor.hh:217
std::string skinFile
Filename for the skin.
Definition: Actor.hh:187
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:44
common::Time prevFrameTime
Time of the previous frame.
Definition: Actor.hh:214
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:90
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:43
double startDelay
Amount of time to delay start by.
Definition: Actor.hh:193