Fawkes API  Fawkes Development Version
reverse_angle.cpp
1 
2 /***************************************************************************
3  * reverse_angle.cpp - Reverse the angle in which laser data is taken
4  *
5  * Created: Wed Jan 06 17:15:38 2010
6  * Copyright 2006-2011 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include "reverse_angle.h"
24 
25 #include <core/exception.h>
26 #include <utils/math/angle.h>
27 #include <utils/time/time.h>
28 #include <cstdlib>
29 
30 /** @class LaserReverseAngleDataFilter "reverse_angle.h"
31  * Reverse the angle of beams.
32  * This filter will reverse the direction in which the beams are stored.
33  * If the original interface stores the data in clockwise direction, the
34  * outcome will be in counter-clockwise direction and vice versa. This is
35  * required for example to convert between the (clockwise) RCSoftX angles,
36  * and the (counter-clockwise) angles in the Fawkes coordinate system.
37  * @author Tim Niemueller
38  */
39 
40 /** Constructor.
41  * @param filter_name name of this filter instance
42  * @param in_data_size number of entries input value arrays
43  * @param in vector of input arrays
44  */
46  unsigned int in_data_size,
47  std::vector<LaserDataFilter::Buffer *> &in)
48  : LaserDataFilter(filter_name, in_data_size, in, in.size())
49 {
50 }
51 
52 void
54 {
55  const unsigned int vecsize = std::min(in.size(), out.size());
56  const unsigned int arrsize = std::min(in_data_size, out_data_size);
57  for (unsigned int a = 0; a < vecsize; ++a) {
58  out[a]->frame = in[a]->frame;
59  out[a]->timestamp->set_time(in[a]->timestamp);
60  float *inbuf = in[a]->values;
61  float *outbuf = out[a]->values;
62  for (unsigned int i = 0; i < arrsize; ++i) {
63  outbuf[i] = inbuf[arrsize - i];
64  }
65  }
66 }
std::vector< Buffer * > out
Vector of output arrays.
Definition: filter.h:76
void filter()
Filter the incoming data.
LaserReverseAngleDataFilter(const std::string filter_name, unsigned int data_size, std::vector< LaserDataFilter::Buffer *> &in)
Constructor.
unsigned int out_data_size
Number of entries in output arrays.
Definition: filter.h:73
std::vector< Buffer * > in
Vector of input arrays.
Definition: filter.h:75
unsigned int in_data_size
Number of entries in input arrays.
Definition: filter.h:74
Laser data filter.
Definition: filter.h:32