|
|
|
Using the Walk Remote Control
|
StepTest Demo
|
#ifndef INCLUDED_BallChaser_h_ #define INCLUDED_BallChaser_h_ #include "Behaviors/BehaviorBase.h" #include "Events/EventRouter.h" #include "Events/VisionObjectEvent.h" #include "Motion/HeadPointerMC.h" #include "Motion/MMAccessor.h" #include "Motion/MotionManager.h" #include "Motion/WalkMC.h" #include "Shared/ProjectInterface.h" #include "Shared/WorldState.h" #include "Shared/mathutils.h" using namespace mathutils; class BallChaser : public BehaviorBase { public: BallChaser() : BehaviorBase("BallChaser"), headpointer_id(MotionManager::invalid_MC_ID), walker_id(MotionManager::invalid_MC_ID) {} virtual void DoStart() { BehaviorBase::DoStart(); SharedObject<HeadPointerMC> head_mc; headpointer_id = motman->addPersistentMotion(head_mc); SharedObject<WalkMC> walk_mc; walker_id = motman->addPersistentMotion(walk_mc); erouter->addListener(this,EventBase::visObjEGID,ProjectInterface::visPinkBallSID); } virtual void DoStop() { motman->removeMotion(headpointer_id); motman->removeMotion(walker_id); BehaviorBase::DoStop(); } virtual void processEvent(const EventBase& event) { /* Placeholder. See actual code below */ } static std::string getClassDescription() { return "Follows ball with head and walks whereever the head is pointing"; } virtual std::string getDescription() const { return getClassDescription(); } protected: MotionManager::MC_ID headpointer_id; MotionManager::MC_ID walker_id; }; #endif |
virtual void processEvent(const EventBase& event) { const VisionObjectEvent &visev = *reinterpret_cast<const VisionObjectEvent*>(&event); float const minBallArea = 0.01; // one percent of the camera image // Stop if we lose sight of the ball. if ( visev.getTypeID() == EventBase::deactivateETID || visev.getObjectArea() < minBallArea ) { MMAccessor<WalkMC>(walker_id)->setTargetVelocity(0, 0, 0); return; }; float const ball_horiz_angle = visev.getCenterX() * CameraFOV/2; float const ball_vert_angle = visev.getCenterY() * CameraFOV/2; double const head_pan_angle = state->outputs[HeadOffset+PanOffset]; double const head_tilt_angle = state->outputs[HeadOffset+TiltOffset]; double const new_pan = min(deg2rad(80.0), max(deg2rad(-80.0), head_pan_angle - ball_horiz_angle)); double const new_tilt = min(deg2rad(40.0), max(deg2rad(-20.0), head_tilt_angle - ball_vert_angle)); // Move the head towards the center of the ball. MMAccessor<HeadPointerMC>(headpointer_id)->setJoints(new_tilt, new_pan, 0); // Walk in the direction the head is pointing. MMAccessor<WalkMC> walker_acc(walker_id); if ( fabs(new_pan) < 0.05 ) walker_acc->setTargetVelocity(160, 0, 0); // high speed straight ahead else walker_acc->setTargetVelocity(100, 0, new_pan); // advance, turning towards ball } |
#include "Motion/PIDMC.h" MotionManager::MC_ID relax_id; relax_id = motman->addPersistentMotion(SharedObject<PIDMC>(TailOffset,TailOffset+NumTailJoints,0.0)) |
Using the WaypointWalk Control
|
| |||
File JUNK.WYP |
Loading a Walk Parameter File
|
Developing a New Walk
|
|
|
|