etrobocon2019 feat.KatLab  ece30a9a007fff7d3ad48592c0d09a74643377bb
Controller.h
[詳解]
1 #ifndef CONTROLLER_H
2 #define CONTROLLER_H
3 
4 #include "ev3api.h"
5 
6 #include "Clock.h"
7 #include "ColorSensor.h"
8 #include "Motor.h"
9 #include "TouchSensor.h"
10 #include "GyroSensor.h"
11 /*
12  * touch_sensor = EV3_PORT_1;
13  * sonar_sensor = EV3_PORT_2;
14  * color_sensor = EV3_PORT_3;
15  * gyro_sensor = EV3_PORT_4;
16  *
17  * left_motor = EV3_PORT_C;
18  * right_motor = EV3_PORT_B;
19  * lift_motor = EV3_PORT_A;
20  * tail_motor = EV3_PORT_D;
21  */
22 
23 struct HsvStatus {
24  //色相 範囲(0~360)
25  double hue = 0;
26  //彩度 範囲(0~100)
27  double saturation = 0;
28  //明度 範囲(0~100)
29  double value = 0;
30 };
31 
32 enum class Color { white, black, red, green, blue, yellow };
33 
34 using namespace ev3api;
35 
36 class Controller {
37  public:
38  Controller();
39  TouchSensor touchSensor;
40  ColorSensor colorSensor;
41  Clock clock;
42  GyroSensor gyroSensor;
43  // モータ入力電圧の最大値
44  static constexpr int MOTOR_PWM_MAX = 100;
45  // モータ入力電圧の最小値
46  static constexpr int MOTOR_PWM_MIN = -100;
47 
48  void speakerSetVolume(int volume);
49  void ledSetColorOrange();
50  void ledSetColorGreen();
51  int getBrightness();
52  static void speakerPlayToneFS6(int duration);
53  bool buttonIsPressedBack();
54  bool buttonIsPressedUp();
55  bool buttonIsPressedDown();
56  bool buttonIsPressedRight();
57  bool buttonIsPressedLeft();
58  bool buttonIsPressedEnter();
59  static float getBatteryVoltage();
60  static void tslpTsk(int time); // 4msec周期起動
61  void getRawColor(int& r, int& g, int& b);
62  void convertHsv(int& r, int& g, int& b); // RGBをHSV変換する
63  HsvStatus getHsv() const;
64  Color hsvToColor(const HsvStatus& status); // HSVから色を識別する
65  static void lcdFillRect(int x, int y, int h);
66  static void lcdDrawString(const char* str, int x, int y);
67  static void lcdSetFont();
68  int getLeftMotorCount();
69  int getRightMotorCount();
70  void setLeftMotorPwm(const int pwm);
71  void setRightMotorPwm(const int pwm);
72  void resetMotorCount();
73  void stopMotor();
74  int getAngleOfRotation();
75  int limitAngle(int angle);
76 
77 private:
78  rgb_raw_t rgb;
79  HsvStatus hsv;
80  Motor liftMotor;
81  Motor rightWheel;
82  Motor leftWheel;
83  Motor tailMotor;
84 
85  static int suppressPwmValue(const int value);
86 };
87 #endif
TouchSensor touchSensor
Definition: Controller.h:39
double hue
Definition: Controller.h:25
Clock clock
Definition: Controller.h:41
GyroSensor gyroSensor
Definition: Controller.h:42
double saturation
Definition: Controller.h:27
double value
Definition: Controller.h:29
ColorSensor colorSensor
Definition: Controller.h:40
Color
Definition: Controller.h:32