Fawkes API  Fawkes Development Version
dcm_thread.h
1 
2 /***************************************************************************
3  * dcm_thread.h - Provide NaoQi DCM to Fawkes
4  *
5  * Created: Tue May 31 14:59:30 2011
6  * Copyright 2006-2011 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_NAO_DCM_THREAD_H_
23 #define _PLUGINS_NAO_DCM_THREAD_H_
24 
25 #include <alcommon/alproxy.h>
26 #include <althread/alprocesssignals.h>
27 #include <aspect/blackboard.h>
28 #include <aspect/blocked_timing.h>
29 #include <aspect/clock.h>
30 #include <aspect/configurable.h>
31 #include <aspect/logging.h>
32 #include <core/threading/thread.h>
33 #include <core/utils/lock_vector.h>
34 #include <interfaces/NaoJointPositionInterface.h>
35 #include <interfaces/NaoSensorInterface.h>
36 #include <plugins/nao/aspect/naoqi.h>
37 
38 #include <vector>
39 
40 namespace AL {
41 class ALMemoryFastAccess;
42 }
43 namespace fawkes {
44 class NaoJointStiffnessInterface;
45 }
46 
48  public fawkes::LoggingAspect,
51  public fawkes::ClockAspect,
53  public fawkes::NaoQiAspect
54 {
55 public:
57  virtual ~NaoQiDCMThread();
58 
59  virtual void init();
60  virtual void loop();
61  virtual void finalize();
62 
63  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
64 protected:
65  virtual void
66  run()
67  {
68  Thread::run();
69  }
70 
71 private:
72  void dcm_callback();
73  void read_values();
74  void update_interfaces(fawkes::NaoJointPositionInterface * joint_pos_if,
75  fawkes::NaoJointStiffnessInterface *joint_stiffness_if,
76  fawkes::NaoSensorInterface * sensor_if);
77  void process_messages();
78  std::vector<std::string> parse_servo_bitfield(unsigned int servos);
79 
80  void send_commands(unsigned int servos, const std::string &what, float value, int time_offset);
81  void send_command(const std::string &name, float value, const std::string &kind, int time_offset);
82 
83  int ultrasonic_value(fawkes::NaoSensorInterface::UltrasonicDirection direction);
84 
85  class HighFreqThread;
86  HighFreqThread *highfreq_thread_;
87 
88 private:
89  AL::ALPtr<AL::DCMProxy> dcm_;
90  AL::ALPtr<AL::ALMotionProxy> almotion_;
91  AL::ALPtr<AL::ALMemoryFastAccess> memfa_;
92  bool robocup_version_;
93 
94  AL::ALProcessSignals::ProcessSignalConnection dcm_sigconn_;
95 
96  int dcm_time_;
98 
99  fawkes::NaoJointPositionInterface * joint_pos_highfreq_if_;
100  fawkes::NaoJointPositionInterface * joint_pos_if_;
101  fawkes::NaoJointStiffnessInterface *joint_stiffness_highfreq_if_;
102  fawkes::NaoJointStiffnessInterface *joint_stiffness_if_;
103  fawkes::NaoSensorInterface * sensor_highfreq_if_;
104  fawkes::NaoSensorInterface * sensor_if_;
105 
106  uint8_t robot_version_[4];
108  int usboard_version_;
109 
110  AL::ALValue alljoint_names_;
111 };
112 
113 #endif
NaoJointPositionInterface Fawkes BlackBoard Interface.
virtual void finalize()
Finalize the thread.
Definition: dcm_thread.cpp:543
Thread aspect to access to BlackBoard.
Definition: blackboard.h:33
virtual void init()
Initialize the thread.
Definition: dcm_thread.cpp:263
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:33
Fawkes library namespace.
Thread class encapsulation of pthreads.
Definition: thread.h:45
NaoSensorInterface Fawkes BlackBoard Interface.
NaoJointStiffnessInterface Fawkes BlackBoard Interface.
Thread aspect to use blocked timing.
UltrasonicDirection
This determines the chosen sender/receiver.
Thread to provide DCM to Fawkes.
Definition: dcm_thread.h:47
const char * name() const
Get name of thread.
Definition: thread.h:100
Thread aspect to log output.
Definition: logging.h:32
Thread aspect to get access to NaoQi broker.
Definition: naoqi.h:35
virtual ~NaoQiDCMThread()
Destructor.
Definition: dcm_thread.cpp:258
Thread aspect to access configuration data.
Definition: configurable.h:32
virtual void loop()
Code to execute in the thread.
Definition: dcm_thread.cpp:578
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: dcm_thread.h:66
RobotType
Enumeration describing the actual version of the robot that's being used.
NaoQiDCMThread()
Constructor.
Definition: dcm_thread.cpp:251