ALMA Computing Group

acscourseMount2LoopImpl.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 *    ALMA - Atacama Large Millimiter Array
00003 *    (c) Associated Universities Inc., 2002 *
00004 *    (c) European Southern Observatory, 2002
00005 *    Copyright by ESO (in the framework of the ALMA collaboration)
00006 *    and Cosylab 2002, All rights reserved
00007 *
00008 *    This library is free software; you can redistribute it and/or
00009 *    modify it under the terms of the GNU Lesser General Public
00010 *    License as published by the Free Software Foundation; either
00011 *    version 2.1 of the License, or (at your option) any later version.
00012 *
00013 *    This library is distributed in the hope that it will be useful,
00014 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 *    Lesser General Public License for more details.
00017 *
00018 *    You should have received a copy of the GNU Lesser General Public
00019 *    License along with this library; if not, write to the Free Software
00020 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00021 *
00022 *
00023 *
00024 * "@(#) $Id: acscourseMount2LoopImpl.cpp,v 1.9 2006/06/22 16:26:30 gchiozzi Exp $"
00025 *
00026 */
00027  
00028 #include <acscourseMount2LoopImpl.h>
00029 
00030 /**********************************
00031  *  Implementation for the thread *
00032  **********************************/
00033 
00034 PositionControlThread::PositionControlThread(
00035     const ACE_CString& name, 
00036     Mount2LoopImpl *_mount_p, 
00037     const ACS::TimeInterval& responseTime, 
00038     const ACS::TimeInterval& sleepTime) :
00039     ACS::Thread(name, responseTime, sleepTime),
00040     mount_p(_mount_p)
00041 {
00042     ACS_TRACE("PositionControlThread::PositionControlThread");
00043 }
00044 
00045 PositionControlThread::~PositionControlThread() 
00046 {
00047     ACS_TRACE("PositionControlThread::~PositionControlThread"); 
00048 }
00049 
00050 void PositionControlThread::runLoop()
00051 {
00052     ACS_TRACE("PositionControlThread::runLoop");
00053 
00054     ACS::Time timestamp;
00055 
00056     double cmdAzValue = mount_p->m_cmdAz_sp->getDevIO()->read(timestamp);
00057     double cmdElValue = mount_p->m_cmdEl_sp->getDevIO()->read(timestamp);
00058     double actAzValue = mount_p->m_actAz_sp->getDevIO()->read(timestamp);
00059     double actElValue = mount_p->m_actEl_sp->getDevIO()->read(timestamp);
00060 
00061 
00062     try
00063         {
00064         /*
00065          * A simple algorithm to simulate the telescope
00066          * mooving.
00067          * Much better can be done!
00068          */
00069         if(cmdAzValue > actAzValue)
00070             mount_p->m_actAz_sp->getDevIO()->write(actAzValue+0.01, timestamp);
00071         if(cmdAzValue < actAzValue)
00072             mount_p->m_actAz_sp->getDevIO()->write(actAzValue-0.01, timestamp);
00073         if(cmdElValue > actElValue)
00074             mount_p->m_actEl_sp->getDevIO()->write(actElValue+0.01, timestamp);
00075         if(cmdElValue < actElValue)
00076             mount_p->m_actEl_sp->getDevIO()->write(actElValue-0.01, timestamp);
00077         }
00078     catch (...) 
00079         {
00080         // Here we have to better handle errors!
00081         ACS_SHORT_LOG((LM_ERROR,"Error accessing devIO"));
00082         }
00083 }
00084 
00085 /* ----------------------------------------------------------------*/
00086 
00087 /************************************
00088  * Implementation for the Component *
00089  ************************************/
00090 
00091 Mount2LoopImpl::Mount2LoopImpl(const ACE_CString &_name, maci::ContainerServices *containerServices) :
00092     CharacteristicComponentImpl(_name, containerServices),
00093     Mount2Impl(_name, containerServices)
00094 {
00095     // ACS_TRACE is used for debugging purposes
00096     ACS_TRACE("::Mount2LoopImpl::Mount2LoopImpl");
00097 
00098 
00099     // Tell the ThreadManager provided to the Component
00100     // by the ContainerServices to instantiate our thread.
00101     Mount2LoopImpl *compPtr = this;
00102     getContainerServices()->getThreadManager()->create<PositionControlThread, Mount2LoopImpl*>("positionControl", compPtr);
00103 
00104     ACS_SHORT_LOG((LM_INFO,"positionControl thread spawned.")); 
00105 }
00106 
00107 Mount2LoopImpl::~Mount2LoopImpl()
00108 {
00109     // ACS_TRACE is used for debugging purposes
00110     ACS_TRACE("::Mount2LoopImpl::~Mount2LoopImpl");
00111 }
00112 
00113 
00114 /* --------------- [ MACI DLL support functions ] -----------------*/
00115 #include <maciACSComponentDefines.h>
00116 MACI_DLL_SUPPORT_FUNCTIONS(Mount2LoopImpl)
00117 /* ----------------------------------------------------------------*/
00118 
00119 
00120 /*___oOo___*/
00121 
00122 
00123 
00124