Tekkotsu Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
MotionExecThread.hGo to the documentation of this file.00001 //-*-c++-*- 00002 #ifndef INCLUDED_MotionExecThread_h_ 00003 #define INCLUDED_MotionExecThread_h_ 00004 00005 #include "IPC/PollThread.h" 00006 #include "Shared/RobotInfo.h" 00007 #include "IPC/MessageQueue.h" 00008 #include "Shared/get_time.h" 00009 #include "Motion/PostureEngine.h" 00010 #include "SharedGlobals.h" 00011 #include <list> 00012 #include <fcntl.h> 00013 00014 #include "local/MotionHook.h" 00015 00016 class RCRegion; 00017 class Resource; 00018 00019 //! description of MotionExecThread 00020 class MotionExecThread : public PollThread { 00021 public: 00022 //! constructor, enables trackPollTime, but not auto-start (call reset() when you're ready to start it) 00023 /*! @arg bl a process lock to ensure mutual exclusion between MotionExecThread::poll() and other threads in the process */ 00024 MotionExecThread(Resource& bl) 00025 : PollThread(0L, FrameTime*NumFrames/globals->timeScale/1000, true), motionLock(bl), 00026 motionBuffers(), motionBufferPos(), lastPoll(-1U) 00027 { 00028 motionBuffers.push_front(new float[NumFrames][NumOutputs]); 00029 for(unsigned int f=0; f<NumFrames; ++f) 00030 for(unsigned int o=0; o<NumOutputs; ++o) 00031 motionBuffers.front()[f][o]=0; 00032 motionBufferPos=motionBuffers.begin(); 00033 } 00034 virtual ~MotionExecThread() { 00035 if(isStarted()) { 00036 stop(); 00037 join(); 00038 } 00039 while(motionBuffers.size()>0) { 00040 delete [] motionBuffers.front(); 00041 motionBuffers.pop_front(); 00042 } 00043 } 00044 00045 virtual void reset(); //!< starts and stops thread as needed, or interrupts thread to reset sleep time if already running 00046 00047 //virtual void start(); 00048 virtual bool poll(); 00049 00050 //! returns time (in milliseconds) of next motion frame -- multiples of FrameTime*NumFrames 00051 static unsigned int getNextMotion() { 00052 unsigned int pd=FrameTime*NumFrames; 00053 return (get_time()/pd+1)*pd; 00054 } 00055 00056 //! writes output values, delayed by SharedGlobals::MotionSimConfig::feedbackDelay, as "sensor" values for outputs without real feedback into SharedGlobals::sensorState 00057 void applyPostureFeedback(); 00058 00059 protected: 00060 virtual bool launched(); 00061 //! resets PollThread::delay and PollThread::period to appropriate values for current SharedGlobals::timeScale value 00062 virtual void interrupted(); 00063 00064 Resource& motionLock; //!< a lock on the motions which should be obtained before updating 00065 00066 std::list<float(*)[NumOutputs]> motionBuffers; 00067 std::list<float(*)[NumOutputs]>::iterator motionBufferPos; 00068 00069 unsigned int lastPoll; 00070 }; 00071 00072 /*! @file 00073 * @brief 00074 * @author Ethan Tira-Thompson (ejt) (Creator) 00075 */ 00076 00077 #endif |
Tekkotsu Hardware Abstraction Layer 5.1CVS |
Generated Mon May 9 05:01:39 2016 by Doxygen 1.6.3 |