gusimplewhiteboard
FilteredOneDimSonar.hpp
Go to the documentation of this file.
1
2/*
3 * FilteredOneDimSonar.h
4 * gusimplewhiteboard
5 *
6 * Created by Vlad Estivill-Castro on 18/06/2014..
7 * Copyright (c) 2013, 2014 Vlad Estivill-Castro. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials
19 * provided with the distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgement:
23 *
24 * This product includes software developed by Rene Hexel.
25 *
26 * 4. Neither the name of the author nor the names of contributors
27 * may be used to endorse or promote products derived from this
28 * software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
34 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
37 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
38 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
39 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 *
42 * -----------------------------------------------------------------------
43 * This program is free software; you can redistribute it and/or
44 * modify it under the above terms or under the terms of the GNU
45 * General Public License as published by the Free Software Foundation;
46 * either version 2 of the License, or (at your option) any later version.
47 *
48 * This program is distributed in the hope that it will be useful,
49 * but WITHOUT ANY WARRANTY; without even the implied warranty of
50 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51 * GNU General Public License for more details.
52 *
53 * You should have received a copy of the GNU General Public License
54 * along with this program; if not, see http://www.gnu.org/licenses/
55 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
56 * Fifth Floor, Boston, MA 02110-1301, USA.
57 *
58 */
59
60
61
62/****************** I M P O R T A N T */
63/* is <class_name>_DEFINED */
64/***************************************/
65
66#ifndef FilteredOneDimSonar_DEFINED
67#define FilteredOneDimSonar_DEFINED
68
69#include <cstdlib>
70#include <sstream>
71#include <gu_util.h>
73
74
75namespace guWhiteboard{
80{
81
82 public:
84 FilteredOneDimSonar(bool isVisible = false,
85 int16_t distance =0,
86 int32_t frameCounter =0
87 ): wb_filteredsonarobject(isVisible,distance,frameCounter)
88 { /* */ }
89
90
92 FilteredOneDimSonar(const FilteredOneDimSonar &other):wb_filteredsonarobject(other.isVisible(), other.distance() ,other.frameCounter())
93 {
94 }
95
98 FilteredOneDimSonar (const wb_filteredsonarobject &other):wb_filteredsonarobject(other.isVisible(), other.distance() ,other.frameCounter())
99 { }
100
103 {
104 set_isVisible ( other.isVisible() );
105 set_distance ( other.distance() );
106 set_frameCounter ( other.frameCounter() );
107
108 return *this;
109 }
110
113 {
114 set_isVisible ( other.isVisible() );
115 set_distance ( other.distance() );
116 set_frameCounter ( other.frameCounter() );
117
118 return *this;
119 }
120#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
121#define SEPARATOR_IS_COMMA ','
122#define SEPARATOR_IS_COLON ':'
123#define IS_VISIBLE_ID 'I'
124
126 FilteredOneDimSonar(const std::string &names) { from_string(names); }
127
129 FilteredOneDimSonar(const char *names) { from_string(names); }
130
132 std::string description() const
133 {
134 std::ostringstream ss;
135
136 if ( isVisible())
137 { ss<<"ISvisible"<< SEPARATOR_IS_COMMA << distance() << SEPARATOR_IS_COMMA; }
138 else ss << "NOTvisible"<< SEPARATOR_IS_COMMA << SEPARATOR_IS_COMMA;
139
140 ss << "FRAME" << SEPARATOR_IS_COLON << frameCounter() << SEPARATOR_IS_COMMA;
141 return ss.str();
142 }
143
145 void from_string(const std::string &str)
146 {
147 std::istringstream iss(str);
148 std::string token;
149 if (getline(iss, token, SEPARATOR_IS_COMMA))
150 { if (IS_VISIBLE_ID==token[0])
151 { set_isVisible ( true );
152 set_distance ( 0 );
153 set_frameCounter ( 0 );
154 std::string comaDel (1,SEPARATOR_IS_COMMA);
155 std::size_t found = str.find(comaDel);
156 if (std::string::npos!=found )
157 { std::string strSecond=str.substr (found+comaDel.size());
158 std::istringstream second_iss(strSecond);
159 if (getline(second_iss, token, SEPARATOR_IS_COMMA))
160 {
161 int16_t distance_value = int16_t ( atoi(token.c_str()));
162 set_distance ( distance_value);
163 std::string colonDel (1,SEPARATOR_IS_COLON);
164 found = strSecond.find(colonDel);
165 if (std::string::npos!=found )
166 { std::string strThird=strSecond.substr (found+colonDel.size());
167 std::istringstream third_iss(strThird);
168 if (getline(third_iss, token, SEPARATOR_IS_COMMA))
169 {
170 int32_t frameValue=int32_t ( atoi(token.c_str()));
171 set_frameCounter (frameValue);
172
173 }
174
175
176 }
177
178 }
179
180 }
181
182
183 }
184 else
185 { *this=FilteredOneDimSonar(); }
186
187
188
189 }
190 else
191 {
192 *this=FilteredOneDimSonar();
193 }
194 }
195#endif // WHITEBOARD_POSTER_STRING_CONVERSION
196
197
198};
199} //namespace
200
201#endif // FilteredOneDimSonar
#define IS_VISIBLE_ID
#define SEPARATOR_IS_COMMA
#define SEPARATOR_IS_COLON
Class for for one filtered sonar message.
FilteredOneDimSonar(bool isVisible=false, int16_t distance=0, int32_t frameCounter=0)
designated constructor
FilteredOneDimSonar & operator=(const FilteredOneDimSonar &other)
copy assignment operator
FilteredOneDimSonar(const std::string &names)
string constructor
std::string description() const
convert to a string; string serialization
FilteredOneDimSonar(const char *names)
const char * constructor
void from_string(const std::string &str)
build from string
FilteredOneDimSonar(const wb_filteredsonarobject &other)
BASECONSTRUCTOR: INTERESTING !!!!
FilteredOneDimSonar(const FilteredOneDimSonar &other)
copy constructor
FilteredOneDimSonar & operator=(const wb_filteredsonarobject &other)
copy assignment operator:INTERESTING!!!
/file APM_Interface.h
Simple sonar information for the whiteboard.
gusimplewhiteboard