sensors.cpp
45 neuronsIteratorResource = ConfigurationHelper::getString(params, prefix + "neuronsIterator", "neuronsIterator");
56 Logger::warning( QString("ObjectPositionSensor %1 - bbMin and/or bbMax parameters are not well specified; they will be ignored").arg(name()) );
70 Descriptor d = addTypeDescription( type, "Sensor for reading the three absolute coordinate (position into the worlf frame) of an object" );
71 d.describeString("neuronsIterator").def("neuronsIterator").help("the name of the resource associated with the neural network iterator (default is \"neuronsIterator\")");
72 d.describeString( "object" ).def( "object" ).props( IsMandatory ).help( "The name of the resource associated with the object to track with this sensor" );
73 d.describeReal( "bbMin" ).props( IsList ).help( "The minimum 3D point used for linearize the object position into [0,1]" );
74 d.describeReal( "bbMax" ).props( IsList ).help( "The maximum 3D point used for linearize the object position into [0,1]" );
102 void ObjectPositionSensor::resourceChanged(QString resourceName, ResourceChangeType changeType) {
128 params.createParameter( prefix, "bbMin", QString("%1 %2 %3").arg(bbMin[0]).arg(bbMin[1]).arg(bbMin[2]) );
129 params.createParameter( prefix, "bbMax", QString("%1 %2 %3").arg(bbMax[0]).arg(bbMax[1]).arg(bbMax[2]) );
170 LinearCameraGraphic(WObject *object, const wMatrix& transformation, double minAngle, double maxAngle, unsigned int numReceptors, QString name = "unamed") :
296 const wVector lineEnd = wVector(cos(curAngle), sin(curAngle), 0.0).scale(linearCameraReceptorsLength);
407 LinearCamera::LinearCamera(WObject* obj, wMatrix mtr, double aperture, unsigned int numReceptors, QColor backgroundColor) :
412 m_aperture((aperture > (2.0 * PI_GRECO)) ? (2.0 * PI_GRECO) : ((aperture < 0.0) ? 0.0 : aperture)),
467 // An helper class to ease computations with multiple intervals. This class starts with a single
510 } else if ((start >= it->start) && (start < it->end) && (end > it->start) && (end <= it->end)) {
552 // Intervals will always be ordered from the one with the lowest start to the one with the highest start.
557 // An helper structure memorizing information about colors in a single receptor. minAngle and maxAngle
558 // are used to store the current portion of the receptor for which we already know the color, while
559 // colorsAndFractions is the list of colors and the portion of the receptor occupied by that color
587 #warning APPENA I ROBOT SONO NELLA LISTA DEGLI OGGETTI, BISOGNA RICORDARSI DI ESCLUDERE L OGGETTO CUI LA CAMERA È ATTACCATA QUANDO SI CALCOLA L ATTIVAZIONE
613 // For the moment we use the distance to order objects (see ColorRangeAndDistance::operator<), however
622 // computeLinearViewFieldOccupiedRange returns a negative distance if the object is outside the view field
634 colorsRangesAndDistances.append(ColorRangeAndDistance(color, minAngle, m_apertureMax, distance));
637 colorsRangesAndDistances.append(ColorRangeAndDistance(color, m_apertureMin, maxAngle, distance));
640 if (((minAngle > m_apertureMin) && (minAngle < m_apertureMax)) || ((maxAngle > m_apertureMin) && (maxAngle < m_apertureMax))) {
649 // Now we can add the background color at the end of the list. It covers all receptors to be sure to fill
651 colorsRangesAndDistances.append(ColorRangeAndDistance(m_backgroundColor, m_apertureMin, m_apertureMax, std::numeric_limits<double>::infinity()));
653 // The next step is to calculate the percentage of each color in the colorsRangesAndDistances list
656 for (QList<ColorRangeAndDistance>::const_iterator it = colorsRangesAndDistances.begin(); it != colorsRangesAndDistances.end(); ++it) {
659 const int maxIndex = min(m_numReceptors - 1, floor((it->maxAngle - m_apertureMin) / m_receptorRange));
670 const double fraction = min(1.0, colorsInReceptors[i].curInterval.removeInterval(it->minAngle, it->maxAngle));
671 colorsInReceptors[i].colorsAndFractions.append(ColorsInReceptor::ColorAndFraction(it->color, fraction));
675 // The final step is to compute the resulting color for each receptor. See class description for a comment
681 for (QList<ColorsInReceptor::ColorAndFraction>::const_iterator it = colorsInReceptors[i].colorsAndFractions.begin(); it != colorsInReceptors[i].colorsAndFractions.end(); ++it) {
703 m_graphicalCamera = new LinearCameraGraphic(m_object, m_transformation, m_apertureMin, m_apertureMax, m_numReceptors, "linearCamera");
752 throw SampleFileLoadingException(m_filename.toAscii().data(), ("Wrong format for the first line, expected 5 elements, got " + QString::number(confs.size())).toAscii().data());
759 throw SampleFileLoadingException(m_filename.toAscii().data(), ("Error reading the first element of the first row: expected an unsigned integer, got \"" + confs[0] + "\"").toAscii().data());
763 throw SampleFileLoadingException(m_filename.toAscii().data(), ("Error reading the second element of the first row: expected an unsigned integer, got \"" + confs[1] + "\"").toAscii().data());
767 throw SampleFileLoadingException(m_filename.toAscii().data(), ("Error reading the third element of the first row: expected an unsigned integer, got \"" + confs[2] + "\"").toAscii().data());
771 throw SampleFileLoadingException(m_filename.toAscii().data(), ("Error reading the fourth element of the first row: expected a real number, got \"" + confs[3] + "\"").toAscii().data());
775 throw SampleFileLoadingException(m_filename.toAscii().data(), ("Error reading the fifth element of the first row: expected a real number, got \"" + confs[4] + "\"").toAscii().data());
783 // Now reading the blocks. I use the id after "TURN" for a safety check, the original evorobot code used that
792 if ((turnLineSplitted.size() != 2) || (turnLineSplitted[0] != "TURN") || (turnLineSplitted[1].toUInt() != dist)) {
793 throw SampleFileLoadingException(m_filename.toAscii().data(), ("Invalid TURN line: \"" + turnLine + "\"").toAscii().data());
803 throw SampleFileLoadingException(m_filename.toAscii().data(), ("Invalid activations line (wrong number of elements, expected " + QString::number(m_numIR) + ", got " + QString::number(activationsLineSplitted.size()) + "): \"" + activationsLine + "\"").toAscii().data());
810 throw SampleFileLoadingException(m_filename.toAscii().data(), ("Invalid activations line (invalid activation value): \"" + activationsLineSplitted[id] + "\"").toAscii().data());
820 throw SampleFileLoadingException(m_filename.toAscii().data(), ("The last line in the file should be \"END\", actual value: \"" + finalLine + "\"").toAscii().data());
837 QVector<unsigned int>::const_iterator SampledIRDataLoader::getActivation(real dist, real ang) const
855 unsigned int SampledIRDataLoader::getLinearIndex(unsigned int id, unsigned int ang, unsigned int dist) const