Example #1
0
QString Sensors::code(const QString &directory
		, const kitBase::robotModel::PortInfo &port
		, const kitBase::robotModel::DeviceInfo &device)
{
	const QString portString = mInputPortConverter->convert(port.name());
	const QString templatePath = QString("%1/%2.t").arg(directory, device.name());
	return readTemplateIfExists(templatePath).replace("@@PORT@@", portString);
}
Example #2
0
QString ConstraintsChecker::portName(const QString &robotId
		, model::RobotModel * const robot, const kitBase::robotModel::PortInfo &port) const
{
	// We wish to know would be there a collision if someone writes "A1" or not.
	int portsWithSuchName = 0;
	for (kitBase::robotModel::PortInfo &otherPort : robot->info().availablePorts()) {
		if (port.name() == otherPort.name()) {
			++portsWithSuchName;
		}
	}

	// Making user write "robot1.DisplayPort_out.ellipses" or "robot1.MarkerPort_out" is non-humanistic.
	// So letting him write "robot1.display.ellipses" or "robot1.marker".
	QRegExp portRegExp("^(\\w+)Port$");
	const QString readablePortName = portRegExp.exactMatch(port.name())
			? utils::StringUtils::lowercaseFirstLetter(portRegExp.cap(1))
			: port.name();

	return portsWithSuchName > 1
			// If collision in name exists then user must specify what port exactly he wishes to process.
			? QString("%1.%2_%3").arg(robotId, readablePortName
					, port.direction() == kitBase::robotModel::input ? "in" : "out")
			: QString("%1.%2").arg(robotId, readablePortName);
}
Example #3
0
NxtInputDevice::NxtInputDevice(
		utils::robotCommunication::RobotCommunicator &robotCommunicator
		, const kitBase::robotModel::PortInfo &port
		, const enums::lowLevelSensorType::SensorTypeEnum &lowLevelSensorType
		, const enums::sensorMode::SensorModeEnum &sensorMode)
	: mRobotCommunicator(robotCommunicator)
	, mLowLevelPort(port.name().at(0).toLatin1() - '1')
	, mLowLevelSensorType(lowLevelSensorType)
	, mSensorMode(sensorMode)
	, mState(idle)
	, mIsConfigured(false)
	, mResetDone(false)
{
	QObject::connect(&mRobotCommunicator, &utils::robotCommunication::RobotCommunicator::response
			, this, &NxtInputDevice::readingDone);
}
QString ReservedVariablesConverter::deviceExpression(const kitBase::robotModel::PortInfo &port) const
{
	const kitBase::robotModel::DeviceInfo device = mDevices[port];
	if (device.isNull()) {
		mErrorReporter.addError(QObject::tr("Device on port %1 is not configured."\
				" Please select it on the \"Configure devices\" panel on the right-hand side.")
						.arg(port.userFriendlyName())
		);
		return QObject::tr("/* ERROR: SELECT DEVICE TYPE */");
	}

	const QString templatePath = mDeviceVariables.variableTemplatePath(device, port);

	// Converter must take a string like "1" or "2" (and etc) and return correct value
	return readTemplate(templatePath).replace("@@PORT@@", mInputConverter->convert(port.name()));
}
Example #5
0
QString TrikDeviceVariables::variableTemplatePath(const kitBase::robotModel::DeviceInfo &device
		, const kitBase::robotModel::PortInfo &port) const
{
	if (device.name() == "trikLineSensor"
			|| device.name() == "trikObjectSensor"
			|| device.name() == "trikColorSensor")
	{
		QString templateName = port.name();
		templateName.remove("Port");
		return "videosensors/" + templateName + ".t";
	} else if (device.name() == "gyroscope" || device.name() == "accelerometer") {
		return QString("%1/%2.t").arg(device.name(), port.reservedVariable());
	} else if (device.name().startsWith("gamepad")) {
		return QString("gamepad/%1.t").arg(device.name());
	}

	return generatorBase::parts::DeviceVariables::variableTemplatePath(device, port);
}
Example #6
0
char I2CCommunicator::toNxtInputPort(const kitBase::robotModel::PortInfo &port)
{
	return static_cast<char>(port.name().toInt() - 1);
}
Example #7
0
Ev3InputDevice::Ev3InputDevice(utils::robotCommunication::RobotCommunicator &robotCommunicator
		, const kitBase::robotModel::PortInfo &port)
	: mRobotCommunicator(robotCommunicator)
	, mLowLevelPort(port.name().at(0).toLatin1() - '1')
{
}
Example #8
0
QString ConstraintsChecker::portName(const QString &robotId, const kitBase::robotModel::PortInfo &port) const
{
	return QString("%1.%2_%3").arg(robotId, port.name()
			, port.direction() == kitBase::robotModel::input ? "in" : "out");
}