snark
thin.h
1 // This file is part of snark, a generic and flexible library
2 // for robotics research.
3 //
4 // Copyright (C) 2011 The University of Sydney
5 //
6 // snark is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // snark is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 // for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with snark. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef SNARK_SENSORS_VELODYNE_THIN_THIN_H_
20 #define SNARK_SENSORS_VELODYNE_THIN_THIN_H_
21 
22 #include <stdlib.h>
23 #include <snark/sensors/velodyne/db.h>
24 #include <snark/sensors/velodyne/packet.h>
25 #include <snark/sensors/velodyne/impl/get_laser_return.h>
26 #include <snark/sensors/velodyne/thin/focus.h>
27 
28 namespace snark { namespace velodyne { namespace thin {
29 
31 void thin( velodyne::packet& packet, float rate );
32 
34 template < typename Random >
35 void thin( velodyne::packet& packet, float rate, Random& random );
36 
38 template < typename Random >
39 void thin( velodyne::packet& packet, const focus& focus, const db& db, Random& random );
40 
42 std::size_t serialize( const velodyne::packet& packet, char* buf );
43 
45 velodyne::packet deserialize( const char* buf );
46 
48 void deserialize( velodyne::packet& packet, const char* buf );
49 
51 enum { maxBlockBufferSize = 64 * 2 + 2 + 64 / 8 + 1 };
52 
54 enum { maxBufferSize = 12 / 2 * maxBlockBufferSize + 1 };
55 
56 template < typename Random >
57 void thin( velodyne::packet& packet, float rate, Random& random )
58 {
59  for( unsigned int block = 0; block < packet.blocks.size(); ++block )
60  {
61  for( unsigned int laser = 0; laser < packet.blocks[block].lasers.size(); ++laser )
62  {
63  if( random() > rate ) { packet.blocks[block].lasers[laser].range = 0; }
64  }
65  }
66 }
67 
68 template < typename Random >
69 void thin( velodyne::packet& packet, const focus& focus, const velodyne::db& db, double angularSpeed, Random& random )
70 {
71  bool upper = true;
72  for( unsigned int block = 0; block < packet.blocks.size(); ++block, upper = !upper )
73  {
74  for( unsigned int laser = 0; laser < packet.blocks[block].lasers.size(); ++laser )
75  {
76  velodyne::laser_return r = impl::getlaser_return( packet, block, laser, boost::posix_time::not_a_date_time, angularSpeed );
77  double azimuth = db.lasers[r.id].azimuth( r.azimuth );
78  double range = db.lasers[r.id].range( r.range );
79  if( !focus.has( range, azimuth, 0, random ) ) { packet.blocks[block].lasers[laser].range = 0; }
80  }
81  }
82 }
83 
84 } } } // namespace snark { namespace velodyne { namespace thin {
85 
86 #endif /*SNARK_SENSORS_VELODYNE_THIN_THIN_H_*/