Robotsystem from Robot Group Leipzig: component_to_robot.cpp Source File

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# component_to_robot.cpp

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
    00003  *    martius@informatik.uni-leipzig.de                                    *
    00004  *    fhesse@informatik.uni-leipzig.de                                     *
    00005  *    der@informatik.uni-leipzig.de                                        *
    00006  *                                                                         *
    00007  *   This program is free software; you can redistribute it and/or modify  *
    00008  *   it under the terms of the GNU General Public License as published by  *
    00009  *   the Free Software Foundation; either version 2 of the License, or     *
    00010  *   (at your option) any later version.                                   *
    00011  *                                                                         *
    00012  *   This program is distributed in the hope that it will be useful,       *
    00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    00015  *   GNU General Public License for more details.                          *
    00016  *                                                                         *
    00017  *   You should have received a copy of the GNU General Public License     *
    00018  *   along with this program; if not, write to the                         *
    00019  *   Free Software Foundation, Inc.,                                       *
    00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    00021  *                                                                         *
    00022  *   $Log: component_to_robot.cpp,v $
    00023  *   Revision 1.1.2.1  2006/01/12 14:52:37  martius
    00024  *   moved here from util directory
    00025  *
    00026  *   Revision 1.4.4.3  2005/12/06 10:13:26  martius
    00027  *   openscenegraph integration started
    00028  *
    00029  *   Revision 1.4.4.2  2005/11/15 12:30:24  martius
    00030  *   new selforg structure and OdeAgent, OdeRobot ...
    00031  *
    00032  *   Revision 1.4.4.1  2005/11/14 17:37:25  martius
    00033  *   moved to selforg
    00034  *
    00035  *   Revision 1.4  2005/11/09 13:31:51  martius
    00036  *   GPL'ised
    00037  *
    00038  ***************************************************************************/
    00039 #include "component_to_robot.h"
    00040
    00041 namespace lpzrobots {
    00042
    00043
    00044 ComponentToRobot::ComponentToRobot(IComponent *_p_component,
    00045                                    const OdeHandle &odehandle,
    00046                                    const OsgHandle &osghandle) :
    00047   OdeRobot(odeHandle, osgHandle),
    00048   p_component(_p_component)
    00049 {
    00050   if(NULL == p_component)
    00051     InvalidArgumentException().raise();
    00052
    00053   _p_component->expose_wires(wire_container);
    00054 }
    00055
    00056
    00057 ComponentToRobot::~ComponentToRobot()
    00058 {
    00059 }
    00060
    00061
    00062 const char* ComponentToRobot::getName() const
    00063 {
    00064   return "ComponentToRobot";
    00065 }
    00066
    00067
    00068 void ComponentToRobot::draw()
    00069 {
    00070   p_component->draw();
    00071 }
    00072
    00073
    00074 void ComponentToRobot::place(Position pos , Color *c)
    00075 {
    00076   // not implemented
    00077   // IPlaceable *p_placeable = dynamic_cast<IPlaceable>(p_component);
    00078 }
    00079
    00080
    00081 bool ComponentToRobot::collisionCallback(void *data, dGeomID o1, dGeomID o2)
    00082 {
    00083   return p_component->collision_callback(NULL, o1, o2);
    00084 }
    00085
    00086 void ComponentToRobot::doInternalStuff(const GlobalData& globalData){
    00087   // todo reset sensors
    00088 }
    00089
    00090
    00091 int ComponentToRobot::getSensors(sensor* sensors, int sensornumber)
    00092 {
    00093   WireContainer::iterator it_wire = wire_container.begin();
    00094
    00095   int current_sensor = 0;
    00096
    00097   for(int i = 0; i < sensornumber; ++i) {
    00098
    00099     IOutputWire *p_output_wire = dynamic_cast<IOutputWire*>(*it_wire);
    00100
    00101     if(NULL == p_output_wire)
    00102       continue;
    00103
    00104     if(wire_container.end() == it_wire)
    00105       IndexOutOfBoundsException().raise();
    00106
    00107     sensors[current_sensor] = p_output_wire->get();
    00108
    00109     ++it_wire;
    00110     ++current_sensor;
    00111   }
    00112
    00113   return current_sensor;
    00114 }
    00115
    00116
    00117 void ComponentToRobot::setMotors(const motor* motors, int motornumber)
    00118 {
    00119   int current_motor_count = 0;
    00120
    00121   WireContainer::iterator it = wire_container.begin();
    00122   for(int i = 0; i < motornumber; ++i) {
    00123     //    std::cout << "MV = " << *motors << "\n";
    00124     if(*motors < -1.0 || *motors > 1.0) {
    00125       std::cerr << "invalid motor value\n";
    00126       exit(-1);
    00127
    00128     }
    00129
    00130     IInputWire *p_input_wire = dynamic_cast<IInputWire*>(*it);
    00131     if(NULL == p_input_wire)
    00132       continue;
    00133
    00134
    00135     if(wire_container.end() == it)
    00136       IndexOutOfBoundsException().raise();
    00137
    00138     ++current_motor_count;
    00139     p_input_wire->put(*(motors++));
    00140
    00141     ++it;
    00142   }
    00143 }
    00144
    00145
    00146 int ComponentToRobot::getSensorNumber()
    00147 {
    00148   WireContainer::const_iterator it_wire = wire_container.begin();
    00149
    00150   unsigned output_wire_count = 0;
    00151
    00152   while(wire_container.end() != it_wire) {
    00153     if(NULL != dynamic_cast<const IOutputWire*>(*(it_wire++)))
    00154       ++output_wire_count;
    00155   }
    00156
    00157   return output_wire_count;
    00158 }
    00159
    00160
    00161 int ComponentToRobot::getMotorNumber()
    00162 {
    00163   WireContainer::const_iterator it_wire = wire_container.begin();
    00164
    00165   unsigned input_wire_count = 0;
    00166
    00167   while(wire_container.end() != it_wire) {
    00168     if(NULL != dynamic_cast<const IInputWire*>(*(it_wire++)))
    00169       ++input_wire_count;
    00170   }
    00171
    00172   return input_wire_count;
    00173 }
    00174
    00175 int ComponentToRobot::getSegmentsPosition(vector<Position> &poslist)
    00176 {
    00177   return 0;
    00178 }
    00179
    00180
    00181 void ComponentToRobot::setColor(Color col)
    00182 {
    00183   // not implemented
    00184 }
    00185
    00186 Primitive* ComponentToRobot::getMainPrimitive(){
    00187   return 0; // FIXME get object from first component
    00188 }
    00189
    00190
    00191
    00192 }