Fawkes API  Fawkes Development Version
direct_com_thread.h
1 /***************************************************************************
2  * direct_com_thread.h - Robotino com thread for direct communication
3  *
4  * Created: Mon Apr 04 11:48:36 2016
5  * Copyright 2011-2016 Tim Niemueller [www.niemueller.de]
6  ****************************************************************************/
7 
8 /* This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Library General Public License for more details.
17  *
18  * Read the full text in the LICENSE.GPL file in the doc directory.
19  */
20 
21 #ifndef __PLUGINS_ROBOTINO_DIRECT_COM_THREAD_H_
22 #define __PLUGINS_ROBOTINO_DIRECT_COM_THREAD_H_
23 
24 #include "com_thread.h"
25 #include "direct_com_message.h"
26 #include <core/threading/thread.h>
27 #include <aspect/configurable.h>
28 #include <aspect/blackboard.h>
29 
30 #include <utils/time/time.h>
31 
32 #include <memory>
33 #include <boost/asio.hpp>
34 #include <boost/thread/mutex.hpp>
35 
37 
38 namespace fawkes {
39  class Mutex;
40  class TimeWait;
41 
42  class BatteryInterface;
43  class RobotinoSensorInterface;
44  class IMUInterface;
45 }
46 
48 : public RobotinoComThread,
50 {
51  public:
53  virtual ~DirectRobotinoComThread();
54 
55  virtual void init();
56  virtual void once();
57  virtual void loop();
58  bool prepare_finalize_user();
59 
60  virtual void finalize();
61 
62  virtual bool is_connected();
63 
64  virtual void set_gripper(bool opened);
65  virtual bool is_gripper_open();
66  virtual void set_speed_points(float s1, float s2, float s3);
67  virtual void get_act_velocity(float &a1, float &a2, float &a3, unsigned int &seq, fawkes::Time &t);
68  virtual void get_odometry(double &x, double &y, double &phi);
69 
70  virtual void reset_odometry();
71  virtual void set_bumper_estop_enabled(bool enabled);
72  virtual void set_motor_accel_limits(float min_accel, float max_accel);
73  virtual void set_digital_output(unsigned int digital_out, bool enable);
74 
75  virtual void set_desired_vel(float vx, float vy, float omega);
76 
77  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
78  protected: virtual void run() { Thread::run(); }
79 
80  private:
81  std::string find_device_udev();
82  bool find_controld3();
83  void open_device(bool wait_replies);
84  void close_device();
85  void flush_device();
86  void check_deadline();
87  void request_data();
88  void handle_request_data(const boost::system::error_code &ec);
89  void handle_nodata(const boost::system::error_code &ec);
90  void update_nodata_timer();
91 
92  void drive();
93  void handle_drive(const boost::system::error_code &ec);
94 
96  void send_message(DirectRobotinoComMessage &msg);
98  send_and_recv(DirectRobotinoComMessage &msg);
99  void process_message(DirectRobotinoComMessage::pointer m);
100 
101  private:
102  std::string cfg_device_;
103  bool cfg_enable_gyro_;
104  unsigned int cfg_sensor_update_cycle_time_;
105  bool cfg_gripper_enabled_;
106  float cfg_rpm_max_;
107  unsigned int cfg_nodata_timeout_;
108  unsigned int cfg_drive_update_interval_;
109  unsigned int cfg_read_timeout_;
110  bool cfg_log_checksum_errors_;
111  unsigned int cfg_checksum_error_recover_;
112  unsigned int cfg_checksum_error_critical_;
113 
114  bool opened_;
115  unsigned int open_tries_;
116 
117  unsigned int checksum_errors_;
118 
119  uint8_t digital_outputs_;
120 
121  boost::asio::io_service io_service_;
122  boost::asio::serial_port serial_;
123  boost::asio::io_service::work io_service_work_;
124  boost::asio::deadline_timer deadline_;
125  boost::asio::streambuf input_buffer_;
126  boost::mutex io_mutex_;
127 
128  boost::asio::deadline_timer request_timer_;
129  boost::asio::deadline_timer nodata_timer_;
130  boost::asio::deadline_timer drive_timer_;
131 
132 };
133 
134 
135 #endif
136 
Fawkes library namespace.
virtual void run()
Code to execute in the thread.
Definition: thread.cpp:939
A class for handling time.
Definition: time.h:91
std::shared_ptr< DirectRobotinoComMessage > pointer
shared pointer to direct com message
Robotino communication message.
Virtual base class for thread that communicates with a Robotino.
Definition: com_thread.h:39
Thread to communicate with Robotino via OpenRobotino API (v1 or v2).
virtual void run()
Stub to see name in backtrace for easier debugging.
Thread aspect to access configuration data.
Definition: configurable.h:35