Homepage Demos Overview Downloads Tutorials Reference
Credits
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Search

DriveMeBehavior.cc

Go to the documentation of this file.
00001 #include "BehaviorBase.h"
00002 #include "Motion/MotionManager.h"
00003 #include "Motion/WalkMC.h"
00004 #include "Motion/MotionSequenceMC.h"
00005 #include "Motion/PostureEngine.h"
00006 #include "Shared/SharedObject.h"
00007 #include "Events/EventRouter.h"
00008 #include "Events/EventBase.h"
00009 
00010 #include "DriveMeBehavior.h"
00011 
00012 #include <iostream>
00013 #include <string>
00014 #include <stdio.h>
00015 
00016 /* A very simple behavior that asks the user for WalkMC walking parameters
00017  * and a walk duration. The AIBO walks accordingly and then stands up, then
00018  * asks again. And so on and so on. */
00019 
00020 // ctor
00021 DriveMeBehavior::DriveMeBehavior()
00022   : BehaviorBase(),
00023     walker_id(MotionManager::invalid_MC_ID),
00024     stand_id(MotionManager::invalid_MC_ID),
00025     stand(),
00026     last_dx(0), last_dy(0), last_da(0), last_time(5000)
00027 {
00028   // Construct the standing up motion that the aibo does after it's done moving
00029   stand->setPlayTime(700); // 700 milliseconds to stand up
00030   stand->setPose(PostureEngine("/ms/data/motion/stand.pos"));
00031 }
00032 
00033 void DriveMeBehavior::DoStart()
00034 {
00035   BehaviorBase::DoStart();
00036   // Insert walker into motion manager
00037   walker_id = motman->addMotion(SharedObject<WalkMC>());
00038   // Insert standing pose into motion manager
00039   stand_id = motman->addMotion(stand, MotionManager::kStdPriority+1, false);
00040   // We listen to timers
00041   erouter->addListener(this, EventBase::timerEGID);
00042   // Turn on timer that goes off now to take us immediately to processEvent
00043   erouter->addTimer(this, 0, 0, false);
00044 }
00045 
00046 void DriveMeBehavior::DoStop()
00047 {
00048   BehaviorBase::DoStop();
00049   // We're not listening to timers anymore.
00050   erouter->removeTimer(this);
00051   // We're not listening to *anything* anymore! (also kills timers on its own)
00052   erouter->forgetListener(this);
00053   // remove walker and stander from motion manager
00054   motman->removeMotion(walker_id);
00055   motman->removeMotion(stand_id);
00056 }
00057 
00058 // The only events we'll ever get are timer events.
00059 void DriveMeBehavior::processEvent(const EventBase& event)
00060 {
00061   using namespace std;
00062 
00063   WalkMC *walker;
00064   MotionSequenceMC<MotionSequence::SizeSmall> *standp;
00065 
00066   // oh, OK, make sure it's a timer event
00067   if(event.getGeneratorID() != EventBase::timerEGID) return;
00068 
00069   // Check out walker and stop us moving
00070   walker = (WalkMC*)motman->checkoutMotion(walker_id);
00071   walker->setTargetVelocity(0,0,0);
00072   motman->checkinMotion(walker_id);
00073 
00074   // Stand us up right now.
00075   standp = (MotionSequenceMC<MotionSequence::SizeSmall>*)motman->checkoutMotion(stand_id);
00076   standp->play();
00077   motman->checkinMotion(stand_id);
00078 
00079   // get new motions
00080   string instr;
00081   cout << "dx? [" << last_dx << "] >\t";
00082   cout.flush();
00083   getline(cin, instr);
00084   sscanf(instr.data(), "%lf", &last_dx);
00085 
00086   cout << "dy? [" << last_dy << "] >\t";
00087   cout.flush();
00088   getline(cin, instr);
00089   sscanf(instr.data(), "%lf", &last_dy);
00090 
00091   cout << "da? [" << last_da << "] >\t";
00092   cout.flush();
00093   getline(cin, instr);
00094   sscanf(instr.data(), "%lf", &last_da);
00095 
00096   cout << "time? [" << last_time << "] >\t";
00097   cout.flush();
00098   getline(cin, instr);
00099   sscanf(instr.data(), "%u", &last_time);
00100 
00101   // Start moving again; start timer; check in walker
00102   walker = (WalkMC*)motman->checkoutMotion(walker_id);
00103   walker->setTargetVelocity(last_dx, last_dy, last_da);
00104   erouter->addTimer(this, 0, last_time, false);
00105   motman->checkinMotion(walker_id);
00106 }
00107 
00108 /*! @file
00109  * @brief Implements DriveMeBehavior, a very simple behavior that asks the user for WalkMC walking parameters and a walk duration.
00110  * @author tss (Creator)
00111  *
00112  * $Author: ejt $
00113  * $Name: tekkotsu-1_4_1 $
00114  * $Revision: 1.3 $
00115  * $State: Exp $
00116  * $Date: 2003/06/12 23:41:39 $
00117  */
00118 

Tekkotsu v1.4
Generated Sat Jul 19 00:06:30 2003 by Doxygen 1.3.2