trikRuntime
lineSensorWorker.h
Go to the documentation of this file.
1 /* Copyright 2014 CyberTech Labs Ltd.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License. */
14 
15 #pragma once
16 
17 #include <QtCore/QObject>
18 #include <QtCore/QString>
19 #include <QtCore/QReadWriteLock>
20 #include <QtCore/QVector>
21 #include <QReadWriteLock>
22 
24 
25 namespace trikControl {
26 
30 {
31  Q_OBJECT
32 
33 public:
40  LineSensorWorker(const QString &script, const QString &inputFile, const QString &outputFile
41  , qreal toleranceFactor, DeviceState &state, trikHal::HardwareAbstractionInterface &hardwareAbstraction);
42 
43  ~LineSensorWorker() override;
44 
45 public slots:
48  void init(bool showOnDisplay);
49 
51  void detect();
52 
55  QVector<int> read();
56 
59  QVector<int> getDetectParameters() const;
60 
61 private:
62  QString sensorName() const override;
63 
64  void onNewData(const QString &dataLine) override;
65 
67  QVector<int> mReading{0, 0, 0};
68 
70  QVector<int> mReadingBuffer{0, 0, 0};
71 
73  qreal mToleranceFactor = 1.0;
74 
76  bool mShowOnDisplay = true;
77 
79  QVector<int> mDetectParametersBuffer{0, 0, 0, 0, 0, 0};
80 
82  QVector<int> mDetectParameters{0, 0, 0, 0, 0, 0};
83 
84  QReadWriteLock mReadingLock;
85 
86  mutable QReadWriteLock mDetectParametersLock;
87 };
88 
89 }
QVector< int > read()
Returns current raw x coordinate of detected object.
Definition: lineSensorWorker.cpp:41
void detect()
Detects the color of an object in center of current frame and memorizes it.
Definition: lineSensorWorker.cpp:36
Helper class to track device state (off, starting, ready, stopping, fail).
Definition: deviceState.h:26
Definition: trikCommunicator.h:27
Worker object that processes line sensor output and updates stored reading.
Definition: lineSensorWorker.h:29
void init()
Launch sensor.
Definition: abstractVirtualSensorWorker.cpp:61
LineSensorWorker(const QString &script, const QString &inputFile, const QString &outputFile, qreal toleranceFactor, DeviceState &state, trikHal::HardwareAbstractionInterface &hardwareAbstraction)
Constructor.
Definition: lineSensorWorker.cpp:19
Base class for all virtual sensor workers.
Definition: abstractVirtualSensorWorker.h:38
QVector< int > getDetectParameters() const
Get values returned by last "detect" operation.
Definition: lineSensorWorker.cpp:47
script
Definition: system.py:83
~LineSensorWorker() override
Definition: lineSensorWorker.cpp:26
Hardware abstraction, provides devices that are used to communicate with robot hardware or emulate it...
Definition: hardwareAbstractionInterface.h:29