void test_verify_1() { cout << "Verify Test 1" << endl; vector<int> res1 (100); vector<int> res2 (100); cout << "res1 == res2: " << TestEnvironment::verify(res1, res2) << endl; vector<int> res3 (50); vector<int> res4 (100); cout << "res3 == res4: " << TestEnvironment::verify(res3, res4) << endl; cout << endl; }
void SIMPLE_Agents::get_IR_reading( vector <double> &_reading){ double x,z,X,Z,rotation = 0.0; this->pos = this->get_pos(); double y = pos[1] + 0.011; btMatrix3x3 m = btMatrix3x3(body->getWorldTransform().getRotation()); double rfPAngle = btAsin(-m[1][2]); if ( rfPAngle < SIMD_HALF_PI ) { if ( rfPAngle > -SIMD_HALF_PI ) rotation = btAtan2(m[0][2],m[2][2]); else rotation = -btAtan2(-m[0][1],m[0][0]); } else rotation = btAtan2(-m[0][1],m[0][0]); // IR0 reading x = pos[0]+((robot_radius) * cos(-rotation + 0.3)); //calc IR sensor X based on robot radius z = pos[2]+((robot_radius) * sin(-rotation + 0.3)); from1[0] = btVector3(x, y, z); //sensor position based on robot rotation vector to hold btVector X = x+((IR_range) * cos(-rotation + 0.3 )); //calc IR ray end position based on IR range and placement of sensor on the robot Z = z+((IR_range) * sin(-rotation + 0.3 )); to1[0] = btVector3( X, y, Z ); //Max reading pos of the IR based on rotation and IR range btCollisionWorld::ClosestRayResultCallback res0(from1[0], to1[0]); //struct for the closest ray callback //uncomment below line if you experience any ray pentration problem to the object this might happened with very slow machine //res0.m_flags = 0xFFFFFFFF; this->world->rayTest(from1[0], to1[0], res0); //check for ray collision between the coords sets if(res0.hasHit()){ _reading[0] = IR_range*res0.m_closestHitFraction ; to1[0]=res0.m_hitPointWorld; //update the vector with the btVector results -> used to render it in openGL } // IR7 reading x = pos[0]+((robot_radius) * cos(-rotation - 0.3)); z = pos[2]+((robot_radius) * sin(-rotation - 0.3)); from1[1] = btVector3(x, y, z); X = x+((IR_range) * cos(-rotation - 0.3 )); Z = z+((IR_range) * sin(-rotation - 0.3 )); to1[1] = btVector3( X, y, Z ); btCollisionWorld::ClosestRayResultCallback res7(from1[1], to1[1]); //uncomment below line if you experience any ray pentration problem to the object this might happened with very slow machine //res7.m_flags = 0xFFFFFFFF; this->world->rayTest(from1[1], to1[1], res7); if(res7.hasHit()){ _reading[1] = IR_range*res7.m_closestHitFraction; to1[1]=res7.m_hitPointWorld; } // IR1 reading corrospond to epuck x = pos[0]+((robot_radius) * cos(-rotation + 0.8)); z = pos[2]+((robot_radius) * sin(-rotation + 0.8)); from1[2] = btVector3(x, y, z); X = x+((IR_range) * cos(-rotation + 0.8 )); Z = z+((IR_range) * sin(-rotation + 0.8 )); to1[2] = btVector3( X, y, Z ); btCollisionWorld::ClosestRayResultCallback res1(from1[2], to1[2]); //uncomment below line if you experience any ray pentration problem to the object this might happened with very slow machine //res1.m_flags = 0xFFFFFFFF; this->world->rayTest(from1[2], to1[2], res1); if(res1.hasHit()){ _reading[2] = IR_range*res1.m_closestHitFraction; to1[2]=res1.m_hitPointWorld; } // IR6 reading x = pos[0]+((robot_radius) * cos(-rotation - 0.8)); z = pos[2]+((robot_radius) * sin(-rotation - 0.8)); from1[3] = btVector3(x, y, z); X = x+((IR_range) * cos(-rotation - 0.8 )); Z = z+((IR_range) * sin(-rotation - 0.8 )); to1[3] = btVector3( X, y, Z ); btCollisionWorld::ClosestRayResultCallback res6(from1[3], to1[3]); //uncomment below line if you experience any ray pentration problem to the object this might happened with very slow machine //res6.m_flags = 0xFFFFFFFF; this->world->rayTest(from1[3], to1[3], res6); if(res6.hasHit()){ _reading[3] = IR_range*res6.m_closestHitFraction; to1[3]=res6.m_hitPointWorld; } // IR2 reading x = pos[0]+((0.028) * cos(-rotation + 1.57)); z = pos[2]+((0.028) * sin(-rotation + 1.57)); from1[4] = btVector3(x, y, z); X = x+((0.049) * cos(-rotation + 1.57 )); Z = z+((0.049) * sin(-rotation + 1.57)); to1[4] = btVector3( X, y, Z ); btCollisionWorld::ClosestRayResultCallback res2(from1[4], to1[4]); //uncomment below line if you experience any ray pentration problem to the object this might happened with very slow machine //res2.m_flags = 0xFFFFFFFF; this->world->rayTest(from1[4], to1[4], res2); if(res2.hasHit()){ _reading[4] = 0.049*(res2.m_closestHitFraction) - 0.009; to1[4]=res2.m_hitPointWorld; } // IR5 reading x = pos[0]+((0.028) * cos(-rotation - 1.57)); z = pos[2]+((0.028) * sin(-rotation - 1.57)); from1[5] = btVector3(x, y, z); X = x+((0.049) * cos(-rotation - 1.57 )); Z = z+((0.049) * sin(-rotation - 1.57 )); to1[5] = btVector3( X, y, Z ); btCollisionWorld::ClosestRayResultCallback res5(from1[5], to1[5]); //uncomment below line if you experience any ray pentration problem to the object this might happened with very slow machine //res5.m_flags = 0xFFFFFFFF; this->world->rayTest(from1[5], to1[5], res5); if(res5.hasHit()){ _reading[5] = 0.049*res5.m_closestHitFraction - 0.009; to1[5]=res5.m_hitPointWorld; } // IR3 reading x = pos[0]+((robot_radius) * cos(-rotation + 2.64)); z = pos[2]+((robot_radius) * sin(-rotation + 2.64)); from1[6] = btVector3(x, y, z); X = x+((IR_range) * cos(-rotation + 2.64 )); Z = z+((IR_range) * sin(-rotation + 2.64 )); to1[6] = btVector3( X, y, Z ); btCollisionWorld::ClosestRayResultCallback res3(from1[6], to1[6]); //uncomment below line if you experience any ray pentration problem to the object this might happened with very slow machine //res3.m_flags = 0xFFFFFFFF; this->world->rayTest(from1[6], to1[6], res3); if(res3.hasHit()){ _reading[6] = IR_range*res3.m_closestHitFraction; to1[6]=res3.m_hitPointWorld; } // IR4 reading x = pos[0]+((robot_radius) * cos(-rotation - 2.64)); z = pos[2]+((robot_radius) * sin(-rotation - 2.64)); from1[7] = btVector3(x, y, z); X = x+((IR_range) * cos(-rotation - 2.64 )); Z = z+((IR_range) * sin(-rotation - 2.64 )); to1[7] = btVector3( X, y, Z ); btCollisionWorld::ClosestRayResultCallback res4(from1[7], to1[7]); //uncomment below line if you experience any ray pentration problem to the object this might happened with very slow machine //res4.m_flags = 0xFFFFFFFF; this->world->rayTest(from1[7], to1[7], res4); if(res4.hasHit()){ _reading[7] = IR_range*res4.m_closestHitFraction; to1[7]=res4.m_hitPointWorld; } // for( int i = 0; i < num_IR_sensors; i++){ // printf(" \nIR%d distance reading= %f ",i,_reading[i]); // } //calibrating distance to IR value reading according to a line equations for(int i = 0; i < num_IR_sensors; i++){ if (_reading[i] > 0.03 && _reading[i] <= 0.04) _reading[i] = -20600 * _reading[i] + 924; else if (_reading[i] > 0.02 && _reading[i] <= 0.03) _reading[i] = -37000 * _reading[i] + 1416; else if (_reading[i] > 0.01 && _reading[i] <= 0.02) _reading[i] = -153500 * _reading[i] + 3746; else if (_reading[i] > 0.005 && _reading[i] <= 0.01) _reading[i] = -252600 * _reading[i] + 4737; else if (_reading[i] >= 0.0 && _reading[i] <= 0.005 ) _reading[i] = -124200 * _reading[i] + 4095; } // for( int i = 0; i < num_IR_sensors; i++){ // printf("\n IR%d distance reading= %f ",i,_reading[i]); // } // take_occupancy_reading(_reading, get_rotation(), get_pos()[0], get_pos()[2] ); }