/*
  Callback method when a new model is added on Gazebo.
  Used to detect the end of asynchronous model loading.
 */
void ArdupilotSitlGazeboPlugin::on_gazebo_modelInfo(ConstModelPtr &_msg)
{
    // This method is executed independently from the main loop thread.
    // Beware of access to shared variables memory. Use mutexes if required.
    
    ROS_DEBUG( PLUGIN_LOG_PREPEND "on_gazebo_modelInfo, name %s", _msg->name().c_str());
    
    if (!_msg->name().compare(PARACHUTE_MODEL_NAME)) {
        // Gazebo has finally finished loading the parachute model.
        // It's about time, our UAV was falling to the ground at high speed !!!
        on_parachute_model_loaded();
    }
}
Ejemplo n.º 2
0
void WorldController::OnModel(ConstModelPtr &msg) {
    auto name = msg->name();

    int id;
    {
        boost::mutex::scoped_lock lock(insertMutex_);
        if (insertMap_.count(name) <= 0) {
            std::cout << "Insertion of model `" << name << "` was not requested here." << std::endl;
            return;
        }
        id = insertMap_[name];
        insertMap_.erase(name);
    }

    // Respond with the inserted model
    gz::msgs::Response resp;
    resp.set_request("insert_sdf");
    resp.set_response("success");
    resp.set_id(id);

    msgs::ModelInserted inserted;
    inserted.mutable_model()->CopyFrom(*msg);
    gz::msgs::Set(inserted.mutable_time(), world_->GetSimTime());
    inserted.SerializeToString(resp.mutable_serialized_data());

    responsePub_->Publish(resp);

    std::cout << "Model `" << name << "` inserted, world now contains " <<
              world_->GetModelCount() << " models." << std::endl;
}