From: Fernyqc <fe...@us...> - 2005-07-04 06:47:42
|
Update of /cvsroot/robotflow/RobotFlow/Behaviors/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21713 Modified Files: Makefile.am Added Files: BumperStall.cc Log Message: - BumperStall behavior - Adding BumperStall.cc to the Makefile.am Index: Makefile.am =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Behaviors/src/Makefile.am,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Makefile.am 3 Jul 2005 04:35:47 -0000 1.18 --- Makefile.am 4 Jul 2005 06:47:32 -0000 1.19 *************** *** 35,39 **** RangeFashion.cc \ SafeVelocityPat.cc \ ! AvoidPat.cc libBehaviors_la_LDFLAGS = -release $(LT_RELEASE) --- 35,40 ---- RangeFashion.cc \ SafeVelocityPat.cc \ ! AvoidPat.cc \ ! BumperStall.cc libBehaviors_la_LDFLAGS = -release $(LT_RELEASE) --- NEW FILE: BumperStall.cc --- /* Copyright (C) 2002 Dominic Letourneau (dom...@co...) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _BUMPER_STALL_CC_ #define _BUMPER_STALL_CC_ #include "Behavior.h" using namespace std; using namespace FD; namespace RobotFlow { class BumperStall; DECLARE_NODE(BumperStall) REGISTER_BEHAVIOR(BumperStall) /*Node * @name BumperStall * @category RobotFlow:Behaviors * @description No description available * * @input_name NBBUMPERS * @input_type int * @input_description Number of bumpers * * @input_name BUMPERSTATE * @input_type int * @input_description Global value of the bumpers state * * @input_name ACTIVATED * @input_type bool * @input_description Behavior activation * * @output_name VELOCITY * @output_type int * @output_description Velocity value * * @output_name ROTATION * @output_type int * @output_description Velocity value * * @output_name EXPLOITATION * @output_description Behavior exploitation * * @parameter_name BEHAVIOR_TYPE * @parameter_type int * @parameter_value 0 * @parameter_description Type of action to do on bumper contact * END*/ class BumperStall : public Behavior { //inputs int nbID; int stateID; //outputs int rotationID; int velocityID; //parameters int m_type; public: BumperStall(string nodeName, ParameterSet params) : Behavior(nodeName, params, "BumperStall") { //inputs nbID = addInput("NBBUMPERS"); stateID = addInput("BUMPERSTATE"); //outputs rotationID = addOutput("ROTATION"); velocityID = addOutput("VELOCITY"); // Parameters m_type = dereference_cast<int> (parameters.get("BEHAVIOR_TYPE")); } void calculate_behavior(int output_id, int count, Buffer &out) { ObjectRef nbRef = getInput(nbID,count); ObjectRef stateRef = getInput(stateID,count); if (!nbRef->isNil() && !stateRef->isNil()){ // Get inputs int nb = dereference_cast<int>(nbRef); int state = dereference_cast<int>(stateRef); // Apply selected behavior bool nilOutputs = true; int rotation = 0; int velocity = 0; switch(m_type){ case 0: // Stall the robot if a bumper is pressed nilOutputs = (state == 0); break; default: std::cout << "BumperStall -> Unknown behavior type" << std::endl; } // Outputs the results if(nilOutputs){ (*outputs[velocityID].buffer)[count] = nilObject; (*outputs[rotationID].buffer)[count] = nilObject; } else{ (*outputs[velocityID].buffer)[count] = ObjectRef(Int::alloc(velocity)); (*outputs[rotationID].buffer)[count] = ObjectRef(Int::alloc(rotation)); } } else { //invalid outputing nothing (*outputs[velocityID].buffer)[count] = nilObject; (*outputs[rotationID].buffer)[count] = nilObject; } }//calculate_behavior }; }//namespace RobotFlow #endif |