Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

me/improve code 3 #814

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class TrikCommunicator : public trikNetwork::TrikServer

~TrikCommunicator() override;

signals:
Q_SIGNALS:
/// Emitted when stop command received from a computer.
void stopCommandReceived();

Expand Down
2 changes: 1 addition & 1 deletion trikCommunicator/src/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void Connection::processData(const QByteArray &data)

QMetaObject::invokeMethod(&mTrikScriptRunner, [=](){mTrikScriptRunner.run(fileContents, command);});
} else if (command == "stop") {
emit stopCommandReceived();
Q_EMIT stopCommandReceived();
} else if (command.startsWith("direct:")) {
command.remove(0, QString("direct:").length());
QMetaObject::invokeMethod(&mTrikScriptRunner, [=](){mTrikScriptRunner.runDirectCommand(command);});
Expand Down
2 changes: 1 addition & 1 deletion trikCommunicator/src/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Connection : public trikNetwork::Connection
/// Writes a given message to inner socket.
void sendMessage(const QString &message);

signals:
Q_SIGNALS:
/// Emitted when a stop command received from a computer.
void stopCommandReceived();

Expand Down
2 changes: 1 addition & 1 deletion trikControl/include/trikControl/batteryInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace trikControl {
class TRIKCONTROL_EXPORT BatteryInterface : public QObject, public DeviceInterface
{
Q_OBJECT
public slots:
public Q_SLOTS:
/// Returns current battery voltage in volts.
virtual float readVoltage() = 0;

Expand Down
60 changes: 31 additions & 29 deletions trikControl/include/trikControl/brickInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class TRIKCONTROL_EXPORT BrickInterface : public QObject
/// Returns version of system configuration file.
virtual QString configVersion() const = 0;

public slots:
public Q_SLOTS:
/// Configures given device on given port. Port must be listed in model-config.xml, device shall be listed
/// in system-config.xml, and device shall be able to be configured on a port (it is also described
/// in system-config.xml). Previously configured device is properly shut down, and new device is created
Expand All @@ -87,87 +87,89 @@ public slots:
/// Returns reference to motor of a given type on a given port
virtual trikControl::MotorInterface *motor(const QString &port) = 0;

/// Stops listening given event device and destroys its watcher object.
virtual void stopEventDevice(const QString &deviceFile) = 0;

public:
/// Returns reference to PWM signal capture device on a given port.
virtual trikControl::PwmCaptureInterface *pwmCapture(const QString &port) = 0;
Q_INVOKABLE virtual trikControl::PwmCaptureInterface *pwmCapture(const QString &port) = 0;

/// Returns reference to sensor on a given port.
virtual trikControl::SensorInterface *sensor(const QString &port) = 0;
Q_INVOKABLE virtual trikControl::SensorInterface *sensor(const QString &port) = 0;

/// Retruns list of ports for motors of a given type.
virtual QStringList motorPorts(MotorInterface::Type type) const = 0;
Q_INVOKABLE virtual QStringList motorPorts(MotorInterface::Type type) const = 0;

/// Returns list of PWM signal capture device ports.
virtual QStringList pwmCapturePorts() const = 0;
Q_INVOKABLE virtual QStringList pwmCapturePorts() const = 0;

/// Returns list of ports for sensors of a given type.
virtual QStringList sensorPorts(SensorInterface::Type type) const = 0;
Q_INVOKABLE virtual QStringList sensorPorts(SensorInterface::Type type) const = 0;

/// Returns list of encoder ports
virtual QStringList encoderPorts() const = 0;
Q_INVOKABLE virtual QStringList encoderPorts() const = 0;

/// Returns on-board accelerometer.
virtual trikControl::VectorSensorInterface *accelerometer() = 0;
Q_INVOKABLE virtual trikControl::VectorSensorInterface *accelerometer() = 0;

/// Returns on-board gyroscope.
virtual trikControl::GyroSensorInterface *gyroscope() = 0;
Q_INVOKABLE virtual trikControl::GyroSensorInterface *gyroscope() = 0;

/// Returns high-level line detector sensor using camera on given port (video0 or video1).
virtual trikControl::LineSensorInterface *lineSensor(const QString &port) = 0;
Q_INVOKABLE virtual trikControl::LineSensorInterface *lineSensor(const QString &port) = 0;

/// Returns high-level color sensor using camera on given port (video0 or video1).
virtual trikControl::ColorSensorInterface *colorSensor(const QString &port) = 0;
Q_INVOKABLE virtual trikControl::ColorSensorInterface *colorSensor(const QString &port) = 0;

/// Returns high-level object detector sensor using camera on given port (video0 or video1).
virtual trikControl::ObjectSensorInterface *objectSensor(const QString &port) = 0;
Q_INVOKABLE virtual trikControl::ObjectSensorInterface *objectSensor(const QString &port) = 0;

/// Returns lidar on given port.
virtual trikControl::LidarInterface *lidar() = 0;
Q_INVOKABLE virtual trikControl::LidarInterface *lidar() = 0;

/// Returns i2c device object
virtual trikControl::I2cDeviceInterface *i2c(int bus, int address) = 0;
Q_INVOKABLE virtual trikControl::I2cDeviceInterface *i2c(int bus, int address) = 0;

/// Returns QVector<uin8_t> with image using camera on given port (video0 or video1).
virtual QVector<uint8_t> getStillImage() = 0;
Q_INVOKABLE virtual QVector<uint8_t> getStillImage() = 0;

/// Returns high-level sound detector sensor using microphones.
virtual trikControl::SoundSensorInterface *soundSensor(const QString &port) = 0;
Q_INVOKABLE virtual trikControl::SoundSensorInterface *soundSensor(const QString &port) = 0;

/// Returns encoder on given port.
virtual trikControl::EncoderInterface *encoder(const QString &port) = 0;
Q_INVOKABLE virtual trikControl::EncoderInterface *encoder(const QString &port) = 0;

/// Returns battery.
virtual trikControl::BatteryInterface *battery() = 0;
Q_INVOKABLE virtual trikControl::BatteryInterface *battery() = 0;

/// Returns keys on a control brick.
virtual trikControl::KeysInterface *keys() = 0;
Q_INVOKABLE virtual trikControl::KeysInterface *keys() = 0;

/// Returns class that provides drawing on display.
virtual trikControl::DisplayInterface *display() = 0;
Q_INVOKABLE virtual trikControl::DisplayInterface *display() = 0;

/// Returns LED control class.
virtual trikControl::LedInterface *led() = 0;
Q_INVOKABLE virtual trikControl::LedInterface *led() = 0;

/// Returns handler for Android gamepad.
virtual trikControl::GamepadInterface *gamepad() = 0;
Q_INVOKABLE virtual trikControl::GamepadInterface *gamepad() = 0;

/// Returns custom FIFO file which can be used as sensor.
virtual trikControl::FifoInterface *fifo(const QString &port) = 0;
Q_INVOKABLE virtual trikControl::FifoInterface *fifo(const QString &port) = 0;

/// Returns marker.
virtual trikControl::MarkerInterface *marker() = 0;
Q_INVOKABLE virtual trikControl::MarkerInterface *marker() = 0;

/// Returns IR camera
virtual trikControl::IrCameraInterface *irCamera() = 0;
Q_INVOKABLE virtual trikControl::IrCameraInterface *irCamera() = 0;

/// Returns custom event device that can be used as a sensor, for example, for custom gamepad support.
/// Creates new event device on first access to a file, then returns already opened device.
/// Ownership retained by brick.
virtual trikControl::EventDeviceInterface *eventDevice(const QString &deviceFile) = 0;
Q_INVOKABLE virtual trikControl::EventDeviceInterface *eventDevice(const QString &deviceFile) = 0;

/// Stops listening given event device and destroys its watcher object.
virtual void stopEventDevice(const QString &deviceFile) = 0;

signals:
Q_SIGNALS:
/// Emitted when all deferred deinitialization is completed and brick completely stopped. Note that if there is no
/// deferred deinitialization (no video sensors are on, for example), signal will NOT be emitted.
void stopped();
Expand Down
4 changes: 2 additions & 2 deletions trikControl/include/trikControl/colorSensorInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class TRIKCONTROL_EXPORT ColorSensorInterface : public QObject, public DeviceInt
{
Q_OBJECT

signals:
Q_SIGNALS:
/// Emitted when sensor is stopped successfully.
void stopped();

public slots:
public Q_SLOTS:
/// Initializes a camera.
/// @param showOnDisplay - true if we want an image from a camera to be drawn on robot display.
virtual void init(bool showOnDisplay) = 0;
Expand Down
2 changes: 1 addition & 1 deletion trikControl/include/trikControl/displayInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TRIKCONTROL_EXPORT DisplayInterface : public QObject
/// Returns widget on which everything is drawn.
virtual DisplayWidgetInterface &graphicsWidget() = 0;

public slots:
public Q_SLOTS:
/// Shows given image on a display.
/// @param fileName - file name (with path) of an image to show. Refer to Qt documentation for
/// supported formats, but .jpg, .png, .bmp, .gif are supported.
Expand Down
2 changes: 1 addition & 1 deletion trikControl/include/trikControl/displayWidgetInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TRIKCONTROL_EXPORT DisplayWidgetInterface : public QWidget
DisplayWidgetInterface() = default;
~DisplayWidgetInterface() override = default;

signals:
Q_SIGNALS:
/// Emitted when widget is shown.
void shown();

Expand Down
2 changes: 1 addition & 1 deletion trikControl/include/trikControl/encoderInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TRIKCONTROL_EXPORT EncoderInterface : public QObject, public DeviceInterfa
{
Q_OBJECT

public slots:
public Q_SLOTS:
/// Returns current encoder reading (in degrees).
virtual int read() = 0;

Expand Down
2 changes: 1 addition & 1 deletion trikControl/include/trikControl/eventCodeInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TRIKCONTROL_EXPORT EventCodeInterface : public QObject
{
Q_OBJECT

signals:
Q_SIGNALS:
/// Emitted when there is new event with specific type and code in an event file.
/// @param value - value sent with the event.
/// @param eventTime - time stamp of the event, in milliseconds from start of the Unix time (modulo 2^32).
Expand Down
4 changes: 2 additions & 2 deletions trikControl/include/trikControl/eventDeviceInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class TRIKCONTROL_EXPORT EventDeviceInterface : public QObject, public DeviceInt
{
Q_OBJECT

public slots:
public Q_SLOTS:
/// Returns object that allows to selectively subscribe only to event with given code.
virtual EventInterface *onEvent(int eventType) = 0;

signals:
Q_SIGNALS:
/// Emitted when there is new event in an event file.
/// @param event - type of the event.
/// @param code - code of the event inside a type.
Expand Down
4 changes: 2 additions & 2 deletions trikControl/include/trikControl/eventInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ class TRIKCONTROL_EXPORT EventInterface : public QObject
{
Q_OBJECT

public slots:
public Q_SLOTS:
/// Returns object that emits only events with specific code. See evtest output for a list of codes for
/// specific device.
virtual EventCodeInterface *code(int code) = 0;

signals:
Q_SIGNALS:
/// Emitted when there is new event in an event file.
/// @param code - code of the event inside a type.
/// @param value - value sent with the event.
Expand Down
12 changes: 6 additions & 6 deletions trikControl/include/trikControl/fifoInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ class TRIKCONTROL_EXPORT FifoInterface : public QObject, public DeviceInterface
{
Q_OBJECT

public slots:
public:
/// Reads line from this FIFO file, returning all available data as string.
virtual QString read() = 0;
Q_INVOKABLE virtual QString read() = 0;
/// Reads data from this FIFO file, returning all available data as string.
virtual QVector<uint8_t> readRaw() = 0;
Q_INVOKABLE virtual QVector<uint8_t> readRaw() = 0;

/// Returns true if FIFO has new line in it.
virtual bool hasLine() const = 0;
Q_INVOKABLE virtual bool hasLine() const = 0;
/// Returns true if FIFO has new bytes in it.
virtual bool hasData() const = 0;
Q_INVOKABLE virtual bool hasData() const = 0;

signals:
Q_SIGNALS:
/// Emitted once per each text line that arrives to FIFO.
void newLine(const QString &data);
/// Emitted when new bytes have arrived to FIFO file.
Expand Down
21 changes: 11 additions & 10 deletions trikControl/include/trikControl/gamepadInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,40 @@ class TRIKCONTROL_EXPORT GamepadInterface : public QObject
{
Q_OBJECT

public slots:
public Q_SLOTS:
/// Clear data about previous pad events.
virtual void reset() = 0;

public:
/// Returns true, if given pad button is pressed, and clears "pressed" state for that button.
/// Buttons have indexes from 1 to 5.
virtual bool buttonWasPressed(int buttonNumber) = 0;
Q_INVOKABLE virtual bool buttonWasPressed(int buttonNumber) = 0;

/// Returns true, if given pad button is pressed now. Buttons have indexes from 1 to 5.
virtual bool buttonIsPressed(int buttonNumber) = 0;
Q_INVOKABLE virtual bool buttonIsPressed(int buttonNumber) = 0;

/// Returns current state of the pad, true if pressed.
virtual bool isPadPressed(int pad) const = 0;
Q_INVOKABLE virtual bool isPadPressed(int pad) const = 0;

/// Returns current X coordinate of given pad or -1 if this pad is not pressed.
virtual int padX(int pad) const = 0;
Q_INVOKABLE virtual int padX(int pad) const = 0;

/// Returns current Y coordinate of given pad or -1 if this pad is not pressed.
virtual int padY(int pad) const = 0;
Q_INVOKABLE virtual int padY(int pad) const = 0;

/// Returns current tilt angle of Android device when "wheel" is turned on.
virtual int wheel() const = 0;
Q_INVOKABLE virtual int wheel() const = 0;

/// Returns true if a gamepad is currently connected to a robot.
virtual bool isConnected() const = 0;
Q_INVOKABLE virtual bool isConnected() const = 0;

/// Disconnects a gamepad.
/// Emits `disconnected` signal and then resets button state if a gamepad was connected to a robot.
/// Returns true if a gamepad was connected
virtual bool disconnect() = 0;
Q_INVOKABLE virtual bool disconnect() = 0;


signals:
Q_SIGNALS:
/// Emitted when user pulls finger off a pad.
/// @param pad - id of a pad on which the event occurs.
void padUp(int pad);
Expand Down
19 changes: 10 additions & 9 deletions trikControl/include/trikControl/gyroSensorInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,32 @@ class TRIKCONTROL_EXPORT GyroSensorInterface : public VectorSensorInterface
{
Q_OBJECT

signals:
Q_SIGNALS:

/// Emites when average mean of bias is counted.
void calibrationFinished();

public slots:
public Q_SLOTS:
/// Calibrates bias value of sensor, sets new bias value, resets other values include tilt values.
/// Preffered duration of calibration -- 15-20 seconds.
/// @param msec - duration of calibration in milliseconds
virtual void calibrate(int msec) = 0;

/// Returns vector with calibration values, which consists of 6 elements:
/// 0-2 -- gyroscope bias, 3-5 -- average accelerometer values.
/// Updated values is available only after calibration is done.
virtual QVector<int> getCalibrationValues() = 0;

/// Sets vector with calibration values to gyroscope sensor.
/// It consists of 6 elements: 0-2 -- gyroscope bias, 3-5 -- average accelerometer values at rest.
virtual void setCalibrationValues(const QVector<int> &values) = 0;

public:
/// Returns vector with calibration values, which consists of 6 elements:
/// 0-2 -- gyroscope bias, 3-5 -- average accelerometer values.
/// Updated values is available only after calibration is done.
Q_INVOKABLE virtual QVector<int> getCalibrationValues() = 0;

/// Checks if bias is counted or not.
virtual bool isCalibrated() const = 0;
Q_INVOKABLE virtual bool isCalibrated() const = 0;

/// Returns current raw reading of a sensor.
virtual QVector<int> readRawData() const = 0;
Q_INVOKABLE virtual QVector<int> readRawData() const = 0;
};

}
Expand Down
9 changes: 5 additions & 4 deletions trikControl/include/trikControl/irCameraInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,18 @@ public Q_SLOTS:
/// Stops frames capturing until init() will be called again.
virtual void stop() = 0;

public:
/// Gets photo as a vector of uint8_t in Grayscale8 format.
virtual QVector<int32_t> getImage() const = 0;
Q_INVOKABLE virtual QVector<int32_t> getImage() const = 0;

/// Returns average value in given cell of a grid.
/// @param[in] m row number
/// @param[in] n column number
virtual int readSensor(int m, int n) const = 0;
Q_INVOKABLE virtual int readSensor(int m, int n) const = 0;

Status status() const override = 0;
Q_INVOKABLE Status status() const override = 0;

signals:
Q_SIGNALS:
/// Emitted when new image is ready.
void imageUpdated();

Expand Down
Loading
Loading