Fawkes API  Fawkes Development Version
openrobotino_com_thread.h
1 /***************************************************************************
2  * com_thread.h - Robotino com thread
3  *
4  * Created: Thu Sep 11 11:43:42 2014
5  * Copyright 2011-2014 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_OPENROBOTINO_COM_THREAD_H_
22 #define __PLUGINS_ROBOTINO_OPENROBOTINO_COM_THREAD_H_
23 
24 #include "com_thread.h"
25 #include <core/threading/thread.h>
26 #include <aspect/configurable.h>
27 #include <aspect/blackboard.h>
28 
29 #include <utils/time/time.h>
30 
31 #ifdef HAVE_OPENROBOTINO_API_1
32 # include <rec/robotino/com/Com.h>
33 namespace rec {
34  namespace sharedmemory {
35  template<typename SharedType> class SharedMemory;
36  }
37  namespace iocontrol {
38  namespace robotstate {
39  class State;
40  }
41  namespace remotestate {
42  class SetState;
43  }
44  }
45 }
46 #else
47 namespace rec {
48  namespace robotino {
49  namespace api2 {
50  class Com;
51  class AnalogInputArray;
52  class Bumper;
53  class DigitalInputArray;
54  class DistanceSensorArray;
55  class ElectricalGripper;
56  class Gyroscope;
57  class MotorArray;
58  class Odometry;
59  class PowerManagement;
60  }
61  }
62 }
63 #endif
64 
65 namespace fawkes {
66  class Mutex;
67  class Clock;
68  class TimeWait;
69 }
70 
72 : public RobotinoComThread,
73 #ifdef HAVE_OPENROBOTINO_API_1
74  public rec::robotino::com::Com,
75 #endif
77 {
78  public:
80  virtual ~OpenRobotinoComThread();
81 
82  virtual void init();
83  virtual void once();
84  virtual void loop();
85  virtual void finalize();
86 
87  virtual bool is_connected();
88 
89  virtual void set_gripper(bool opened);
90  virtual bool is_gripper_open();
91  virtual void set_speed_points(float s1, float s2, float s3);
92  virtual void get_act_velocity(float &a1, float &a2, float &a3, unsigned int &seq, fawkes::Time &t);
93  virtual void get_odometry(double &x, double &y, double &phi);
94 
95  virtual void reset_odometry();
96  virtual void set_bumper_estop_enabled(bool enabled);
97  virtual void set_motor_accel_limits(float min_accel, float max_accel);
98  virtual void set_digital_output(unsigned int digital_out, bool enable);
99 
100  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
101  protected: virtual void run() { Thread::run(); }
102 
103  private:
104 #ifdef HAVE_OPENROBOTINO_API_1
105  using rec::robotino::com::Com::sensorState;
106  virtual void updateEvent();
107 #endif
108  void process_api_v1();
109  void process_api_v2();
110 
111  private:
112  std::string cfg_hostname_;
113  bool cfg_quit_on_disconnect_;
114  unsigned int cfg_sensor_update_cycle_time_;
115  bool cfg_gripper_enabled_;
116  bool cfg_enable_gyro_;
117 
118  fawkes::TimeWait *time_wait_;
119  unsigned int last_seqnum_;
120 
121 #ifdef HAVE_OPENROBOTINO_API_1
122  rec::robotino::com::Com *com_;
123  fawkes::Mutex *state_mutex_;
124  unsigned int active_state_;
125  rec::iocontrol::remotestate::SensorState sensor_states_[2];
126  fawkes::Time times_[2];
127 
128  rec::sharedmemory::SharedMemory<rec::iocontrol::robotstate::State> *statemem_;
129  rec::iocontrol::robotstate::State *state_;
130 
131  rec::iocontrol::remotestate::SetState *set_state_;
132 
133 #else
134  rec::robotino::api2::Com *com_;
135  rec::robotino::api2::AnalogInputArray *analog_inputs_com_;
136  rec::robotino::api2::Bumper *bumper_com_;
137  rec::robotino::api2::DigitalInputArray *digital_inputs_com_;
138  rec::robotino::api2::DistanceSensorArray *distances_com_;
139  rec::robotino::api2::ElectricalGripper *gripper_com_;
140  rec::robotino::api2::Gyroscope *gyroscope_com_;
141  rec::robotino::api2::MotorArray *motors_com_;
142  rec::robotino::api2::Odometry *odom_com_;
143  rec::robotino::api2::PowerManagement *power_com_;
144 #endif
145 };
146 
147 
148 #endif
149 
virtual void once()
Execute an action exactly once.
Fawkes library namespace.
virtual void init()
Initialize the thread.
A class for handling time.
Definition: time.h:91
virtual void set_gripper(bool opened)
Open or close gripper.
Thread to communicate with Robotino via OpenRobotino API (v1 or v2).
virtual void get_act_velocity(float &a1, float &a2, float &a3, unsigned int &seq, fawkes::Time &t)
Get actual velocity.
virtual void set_motor_accel_limits(float min_accel, float max_accel)
Set acceleration limits of motors.
virtual void set_bumper_estop_enabled(bool enabled)
Enable or disable emergency stop on bumper contact.
virtual void reset_odometry()
Reset odometry to zero.
virtual bool is_connected()
Check if we are connected to OpenRobotino.
Virtual base class for thread that communicates with a Robotino.
Definition: com_thread.h:39
Thread aspect to access configuration data.
Definition: configurable.h:35
virtual void set_speed_points(float s1, float s2, float s3)
Set speed points for wheels.
virtual void run()
Stub to see name in backtrace for easier debugging.
virtual void finalize()
Finalize the thread.
virtual void set_digital_output(unsigned int digital_out, bool enable)
Set digital output state.
virtual bool is_gripper_open()
Check if gripper is open.
Mutex mutual exclusion lock.
Definition: mutex.h:32
virtual void loop()
Code to execute in the thread.
virtual ~OpenRobotinoComThread()
Destructor.
Time wait utility.
Definition: wait.h:32
virtual void get_odometry(double &x, double &y, double &phi)
Get current odometry.