コード例 #1
0
ServoMotor::ServoMotor(QString const &port, trikKernel::Configurer const &configurer)
	: mDutyFile(configurer.attributeByPort(port, "deviceFile"))
	, mPeriodFile(configurer.attributeByPort(port, "periodFile"))
	, mCurrentDutyPercent(0)
	, mInvert(configurer.attributeByPort(port, "invert") == "true")
	, mCurrentPower(0)
{
	auto configure = [this, &port, &configurer](QString const &parameterName) {
		return ConfigurerHelper::configureInt(configurer, mState, port, parameterName);
	};

	mPeriod = configure("period");
	mMin = configure("min");
	mMax = configure("max");
	mZero = configure("zero");
	mStop = configure("stop");

	mMotorType = configurer.attributeByPort(port, "type") == "angular" ? Type::angular : Type::continiousRotation;

	if (!mPeriodFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Unbuffered | QIODevice::Text)) {
		QLOG_ERROR() << "Can't open motor period file " << mPeriodFile.fileName();
		mState.fail();
		return;
	}

	QString const command = QString::number(mPeriod);

	mPeriodFile.write(command.toLatin1());
	mPeriodFile.close();

	mState.ready();
}
コード例 #2
0
ファイル: rangeSensor.cpp プロジェクト: AnnaAK/trikRuntime
RangeSensor::RangeSensor(const QString &port, const trikKernel::Configurer &configurer, ModuleLoader &moduleLoader
		, const trikHal::HardwareAbstractionInterface &hardwareAbstraction)
	: mState("Range Sensor on " + port)
{
	if (!moduleLoader.load(configurer.attributeByPort(port, "module"))
			|| !moduleLoader.load(configurer.attributeByDevice("rangeSensor", "commonModule")))
	{
		QLOG_ERROR() << "Module loading failed";
		mState.fail();
		return;
	}

	mMinValue = ConfigurerHelper::configureInt(configurer, mState, port, "minValue");
	mMaxValue = ConfigurerHelper::configureInt(configurer, mState, port, "maxValue");

	mSensorWorker.reset(new RangeSensorWorker(configurer.attributeByPort(port, "eventFile"), mState
			, hardwareAbstraction));

	if (!mState.isFailed()) {
		mSensorWorker->moveToThread(&mWorkerThread);

		connect(mSensorWorker.data(), SIGNAL(newData(int, int, trikKernel::TimeVal))
				, this, SIGNAL(newData(int, int, trikKernel::TimeVal)));

		QLOG_INFO() << "Starting RangeSensor worker thread" << &mWorkerThread;

		mWorkerThread.start();
	}
コード例 #3
0
RangeSensor::RangeSensor(QString const &port, trikKernel::Configurer const &configurer, ModuleLoader &moduleLoader)
{
	if (!moduleLoader.load(configurer.attributeByPort(port, "module"))
			|| !moduleLoader.load(configurer.attributeByDevice("rangeSensor", "commonModule")))
	{
		QLOG_ERROR() << "Module loading failed";
		mState.fail();
		return;
	}

	mSensorWorker.reset(new RangeSensorWorker(configurer.attributeByPort(port, "eventFile"), mState));

	if (!mState.isFailed()) {
		mSensorWorker->moveToThread(&mWorkerThread);

		connect(mSensorWorker.data(), SIGNAL(newData(int, int)), this, SIGNAL(newData(int, int)));

		mWorkerThread.start();
	}
コード例 #4
0
DigitalSensor::DigitalSensor(const QString &port, const trikKernel::Configurer &configurer)
	: mDeviceFile(configurer.attributeByPort(port, "deviceFile"))
{

	mMin = ConfigurerHelper::configureInt(configurer, mState, port, "min");
	mMax = ConfigurerHelper::configureInt(configurer, mState, port, "max");

	mState.ready();

	// Testing availability of a device.
	read();
}