Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <boost/bind.hpp>
00018 #include "physics/physics.h"
00019 #include "transport/Node.hh"
00020 #include "transport/TransportTypes.hh"
00021 #include "msgs/MessageTypes.hh"
00022 #include "common/Time.hh"
00023 #include "common/Plugin.hh"
00024 #include "common/Events.hh"
00025
00026 namespace gazebo
00027 {
00028 class MoveModelTest : public ModelPlugin
00029 {
00030 public: void Load( physics::ModelPtr _parent, sdf::ElementPtr _sdf )
00031 {
00032
00033
00034
00035
00036 this->world = _parent->GetWorld();
00037
00038
00039
00040 this->model = _parent;
00041
00042
00043 if (!this->model)
00044 gzerr << "Unable to get parent model\n";
00045
00046
00047
00048 this->updateConnection = event::Events::ConnectWorldUpdateStart(
00049 boost::bind(&MoveModelTest::OnUpdate, this));
00050 gzdbg << "plugin model name: " << this->model->GetName() << "\n";
00051
00052
00053 this->node = transport::NodePtr(new transport::Node());
00054 this->node->Init(this->world->GetName());
00055 this->statsSub = this->node->Subscribe("~/world_stats", &MoveModelTest::OnStats, this);
00056
00057 }
00058
00059
00060 public: void OnUpdate()
00061 {
00062
00063 this->simTime = this->world->GetSimTime();
00064
00065 math::Pose orig_pose = this->model->GetWorldPose();
00066
00067 math::Pose new_pose = orig_pose;
00068
00069 new_pose.rot.SetFromEuler(math::Vector3(0,0,this->simTime.Double()));
00070
00071
00072 this->model->SetWorldPose( new_pose );
00073
00074 gzdbg << "plugin simTime [" << this->simTime.Double() << "] update new_pose [" << new_pose << "] orig pose [" << orig_pose << "]\n";
00075 }
00076
00077 public: void OnStats( const boost::shared_ptr<msgs::WorldStatistics const> &_msg)
00078 {
00079 this->simTime = msgs::Convert( _msg->sim_time() );
00080
00081 }
00082
00083
00084 private: physics::ModelPtr model;
00085
00086
00087 private: event::ConnectionPtr updateConnection;
00088
00089
00090 private: transport::NodePtr node;
00091 private: transport::SubscriberPtr statsSub;
00092 private: common::Time simTime;
00093 private: physics::WorldPtr world;
00094
00095 };
00096
00097
00098 GZ_REGISTER_MODEL_PLUGIN(MoveModelTest)
00099 }