callback_data_mediator.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 
00018 #include <limits>
00019 #include <ros/ros.h>
00020 
00021 #include "cob_twist_controller/callback_data_mediator.h"
00022 
00023 #include <eigen_conversions/eigen_msg.h>
00024 
00026 uint32_t CallbackDataMediator::obstacleDistancesCnt()
00027 {
00028     boost::mutex::scoped_lock lock(distances_to_obstacles_lock_);
00029     return this->obstacle_distances_.size();
00030 }
00031 
00033 bool CallbackDataMediator::fill(ConstraintParamsCA& params_ca)
00034 {
00035     boost::mutex::scoped_lock lock(distances_to_obstacles_lock_);
00036     bool success = false;
00037     double last_min_distance = std::numeric_limits<double>::max();
00038     params_ca.current_distances_.clear();
00039     for (ObstacleDistancesIter_t it = this->obstacle_distances_.begin(); it != this->obstacle_distances_.end(); it++)
00040     {
00041         if (it->first == params_ca.id_)  // select the appropriate distances for frame id of interest
00042         {
00043             params_ca.current_distances_ = it->second;  // copy all distances for frame to current distances of param struct
00044             success = true;
00045         }
00046     }
00047 
00048     return success;
00049 }
00050 
00052 bool CallbackDataMediator::fill(ConstraintParamsJLA& params_jla)
00053 {
00054     return true;
00055 }
00056 
00058 void CallbackDataMediator::distancesToObstaclesCallback(const cob_control_msgs::ObstacleDistances::ConstPtr& msg)
00059 {
00060     boost::mutex::scoped_lock lock(distances_to_obstacles_lock_);
00061     this->obstacle_distances_.clear();
00062     for (cob_control_msgs::ObstacleDistances::_distances_type::const_iterator it = msg->distances.begin(); it != msg->distances.end(); it++)
00063     {
00064         ObstacleDistanceData d;
00065         d.min_distance = it->distance;
00066         tf::vectorMsgToEigen(it->frame_vector, d.frame_vector);
00067         tf::vectorMsgToEigen(it->nearest_point_frame_vector, d.nearest_point_frame_vector);
00068         tf::vectorMsgToEigen(it->nearest_point_obstacle_vector, d.nearest_point_obstacle_vector);
00069         this->obstacle_distances_[it->link_of_interest].push_back(d);
00070     }
00071 }


cob_twist_controller
Author(s): Felix Messmer , Marco Bezzon , Christoph Mark , Francisco Moreno
autogenerated on Thu Jun 6 2019 21:19:26