etrobocon2018 feat.KatLab  770af34cce41ae9c30c41303275e1add2daae0c3 (with uncommitted changes)
 全て クラス 名前空間 ファイル 関数 変数 列挙型 列挙値 フレンド マクロ定義 ページ
Motor.h
[詳解]
1 //
2 // Motor.h
3 //
4 // Copyright (c) 2015-2016 Embedded Technology Software Design Robot Contest
5 //
6 
7 #ifndef EV3CPPAPI_MOTOR_H_
8 #define EV3CPPAPI_MOTOR_H_
9 
10 #include "Port.h"
11 #include "ev3api.h"
12 
13 namespace ev3api {
17 class Motor
18 {
19 public:
20  friend class Steering;
21 
25  static const int PWM_MAX = 100;
26 
30  static const int PWM_MIN = -100;
31 
39  explicit Motor(ePortM port, bool brake = true, motor_type_t type = LARGE_MOTOR);
40 
47  ~Motor(void);
48 
55  inline void reset(void)
56  {
57  ev3_motor_stop(mPort, true); // need to set brake to stop the motor immidiately
58  ev3_motor_reset_counts(mPort);
59  mOffset = 0;
60  }
61 
67  inline int32_t getCount(void) const { return ev3_motor_get_counts(mPort) - mOffset; }
68 
75  inline void setCount(int32_t count) { mOffset = ev3_motor_get_counts(mPort) - count; }
76 
83  void setPWM(int pwm);
84 
90  void setBrake(bool brake);
91 
97  inline void stop() { (void)ev3_motor_stop(mPort, mBrake); }
98 
99 protected:
105  inline motor_port_t getPort(void) const { return mPort; }
106 
113  inline bool getBrake(void) const { return mBrake; }
114 
120  inline int getPWM(void) const { return mPWM; }
121 
122 private:
123  motor_port_t mPort;
124  bool mBrake;
125  motor_type_t mType;
126  int mPWM;
127  int32_t mOffset;
128 }; // class Motor
129 } // namespace ev3api
130 
131 #endif // ! EV3CPPAPI_MOTOR_H_
void setPWM(int pwm)
Definition: Motor.cpp:31
motor_port_t getPort(void) const
Definition: Motor.h:105
void setBrake(bool brake)
Definition: Motor.cpp:47
void reset(void)
Definition: Motor.h:55
モータ/センサポート関連定義
bool getBrake(void) const
Definition: Motor.h:113
void setCount(int32_t count)
Definition: Motor.h:75
ePortM
Definition: Port.h:29
~Motor(void)
Definition: Motor.cpp:24
int getPWM(void) const
Definition: Motor.h:120
static const int PWM_MIN
Definition: Motor.h:30
void stop()
Definition: Motor.h:97
Motor(ePortM port, bool brake=true, motor_type_t type=LARGE_MOTOR)
Definition: Motor.cpp:12
static const int PWM_MAX
Definition: Motor.h:25
int32_t getCount(void) const
Definition: Motor.h:67