28 #include "ConnectGazeboToRosTopic.pb.h" 37 sdf::ElementPtr _sdf) {
39 gzdbg << __FUNCTION__ <<
"() called." << std::endl;
51 getSdfParam<double>(_sdf,
"rotorVelocitySlowdownSim",
55 node_handle_ = gazebo::transport::NodePtr(
new transport::Node());
64 gzthrow(
"[gazebo_multirotor_base_plugin] Couldn't find specified link \"" 65 << link_name_ <<
"\".");
74 std::string link_name =
child_links_[i]->GetScopedName();
77 int pos = link_name.find(
"rotor_");
78 if (pos != link_name.npos) {
79 std::string motor_number_str = link_name.substr(pos + 6);
80 unsigned int motor_number = std::stoi(motor_number_str);
81 std::string joint_name =
child_links_[i]->GetName() +
"_joint";
82 physics::JointPtr joint = this->
model_->GetJoint(joint_name);
91 gzdbg << __FUNCTION__ <<
"() called." << std::endl;
100 common::Time now =
world_->SimTime();
102 actuators_msg_.mutable_header()->mutable_stamp()->set_sec(now.sec);
103 actuators_msg_.mutable_header()->mutable_stamp()->set_nsec(now.nsec);
115 MotorNumberToJointMap::iterator
m;
117 double motor_rot_vel =
132 gazebo::transport::PublisherPtr connect_gazebo_to_ros_topic_pub =
133 node_handle_->Advertise<gz_std_msgs::ConnectGazeboToRosTopic>(
136 gz_std_msgs::ConnectGazeboToRosTopic connect_gazebo_to_ros_topic_msg;
145 connect_gazebo_to_ros_topic_msg.set_gazebo_topic(
"~/" +
model_->GetName() +
147 connect_gazebo_to_ros_topic_msg.set_ros_topic(
namespace_ +
"/" +
148 actuators_pub_topic_);
149 connect_gazebo_to_ros_topic_msg.set_msgtype(
150 gz_std_msgs::ConnectGazeboToRosTopic::ACTUATORS);
151 connect_gazebo_to_ros_topic_pub->Publish(connect_gazebo_to_ros_topic_msg,
161 connect_gazebo_to_ros_topic_msg.set_gazebo_topic(
"~/" +
namespace_ +
"/" +
162 joint_state_pub_topic_);
163 connect_gazebo_to_ros_topic_msg.set_ros_topic(
namespace_ +
"/" +
164 joint_state_pub_topic_);
165 connect_gazebo_to_ros_topic_msg.set_msgtype(
166 gz_std_msgs::ConnectGazeboToRosTopic::JOINT_STATE);
167 connect_gazebo_to_ros_topic_pub->Publish(connect_gazebo_to_ros_topic_msg,
void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
Load the plugin.
gz_sensor_msgs::Actuators actuators_msg_
This plugin publishes the motor speeds of your multirotor model.
virtual ~GazeboMultirotorBasePlugin()
std::string joint_state_pub_topic_
MotorNumberToJointMap motor_joints_
event::ConnectionPtr update_connection_
Pointer to the update event connection.
gazebo::transport::NodePtr node_handle_
void CreatePubsAndSubs()
Creates all required publishers and subscribers, incl. routing of messages to/from ROS if required...
gazebo::transport::PublisherPtr joint_state_pub_
std::string actuators_pub_topic_
bool pubs_and_subs_created_
Flag that is set to true once CreatePubsAndSubs() is called, used to prevent CreatePubsAndSubs() from...
double rotor_velocity_slowdown_sim_
std::pair< const unsigned int, const physics::JointPtr > MotorNumberToJointPair
static const bool kPrintOnPluginLoad
physics::Link_V child_links_
gazebo::transport::PublisherPtr motor_pub_
static const bool kPrintOnUpdates
GZ_REGISTER_MODEL_PLUGIN(GazeboRosP3D)
static const std::string kConnectGazeboToRosSubtopic
void OnUpdate(const common::UpdateInfo &)
Called when the world is updated.
gz_sensor_msgs::JointState joint_state_msg_