00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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
00077
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
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
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
00184 }
00185
00186 Primitive* ComponentToRobot::getMainPrimitive(){
00187 return 0;
00188 }
00189
00190
00191
00192 }