Fawkes API Fawkes Development Version
imu_cruizcore_xg1010.h
1
2/***************************************************************************
3 * imu_cruizcore_xg1010.h - Retrieve IMU data from CruizCore XG1010
4 *
5 * Created: Sun Jun 22 21:41:38 2014
6 * Copyright 2008-2014 Tim Niemueller [www.niemueller.de]
7 ****************************************************************************/
8
9/* This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Library General Public License for more details.
18 *
19 * Read the full text in the LICENSE.GPL file in the doc directory.
20 */
21
22#ifndef _PLUGINS_IMU_IMU_CRUIZCORE_XG1010_H_
23#define _PLUGINS_IMU_IMU_CRUIZCORE_XG1010_H_
24
25#include "acquisition_thread.h"
26#include "imu_cruizcore_xg1010.h"
27
28#include <boost/asio.hpp>
29#include <boost/lambda/bind.hpp>
30#include <boost/lambda/lambda.hpp>
31#include <string>
32#include <thread>
33
34#define CRUIZCORE_XG1010_PACKET_SIZE 8
35
36namespace fawkes {
37class Mutex;
38class Time;
39#ifdef USE_TIMETRACKER
40class TimeTracker;
41#endif
42} // namespace fawkes
43
45{
46public:
47 CruizCoreXG1010AcquisitionThread(std::string &cfg_name, std::string &cfg_prefix, bool continuous);
48
49 virtual void init();
50 virtual void finalize();
51 virtual void loop();
52
53private:
54 void open_device();
55 void close_device();
56 void resync();
57 void send_init_packet(bool enable_transfer);
58
59 void parse_packet();
60 void check_deadline();
61
62#if BOOST_VERSION < 104800
63 void
64 handle_read(boost::system::error_code ec, size_t bytes_read)
65 {
66 ec_ = ec;
67 bytes_read_ = bytes_read;
68 }
69#endif
70
71private:
72 std::string cfg_serial_;
73 unsigned int cfg_baud_rate_;
74 unsigned int cfg_freq_;
75
76 boost::asio::io_service io_service_;
77 boost::asio::serial_port serial_;
78 boost::asio::io_service::work io_service_work_;
79 boost::asio::deadline_timer deadline_;
80 boost::asio::streambuf input_buffer_;
81
82 unsigned int receive_timeout_;
83 unsigned char in_packet_[CRUIZCORE_XG1010_PACKET_SIZE];
84
85 boost::system::error_code ec_;
86 size_t bytes_read_;
87
88#ifdef USE_TIMETRACKER
90 unsigned int tt_loopcount_;
91 unsigned int ttc_full_loop_;
92 unsigned int ttc_read_;
93 unsigned int ttc_catch_up_;
94 unsigned int ttc_parse_;
95#endif
96};
97
98#endif
IMU acquisition thread for CruizCore XG1010 gyros.
virtual void finalize()
Finalize the thread.
CruizCoreXG1010AcquisitionThread(std::string &cfg_name, std::string &cfg_prefix, bool continuous)
Constructor.
virtual void init()
Initialize the thread.
virtual void loop()
Code to execute in the thread.
IMU acqusition thread.
Time tracking utility.
Definition: tracker.h:37
Fawkes library namespace.