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 EntryPoint; 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(EntryPoint& bl) 00025 : PollThread(0L, FrameTime*NumFrames/globals->timeScale/1000, true,false), motionLock(bl), 00026 motionBuffers(), motionBufferPos(), curPose(), 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 curPose.setWeights(1); 00034 } 00035 virtual ~MotionExecThread() { 00036 if(isStarted()) { 00037 stop(); 00038 join(); 00039 } 00040 while(motionBuffers.size()>0) { 00041 delete [] motionBuffers.front(); 00042 motionBuffers.pop_front(); 00043 } 00044 } 00045 00046 virtual void reset(); //!< starts and stops thread as needed, or interrupts thread to reset sleep time if already running 00047 00048 //virtual void start(); 00049 virtual bool poll(); 00050 00051 //! returns time (in milliseconds) of next motion frame -- multiples of FrameTime*NumFrames 00052 static unsigned int getNextMotion() { 00053 unsigned int pd=FrameTime*NumFrames; 00054 return (get_time()/pd+1)*pd; 00055 } 00056 00057 //! returns a posture storing the "current" output values, delayed by SharedGlobals::MotionSimConfig::feedbackDelay 00058 const PostureEngine& getPostureFeedback(); 00059 00060 protected: 00061 virtual bool launched(); 00062 //! resets PollThread::delay and PollThread::period to appropriate values for current SharedGlobals::timeScale value 00063 virtual void interrupted(); 00064 00065 EntryPoint& motionLock; //!< a lock on the motions which should be obtained before updating 00066 00067 std::list<float(*)[NumOutputs]> motionBuffers; 00068 std::list<float(*)[NumOutputs]>::iterator motionBufferPos; 00069 PostureEngine curPose; 00070 00071 unsigned int lastPoll; 00072 }; 00073 00074 /*! @file 00075 * @brief 00076 * @author Ethan Tira-Thompson (ejt) (Creator) 00077 * 00078 * $Author: ejt $ 00079 * $Name: tekkotsu-4_0 $ 00080 * $Revision: 1.2 $ 00081 * $State: Exp $ 00082 * $Date: 2007/10/12 16:55:05 $ 00083 */ 00084 00085 #endif |
Tekkotsu Hardware Abstraction Layer 4.0 |
Generated Thu Nov 22 01:00:53 2007 by Doxygen 1.5.4 |