marxbotsensors.cpp
42 m_marxbotResource = actualResourceNameForMultirobot(ConfigurationHelper::getString(params, prefix + "marxbot", m_marxbotResource));
43 m_neuronsIteratorResource = actualResourceNameForMultirobot(ConfigurationHelper::getString(params, prefix + "neuronsIterator", m_neuronsIteratorResource));
72 d.describeString("marxbot").def("robot").help("The name of the resource associated with the MarXbot robot to use (default is \"robot\")");
73 d.describeString("neuronsIterator").def("neuronsIterator").help("The name of the resource associated with the neural network iterator (default is \"neuronsIterator\")");
89 MarXbotProximityIRSensor::MarXbotProximityIRSensor(ConfigurationParameters& params, QString prefix) :
93 m_activeSensors(ConfigurationHelper::getBoolVector(params, prefix + "activeSensors", "111111111111111111111111")),
97 ConfigurationHelper::throwUserConfigError(prefix + "activeSensors", params.getValue(prefix + "activeSensors"), "The parameter must be a list of exactly 24 elements either equal to 1 or to 0 (do not use any space to separate elements, just put them directly one after the other)");
126 Descriptor d = addTypeDescription(type, "The infrared proximity sensors of the MarXbot robot", "The infrared proximity sensors of the MarXbot robot. These are the very short range IR sensors all around the base");
127 d.describeString("activeSensors").def("111111111111111111111111").help("Which IR sensors of the robot are actually enabled", "This is a string of exactly 24 elements. Each element can be either \"0\" or \"1\" to respectively disable/enable the corresponding proximity IR sensor. The first sensor is the one on the left side of the robot and the others follow counterclockwise (i.e. left, back, right, front)");
141 m_neuronsIterator->setInput(applyNoise(m_robot->proximityIRSensorController()->activation(i), 0.0, 1.0));
152 void MarXbotProximityIRSensor::resourceChanged(QString resourceName, ResourceChangeType changeType)
187 MarXbotGroundBottomIRSensor::MarXbotGroundBottomIRSensor(ConfigurationParameters& params, QString prefix) :
219 Descriptor d = addTypeDescription(type, "The infrared ground bottom sensors of the MarXbot robot", "The infrared ground bottom sensors of the MarXbot robot. These are the four ground sensors below the robot battery pack.");
220 d.describeBool("invertActivation").def(false).help("If true inverts the activation of the sensors", "If true the sensor is activated with 0.0 above white and with 1.0 above black, if false the opposite holds. The default value is false");
234 const wVector sensorPosition = m_robot->matrix().transformVector(m_robot->groundBottomIRSensorController()->sensors()[i].getPosition());
251 void MarXbotGroundBottomIRSensor::resourceChanged(QString resourceName, ResourceChangeType changeType)
279 MarXbotGroundAroundIRSensor::MarXbotGroundAroundIRSensor(ConfigurationParameters& params, QString prefix) :
309 Descriptor d = addTypeDescription(type, "The infrared ground around sensors of the MarXbot robot", "The infrared ground around sensors of the MarXbot robot. These are the eight ground sensors below the base of the robot (just above the wheels).");
323 const wVector sensorPosition = m_robot->matrix().transformVector(m_robot->groundAroundIRSensorController()->sensors()[i].getPosition());
336 void MarXbotGroundAroundIRSensor::resourceChanged(QString resourceName, ResourceChangeType changeType)
364 MarXbotLinearCameraSensor::MarXbotLinearCameraSensor(ConfigurationParameters& params, QString prefix) :
372 m_usedColorChannels((m_useRedChannel ? 1 : 0) + (m_useGreenChannel ? 1 : 0) + (m_useBlueChannel ? 1 : 0)),
380 ConfigurationHelper::throwUserConfigError(prefix + "numReceptors", params.getValue(prefix + "numReceptors"), "The parameter must be an integer greater or equal to 1");
383 ConfigurationHelper::throwUserConfigError(prefix + "aperture", params.getValue(prefix + "aperture"), "The parameter must be a real number between 0 and 360");
415 Descriptor d = addTypeDescription(type, "The linear camera sensor of the MarXbot robot", "This is a 360° linear camera");
416 d.describeInt("numReceptors").def(8).limits(1, MaxInteger).help("The number of receptors of the sensor", "Each receptor returns three values, one for each of the three colors (red, green, blue). This means that the size returned by this sensor is 3 * numReceptors (default is 8)");
417 d.describeBool("useRedChannel").def(true).help("Whether the red component of the perceived objects should be used or not (default true)");
418 d.describeBool("useGreenChannel").def(true).help("Whether the green component of the perceived objects should be used or not (default true)");
419 d.describeBool("useBlueChannel").def(true).help("Whether the blue component of the perceived objects should be used or not (default true)");
420 d.describeReal("aperture").def(360.0f).limits(0.0f, 360.0f).help("The aperture of the camera in degrees", "The real MarXbot has an omnidirectional camera, so you can use here any value up to 360 degrees (default is 360)");
421 d.describeReal("maxDistance").def(+Infinity).limits(0.0f, +Infinity).help("The distance above which objects are not seen by the camera in meters");
460 void MarXbotLinearCameraSensor::resourceChanged(QString resourceName, ResourceChangeType changeType)
484 m_camera = new LinearCamera(m_robot, mtr, toRad(m_aperture), m_numReceptors, m_maxDistance, Qt::black);
512 MarXbotLinearCameraSensorNew::MarXbotLinearCameraSensorNew(ConfigurationParameters& params, QString prefix) :
520 m_usedColorChannels((m_useRedChannel ? 1 : 0) + (m_useGreenChannel ? 1 : 0) + (m_useBlueChannel ? 1 : 0)),
532 ConfigurationHelper::throwUserConfigError(prefix + "numReceptors", params.getValue(prefix + "numReceptors"), "The parameter must be an integer greater or equal to 1");
535 ConfigurationHelper::throwUserConfigError(prefix + "aperture", params.getValue(prefix + "aperture"), "The parameter must be a real number between 0 and 360");
539 if (!params.getValue(prefix + "numReceptors").isEmpty() || !params.getValue(prefix + "aperture").isEmpty()) {
540 ConfigurationHelper::throwUserConfigError(prefix + "receptorsRanges", params.getValue(prefix + "receptorsRanges"), "You must not specify the receptorsRanges parameter if either aperture or numReceptors has been specified");
547 ConfigurationHelper::throwUserConfigError(prefix + "receptorsRanges", params.getValue(prefix + "receptorsRanges"), "The receptorsRanges parameter must be a comma separated list of simple intervals");
589 Descriptor d = addTypeDescription(type, "The linear camera sensor of the MarXbot robot (new implementation)", "This is a 360° linear camera");
590 d.describeInt("numReceptors").def(8).limits(1, MaxInteger).help("The number of receptors of the sensor", "Each receptor returns three values, one for each of the three colors (red, green, blue). This means that the size returned by this sensor is 3 * numReceptors (default is 8)");
591 d.describeReal("aperture").def(360.0f).limits(0.0f, 360.0f).help("The aperture of the camera in degrees", "The real MarXbot has an omnidirectional camera, so you can use here any value up to 360 degrees (default is 360)");
592 d.describeReal("maxDistance").def(+Infinity).limits(0.0f, +Infinity).help("The distance above which objects are not seen by the camera in meters");
593 d.describeString("receptorsRanges").def("").help("The range for each receptor", "This parameter is a comma separated list of ranges (in the form [start, end]), each range being the aperture of a single receptor. The number of receptors is equal to the number of ranges. The start and end angles of the range are in degrees. Note that if you specify this parameter you must not specify the aperture neither the numReceptors parameters.");
594 d.describeBool("useRedChannel").def(true).help("Whether the red component of the perceived objects should be used or not (default true)");
595 d.describeBool("useGreenChannel").def(true).help("Whether the green component of the perceived objects should be used or not (default true)");
596 d.describeBool("useBlueChannel").def(true).help("Whether the blue component of the perceived objects should be used or not (default true)");
635 void MarXbotLinearCameraSensorNew::resourceChanged(QString resourceName, ResourceChangeType changeType)
660 m_camera = new LinearCameraNew::LinearCamera(m_robot, mtr, toRad(m_aperture), m_numReceptors, m_maxDistance, Qt::black);
662 m_camera = new LinearCameraNew::LinearCamera(m_robot, mtr, m_receptorsRanges, m_maxDistance, Qt::black);
730 TractionSensorGraphic(WObject *object, const wVector& offset, real radius, real scale = 1.0, real maxLength = 1.0, real minLength = 0.0, QString name = "unamed") :
795 const wVector vectorToDraw = wVector(limitComponent(vector.x, xLimited), limitComponent(vector.y, yLimited), vector.z).scale(m_scale);
800 drawArrow(xComponent, m_radius / 2.0, m_maxTipLength / 2.0, (xLimited ? Qt::red : Qt::cyan), renderer, gw);
801 drawArrow(yComponent, m_radius / 2.0, m_maxTipLength / 2.0, (yLimited ? Qt::red : Qt::cyan), renderer, gw);
823 void drawArrow(wVector vector, real radius, real maxTipLength, QColor col, RenderWObject* renderer, QGLContext* gw)
837 RenderWObjectContainer::drawCylinder(axis, axis.scale(0.5 * bodyLength), bodyLength, radius, color());
847 const wVector tipDisplacement = (bodyLength < 0.0) ? wVector(0.0, 0.0, 0.0) : axis.scale(bodyLength);
959 ConfigurationHelper::throwUserConfigError(prefix + "maxForce", params.getValue(prefix + "maxForce"), "The parameter must be a positive real number");
962 ConfigurationHelper::throwUserConfigError(prefix + "minForce", params.getValue(prefix + "minForce"), "The parameter must be a positive real number");
980 params.createParameter(prefix, "drawSensor", m_drawSensor ? QString("true") : QString("false"));
989 Descriptor d = addTypeDescription(type, "The traction sensors of the MarXbot robot", "The traction sensors of the MarXbot robot. It is placed between the base and the turret. Note that this sensor only works when the robot is in dynamic mode");
990 d.describeReal("maxForce").def(1.0f).limits(0.0f, +Infinity).help("The maximum possible value of the force", "This is the value of the force on one axis over which the corresponding neuron is activated with 1");
991 d.describeReal("minForce").def(0.0f).limits(0.0f, +Infinity).help("The minimum possible value of the force", "This is the value of the force on one axis under which the corresponding neuron is activated with 0");
992 d.describeBool("drawSensor").def(true).help("Whether to draw the sensor", "If true the sensor is graphically represented by an arrow in the direction of the current traction");
1047 void MarXbotTractionSensor::resourceChanged(QString resourceName, ResourceChangeType changeType)
1066 m_graphics = new TractionSensorGraphic(m_robot, offset, 0.005f, 0.1f / m_maxForce, m_maxForce, m_minForce, "Traction sensor");
1083 MarXbotSampledProximityIRSensor::MarXbotSampledProximityIRSensor(ConfigurationParameters& params, QString prefix) :
1088 m_activeSensors(ConfigurationHelper::getBoolVector(params, prefix + "activeSensors", "111111111111111111111111")),
1096 ConfigurationHelper::throwUserConfigError(prefix + "activeSensors", params.getValue(prefix + "activeSensors"), "The parameter must be a list of exactly 24 elements either equal to 1 or to 0 (do not use any space to separate elements, just put them directly one after the other)");
1099 if ((m_averageNum != 0) && (m_averageNum != 2) && (m_averageNum != 3) && (m_averageNum != 4) && (m_averageNum != 6)) {
1100 ConfigurationHelper::throwUserConfigError(prefix + "averageNum", params.getValue(prefix + "averageNum"), "The parameter can only be 0, 2, 3, 4 or 6");
1105 ConfigurationHelper::throwUserConfigError(prefix + "roundSamples", m_roundSamples.filename(), "The file has samples for the wrong number of sensors, expected 24, got " + QString::number(m_roundSamples.numIR()));
1108 ConfigurationHelper::throwUserConfigError(prefix + "smallSamples", m_smallSamples.filename(), "The file has samples for the wrong number of sensors, expected 24, got " + QString::number(m_smallSamples.numIR()));
1111 ConfigurationHelper::throwUserConfigError(prefix + "wallSamples", m_wallSamples.filename(), "The file has samples for the wrong number of sensors, expected 8, got " + QString::number(m_wallSamples.numIR()));
1147 Descriptor d = addTypeDescription(type, "The sampled proximity infrared sensors of the MarXbot", "This is the sampled version of the proximity infrared sensors of the MarXbot. This sensor only works with objects created using the Arena");
1148 d.describeString("activeSensors").def("111111111111111111111111").help("Which IR sensors of the robot are actually enabled", "This is a string of exactly 24 elements. Each element can be either \"0\" or \"1\" to respectively disable/enable the corresponding proximity IR sensor. The first sensor is the one on the left side of the robot and the others follow counterclockwise (i.e. left, back, right, front)");
1149 d.describeInt("averageNum").def(0).limits(0, 6).help("How many sensors should be averaged", "This can only be 0, 2, 3, 4 or 6. If 2, for each couple of consecutive sensors the average is returned, if 3 for each triplet of consecutive sensors the average is returned and so on. If this is zero, no average is computed and the activeSensors parameter is used. The default value is 0");
1150 d.describeString("roundSamples").def("round.sam").help("The name of the file with samples for big round objects");
1151 d.describeString("smallSamples").def("small.sam").help("The name of the file with samples for small round objects");
1152 d.describeString("wallSamples").def("wall.sam").help("The name of the file with samples for walls");
1169 // Cycling through the list of objects. We first need to get the current position and orientation of the robot
1173 // Computing angle and distance. We don't need to remove the robot to which this sensor belongs because
1179 if (!obj->computeDistanceAndOrientationFromRobot(*(m_arena->getRobotWrapper(m_marxbotResource)), distance, angle)) {
1197 //Logger::warning("The sampled infrared sensor only works with Small Cylinders, Big Cylinders, Walls and other Robots");
1202 for (QVector<real>::iterator it = activations.begin(); it != activations.end(); ++it, ++actIt) {
1240 void MarXbotSampledProximityIRSensor::resourceChanged(QString resourceName, ResourceChangeType changeType)
1268 m_neuronsIterator->setGraphicProperties(QString("ir%1-%2").arg(i).arg(i + m_averageNum - 1), 0.0, 1.0, Qt::red);
1280 MarXbotAttachmentDeviceSensor::MarXbotAttachmentDeviceSensor(ConfigurationParameters& params, QString prefix) :
1287 m_enableOtherAttached(ConfigurationHelper::getBool(params, prefix + "enableOtherAttached", true)),
1288 m_numInputs((m_enablePosition ? 2 : 0) + (m_enableStatus ? 1 : 0) + (m_enableAttached ? 1 : 0) + (m_enableOtherAttached ? 1 : 0))
1307 params.createParameter(prefix, "enableOtherAttached", (m_enableOtherAttached ? "true" : "false"));
1316 Descriptor d = addTypeDescription(type, "The sensor providing the attachment device proprioception", "This sensor provides information about the current status of the attachment device. It provides several inputs (which can be disabled using parameters). The position of the gripper is provided using two neurons (the sin() and the cos() of the angle) to alleviate the problem of 0° and 360° being the same angle with opposite activations.");
1317 d.describeBool("enablePosition").def(true).help("Whether inputs with the position of the attachment device should be enabled or not (default: true)");
1318 d.describeBool("enableStatus").def(true).help("Whether the input with the status of the attachment device should be enabled or not (default: true)");
1319 d.describeBool("enableAttached").def(true).help("Whether the input telling if this robot is attached to another robot should be enabled or not (default: true)");
1320 d.describeBool("enableOtherAttached").def(true).help("Whether the input telling if another robot is attached to this robot should be enabled or not (default: true)");
1332 const MarXbotAttachmentDeviceMotorController *const ctrl = m_robot->attachmentDeviceController();
1380 void MarXbotAttachmentDeviceSensor::resourceChanged(QString resourceName, ResourceChangeType changeType)
1453 MarXbotWheelSpeedsSensor::MarXbotWheelSpeedsSensor(ConfigurationParameters& params, QString prefix) :
1460 ConfigurationHelper::throwUserConfigError(prefix + "mode", params.getValue(prefix + "mode"), "The parameter must be one of \"Absolute\" or \"Delta\" (case insensitive)");
1485 Descriptor d = addTypeDescription(type, "The sensor reporting the actual velocity of the wheels of the MarXbot", "This sensor have three modalities, see the mode parameter");
1486 d.describeEnum("mode").def("Absolute").values(QStringList() << "Absolute" << "Delta").help("The modality of the sensor", "The possible modalities are: \"Absolute\" meaning that the senors returns the current velocity of the wheels (scaled between -1 and 1) and \"Delta\", meaning that the sensor returns the absolute value of the difference between the desired velocity and the current velocity. The default value is \"Absolute\"");
1544 void MarXbotWheelSpeedsSensor::resourceChanged(QString resourceName, ResourceChangeType changeType)
1586 MarXbotLaserFrontDistanceSensor::MarXbotLaserFrontDistanceSensor(ConfigurationParameters& params, QString prefix) :
1601 ConfigurationHelper::throwUserConfigError(prefix + "maxDistance", params.getValue(prefix + "maxDistance"), "The parameter must be a positive real number");
1603 ConfigurationHelper::throwUserConfigError(prefix + "aperture", params.getValue(prefix + "aperture"), "The parameter must be a positive real number smaller than 360");
1623 params.createParameter(prefix, "drawSensors", m_drawSensors ? QString("true") : QString("false"));
1625 params.createParameter(prefix, "drawRaysRange", m_drawRaysRange ? QString("true") : QString("false"));
1634 Descriptor d = addTypeDescription(type, "A frontal distance sensor for long distances", "This is a simple distance sensor in the frontal part of the robot with three rays, at -30°, 0° and 30° with respect to the frontal part of the robot. This could be implemented on the real robot using the laser scanner.");
1635 d.describeReal("maxDistance").def(1.0).limits(0.0f, +Infinity).help("The maximum distance of the sensors");
1636 d.describeReal("aperture").def(60.0).limits(0.0f, 360.0f).help("The sensor aperture in degrees");
1638 d.describeBool("drawRays").def(false).help("When drawing the sensor, whether to draw the rays or not");
1639 d.describeBool("drawRaysRange").def(false).help("When drawing the rays, whether to draw the real range or not");
1658 m_neuronsIterator->setInput(applyNoise(1.0 - m_sensorLeft->getRayCastHit().distance, 0.0, 1.0));
1660 m_neuronsIterator->setInput(applyNoise(1.0 - m_sensorCenter->getRayCastHit().distance, 0.0, 1.0));
1662 m_neuronsIterator->setInput(applyNoise(1.0 - m_sensorRight->getRayCastHit().distance, 0.0, 1.0));
1671 void MarXbotLaserFrontDistanceSensor::resourceChanged(QString resourceName, ResourceChangeType changeType)
1689 centralMtr.w_pos = wVector(0.0, -PhyMarXbot::bodyr, PhyMarXbot::basez + PhyMarXbot::trackradius * 2.0f + PhyMarXbot::treaddepth);