trikRuntime
powerMotor.h
Go to the documentation of this file.
1 /* Copyright 2013 - 2016 Yurii Litvinov, Anastasiia Kornilova 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/QObject>
18 #include <QtCore/QString>
19 #include <QtCore/QVector>
20 
21 #include "motorInterface.h"
22 #include "deviceState.h"
23 
24 namespace trikKernel {
25 class Configurer;
26 }
27 
28 namespace trikControl {
29 
30 class MspCommunicatorInterface;
31 
33 class PowerMotor : public MotorInterface
34 {
35  Q_OBJECT
36 
37 public:
42  PowerMotor(const QString &port, const trikKernel::Configurer &configurer, MspCommunicatorInterface &communicator);
43 
44  ~PowerMotor() override;
45 
46  Status status() const override;
47 
48  int minControl() const override;
49 
50  int maxControl() const override;
51 
52 public slots:
53  void setPower(int power, bool constrain = true) override;
54 
55  int power() const override;
56 
57  void powerOff() override;
58 
60  int period() const;
61 
64  void setPeriod(int period) override;
65 
67  void brake(int durationMs = 500) override;
68 
69 private:
70  void lineariseMotor(const QString &port, const trikKernel::Configurer &configurer);
71 
72  MspCommunicatorInterface &mCommunicator;
73  int mMspCommandNumber;
74  const bool mInvert;
75  int mCurrentPower;
76  int mCurrentPeriod;
77  DeviceState mState;
78  QVector<int> mPowerMap;
79 };
80 
81 }
82 
83 Q_DECLARE_METATYPE(trikControl::PowerMotor*)
Definition: analogSensor.h:23
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
T constrain(T value, T max, T min)
Definition: gyroscopeIndicator.cpp:72
Helper class to track device state (off, starting, ready, stopping, fail).
Definition: deviceState.h:26
Abstract motor. It is differently implemented by different motor types (like servo and power motors)...
Definition: motorInterface.h:26
Status
Device status.
Definition: deviceInterface.h:33
Abstract interface for communication with MSP, may be implemented by I2C or USB buses, depending on current MSP configuration.
Definition: mspCommunicatorInterface.h:26
Definition: trikCommunicator.h:27
TRIK power motor.
Definition: powerMotor.h:33