Homepage Demos Overview Downloads Tutorials Reference
Credits

EmergencyStopMC.h

Go to the documentation of this file.
00001 #ifndef INCLUDED_EmergencyStopMC_h
00002 #define INCLUDED_EmergencyStopMC_h
00003 
00004 #include "PostureMC.h"
00005 #include "LedEngine.h"
00006 
00007 //!overrides all joints with high priority freeze, blinks tail pink/red/blue cycle
00008 /*! Uses MotionCommand::kEmergencyPriority.  Monitors the feedback on joints and
00009  *  adjusts joints to react to pressures above a certain threshold.  This allows
00010  *  you to mold the body while it's in this mode, while retaining enough stiffness
00011  *  to hold against gravity.
00012  *
00013  *  This MotionCommand is intended to always be left running.  It polls WorldState::state
00014  *  for a double-tap on the back button, which causes it to set its joint values.
00015  *  to whatever their current state is.  LEDs are left blank, except the tail,
00016  *  which is used to indicate that the emergency stop is on.
00017  *
00018  *  A second double-tap will cause it to set all joints to 0 weight
00019  *
00020  *  The tail LEDs only ever go up to .5, so that if you really care whether the tail
00021  *  light was set by an underlying behavior/motion, you should be able to tell by
00022  *  looking closely (if blue is going from .5 to 1, that's because it's already set)
00023  */
00024 class EmergencyStopMC : public PostureMC {
00025  public:
00026   EmergencyStopMC(); //!< constructor
00027   virtual ~EmergencyStopMC() {} //!< destructor
00028   virtual int updateOutputs(); //!< checks for feedback or double tap
00029 
00030   virtual void takeSnapshot(); //!< records current positions of joints
00031   virtual void takeSnapshot(const WorldState* st); //!< records current positions of joints
00032 
00033   void setActive(bool a); //!< allows you to modify #active
00034   bool getActive() { return active; } //!< returns #active
00035   void setStopped(bool p, bool sound=true); //!< allows you to modify #paused
00036   bool getStopped() const { return paused; } //!< returns #paused
00037   void setDblTapDuration(unsigned int d) { duration=d; } //!< sets #duration
00038   unsigned int getDblTapDuration() const { return duration; } //!< returns #duration
00039   void setResetSensitivity(float r) { pidcutoff=static_cast<unsigned char>(r*255); } //!< takes a value [0,1] to set #pidcutoff
00040   float getResetSensitivity() { return pidcutoff/255.0; } //!< returns a value [0-1], corresponding to #pidcutoff
00041 
00042  protected:
00043   void freezeJoints(); //!< code to execute when locking joints
00044   void releaseJoints(); //!< code to execute when releasing joints
00045   static bool trigger(); //!< true when the trigger condition is active
00046 
00047   bool paused; //!< true if the joints are current locked up
00048   bool stilldown; //!< true if the back button was down on last updateJointCmds
00049   bool active; //!< true if the EmergencyStopMC is monitoring the back button (if false, won't pause on a double-tap)
00050   unsigned int period; //!< period of cycles on tail LEDs
00051   unsigned int timeoflastbtn; //!< time of the last button press
00052   unsigned int timeofthisbtn; //!< time of the current button press
00053   unsigned int timeoflastfreeze; //!< the time estop was last turned on
00054   unsigned int duration; //!<the maximum time (in milliseconds) of consecutive button-down's to count as a double tap
00055   unsigned char piddutyavgs[NumPIDJoints]; //!< a running average of PID feedback ("duty"), so one bad reading doesn't cause a movement, need a consistent pressure
00056   unsigned char pidcutoff; //!<abs pid duty cycle above which we just reset joint to current
00057   LedEngine ledengine; //!< used to do LED effects on the tail
00058 };
00059 
00060 /*! @file
00061  * @brief Describes EmergencyStopMC, overrides all joints, allows modelling, blinks tail
00062  * @author ejt (Creator)
00063  *
00064  * $Author: ejt $
00065  * $Name: tekkotsu-2_2 $
00066  * $Revision: 1.11 $
00067  * $State: Exp $
00068  * $Date: 2004/08/30 20:26:45 $
00069  */
00070 
00071 #endif

Tekkotsu v2.2
Generated Tue Oct 19 14:19:13 2004 by Doxygen 1.3.9.1