EV3RT C++ API Reference  Version 1.0
An RTOS-based development platform for LEGO Mindstorms EV3.
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_
Definition: Clock.h:12
static const int PWM_MAX
Definition: Motor.h:25
モータ/センサポート関連定義
ePortM
Definition: Port.h:29
void setPWM(int pwm)
void stop()
Definition: Motor.h:97
void reset(void)
Definition: Motor.h:55
static const int PWM_MIN
Definition: Motor.h:30
int32_t getCount(void) const
Definition: Motor.h:67
Definition: Motor.h:17
motor_port_t getPort(void) const
Definition: Motor.h:105
Definition: Steering.h:16
bool getBrake(void) const
Definition: Motor.h:113
void setCount(int32_t count)
Definition: Motor.h:75
Motor(ePortM port, bool brake=true, motor_type_t type=LARGE_MOTOR)
void setBrake(bool brake)
int getPWM(void) const
Definition: Motor.h:120