|
| 1 | +/* |
| 2 | + * @brief cola_configuration sets the initial SIM result output configuration |
| 3 | + * using ros cola services. |
| 4 | + * Configures the following result output settings from launch file: |
| 5 | + * LocSetResultPort, LocSetResultMode, LocSetResultPoseEnabled, LocSetResultEndianness, LocSetResultPoseInterval, |
| 6 | + * LocRequestResultData |
| 7 | + * |
| 8 | + * Copyright (C) 2019 Ing.-Buero Dr. Michael Lehning, Hildesheim |
| 9 | + * Copyright (C) 2019 SICK AG, Waldkirch |
| 10 | + * |
| 11 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 12 | + * you may not use this file except in compliance with the License. |
| 13 | + * You may obtain a copy of the License at |
| 14 | + * |
| 15 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 16 | + * |
| 17 | + * Unless required by applicable law or agreed to in writing, software |
| 18 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 19 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 20 | + * See the License for the specific language governing permissions and |
| 21 | + * limitations under the License. |
| 22 | + * |
| 23 | + * All rights reserved. |
| 24 | + * |
| 25 | + * Redistribution and use in source and binary forms, with or without |
| 26 | + * modification, are permitted provided that the following conditions are met: |
| 27 | + * |
| 28 | + * * Redistributions of source code must retain the above copyright |
| 29 | + * notice, this list of conditions and the following disclaimer. |
| 30 | + * * Redistributions in binary form must reproduce the above copyright |
| 31 | + * notice, this list of conditions and the following disclaimer in the |
| 32 | + * documentation and/or other materials provided with the distribution. |
| 33 | + * * Neither the name of SICK AG nor the names of its |
| 34 | + * contributors may be used to endorse or promote products derived from |
| 35 | + * this software without specific prior written permission |
| 36 | + * * Neither the name of Ing.-Buero Dr. Michael Lehning nor the names of its |
| 37 | + * contributors may be used to endorse or promote products derived from |
| 38 | + * this software without specific prior written permission |
| 39 | + * |
| 40 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 41 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 42 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 43 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 44 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 45 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 46 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 47 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 48 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 49 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 50 | + * POSSIBILITY OF SUCH DAMAGE. |
| 51 | + * |
| 52 | + * Authors: |
| 53 | + * Michael Lehning <michael.lehning@lehning.de> |
| 54 | + * |
| 55 | + * Copyright 2019 SICK AG |
| 56 | + * Copyright 2019 Ing.-Buero Dr. Michael Lehning |
| 57 | + * |
| 58 | + */ |
| 59 | +#ifndef __SIM_LOC_COLA_CONFIGURATION_H_INCLUDED |
| 60 | +#define __SIM_LOC_COLA_CONFIGURATION_H_INCLUDED |
| 61 | + |
| 62 | +#include "sick_lidar_localization/cola_services.h" |
| 63 | + |
| 64 | +namespace sick_lidar_localization |
| 65 | +{ |
| 66 | + /*! |
| 67 | + * Class sick_lidar_localization::ColaConfiguration sets the initial SIM result output configuration |
| 68 | + * using ros cola services. |
| 69 | + * Configures the following result output settings from launch file: |
| 70 | + * LocSetResultPort, LocSetResultMode, LocSetResultPoseEnabled, LocSetResultEndianness, LocSetResultPoseInterval, |
| 71 | + * LocRequestResultData |
| 72 | + */ |
| 73 | + class ColaConfiguration |
| 74 | + { |
| 75 | + public: |
| 76 | + |
| 77 | + /*! |
| 78 | + * Constructor |
| 79 | + */ |
| 80 | + ColaConfiguration(ros::NodeHandle* nh = 0); |
| 81 | + |
| 82 | + /*! |
| 83 | + * Destructor |
| 84 | + */ |
| 85 | + virtual ~ColaConfiguration(); |
| 86 | + |
| 87 | + /*! |
| 88 | + * Starts transmitting the initial result output configuration to the localization controller. |
| 89 | + * Configures the following result output settings from launch file: |
| 90 | + * LocSetResultPort, LocSetResultMode, LocSetResultPoseEnabled, LocSetResultEndianness, LocSetResultPoseInterval, |
| 91 | + * LocRequestResultData |
| 92 | + * @return true on success, false in case of errors. |
| 93 | + */ |
| 94 | + virtual bool start(void); |
| 95 | + |
| 96 | + /*! |
| 97 | + * Stops transmitting the initial result output configuration to the localization controller. |
| 98 | + */ |
| 99 | + virtual void stop(void); |
| 100 | + |
| 101 | + protected: |
| 102 | + |
| 103 | + /*! |
| 104 | + * Thread callback, transmits the initial SIM result output configuration using ros cola services. |
| 105 | + * Configures the following result output settings from launch file: |
| 106 | + * LocSetResultPort, LocSetResultMode, LocSetResultPoseEnabled, LocSetResultEndianness, LocSetResultPoseInterval, |
| 107 | + * LocRequestResultData |
| 108 | + */ |
| 109 | + virtual void runConfigurationThreadCb(void); |
| 110 | + |
| 111 | + /*! |
| 112 | + * Calls a ros service until successfully executed or configuration thread cancelled. |
| 113 | + * @param[in/out] service_telegram service request and response |
| 114 | + * @param[in] service_client ros service client |
| 115 | + * @param[in] retry_delay delay before next retry in case of errors |
| 116 | + * @return true on success or false on failure |
| 117 | + */ |
| 118 | + template<typename T> bool callService(T & service_telegram, ros::ServiceClient & service_client, double retry_delay) |
| 119 | + { |
| 120 | + service_telegram.response.success = false; |
| 121 | + while(ros::ok() && m_nh && m_configuration_thread_running && (!service_client.call(service_telegram) || !service_telegram.response.success)) |
| 122 | + { |
| 123 | + ROS_WARN_STREAM("## ERROR ColaConfiguration: service call(" << sick_lidar_localization::Utils::flattenToString(service_telegram.request) << ") failed, response: " << sick_lidar_localization::Utils::flattenToString(service_telegram.response) << ", retrying"); |
| 124 | + ros::Duration(retry_delay).sleep(); |
| 125 | + } |
| 126 | + ROS_INFO_STREAM("ColaConfiguration " << typeid(T).name() << " " << (service_telegram.response.success ? "successfull" : "failed")); |
| 127 | + return service_telegram.response.success; |
| 128 | + } |
| 129 | + |
| 130 | + /* |
| 131 | + * member variables |
| 132 | + */ |
| 133 | + |
| 134 | + ros::NodeHandle* m_nh; ///< ros node handle |
| 135 | + boost::thread* m_configuration_thread; ///< thread to transmit configuration |
| 136 | + bool m_configuration_thread_running; ///< true: m_configuration_thread is running, otherwise false |
| 137 | + |
| 138 | + }; // class ColaServices |
| 139 | + |
| 140 | +} // namespace sick_lidar_localization |
| 141 | +#endif // __SIM_LOC_COLA_CONFIGURATION_H_INCLUDED |
0 commit comments