Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

TailWagMC.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_TailWagMC_h
00003 #define INCLUDED_TailWagMC_h
00004 
00005 #include "Motion/MotionCommand.h"
00006 #include "Motion/MotionManager.h"
00007 #include "Shared/get_time.h"
00008 #include "math.h"
00009 #include "Shared/ERS7Info.h"
00010 #include "Shared/ERS210Info.h"
00011 #include "Shared/WorldState.h"
00012 
00013 //! A simple motion command for wagging the tail - you can specify period, magnitude, and tilt
00014 class TailWagMC : public MotionCommand {
00015  public:
00016   //!constructor
00017   TailWagMC() : period(500), magnitude(22*M_PI/180), active(true), tilt() { }
00018   //!constructor
00019   TailWagMC(unsigned int cyc_period, float cyc_magnitude) : period(cyc_period), magnitude(cyc_magnitude), active(true), tilt() { }
00020   //!destructor
00021   virtual ~TailWagMC() {}
00022   virtual int updateOutputs() {
00023     if(!active)
00024       return 0;
00025     if(state->robotDesign&WorldState::ERS210Mask) {
00026       for(unsigned int i=0; i<NumFrames; i++)
00027         pans[i].set(sin((2*M_PI*(get_time()+i*FrameTime))/period)*magnitude); //bug fix thanks L.A.Olsson AT herts ac uk
00028       motman->setOutput(this,ERS210Info::TailOffset+PanOffset,pans);
00029       motman->setOutput(this,ERS210Info::TailOffset+TiltOffset,tilt);
00030       return tilt.weight>0?2:1;
00031     } else if(state->robotDesign&WorldState::ERS7Mask) {
00032       for(unsigned int i=0; i<NumFrames; i++)
00033         pans[i].set(sin((2*M_PI*(get_time()+i*FrameTime))/period)*magnitude); //bug fix thanks L.A.Olsson AT herts ac uk
00034       motman->setOutput(this,ERS7Info::TailOffset+PanOffset,pans);
00035       motman->setOutput(this,ERS7Info::TailOffset+TiltOffset,tilt);
00036       return tilt.weight>0?2:1;
00037     } else
00038       return 0;
00039   }
00040   virtual int isDirty() { return active; }
00041   virtual int isAlive() { return true; }
00042 
00043   void setPeriod(unsigned int p) { period=p; } //!< sets the period of time between swings, in milliseconds
00044   unsigned int getPeriod() { return period; } //!< gets the period of time between swings, in milliseconds
00045   void setMagnitude(double mag) { magnitude=mag; } //!< sets the magnitude of swings, in radians
00046   double getMagnitude() { return magnitude; } //!< gets the magnitude of swings, in radians
00047   void setTilt(double r) { tilt.set(r,1); }  //!< sets the tilt of the tail while wagging, in radians
00048   void unsetTilt() { tilt.unset(); } //!< makes the tilt control unspecified, will let something else control tilt
00049   double getTilt() { return tilt.value; }  //!< sets the tilt of the tail while wagging, in radians
00050   void setActive(bool a) { active=a; } //!< turns the tail wagger on or off
00051   bool getActive() { return active; } //!< returns true if this is currently trying to wag the tail
00052   
00053  protected:
00054   unsigned int period; //!< period of time between swings, in milliseconds
00055   double magnitude; //!< magnitude of swings, in radians
00056   bool active; //!< true if this is currently trying to wag the tail
00057   OutputCmd tilt; //!< holds current setting for the tilt joint
00058   OutputCmd pans[NumFrames]; //!< holds commands for planning ahead the wagging
00059 };
00060 
00061 /*! @file
00062  * @brief Defines TailWagMC, which will wag the tail on a ERS-210 robot.
00063  * @author ejt (Creator)
00064  *
00065  * $Author: ejt $
00066  * $Name: tekkotsu-2_4_1 $
00067  * $Revision: 1.8 $
00068  * $State: Exp $
00069  * $Date: 2005/04/06 20:36:00 $
00070  */
00071 
00072 #endif
00073 

Tekkotsu v2.4.1
Generated Tue Aug 16 16:32:49 2005 by Doxygen 1.4.4