From: Dominic L. <ma...@us...> - 2004-10-28 15:03:45
|
Update of /cvsroot/robotflow/RobotFlow/MARIE/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31325 Modified Files: Makefile.am Added Files: extractMarieCommandBehavior.cpp extractMarieCommandCamera.cpp newMarieCommandCamera.cpp newMarieDataCamera.cpp Log Message: added extract and new for MARIE objects Index: Makefile.am =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/MARIE/src/Makefile.am,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Makefile.am 26 Oct 2004 19:47:03 -0000 1.18 --- Makefile.am 28 Oct 2004 15:03:29 -0000 1.19 *************** *** 29,33 **** MarieRequestSystem.cpp \ newMarieRequestSystem.cpp \ ! newMarieCommandBehavior.cpp install-data-local: --- 29,36 ---- MarieRequestSystem.cpp \ newMarieRequestSystem.cpp \ ! extractMarieCommandBehavior.cpp \ ! newMarieCommandBehavior.cpp \ ! extractMarieCommandCamera.cpp \ ! newMarieCommandCamera.cpp install-data-local: --- NEW FILE: extractMarieCommandBehavior.cpp --- /* * MARIE - Mobile and Autonomous Robotics Integration Environment * Copyright (C) 2004 Dominic Letourneau / Carle Cote * * 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 * * You can contact MARIE development team at http://marie.sourceforge.net */ #include <sstream> #include <string> #include "MarieCommandBehavior.h" #include "MarieXMLDataFactory.h" #include "Behavior.h" #include "Vector.h" #include "MarieDataNull.h" namespace marie { //forward declaration class extractMarieCommandBehavior; DECLARE_NODE(extractMarieCommandBehavior) /*Node * * @name extractMarieCommandBehavior * @category RobotFlow:MARIE:COMMAND * @description Extract data in the FlowDesigner format from MarieCommandBehavior * * @input_name COMMAND_BEHAVIOR * @input_type MarieCommandBehavior * @input_description The MarieCommandBehavior object * * @output_name ROBOTFLOW_ACTIVATION * @output_description RobotFlow activation vector * @output_type Vector<int> * END*/ using namespace std; class extractMarieCommandBehavior : public BufferedNode { private: //intputs int m_behaviorCommandID; //outputs int m_activationID; public: extractMarieCommandBehavior(string nodeName, ParameterSet params) : BufferedNode(nodeName,params) { //inputs m_behaviorCommandID = addInput("COMMAND_BEHAVIOR"); //outputs m_activationID = addOutput("ROBOTFLOW_ACTIVATION"); } void calculate(int output_id, int count, Buffer &out) { try { RCPtr<MarieCommandBehavior> command = getInput(m_behaviorCommandID,count); //create behavior activation vector (RobotFlow) Vector<int> *vect = Vector<int>::alloc(Behavior::get_behavior_size()); //get known behavior names vector<string>& behaviorNames = Behavior::get_behaviors(); const std::map<std::string, bool> &activationMap = command->getActivationMap(); //copy activation values if they exists, else set activation to false (0) for (int i = 0; i < vect->size(); i++) { //check if behavior exists if (activationMap.find(behaviorNames[i]) != activationMap.end()) { (*vect)[i] = (int) command->getActivation(behaviorNames[i]); } else { //default, not activated (*vect)[i] = 0; } } //output result out[count] = ObjectRef(vect); } catch (BaseException *e) { e->print(cerr); e->add(new GeneralException("Unable to process",__FILE__,__LINE__)); throw e; } } };//class extractMarieCommandBehavior }//namespace marie --- NEW FILE: extractMarieCommandCamera.cpp --- /* * MARIE - Mobile and Autonomous Robotics Integration Environment * Copyright (C) 2004 Dominic Letourneau / Carle Cote * * 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 * * You can contact MARIE development team at http://marie.sourceforge.net */ #include <sstream> #include <string> #include "MarieCommandCamera.h" #include "MarieXMLDataFactory.h" #include "Behavior.h" #include "Vector.h" #include "MarieDataNull.h" namespace marie { //forward declaration class extractMarieCommandCamera; DECLARE_NODE(extractMarieCommandCamera) /*Node * * @name extractMarieCommandCamera * @category RobotFlow:MARIE:COMMAND * @description Extract data in the FlowDesigner format from MarieCommandBehavior * * @input_name COMMAND_CAMERA * @input_type MarieCommandCamera * @input_description The MarieCommandCamera object * * @output_name REL_BRIGHTNESS * @output_type int * @output_description output brightness * * @output_name REL_CONTRAST * @output_type int * @output_description output contrast * * @output_name REL_PAN * @output_type int * @output_description output pan * * @output_name REL_TILT * @output_type int * @output_description output tilt * * @output_name REL_ZOOM * @output_type int * @output_description output zoom * * @output_name ABS_BRIGHTNESS * @output_type int * @output_description output brightness * * @output_name ABS_CONTRAST * @output_type int * @output_description output contrast * * @output_name ABS_PAN * @output_type int * @output_description output pan * * @output_name ABS_TILT * @output_type int * @output_description output tilt * * @output_name ABS_ZOOM * @output_type int * @output_description output zoom * END*/ using namespace std; class extractMarieCommandCamera : public BufferedNode { private: //intputs int m_commandCameraID; //outputs int m_relBrightnessOutID; int m_relContrastOutID; int m_relPanOutID; int m_relTiltOutID; int m_relZoomOutID; int m_absBrightnessOutID; int m_absContrastOutID; int m_absPanOutID; int m_absTiltOutID; int m_absZoomOutID; public: extractMarieCommandCamera(string nodeName, ParameterSet params) : BufferedNode(nodeName,params) { //inputs m_commandCameraID = addInput("COMMAND_CAMERA"); //outputs m_relBrightnessOutID = addOutput("REL_BRIGHTNESS"); m_relContrastOutID = addOutput("REL_CONTRAST"); m_relPanOutID = addOutput("REL_PAN"); m_relTiltOutID = addOutput("REL_TILT"); m_relZoomOutID = addOutput("REL_ZOOM"); m_absBrightnessOutID = addOutput("ABS_BRIGHTNESS"); m_absContrastOutID = addOutput("ABS_CONTRAST"); m_absPanOutID = addOutput("ABS_PAN"); m_absTiltOutID = addOutput("ABS_TILT"); m_absZoomOutID = addOutput("ABS_ZOOM"); } void calculate(int output_id, int count, Buffer &out) { try { RCPtr<MarieCommandCamera> command = getInput(m_commandCameraID,count); int relPan, relTilt, relZoom, relContrast, relBrightness = 0; int absPan, absTilt, absZoom, absContrast, absBrightness = 0; std::bitset<10> state = command->getState(); //get camera data relPan = command->getRelativePan(); relTilt = command->getRelativeTilt(); relZoom = command->getRelativeZoom(); relContrast = command->getRelativeContrast(); relBrightness = command->getRelativeBrightness(); absPan = command->getAbsolutePan(); absTilt = command->getAbsoluteTilt(); absZoom = command->getAbsoluteZoom(); absContrast = command->getAbsoluteContrast(); absBrightness = command->getAbsoluteBrightness(); if(state[CommandCamera::REL_PAN] == 1) (*outputs[m_relPanOutID].buffer)[count] = ObjectRef(Int::alloc(relPan)); else (*outputs[m_relPanOutID].buffer)[count] = nilObject; if(state[CommandCamera::REL_TILT] == 1) (*outputs[m_relTiltOutID].buffer)[count] = ObjectRef(Int::alloc(relTilt)); else (*outputs[m_relTiltOutID].buffer)[count] = nilObject; if(state[CommandCamera::REL_ZOOM] == 1) (*outputs[m_relZoomOutID].buffer)[count] = ObjectRef(Int::alloc(relZoom)); else (*outputs[m_relZoomOutID].buffer)[count] = nilObject; if(state[CommandCamera::REL_BRIGHTNESS] == 1) (*outputs[m_relBrightnessOutID].buffer)[count] = ObjectRef(Int::alloc(relBrightness)); else (*outputs[m_relBrightnessOutID].buffer)[count] = nilObject; if(state[CommandCamera::REL_CONTRAST] == 1) (*outputs[m_relContrastOutID].buffer)[count] = ObjectRef(Int::alloc(relContrast)); else (*outputs[m_relContrastOutID].buffer)[count] = nilObject; if(state[CommandCamera::ABS_PAN] == 1) (*outputs[m_absPanOutID].buffer)[count] = ObjectRef(Int::alloc(absPan)); else (*outputs[m_absPanOutID].buffer)[count] = nilObject; if(state[CommandCamera::ABS_TILT] == 1) (*outputs[m_absTiltOutID].buffer)[count] = ObjectRef(Int::alloc(absTilt)); else (*outputs[m_absTiltOutID].buffer)[count] = nilObject; if(state[CommandCamera::ABS_ZOOM] == 1) (*outputs[m_absZoomOutID].buffer)[count] = ObjectRef(Int::alloc(absZoom)); else (*outputs[m_absZoomOutID].buffer)[count] = nilObject; if(state[CommandCamera::ABS_BRIGHTNESS] == 1) (*outputs[m_absBrightnessOutID].buffer)[count] = ObjectRef(Int::alloc(absBrightness)); else (*outputs[m_absBrightnessOutID].buffer)[count] = nilObject; if(state[CommandCamera::ABS_CONTRAST] == 1) (*outputs[m_absContrastOutID].buffer)[count] = ObjectRef(Int::alloc(absContrast)); else (*outputs[m_absContrastOutID].buffer)[count] = nilObject; } catch (BaseException *e) { e->print(cerr); e->add(new GeneralException("Unable to process",__FILE__,__LINE__)); throw e; } } };//class extractMarieCommandCamera }//namespace marie --- NEW FILE: newMarieCommandCamera.cpp --- /* * MARIE - Mobile and Autonomous Robotics Integration Environment * Copyright (C) 2004 Dominic Letourneau * * 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 * * You can contact MARIE development team at http://marie.sourceforge.net */ #include "MarieCommandCamera.h" #include "MarieDataNull.h" #include <sstream> #include <string> namespace marie { class newMarieCommandCamera; DECLARE_NODE(newMarieCommandCamera) /*Node * * @name newMarieCommandCamera * @category RobotFlow:MARIE:DATA * @description Create MARIE DataCamera object * * @input_name COMMAND_CAMERA * @input_type Input MarieCommandCamera * @input_description input CommandCamera, nilObject if not used * * @input_name REL_BRIGHTNESS * @input_type int * @input_description input brightness, nilObject if not used * * @input_name REL_CONTRAST * @input_type int * @input_description input contrast, nilObject if not used * * @input_name REL_PAN * @input_type int * @input_description input pan, nilObject if not used * * @input_name REL_TILT * @input_type int * @input_description input tilt, nilObject if not used * * @input_name REL_ZOOM * @input_type int * @input_description input zoom, nilObject if not used * * @input_name ABS_BRIGHTNESS * @input_type int * @input_description input brightness, nilObject if not used * * @input_name ABS_CONTRAST * @input_type int * @input_description input contrast, nilObject if not used * * @input_name ABS_PAN * @input_type int * @input_description input pan, nilObject if not used * * @input_name ABS_TILT * @input_type int * @input_description input tilt, nilObject if not used * * @input_name ABS_ZOOM * @input_type int * @input_description input zoom, nilObject if not used * * @output_name COMMAND_CAMERA * @output_type MarieCommandCamera * @output_description Output MarieCommandCamera (with new pan,tilt,zoom, brightness, contrast) * END*/ using namespace std; class newMarieCommandCamera : public BufferedNode { private: //inputs int m_relBrightnessInID; int m_relContrastInID; int m_relPanInID; int m_relTiltInID; int m_relZoomInID; int m_absBrightnessInID; int m_absContrastInID; int m_absPanInID; int m_absTiltInID; int m_absZoomInID; //outputs int m_commandOutID; public: newMarieCommandCamera(string nodeName, ParameterSet params) : BufferedNode(nodeName,params) { //inputs m_relBrightnessInID = addInput("REL_BRIGHTNESS"); m_relContrastInID = addInput("REL_CONTRAST"); m_relPanInID = addInput("REL_PAN"); m_relTiltInID = addInput("REL_TILT"); m_relZoomInID = addInput("REL_ZOOM"); m_absBrightnessInID = addInput("ABS_BRIGHTNESS"); m_absContrastInID = addInput("ABS_CONTRAST"); m_absPanInID = addInput("ABS_PAN"); m_absTiltInID = addInput("ABS_TILT"); m_absZoomInID = addInput("ABS_ZOOM"); //outputs m_commandOutID = addOutput("COMMAND_CAMERA"); } void calculate(int output_id, int count, Buffer &out) { try { //get all inputs ObjectRef relBrightnessInValue = getInput(m_relBrightnessInID,count); ObjectRef relContrastInValue = getInput(m_relContrastInID,count); ObjectRef relPanInValue = getInput(m_relPanInID,count); ObjectRef relTiltInValue = getInput(m_relTiltInID,count); ObjectRef relZoomInValue = getInput(m_relZoomInID,count); ObjectRef absBrightnessInValue = getInput(m_absBrightnessInID,count); ObjectRef absContrastInValue = getInput(m_absContrastInID,count); ObjectRef absPanInValue = getInput(m_absPanInID,count); ObjectRef absTiltInValue = getInput(m_absTiltInID,count); ObjectRef absZoomInValue = getInput(m_absZoomInID,count); //create command object MarieCommandCamera *command = new MarieCommandCamera(); //get pan if (!relPanInValue->isNil()) { RCPtr<Int> relPanPtr = relPanInValue; int relPan = *relPanPtr; command->setRelativePan(relPan); } //get tilt if (!relTiltInValue->isNil()) { RCPtr<Int> relTiltPtr = relTiltInValue; int relTilt = *relTiltPtr; command->setRelativeTilt(relTilt); } //get zoom if (!relZoomInValue->isNil()) { RCPtr<Int> relZoomPtr = relZoomInValue; int relZoom = *relZoomPtr; command->setRelativeZoom(relZoom); } //get contrast if (!relContrastInValue->isNil()) { RCPtr<Int> relContrastPtr = relContrastInValue; int relContrast = *relContrastPtr; command->setRelativeContrast(relContrast); } //get brightness if (!relBrightnessInValue->isNil()) { RCPtr<Int> relBrightnessPtr = relBrightnessInValue; int relBrightness = *relBrightnessPtr; command->setRelativeBrightness(relBrightness); } //get pan if (!absPanInValue->isNil()) { RCPtr<Int> absPanPtr = absPanInValue; int absPan = *absPanPtr; command->setAbsolutePan(absPan); } //get tilt if (!absTiltInValue->isNil()) { RCPtr<Int> absTiltPtr = absTiltInValue; int absTilt = *absTiltPtr; command->setAbsoluteTilt(absTilt); } //get zoom if (!absZoomInValue->isNil()) { RCPtr<Int> absZoomPtr = absZoomInValue; int absZoom = *absZoomPtr; command->setAbsoluteZoom(absZoom); } //get contrast if (!absContrastInValue->isNil()) { RCPtr<Int> absContrastPtr = absContrastInValue; int absContrast = *absContrastPtr; command->setAbsoluteContrast(absContrast); } //get brightness if (!absBrightnessInValue->isNil()) { RCPtr<Int> absBrightnessPtr = absBrightnessInValue; int absBrightness = *absBrightnessPtr; command->setAbsoluteBrightness(absBrightness); } //output command object out[count] = ObjectRef(command); } catch(BaseException *e) { e->print(cerr); throw e->add(new GeneralException("",__FILE__,__LINE__)); } } };//class newMarieCommandCamera }//namespace marie --- NEW FILE: newMarieDataCamera.cpp --- /* * MARIE - Mobile and Autonomous Robotics Integration Environment * Copyright (C) 2004 Dominic Letourneau * * 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 * * You can contact MARIE development team at http://marie.sourceforge.net */ #include "MarieDataCamera.h" #include "MarieDataNull.h" #include <sstream> #include <string> namespace marie { class newMarieDataCamera; DECLARE_NODE(newMarieDataCamera) /*Node * * @name newMarieDataCamera * @category RobotFlow:MARIE:DATA * @description Create MARIE DataCamera object * * @input_name ABS_PAN * @input_type int * @input_description Absolute PAN * * @input_name ABS_TILT * @input_type int * @input_description Absolute TILT * * @input_name ABS_ZOOM * @input_type int * @input_description Absolute ZOOM * * @output_name DATA_CAMERA * @output_type DataCamera * @output_description new MARIE DataCamera Object * END*/ using namespace std; class newMarieDataCamera : public BufferedNode { private: //inputs int m_panID; int m_tiltID; int m_zoomID; //outputs int m_dataCameraID; public: newMarieDataCamera(string nodeName, ParameterSet params) : BufferedNode(nodeName,params) { //inputs m_panID = addInput("ABS_PAN"); m_tiltID = addInput("ABS_TILT"); m_zoomID = addInput("ABS_ZOOM"); //outputs m_dataCameraID = addOutput("DATA_CAMERA"); } void calculate(int output_id, int count, Buffer &out) { ObjectRef panValue = getInput(m_panID,count); ObjectRef tiltValue = getInput(m_tiltID,count); ObjectRef zoomValue = getInput(m_zoomID,count); if (!panValue->isNil() && !tiltValue->isNil() && !zoomValue->isNil()) { MarieDataCamera *camera = new MarieDataCamera(); RCPtr<Int> pan = panValue; RCPtr<Int> tilt = tiltValue; RCPtr<Int> zoom = zoomValue; camera->setPTZ(*pan,*tilt,*zoom); out[count] = ObjectRef(camera); } else { out[count] = ObjectRef(new MarieDataNull()); } } };//class newMarieDataCamera }//namespace marie |