sensacq_thread.cpp

00001 
00002 /***************************************************************************
00003  *  sensaqt_thread.cpp - Katana sensor acqusition thread
00004  *
00005  *  Created: Fri Jun 12 15:08:56 2009
00006  *  Copyright  2006-2009  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022 
00023 #include "sensacq_thread.h"
00024 
00025 #include <cstdlib>
00026 #include <kniBase.h>
00027 
00028 using namespace fawkes;
00029 
00030 /** @class KatanaSensorAcquisitionThread "sensacq_thread.h"
00031  * Katana sensor acquisition thread.
00032  * This thread runs continuously and acquires data from the sensor. Since the
00033  * operation is blocking and may take several miliseconds it is done concurrently
00034  * to the main loop at specified intervals.
00035  * @author Tim Niemueller
00036  */
00037 
00038 /** Constructor.
00039  * @param katana katana linear motion base class
00040  * @param logger logger
00041  */
00042 KatanaSensorAcquisitionThread::KatanaSensorAcquisitionThread(fawkes::RefPtr<CLMBase> katana,
00043                                                              fawkes::Logger *logger)
00044   : Thread("KatanaSensorAcqusitionThread", Thread::OPMODE_WAITFORWAKEUP)
00045 {
00046   __katana  = katana;
00047   __logger  = logger;
00048   __enabled = false;
00049 
00050   __sensor_ctrl = &__katana->GetBase()->GetSCT()->arr[0];
00051 }
00052 
00053 
00054 /** Set whether data acquisition is enabled or not.
00055  * In general the thread should only be woken up if sensor data can be acquired.
00056  * But for safety data acqusition can also be turned off to be safe against
00057  * spurious wakeups. Additionally, this method will acquire the loop mutex,
00058  * thereby assuring that a possibly running loop has finished.
00059  * @param enabled true to enable sensor data acquisition, false to disable.
00060  */
00061 void
00062 KatanaSensorAcquisitionThread::set_enabled(bool enabled)
00063 {
00064   loop_mutex->lock();
00065   __enabled = enabled;
00066   loop_mutex->unlock();
00067 }
00068 
00069 
00070 void
00071 KatanaSensorAcquisitionThread::loop()
00072 {
00073   if (__enabled) {
00074     try {
00075       __sensor_ctrl->recvDAT();
00076     } catch (/*KNI*/::ParameterReadingException &e) {
00077       __logger->log_warn(name(), "Failed to read parameters: %s", e.what());
00078     } catch (/*KNI*/::Exception &e) {
00079       __logger->log_warn(name(), "Updating sensor values failed: %s", e.what());
00080     }
00081   }
00082 }

Generated on 1 Mar 2011 for Fawkes API by  doxygen 1.6.1