Fawkes API Fawkes Development Version
acquisition_thread.h
1
2/***************************************************************************
3 * acquisition_thread.h - Thread that retrieves the laser data
4 *
5 * Created: Wed Oct 08 13:41:02 2008
6 * Copyright 2006-2008 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#ifndef _PLUGINS_LASER_ACQUISITION_THREAD_H_
24#define _PLUGINS_LASER_ACQUISITION_THREAD_H_
25
26#include <aspect/clock.h>
27#include <aspect/configurable.h>
28#include <aspect/logging.h>
29#include <core/threading/thread.h>
30
31namespace fawkes {
32class Mutex;
33class Configuration;
34class Logger;
35class Time;
36} // namespace fawkes
37
42{
43public:
44 LaserAcquisitionThread(const char *thread_name);
46
47 bool lock_if_new_data();
48 void unlock();
49
51
52 const float * get_distance_data();
53 const float * get_echo_data();
55
56 unsigned int get_distance_data_size();
57 unsigned int get_echo_data_size();
58
59 /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
60protected:
61 virtual void
63 {
64 Thread::run();
65 }
66
67protected:
68 void alloc_distances(unsigned int num_distances);
69 void alloc_echoes(unsigned int num_echoes);
70 void reset_distances();
71 void reset_echoes();
72
73protected:
76
78 float *_distances;
79 float *_echoes;
80
81 unsigned int _distances_size;
82 unsigned int _echoes_size;
83};
84
85#endif
Laser acqusition thread.
virtual void pre_init(fawkes::Configuration *config, fawkes::Logger *logger)=0
Pre initialization.
const float * get_echo_data()
Get echo data.
unsigned int get_echo_data_size()
Get echo data size.
const fawkes::Time * get_timestamp()
Get timestamp of data.
LaserAcquisitionThread(const char *thread_name)
Constructor.
void alloc_echoes(unsigned int num_echoes)
Allocate echoes array.
unsigned int _echoes_size
Assign this the size of the _echoes array.
const float * get_distance_data()
Get distance data.
float * _distances
Allocate a float array and copy your distance values measured in meters here.
fawkes::Mutex * _data_mutex
Lock while writing to distances or echoes array or marking new data.
bool _new_data
Set to true in your loop if new data is available.
void alloc_distances(unsigned int num_distances)
Allocate distances array.
void reset_distances()
Reset all distance values to NaN.
void unlock()
Unlock data,.
unsigned int _distances_size
Assign this the size of the _distances array.
float * _echoes
Allocate a float array and copy your echo values here.
virtual void run()
Stub to see name in backtrace for easier debugging.
unsigned int get_distance_data_size()
Get distance data size.
fawkes::Time * _timestamp
Time when the most recent data was received.
bool lock_if_new_data()
Lock data if fresh.
void reset_echoes()
Reset all distance values to NaN.
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:34
Thread aspect to access configuration data.
Definition: configurable.h:33
Configuration * config
This is the Configuration member used to access the configuration.
Definition: configurable.h:41
Interface for configuration handling.
Definition: config.h:68
Interface for logging.
Definition: logger.h:42
Thread aspect to log output.
Definition: logging.h:33
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:41
Mutex mutual exclusion lock.
Definition: mutex.h:33
Thread class encapsulation of pthreads.
Definition: thread.h:46
A class for handling time.
Definition: time.h:93
Fawkes library namespace.