File indexing completed on 2024-05-12 05:53:14
0001 /* 0002 * Copyright 2019 Eike Hein <hein@kde.org> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) version 3, or any 0008 * later version accepted by the membership of KDE e.V. (or its 0009 * successor approved by the membership of KDE e.V.), which shall 0010 * act as a proxy defined in Section 6 of version 3 of the license. 0011 * 0012 * This library is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Lesser General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Lesser General Public 0018 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 0021 #pragma once 0022 0023 #include <QGeoCoordinate> 0024 #include <QObject> 0025 #include <QSharedPointer> 0026 0027 #include "kirogicore_export.h" 0028 0029 class ParameterModel; 0030 0031 namespace Kirogi 0032 { 0033 class KIROGI_EXPORT AbstractVehicle : public QObject 0034 { 0035 Q_OBJECT 0036 0037 Q_PROPERTY(int id READ id CONSTANT) 0038 0039 Q_PROPERTY(QString name READ name NOTIFY nameChanged) 0040 Q_PROPERTY(QString iconName READ iconName NOTIFY iconNameChanged) 0041 0042 Q_PROPERTY(VehicleType vehicleType READ vehicleType CONSTANT) 0043 0044 Q_PROPERTY(ConnectionState connectionState READ connectionState NOTIFY connectionStateChanged) 0045 Q_PROPERTY(FlyingState flyingState READ flyingState NOTIFY flyingStateChanged) 0046 Q_PROPERTY(bool connected READ connected NOTIFY connectionStateChanged) 0047 Q_PROPERTY(bool ready READ ready NOTIFY connectionStateChanged) 0048 Q_PROPERTY(bool flying READ flying NOTIFY flyingStateChanged) 0049 0050 Q_PROPERTY(QList<VehicleAction> supportedActions READ supportedActions CONSTANT) 0051 0052 Q_PROPERTY(bool piloting READ piloting WRITE setPiloting NOTIFY pilotingChanged) 0053 0054 Q_PROPERTY(int flightTime READ flightTime NOTIFY flightTimeChanged) 0055 0056 Q_PROPERTY(PerformanceMode performanceMode READ performanceMode NOTIFY performanceModeChanged) 0057 0058 Q_PROPERTY(float maxRollSpeed READ maxRollSpeed NOTIFY maxRollSpeedChanged) 0059 Q_PROPERTY(float maxRollSpeedMin READ maxRollSpeedMin NOTIFY maxRollSpeedMinChanged) 0060 Q_PROPERTY(float maxRollSpeedMax READ maxRollSpeedMax NOTIFY maxRollSpeedMaxChanged) 0061 0062 Q_PROPERTY(float maxPitchSpeed READ maxPitchSpeed NOTIFY maxPitchSpeedChanged) 0063 Q_PROPERTY(float maxPitchSpeedMin READ maxPitchSpeedMin NOTIFY maxPitchSpeedMinChanged) 0064 Q_PROPERTY(float maxPitchSpeedMax READ maxPitchSpeedMax NOTIFY maxPitchSpeedMaxChanged) 0065 0066 Q_PROPERTY(float maxYawSpeed READ maxYawSpeed NOTIFY maxYawSpeedChanged) 0067 Q_PROPERTY(float maxYawSpeedMin READ maxYawSpeedMin NOTIFY maxYawSpeedMinChanged) 0068 Q_PROPERTY(float maxYawSpeedMax READ maxYawSpeedMax NOTIFY maxYawSpeedMaxChanged) 0069 0070 Q_PROPERTY(float maxGazSpeed READ maxGazSpeed NOTIFY maxGazSpeedChanged) 0071 Q_PROPERTY(float maxGazSpeedMin READ maxGazSpeedMin NOTIFY maxGazSpeedMinChanged) 0072 Q_PROPERTY(float maxGazSpeedMax READ maxGazSpeedMax NOTIFY maxGazSpeedMaxChanged) 0073 0074 Q_PROPERTY(float maxTilt READ maxTilt NOTIFY maxTiltChanged) 0075 Q_PROPERTY(float maxTiltMin READ maxTiltMin NOTIFY maxTiltMinChanged) 0076 Q_PROPERTY(float maxTiltMax READ maxTiltMax NOTIFY maxTiltMaxChanged) 0077 0078 Q_PROPERTY(bool bankedTurns READ bankedTurns NOTIFY bankedTurnsChanged) 0079 0080 Q_PROPERTY(bool geofence READ geofence NOTIFY geofenceChanged) 0081 0082 Q_PROPERTY(float maxAltitude READ maxAltitude NOTIFY maxAltitudeChanged) 0083 Q_PROPERTY(float maxAltitudeMin READ maxAltitudeMin NOTIFY maxAltitudeMinChanged) 0084 Q_PROPERTY(float maxAltitudeMax READ maxAltitudeMax NOTIFY maxAltitudeMaxChanged) 0085 0086 Q_PROPERTY(float maxDistance READ maxDistance NOTIFY maxDistanceChanged) 0087 Q_PROPERTY(float maxDistanceMin READ maxDistanceMin NOTIFY maxDistanceMinChanged) 0088 Q_PROPERTY(float maxDistanceMax READ maxDistanceMax NOTIFY maxDistanceMaxChanged) 0089 0090 Q_PROPERTY(QGeoCoordinate gpsPosition READ gpsPosition NOTIFY gpsPositionChanged) 0091 Q_PROPERTY(float distance READ distance NOTIFY distanceChanged) 0092 Q_PROPERTY(float altitude READ altitude NOTIFY altitudeChanged) 0093 0094 Q_PROPERTY(int speed READ speed NOTIFY speedChanged) 0095 0096 Q_PROPERTY(float roll READ roll NOTIFY attitudeChanged) 0097 Q_PROPERTY(float pitch READ pitch NOTIFY attitudeChanged) 0098 Q_PROPERTY(float yaw READ yaw NOTIFY attitudeChanged) 0099 0100 Q_PROPERTY(int signalStrength READ signalStrength NOTIFY signalStrengthChanged) 0101 Q_PROPERTY(int batteryLevel READ batteryLevel NOTIFY batteryLevelChanged) 0102 Q_PROPERTY(bool gpsSupported READ gpsSupported NOTIFY gpsSupportedChanged) 0103 Q_PROPERTY(bool gpsFix READ gpsFix NOTIFY gpsFixChanged) 0104 0105 Q_PROPERTY(QString videoSource READ videoSource NOTIFY videoSourceChanged) 0106 Q_PROPERTY(bool videoStreamEnabled READ videoStreamEnabled NOTIFY videoStreamEnabledChanged) 0107 Q_PROPERTY(bool videoStabilization READ videoStabilization NOTIFY videoStabilizationChanged) 0108 Q_PROPERTY(bool canTakePicture READ canTakePicture NOTIFY canTakePictureChanged) 0109 Q_PROPERTY(bool isRecordingVideo READ isRecordingVideo NOTIFY isRecordingVideoChanged) 0110 0111 Q_PROPERTY(quint16 numberOfFlights READ numberOfFlights NOTIFY numberOfFlightsChanged) 0112 Q_PROPERTY(quint16 lastFlightDuration READ lastFlightDuration NOTIFY lastFlightDurationChanged) 0113 0114 Q_PROPERTY(ParameterModel *parameters READ parameters NOTIFY parametersChanged) 0115 0116 public: 0117 enum VehicleType { UnknownVehicleType = 0, QuadCopter = 1 }; 0118 Q_ENUM(VehicleType) 0119 0120 enum ConnectionState { Disconnected = 0, Connecting = 1, Connected = 2, Ready = 3 }; 0121 Q_ENUM(ConnectionState) 0122 0123 enum FlyingState { 0124 Unknown = 0, 0125 Landed = 1, 0126 TakingOff = 2, 0127 Hovering = 3, 0128 Flying = 4, 0129 Landing = 5, 0130 // FIXME: (Parrot) Not handled yet. 0131 // Emergency = 5, 0132 // UserTakeoff = 6, 0133 // MotorRamping = 7, 0134 // EmergencyLanding = 8 0135 }; 0136 Q_ENUM(FlyingState) 0137 0138 enum VehicleAction { 0139 TakeOff = 1, 0140 Land = 2, 0141 MoveTo = 3, 0142 FlatTrim = 4, 0143 FlipForward = 5, 0144 FlipBackward = 6, 0145 FlipLeft = 7, 0146 FlipRight = 8, 0147 SwitchPerformanceMode = 9, 0148 SetMaxRollSpeed = 10, 0149 SetMaxPitchSpeed = 11, 0150 SetMaxYawSpeed = 12, 0151 SetMaxGazSpeed = 13, 0152 SetMaxTilt = 14, 0153 ToggleBankedTurns = 15, 0154 ToggleGeofence = 16, 0155 SetMaxAltitude = 17, 0156 SetMaxDistance = 18, 0157 ToggleVideoStream = 19, 0158 ToggleVideoStabilization = 20, 0159 TakePicture = 21, 0160 RecordVideo = 22 0161 }; 0162 Q_ENUM(VehicleAction) 0163 0164 enum PerformanceMode { CustomPerformance = 0, FilmPerformance = 1, SportPerformance = 2 }; 0165 Q_ENUM(PerformanceMode) 0166 0167 explicit AbstractVehicle(QObject *parent = nullptr); 0168 virtual ~AbstractVehicle() override; 0169 0170 int id() const; 0171 0172 virtual QString name() const = 0; 0173 virtual QString iconName() const; 0174 0175 virtual VehicleType vehicleType() const; 0176 0177 virtual ConnectionState connectionState() const; 0178 virtual FlyingState flyingState() const; 0179 bool connected() const; 0180 bool ready() const; 0181 bool flying() const; 0182 0183 virtual QList<VehicleAction> supportedActions() const; 0184 Q_INVOKABLE virtual bool isActionSupported(VehicleAction action) const; 0185 0186 virtual bool piloting() const; 0187 Q_INVOKABLE virtual void setPiloting(bool piloting); 0188 0189 Q_INVOKABLE virtual void requestAction(VehicleAction action); 0190 Q_INVOKABLE virtual void requestTakeOff(); 0191 Q_INVOKABLE virtual void requestLand(); 0192 0193 Q_INVOKABLE virtual void pilot(qint8 roll, qint8 pitch, qint8 yaw, qint8 gaz); 0194 Q_INVOKABLE virtual void requestMoveTo(QGeoCoordinate destination); 0195 0196 virtual int flightTime() const; 0197 0198 virtual PerformanceMode performanceMode() const; 0199 Q_INVOKABLE virtual void requestPerformanceMode(PerformanceMode mode); 0200 0201 virtual float maxRollSpeed() const; 0202 Q_INVOKABLE virtual void requestMaxRollSpeed(float speed); 0203 virtual float maxRollSpeedMin() const; 0204 virtual float maxRollSpeedMax() const; 0205 0206 virtual float maxPitchSpeed() const; 0207 Q_INVOKABLE virtual void requestMaxPitchSpeed(float speed); 0208 virtual float maxPitchSpeedMin() const; 0209 virtual float maxPitchSpeedMax() const; 0210 0211 virtual float maxYawSpeed() const; 0212 Q_INVOKABLE virtual void requestMaxYawSpeed(float speed); 0213 virtual float maxYawSpeedMin() const; 0214 virtual float maxYawSpeedMax() const; 0215 0216 virtual float maxGazSpeed() const; 0217 Q_INVOKABLE virtual void requestMaxGazSpeed(float speed); 0218 virtual float maxGazSpeedMin() const; 0219 virtual float maxGazSpeedMax() const; 0220 0221 virtual float maxTilt() const; 0222 Q_INVOKABLE virtual void requestMaxTilt(float tilt); 0223 virtual float maxTiltMin() const; 0224 virtual float maxTiltMax() const; 0225 0226 virtual bool bankedTurns() const; 0227 Q_INVOKABLE virtual void requestEnableBankedTurns(bool enable); 0228 0229 virtual bool geofence() const; 0230 Q_INVOKABLE virtual void requestEnableGeofence(bool enable); 0231 0232 virtual float maxAltitude() const; 0233 Q_INVOKABLE virtual void requestMaxAltitude(float altitude); 0234 virtual float maxAltitudeMin() const; 0235 virtual float maxAltitudeMax() const; 0236 0237 virtual float maxDistance() const; 0238 Q_INVOKABLE virtual void requestMaxDistance(float distance); 0239 virtual float maxDistanceMin() const; 0240 virtual float maxDistanceMax() const; 0241 0242 virtual float roll() const; 0243 virtual float pitch() const; 0244 virtual float yaw() const; 0245 0246 virtual int signalStrength() const; 0247 virtual int batteryLevel() const; 0248 0249 virtual bool gpsSupported() const; 0250 virtual bool gpsFix() const; 0251 virtual QGeoCoordinate gpsPosition() const; 0252 virtual float distance() const; 0253 virtual float altitude() const; 0254 Q_INVOKABLE virtual void setControllerGpsPosition(const QGeoCoordinate &position); 0255 Q_INVOKABLE virtual void requestReturnHome(); 0256 0257 virtual float speed() const; 0258 0259 virtual QString videoSource() const; 0260 virtual bool videoStreamEnabled() const; 0261 Q_INVOKABLE virtual void requestEnableVideoStream(bool enable); 0262 virtual bool videoStabilization() const; 0263 Q_INVOKABLE virtual void requestEnableVideoStabilization(bool enable); 0264 virtual bool canTakePicture() const; 0265 virtual bool isRecordingVideo() const; 0266 0267 virtual quint16 numberOfFlights() const; 0268 virtual quint16 lastFlightDuration() const; 0269 0270 ParameterModel *parameters(); 0271 0272 Q_SIGNALS: 0273 void nameChanged(); 0274 void iconNameChanged(); 0275 0276 void connectionStateChanged(); 0277 void flyingStateChanged(); 0278 0279 void pilotingChanged(); 0280 0281 void flightTimeChanged(); 0282 0283 void performanceModeChanged(); 0284 0285 void maxRollSpeedChanged(); 0286 void maxRollSpeedMinChanged(); 0287 void maxRollSpeedMaxChanged(); 0288 0289 void maxPitchSpeedChanged(); 0290 void maxPitchSpeedMinChanged(); 0291 void maxPitchSpeedMaxChanged(); 0292 0293 void maxYawSpeedChanged(); 0294 void maxYawSpeedMinChanged(); 0295 void maxYawSpeedMaxChanged(); 0296 0297 void maxGazSpeedChanged(); 0298 void maxGazSpeedMinChanged(); 0299 void maxGazSpeedMaxChanged(); 0300 0301 void maxTiltChanged(); 0302 void maxTiltMinChanged(); 0303 void maxTiltMaxChanged(); 0304 0305 void bankedTurnsChanged(); 0306 0307 void geofenceChanged(); 0308 0309 void maxAltitudeChanged(); 0310 void maxAltitudeMinChanged(); 0311 void maxAltitudeMaxChanged(); 0312 0313 void maxDistanceChanged(); 0314 void maxDistanceMinChanged(); 0315 void maxDistanceMaxChanged(); 0316 0317 void attitudeChanged(); 0318 void rollChanged(); 0319 void pitchChanged(); 0320 void yawChanged(); 0321 0322 void signalStrengthChanged(); 0323 void batteryLevelChanged(); 0324 0325 void gpsSupportedChanged(); 0326 void gpsFixChanged(); 0327 void gpsPositionChanged(); 0328 void distanceChanged(); 0329 void altitudeChanged(); 0330 0331 void speedChanged(); 0332 0333 void videoSourceChanged(); 0334 void videoStreamEnabledChanged(); 0335 void videoStabilizationChanged(); 0336 void canTakePictureChanged(); 0337 void isRecordingVideoChanged(); 0338 0339 void numberOfFlightsChanged(); 0340 void lastFlightDurationChanged(); 0341 0342 void parametersChanged(); 0343 0344 protected Q_SLOTS: 0345 virtual void setConnectionState(ConnectionState state); 0346 virtual void setFlyingState(FlyingState state); 0347 0348 private: 0349 class Private; 0350 QScopedPointer<Private> d; 0351 }; 0352 0353 }