/* * Copyright (C) 2017 Open Source Robotics Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #include #include #include #include #include #include #include "TouchPlugin.hh" using namespace gazebo; GZ_REGISTER_MODEL_PLUGIN(TouchPlugin) ///////////////////////////////////////////////// TouchPlugin::TouchPlugin() { } ///////////////////////////////////////////////// void TouchPlugin::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf) { GZ_ASSERT(_model, "Model pointer is null"); GZ_ASSERT(_sdf, "SDF pointer is null"); // Get sensors if (_sdf->HasElement("sensor")) { auto elem = _sdf->GetElement("sensor"); while (elem) { auto sensorName = elem->Get(); auto sensor = std::dynamic_pointer_cast( sensors::SensorManager::Instance()->GetSensor(sensorName)); if (!sensor) { gzerr << "Couldn't find sensor [" << sensorName << "]" << std::endl; return; } this->contactSensors.push_back(sensor); elem = elem->GetNextElement("sensor"); } } else { gzerr << "Missing required parameter ." << std::endl; return; } // Get target substring if (!_sdf->HasElement("target")) { gzerr << "Missing required parameter ." << std::endl; return; } this->target = _sdf->GetElement("target")->Get(); this->modelName = _model->GetName(); // Namespace if (!_sdf->HasElement("namespace")) { gzerr << "Missing required parameter " << std::endl; return; } this->ns = _sdf->Get("namespace"); // Target time if (!_sdf->HasElement("time")) { gzerr << "Missing required parameter