Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

RelaxBehavior.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include "Behaviors/BehaviorBase.h"
00003 #include "Motion/PIDMC.h"
00004 #include "IPC/SharedObject.h"
00005 #include "Motion/MotionManager.h"
00006 #include "Motion/MotionPtr.h"
00007 
00008 //! A behavior that sets all the pids to zero for the tail and legs servos.
00009 /*! This should hopefully make the robot quieter and consume less power. */
00010 class RelaxBehavior : public BehaviorBase {
00011 public:
00012   //! contstructor
00013   RelaxBehavior() : BehaviorBase("RelaxBehavior"), 
00014     pid(SharedObject<PIDMC>(0)) // initialize PIDMC using constructor with "power level" of 0 for all joints
00015   {}
00016   
00017   virtual void doStart() {
00018     std::cout << "Relaxing servos." << std::endl;
00019     
00020     // You could also change the priority level so that anytime
00021     // a joint is not in use it goes limp (try kBackgroundPriority)
00022     addMotion(pid,PERSISTENT,MotionManager::kHighPriority);
00023 
00024     // if you want to keep some joints from being turned off, e.g.:
00025     //pid->setJointPowerLevel(HeadOffset+TiltOffset,1);
00026     // (or you could change the contructor too...)
00027     // http://www.tekkotsu.org/dox/classPIDMC.html
00028   }
00029 
00030   virtual void doStop() {
00031     std::cout << "Relax terminated." << std::endl;
00032     removeMotion(pid);
00033     // this "one-shot" version of doing things will restore the PIDs on our way out
00034     // note the explicit call to motman with a naked SharedObject instead of using
00035     // BehaviorBase::addMotion or MotionPtr Ñ otherwise this would be immediately
00036     // stopped again as the behavior exits and not have time to do anything
00037     motman->addPrunableMotion(SharedObject<PIDMC>(1));
00038   }
00039 
00040   static std::string getClassDescription() { return "Sets PID parameters for all applicable joints to 0, allowing the joints to move freely, reducing noise and power consumption"; }
00041 
00042   virtual std::string getDescription() const { return getClassDescription(); }
00043 
00044 protected:
00045   MotionPtr<PIDMC> pid; //!< the pid motion command
00046 };
00047 
00048 REGISTER_BEHAVIOR_MENU_OPT(RelaxBehavior,"Background Behaviors",BEH_NONEXCLUSIVE);
00049 
00050 /*! @file
00051  * @brief Defines RelaxBehavior, which sets all the PIDs to zero for the tail and legs servos.
00052  * @author Erik Berglund <tekkotsu.dev.spam.345@blog.no> (Creator)
00053  * @author ejt (Modifications)
00054  */

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:50 2016 by Doxygen 1.6.3