00001 #include "StartupBehavior.h"
00002
00003 #include "Behaviors/Controller.h"
00004 #include "Behaviors/Controls/BatteryCheckControl.h"
00005 #include "Behaviors/Controls/ControlBase.h"
00006 #include "Behaviors/Controls/HelpControl.h"
00007 #include "Behaviors/Controls/RebootControl.h"
00008 #include "Behaviors/Controls/ShutdownControl.h"
00009
00010 #include "Motion/MotionCommand.h"
00011 #include "Motion/PostureMC.h"
00012 #include "Motion/EmergencyStopMC.h"
00013 #include "Motion/PIDMC.h"
00014 #include "Motion/MotionSequenceMC.h"
00015 #include "Motion/MMAccessor.h"
00016
00017 #include "Vision/Vision.h"
00018
00019 #include "SoundPlay/SoundManager.h"
00020
00021 #include "Shared/ERS210Info.h"
00022
00023 StartupBehavior theStartup;
00024 BehaviorBase& startupBehavior=theStartup;
00025
00026 StartupBehavior::StartupBehavior()
00027 : BehaviorBase(), spawned(),setup(),
00028 stop_id(MotionManager::invalid_MC_ID),
00029 pid_id(MotionManager::invalid_MC_ID)
00030 {
00031 AddReference();
00032 }
00033
00034 StartupBehavior::~StartupBehavior() {cout << "Goodbye" << endl;}
00035
00036 void StartupBehavior::DoStart() {
00037 BehaviorBase::DoStart();
00038
00039
00040 pid_id=motman->addMotion(SharedObject<PIDMC>(0),MotionManager::kEmergencyPriority+1,false);
00041
00042 erouter->addTimer(this,0,4*FrameTime*NumFrames,true);
00043
00044
00045 const SharedObject<EmergencyStopMC> stop;
00046 stop->LoadFile("/ms/data/motion/liedown.pos");
00047 stop->setStopped(true,false);
00048
00049 stop_id=motman->addMotion(stop,MotionManager::kEmergencyPriority);
00050
00051
00052 BatteryCheckControl batchk;
00053 batchk.activate(MotionManager::invalid_MC_ID,NULL);
00054
00055
00056 batchk.deactivate();
00057
00058
00059 Controller * controller=new Controller;
00060 controller->DoStart();
00061 controller->setEStopID(stop_id);
00062 controller->setRoot(SetupMenus());
00063 wireless->setReceiver(sout, Controller::console_callback);
00064 spawned.push_back(controller);
00065
00066 sndman->PlayFile("roar.wav");
00067
00068
00069
00070
00071
00072
00073
00074 }
00075
00076 void StartupBehavior::DoStop() {
00077 for(std::vector<BehaviorBase*>::iterator it=spawned.begin(); it!=spawned.end(); it++)
00078 (*it)->DoStop();
00079 motman->removeMotion(stop_id);
00080 BehaviorBase::DoStop();
00081 }
00082
00083
00084 void StartupBehavior::processEvent(const EventBase&) {
00085 static unsigned int start_time=-1U;
00086 const unsigned int tot_time=2047;
00087 if(start_time==-1U) {
00088 start_time=get_time();
00089 MMAccessor<EmergencyStopMC>(stop_id)->takeSnapshot();
00090 } else {
00091 float power=(get_time()-start_time)/(float)tot_time;
00092 if(power>1)
00093 power=1;
00094 { MMAccessor<PIDMC>(pid_id)->setAllPowerLevel(power); }
00095 if(state->robotDesign & WorldState::ERS210Mask)
00096 { MMAccessor<EmergencyStopMC>(stop_id)->setOutputCmd(ERS210Info::MouthOffset,outputRanges[ERS210Info::MouthOffset][MaxRange]); }
00097 }
00098 if((get_time()-start_time)>=tot_time) {
00099 erouter->removeTimer(this);
00100 motman->removeMotion(pid_id);
00101 pid_id=MotionManager::invalid_MC_ID;
00102 }
00103 }
00104
00105
00106
00107
00108
00109
00110
00111 ControlBase*
00112 StartupBehavior::SetupMenus() {
00113 std::cout << "CONTROLLER-INIT..." << std::flush;
00114 ControlBase* root=new ControlBase("Root Control");
00115 setup.push(root);
00116
00117
00118 {
00119 SetupModeSwitch();
00120 SetupBackgroundBehaviors();
00121 SetupTekkotsuMon();
00122 SetupStatusReports();
00123 SetupFileAccess();
00124 SetupWalkEdit();
00125 addItem(new ControlBase("Shutdown?"));
00126 startSubMenu();
00127 {
00128 addItem(new ShutdownControl());
00129 addItem(new RebootControl());
00130 }
00131 endSubMenu();
00132 addItem(new HelpControl(root));
00133 }
00134
00135 if(endSubMenu()!=root)
00136 cout << "\n*** WARNING *** menu setup stack corrupted" << endl;
00137 cout << "DONE" << endl;
00138 return root;
00139 }
00140
00141 void
00142 StartupBehavior::startSubMenu() {
00143 setup.push(setup.top()->getSlots().back());
00144 }
00145
00146 void
00147 StartupBehavior::addItem(ControlBase * control) {
00148 setup.top()->pushSlot(control);
00149 }
00150
00151 ControlBase*
00152 StartupBehavior::endSubMenu() {
00153 ControlBase * tmp=setup.top();
00154 setup.pop();
00155 return tmp;
00156 }