Fawkes API  Fawkes Development Version
motion_thread.cpp
1 
2 /***************************************************************************
3  * motion_thread.h - Katana one-time thread interface for motions
4  *
5  * Created: Wed Jun 10 11:41:36 2009
6  * Copyright 2006-2009 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include "motion_thread.h"
24 #include "controller.h"
25 
26 /** @class KatanaMotionThread "motion_thread.h"
27  * Katana motion thread base class.
28  * Base class for motion threads for the Katana.
29  *
30  * When implementing a motion thread ensure that you read the sensor data
31  * during the communication with the arm. The main (act) thread will not do
32  * this as not to interfere with motion thread communication. You can use
33  * code like this:
34  * @code
35  * _katana->GetBase()->GetSCT()->arr[0].recvDAT(); // update sensor values
36  * @endcode
37  * @author Tim Niemueller.
38  */
39 
40 /** Constructor.
41  * @param thread_name name of the thread
42  * @param katana katana controller base class
43  * @param logger logger
44  */
45 KatanaMotionThread::KatanaMotionThread(const char * thread_name,
47  fawkes::Logger *logger)
48  : Thread(thread_name, Thread::OPMODE_CONTINUOUS)
49 {
50  _katana = katana;
51  _logger = logger;
52  _finished = false;
53  _error_code = 0;
54 }
55 
56 
57 /** Did the motion finish already?
58  * @return true if the motion was finished, flase otherwise
59  */
60 bool
62 {
63  return _finished;
64 }
65 
66 
67 /** Error code.
68  * @return error code, one or more of the ERROR_* constants from the
69  * KatanaInterface or'ed.
70  */
71 unsigned int
73 {
74  return _error_code;
75 }
76 
77 
78 /** Reset for next execution.
79  * Resets _finished and _error_code. If you override this method call the base
80  * class method in your method. It should be used to do anything that is required
81  * to be able to run the thread again.
82  */
83 void
85 {
86  _finished = false;
87  _error_code = 0;
88 }
fawkes::RefPtr< fawkes::KatanaController > _katana
Katana object for interaction with the arm.
Definition: motion_thread.h:48
fawkes::Logger * _logger
Logger.
Definition: motion_thread.h:52
KatanaMotionThread(const char *thread_name, fawkes::RefPtr< fawkes::KatanaController > katana, fawkes::Logger *logger)
Constructor.
bool finished() const
Did the motion finish already?
virtual void reset()
Reset for next execution.
unsigned int error_code() const
Error code.
bool _finished
Set to true when motion is finished, to false on reset.
Definition: motion_thread.h:50
unsigned int _error_code
Set to the desired error code on error.
Definition: motion_thread.h:54
Interface for logging.
Definition: logger.h:34