Skip to content

Commit 470e539

Browse files
Added the ability to stop videosensors, updated configs to use videomodules, updated line sensor to return crossroad probability
1 parent 927bfa9 commit 470e539

14 files changed

+78
-24
lines changed

trikControl/config.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,13 @@ Use it if JCx ports are configured to work as PWM signal generators.
191191
<i2c path="/dev/i2c-2" deviceId="0x48" />
192192

193193
<!-- Settings for virtual camera line sensor. -->
194-
<lineSensor script="/etc/init.d/line-sensor.sh" inputFile="/run/line-sensor.in.fifo" outputFile="/run/line-sensor.out.fifo" toleranceFactor="1.0" disabled="false" />
194+
<lineSensor script="/etc/init.d/line-sensor-ov7670.sh" inputFile="/run/line-sensor.in.fifo" outputFile="/run/line-sensor.out.fifo" toleranceFactor="1.0" disabled="false" />
195195

196196
<!-- Settings for virtual camera object detector sensor. -->
197-
<objectSensor script="/etc/init.d/object-sensor.sh" inputFile="/run/object-sensor.in.fifo" outputFile="/run/object-sensor.out.fifo" toleranceFactor="1.0" disabled="false" />
197+
<objectSensor script="/etc/init.d/object-sensor-7670.sh" inputFile="/run/object-sensor.in.fifo" outputFile="/run/object-sensor.out.fifo" toleranceFactor="1.0" disabled="false" />
198198

199199
<!-- Settings for virtual camera MxN color sensor. It splits field of view of a camera into MxN grid and reports dominant color in each cell of a grid. -->
200-
<colorSensor script="/etc/init.d/mxn-sensor.sh" inputFile="/run/mxn-sensor.in.fifo" outputFile="/run/mxn-sensor.out.fifo" m="3" n="3" disabled="false" />
200+
<colorSensor script="/etc/init.d/mxn-sensor-7670.sh" inputFile="/run/mxn-sensor.in.fifo" outputFile="/run/mxn-sensor.out.fifo" m="3" n="3" disabled="false" />
201201

202202
<!-- Settings for gamepad TCP server to communicate with Android "TRIK Gamepad" application -->
203203
<gamepad port="4444" disabled="false" />

trikControl/include/trikControl/colorSensor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public slots:
5050
/// Returns dominant color in given cell of a grid as a vector [R; G; B] in RGB color scale.
5151
QVector<int> read(int m, int n);
5252

53+
/// Stops detection until init() will be called again.
54+
void stop();
55+
5356
private:
5457
/// Worker object that handles sensor in separate thread.
5558
QScopedPointer<ColorSensorWorker> mColorSensorWorker;

trikControl/include/trikControl/lineSensor.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <QtCore/QString>
1919
#include <QtCore/QThread>
2020
#include <QtCore/QScopedPointer>
21+
#include <QtCore/QVector>
2122

2223
#include "declSpec.h"
2324
#include "sensor.h"
@@ -28,7 +29,7 @@ class LineSensorWorker;
2829

2930
/// Uses virtual line sensor to detect x coordinate of a center of an object that was in camera's field of view
3031
/// when "detect" method was called. Used mainly to follow the line.
31-
class TRIKCONTROL_EXPORT LineSensor : public Sensor
32+
class TRIKCONTROL_EXPORT LineSensor : public QObject
3233
{
3334
Q_OBJECT
3435

@@ -52,7 +53,10 @@ public slots:
5253
void detect();
5354

5455
/// Returns current raw x coordinate of detected object. Sensor returns 0 if detect() was not called.
55-
int read(); // override.
56+
QVector<int> read();
57+
58+
/// Stops detection until init() will be called again.
59+
void stop();
5660

5761
private:
5862
/// Worker object that handles sensor in separate thread.

trikControl/include/trikControl/objectSensor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public slots:
5656
/// Returns 0 in every field if detect() was not called.
5757
QVector<int> read();
5858

59+
/// Stops detection until init() will be called again.
60+
void stop();
61+
5962
private:
6063
/// Worker object that handles sensor in separate thread.
6164
QScopedPointer<ObjectSensorWorker> mObjectSensorWorker;

trikControl/src/abstractVirtualSensorWorker.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ class AbstractVirtualSensorWorker : public QObject
4242

4343
~AbstractVirtualSensorWorker() override;
4444

45+
public slots:
46+
/// Stops detection until init() will be called again.
47+
virtual void stop();
48+
4549
protected:
4650
/// Launch sensor.
4751
void init();

trikControl/src/brick.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,18 @@ void Brick::stop()
236236

237237
mLed->red();
238238
mDisplay.hide();
239+
240+
if (mLineSensor) {
241+
mLineSensor->stop();
242+
}
243+
244+
if (mColorSensor) {
245+
mColorSensor->stop();
246+
}
247+
248+
if (mObjectSensor) {
249+
mObjectSensor->stop();
250+
}
239251
}
240252

241253
Motor *Brick::motor(QString const &port)

trikControl/src/colorSensor.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,8 @@ QVector<int> ColorSensor::read(int m, int n)
4343
// Read is called synchronously and only takes prepared value from sensor.
4444
return mColorSensorWorker->read(m, n);
4545
}
46+
47+
void ColorSensor::stop()
48+
{
49+
QMetaObject::invokeMethod(mColorSensorWorker.data(), "stop");
50+
}

trikControl/src/colorSensorWorker.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ void ColorSensorWorker::onNewData(QString const &dataLine)
6464
{
6565
QStringList const parsedLine = dataLine.split(" ", QString::SkipEmptyParts);
6666

67-
qDebug() << "parsed: " << parsedLine;
68-
6967
if (parsedLine[0] == "color:") {
7068
mLock.lockForWrite();
7169
for (int i = 0; i < mReading.size(); ++i) {

trikControl/src/lineSensor.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ void LineSensor::detect()
4444
QMetaObject::invokeMethod(mLineSensorWorker.data(), "detect");
4545
}
4646

47-
int LineSensor::read()
47+
QVector<int> LineSensor::read()
4848
{
4949
// Read is called synchronously and only takes prepared value from sensor.
5050
return mLineSensorWorker->read();
5151
}
52+
53+
void LineSensor::stop()
54+
{
55+
QMetaObject::invokeMethod(mLineSensorWorker.data(), "stop");
56+
}

trikControl/src/lineSensorWorker.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ void LineSensorWorker::detect()
4040
sendCommand("detect");
4141
}
4242

43-
int LineSensorWorker::read()
43+
QVector<int> LineSensorWorker::read()
4444
{
45-
return mReading;
45+
mLock.lockForRead();
46+
QVector<int> result = mReading;
47+
mLock.unlock();
48+
return result;
4649
}
4750

4851
QString LineSensorWorker::sensorName() const
@@ -54,18 +57,16 @@ void LineSensorWorker::onNewData(QString const &dataLine)
5457
{
5558
QStringList const parsedLine = dataLine.split(" ", QString::SkipEmptyParts);
5659

57-
qDebug() << "parsed: " << parsedLine;
58-
5960
if (parsedLine[0] == "loc:") {
6061
int const x = parsedLine[1].toInt();
61-
int const angle = parsedLine[2].toInt();
62+
int const crossroadsProbability = parsedLine[2].toInt();
6263
int const mass = parsedLine[3].toInt();
6364

64-
mReading = x;
65-
66-
// These values are not needed in current implementation, but are left here for reference.
67-
Q_UNUSED(angle)
68-
Q_UNUSED(mass)
65+
mLock.lockForWrite();
66+
mReading[0] = x;
67+
mReading[1] = crossroadsProbability;
68+
mReading[2] = mass;
69+
mLock.unlock();
6970
}
7071

7172
if (parsedLine[0] == "hsv:") {

0 commit comments

Comments
 (0)