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