trikRuntime
servoMotor.h
Go to the documentation of this file.
1 /* Copyright 2013 - 2015 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/QObject>
18 #include <QtCore/QString>
19 #include <QtCore/QScopedPointer>
20 
21 #include "motorInterface.h"
22 
23 #include "deviceState.h"
24 
25 namespace trikKernel {
26 class Configurer;
27 }
28 
29 namespace trikHal {
30 class HardwareAbstractionInterface;
31 class OutputDeviceFileInterface;
32 }
33 
34 namespace trikControl {
35 
37 class ServoMotor : public MotorInterface
38 {
39  Q_OBJECT
40 
41 public:
45  ServoMotor(const QString &port, const trikKernel::Configurer &configurer
46  , const trikHal::HardwareAbstractionInterface &hardwareAbstraction);
47 
48  ~ServoMotor() override;
49 
50  Status status() const override;
51 
52  int minControl() const override;
53 
54  int maxControl() const override;
55 
56 public slots:
57  int power() const override;
58 
60  int frequency() const;
61 
63  int duty() const;
64 
65  void powerOff() override;
66 
73  void setPower(int power, bool constrain = true) override;
74 
75  void brake(int /* durationMs */ = 0) override { }
76 
77  void setPeriod(int uSec = 20000) override;
78 private:
79  QScopedPointer<trikHal::OutputDeviceFileInterface> mDutyFile;
80  QScopedPointer<trikHal::OutputDeviceFileInterface> mPeriodFile;
81  QScopedPointer<trikHal::OutputDeviceFileInterface> mRunFile;
82  int mPeriod;
83  int mCurrentDutyPercent;
84  int mMin;
85  int mMax;
86  int mZero;
87  int mStop;
88  int mMinControlRange;
89  int mMaxControlRange;
90  bool mInvert;
91  int mCurrentPower;
92  bool mRun;
93  DeviceState mState;
94 };
95 
96 }
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
TRIK servomotor.
Definition: servoMotor.h:37
Status
Device status.
Definition: deviceInterface.h:33
Definition: trikCommunicator.h:27
void brake(int=0) override
Definition: servoMotor.h:75
Definition: brickFactory.h:21
Hardware abstraction, provides devices that are used to communicate with robot hardware or emulate it...
Definition: hardwareAbstractionInterface.h:29