Homepage | Demos | Overview | Downloads | Tutorials | Reference | Credits |
00001 //-*-c++-*- 00002 #ifndef INCLUDED_AlanBehavior_h_ 00003 #define INCLUDED_AlanBehavior_h_ 00004 00005 #include "Behaviors/BehaviorBase.h" 00006 #include "Motion/MotionManager.h" 00007 #include "Motion/MMAccessor.h" 00008 #include "Shared/SharedObject.h" 00009 #include "Shared/WorldState.h" 00010 #include "Events/EventRouter.h" 00011 #include "Motion/PostureMC.h" 00012 #include "Shared/ERS210Info.h" 00013 00014 //! just a little demo behavior which lifts a leg higher as more pressure is put on a head button 00015 /*! Based on an idea from Alan Chun-ho Ho for a basic demo program */ 00016 class AlanBehavior : public BehaviorBase { 00017 public: 00018 AlanBehavior() 00019 : BehaviorBase(), pose_id(MotionManager::invalid_MC_ID) 00020 {} 00021 00022 virtual void DoStart() { 00023 //call superclass first for housekeeping: 00024 BehaviorBase::DoStart(); 00025 00026 //now do your code: 00027 00028 // creates a PostureMC class to move the joint(s) and adds it to global MotionManager 00029 pose_id=motman->addMotion(SharedObject<PostureMC>()); 00030 // subscribe to sensor updated events through the global EventRouter 00031 erouter->addListener(this,EventBase::sensorEGID,SensorSourceID::UpdatedSID); 00032 } 00033 00034 virtual void DoStop() { 00035 //do your code first: 00036 motman->removeMotion(pose_id); // removes your posture controller 00037 erouter->forgetListener(this); // stops getting events (and timers, if we had any) 00038 00039 //but don't forget to call superclass at the end: 00040 BehaviorBase::DoStop(); 00041 } 00042 00043 virtual void processEvent(const EventBase& event) { 00044 // to be more general, let's check that it's the right event: 00045 if(event.getGeneratorID()==EventBase::sensorEGID) { 00046 //only really works on the 210 model - the others don't have a proper pressure sensor 00047 //(the 220's antenna-thing is close, but doesn't give a continuous range) 00048 if( !(state->robotDesign&WorldState::ERS210Mask) ) 00049 return; 00050 //we'll need to specify the ERS210Info namespace below when 00051 //referencing the button offsets so that this will compile for 00052 //the ERS-7 as well (which lacks front and back head buttons), 00053 //but for your own code, you could leave it off if you weren't 00054 //worried about compiling for other models. 00055 00056 // "checks out" the posture motion command from MotionManager 00057 // (this is the PostureMC we created in DoStart()) 00058 MMAccessor<PostureMC> pose_mc(pose_id); 00059 00060 //Joint offsets are defined in ERS210Info.h, ERS220Info.h and ERS2xxInfo.h 00061 unsigned int joint=LFrLegOffset+RotatorOffset; 00062 00063 //state is a global instantiation of WorldState, kept up to date by framework; 00064 //pressure is in range 0 to 1 - we use the pressure on the front head button here 00065 float pressure=state->buttons[ERS210Info::HeadFrButOffset]; 00066 std::cout << "HeadFrBut Pressure: " << pressure << std::endl; 00067 00068 //outputRanges is a constant table, also defined in ERS210Info.h or ERS220Info.h 00069 float angle=outputRanges[joint][MaxRange]*pressure; 00070 00071 // now send the joint angle to the posture motion command 00072 pose_mc->setOutputCmd(joint,angle); 00073 00074 //let's do the whole thing again with the other head button for the other leg: 00075 // (cutting out a some of the intermediary steps this time) 00076 joint=RFrLegOffset+RotatorOffset; 00077 pose_mc->setOutputCmd(joint,outputRanges[joint][MaxRange]*state->buttons[ERS210Info::HeadBkButOffset]); 00078 00079 // notice that there's no "check in" for pose_mc 00080 // MMAccessor's destructor does this automatically 00081 00082 } else { 00083 //should never happen 00084 cout << "Unhandled Event:" << event.getName() << endl; 00085 } 00086 } 00087 00088 virtual std::string getName() const { 00089 // Name is used for menus, or debugging. 00090 return "AlanBehavior"; 00091 } 00092 00093 static std::string getClassDescription() { 00094 // This string will be shown by the HelpControl or by the tooltips of the Controller GUI 00095 return "Lifts the left/right front legs higher as more pressure is applied to the front/back head buttons"; 00096 } 00097 00098 protected: 00099 MotionManager::MC_ID pose_id; //!< ID of PostureMC, set up in DoStart() and used in processEvent() 00100 }; 00101 00102 /*! @file 00103 * @brief Defines AlanBehavior, a little demo behavior which lifts a leg higher as more pressure is put on the back head button 00104 * @author ejt (Creator) 00105 * 00106 * $Author: ejt $ 00107 * $Name: tekkotsu-2_0 $ 00108 * $Revision: 1.5 $ 00109 * $State: Exp $ 00110 * $Date: 2003/12/23 06:33:42 $ 00111 */ 00112 00113 #endif
Tekkotsu v2.0 |
Generated Wed Jan 21 03:20:27 2004 by Doxygen 1.3.4 |