trikRuntime
brick.h
Go to the documentation of this file.
1 /* Copyright 2013 - 2016 Yurii Litvinov and 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/QHash>
18 #include <QtCore/QScopedPointer>
19 
20 #include <trikKernel/configurer.h>
22 
23 #include "brickInterface.h"
24 
25 namespace trikHal {
26 class HardwareAbstractionInterface;
27 }
28 
29 namespace trikControl {
30 
31 class AnalogSensor;
32 class Battery;
33 class ColorSensor;
34 class DigitalSensor;
35 class Display;
36 class Encoder;
37 class EventDevice;
38 class Fifo;
39 class Gamepad;
40 class GyroSensor;
41 class MspCommunicatorInterface;
42 class Keys;
43 class Led;
44 class LineSensor;
45 class ModuleLoader;
46 class ObjectSensor;
47 class SoundSensor;
48 class PowerMotor;
49 class PwmCapture;
50 class RangeSensor;
51 class ServoMotor;
52 class TonePlayer;
53 class VectorSensor;
54 class CameraDeviceInterface;
55 class I2cCommunicator;
56 
60 class /* TRIKCONTROL_EXPORT for ScriptRunner/PythonQt */ TRIKCONTROL_EXPORT Brick : public BrickInterface
61 {
62  Q_OBJECT
63 
64 public:
69  Brick(const QString &systemConfig, const QString &modelConfig, const QString &mediaPath);
70 
76  Brick(trikHal::HardwareAbstractionInterface &hardwareAbstraction, const QString &systemConfig
77  , const QString &modelConfig, const QString &mediaPath);
78 
79  ~Brick() override;
80 
81  void reset() override;
82 
83  DisplayWidgetInterface *graphicsWidget() override;
84 
85  QString configVersion() const override;
86 
87 public slots:
88  void configure(const QString &portName, const QString &deviceName) override;
89 
90  void playSound(const QString &soundFileName) override;
91 
92  void playTone(int hzFreq, int msDuration) override;
93 
94  void say(const QString &text) override;
95 
96  void stop() override;
97 
98  MotorInterface *motor(const QString &port) override;
99 
100  PwmCaptureInterface *pwmCapture(const QString &port) override;
101 
102  SensorInterface *sensor(const QString &port) override;
103 
104  QStringList motorPorts(MotorInterface::Type type) const override;
105 
106  QStringList pwmCapturePorts() const override;
107 
108  QStringList sensorPorts(SensorInterface::Type type) const override;
109 
110  QStringList encoderPorts() const override;
111 
112  VectorSensorInterface *accelerometer() override;
113 
114  GyroSensorInterface *gyroscope() override;
115 
116  LineSensorInterface *lineSensor(const QString &port) override;
117 
118  ColorSensorInterface *colorSensor(const QString &port) override;
119 
120  ObjectSensorInterface *objectSensor(const QString &port) override;
121 
122  I2cDeviceInterface *i2c(int bus, int address) override;
123 
124  QVector<uint8_t> getStillImage() override;
125 
126  SoundSensorInterface *soundSensor(const QString &port) override;
127 
128  EncoderInterface *encoder(const QString &port) override;
129 
130  BatteryInterface *battery() override;
131 
132  KeysInterface *keys() override;
133 
134  DisplayInterface *display() override;
135 
136  LedInterface *led() override;
137 
138  GamepadInterface *gamepad() override;
139 
140  FifoInterface *fifo(const QString &port) override;
141 
142  MarkerInterface *marker() override;
143 
144  EventDeviceInterface *eventDevice(const QString &deviceFile) override;
145 
146  void stopEventDevice(const QString &deviceFile) override;
147 
148 private:
150  , const QString &systemConfig
151  , const QString &modelConfig
152  , const QString &mediaPath);
153 
155  void shutdownDevice(const QString &port);
156 
158  void createDevice(const QString &port);
159 
163 
164  QScopedPointer<MspCommunicatorInterface> mMspCommunicator;
165  QScopedPointer<ModuleLoader> mModuleLoader;
166 
167  QScopedPointer<VectorSensor> mAccelerometer;
168  QScopedPointer<GyroSensor> mGyroscope;
169  QScopedPointer<Battery> mBattery;
170  QScopedPointer<Keys> mKeys;
171  QScopedPointer<Display> mDisplay;
172  QScopedPointer<Led> mLed;
173  QScopedPointer<Gamepad> mGamepad;
174  QScopedPointer<TonePlayer> mTonePlayer;
175  QScopedPointer<CameraDeviceInterface> mCamera;
176 
177  QHash<QString, ServoMotor *> mServoMotors; // Has ownership.
178  QHash<QString, PwmCapture *> mPwmCaptures; // Has ownership.
179  QHash<QString, PowerMotor *> mPowerMotors; // Has ownership.
180  QHash<QString, AnalogSensor *> mAnalogSensors; // Has ownership.
181  QHash<QString, Encoder *> mEncoders; // Has ownership.
182  QHash<QString, DigitalSensor *> mDigitalSensors; // Has ownership.
183  QHash<QString, RangeSensor *> mRangeSensors; // Has ownership.
184  QHash<QString, LineSensor *> mLineSensors; // Has ownership.
185  QHash<QString, ColorSensor *> mColorSensors; // Has ownership.
186  QHash<QString, ObjectSensor *> mObjectSensors; // Has ownership.
187  QHash<QString, SoundSensor *> mSoundSensors; // Has ownership.
188  QHash<QString, Fifo *> mFifos; // Has ownership.
189  QHash<QString, EventDeviceInterface *> mEventDevices; // Has ownership.
190  QHash<uint16_t, I2cDeviceInterface *> mI2cDevices; // Has ownership.
191 
192  QString mPlayWavFileCommand;
193  QString mPlayMp3FileCommand;
194  QString mMediaPath;
195 
196  trikKernel::Configurer mConfigurer;
197 };
198 
199 }
Uses virtual line sensor to detect x coordinate of a center of an object that was in camera&#39;s field o...
Definition: lineSensorInterface.h:29
Class for work with i2c.
Definition: i2cDeviceInterface.h:26
Generic configuration helper, parses configuration XML files and presents configuration as a set of a...
Definition: configurer.h:28
static const int port
Definition: trikCommunicatorTest.cpp:24
Controls light-emitting diode on a brick.
Definition: ledInterface.h:26
Interface that represents linux FIFO file, which is commonly used by various sensors.
Definition: fifoInterface.h:26
Interface for widget on which Brick draws its graphics. Can notify when it shows or hides itself...
Definition: displayWidgetInterface.h:30
Abstract motor. It is differently implemented by different motor types (like servo and power motors)...
Definition: motorInterface.h:26
Sensor that returns a vector.
Definition: vectorSensorInterface.h:29
Provides characteristics of PWM signal supplied to the port.
Definition: pwmCaptureInterface.h:27
Generic event device.
Definition: eventDeviceInterface.h:27
Provides battery voltage info.
Definition: batteryInterface.h:26
Encoder of power motor.
Definition: encoderInterface.h:26
#define TRIKCONTROL_EXPORT
Definition: declSpec.h:23
Definition: trikCommunicator.h:27
Uses virtual color sensor to detect dominant color in every cell of m * n grid of camera field of vie...
Definition: colorSensorInterface.h:27
Remote control of a robot via Android gamepad.
Definition: gamepadInterface.h:24
Abstract sensor, inherited by various sensor types.
Definition: sensorInterface.h:26
Class that returns raw and processed data from the gyroscope.
Definition: gyroSensorInterface.h:27
Provides ability to draw something on robot display.
Definition: displayInterface.h:28
Class representing TRIK controller board and devices installed on it, also provides access to periphe...
Definition: brick.h:60
Class for handling keys on a brick.
Definition: keysInterface.h:26
Type
Definition: motorInterface.h:31
Definition: brickFactory.h:21
Type
Definition: sensorInterface.h:31
Uses virtual sound sensor to detect angle of sound source.
Definition: soundSensorInterface.h:27
Controls marker.
Definition: markerInterface.h:27
Uses virtual line sensor to detect x coordinate of a center of an object that was in camera&#39;s field o...
Definition: objectSensorInterface.h:28
Interface representing TRIK controller board and devices installed on it, also provides access to per...
Definition: brickInterface.h:46
Hardware abstraction, provides devices that are used to communicate with robot hardware or emulate it...
Definition: hardwareAbstractionInterface.h:29