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 
32 #include <string>
33 #include <thread>
34 
35 #define CRUIZCORE_XG1010_PACKET_SIZE 8
36 
37 namespace fawkes {
38  class Mutex;
39  class Time;
40 #ifdef USE_TIMETRACKER
41  class TimeTracker;
42 #endif
43 }
44 
46 {
47  public:
48  CruizCoreXG1010AcquisitionThread(std::string &cfg_name, std::string &cfg_prefix,
49  bool continuous);
50 
51  virtual void init();
52  virtual void finalize();
53  virtual void loop();
54 
55  private:
56  void open_device();
57  void close_device();
58  void resync();
59  void send_init_packet(bool enable_transfer);
60 
61  void parse_packet();
62  void check_deadline();
63 
64 #if BOOST_VERSION < 104800
65  void handle_read(boost::system::error_code ec, size_t bytes_read)
66  {
67  ec_ = ec;
68  bytes_read_ = bytes_read;
69  }
70 #endif
71 
72  private:
73  std::string cfg_serial_;
74  unsigned int cfg_baud_rate_;
75  unsigned int cfg_freq_;
76 
77  boost::asio::io_service io_service_;
78  boost::asio::serial_port serial_;
79  boost::asio::io_service::work io_service_work_;
80  boost::asio::deadline_timer deadline_;
81  boost::asio::streambuf input_buffer_;
82 
83  unsigned int receive_timeout_;
84  unsigned char in_packet_[CRUIZCORE_XG1010_PACKET_SIZE];
85 
86  boost::system::error_code ec_;
87  size_t bytes_read_;
88 
89 #ifdef USE_TIMETRACKER
91  unsigned int tt_loopcount_;
92  unsigned int ttc_full_loop_;
93  unsigned int ttc_read_;
94  unsigned int ttc_catch_up_;
95  unsigned int ttc_parse_;
96 #endif
97 };
98 
99 
100 #endif
Fawkes library namespace.
IMU acqusition thread.
Time tracking utility.
Definition: tracker.h:38
IMU acquisition thread for CruizCore XG1010 gyros.