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
25#include "controller.h"
26
27/** @class KatanaMotionThread "motion_thread.h"
28 * Katana motion thread base class.
29 * Base class for motion threads for the Katana.
30 *
31 * When implementing a motion thread ensure that you read the sensor data
32 * during the communication with the arm. The main (act) thread will not do
33 * this as not to interfere with motion thread communication. You can use
34 * code like this:
35 * @code
36 * _katana->GetBase()->GetSCT()->arr[0].recvDAT(); // update sensor values
37 * @endcode
38 * @author Tim Niemueller.
39 */
40
41/** Constructor.
42 * @param thread_name name of the thread
43 * @param katana katana controller base class
44 * @param logger logger
45 */
48 fawkes::Logger * logger)
49: Thread(thread_name, Thread::OPMODE_CONTINUOUS)
50{
51 _katana = katana;
52 _logger = logger;
53 _finished = false;
54 _error_code = 0;
55}
56
57/** Did the motion finish already?
58 * @return true if the motion was finished, flase otherwise
59 */
60bool
62{
63 return _finished;
64}
65
66/** Error code.
67 * @return error code, one or more of the ERROR_* constants from the
68 * KatanaInterface or'ed.
69 */
70unsigned int
72{
73 return _error_code;
74}
75
76/** Reset for next execution.
77 * Resets _finished and _error_code. If you override this method call the base
78 * class method in your method. It should be used to do anything that is required
79 * to be able to run the thread again.
80 */
81void
83{
84 _finished = false;
85 _error_code = 0;
86}
fawkes::Logger * _logger
Logger.
Definition: motion_thread.h:52
virtual void reset()
Reset for next execution.
fawkes::RefPtr< fawkes::KatanaController > _katana
Katana object for interaction with the arm.
Definition: motion_thread.h:48
bool _finished
Set to true when motion is finished, to false on reset.
Definition: motion_thread.h:50
unsigned int error_code() const
Error code.
unsigned int _error_code
Set to the desired error code on error.
Definition: motion_thread.h:54
KatanaMotionThread(const char *thread_name, fawkes::RefPtr< fawkes::KatanaController > katana, fawkes::Logger *logger)
Constructor.
bool finished() const
Did the motion finish already?
Interface for logging.
Definition: logger.h:42