-
Notifications
You must be signed in to change notification settings - Fork 0
#KL25-18 カラーセンサから値を取得する #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
1aa551d
9940a39
3560b27
ac4f364
d9fdb39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,7 +2,6 @@ USE_RASPIKE_ART=1 | |||||||
|
|
||||||||
| mkfile_path := $(dir $(lastword $(MAKEFILE_LIST))) | ||||||||
|
|
||||||||
|
|
||||||||
| # Shellスクリプトで、moduleディレクトリ中のソースコード名をオブジェクトファイル名に変換している | ||||||||
| SRCS := $(shell find ${mkfile_path}modules -name '*.cpp') | ||||||||
| OBJS := $(notdir $(SRCS:.cpp=.o)) | ||||||||
|
|
@@ -12,7 +11,16 @@ SRCLANG := c++ | |||||||
|
|
||||||||
| APPL_LIBS += -lm | ||||||||
|
|
||||||||
| APPL_DIRS += $(mkfile_path)modules | ||||||||
| APPL_DIRS += \ | ||||||||
| $(mkfile_path)modules\ | ||||||||
| $(mkfile_path)modules/API | ||||||||
|
|
||||||||
|
|
||||||||
|
|
||||||||
|
|
||||||||
| INCLUDES += \ | ||||||||
| -I$(mkfile_path)modules\ | ||||||||
| -I$(mkfile_path)modules/API | ||||||||
|
|
||||||||
|
|
||||||||
|
|
||||||||
|
Comment on lines
+24
to
+26
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. どうせコンフリクトするところだから直さなくてもいい気がするけど、
Suggested change
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,138 @@ | ||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||
| * @file ColorSensor.h | ||||||||||||||||||||||||||||
| * @brief カラーセンサクラス (ラッパクラス) | ||||||||||||||||||||||||||||
aridome222 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
| * @author HaruArima08 | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| #ifndef COLOR_SENSOR_H_ | ||||||||||||||||||||||||||||
| #define COLOR_SENSOR_H_ | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| #include "spikeapi.h" | ||||||||||||||||||||||||||||
molpui0726 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
| #include "spike/pup/colorsensor.h" | ||||||||||||||||||||||||||||
| #include "Port.h" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||
| * SPIKE カラーセンサクラス | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
| class ColorSensor { | ||||||||||||||||||||||||||||
| public: | ||||||||||||||||||||||||||||
| struct RGB { | ||||||||||||||||||||||||||||
| uint16_t r; | ||||||||||||||||||||||||||||
| uint16_t g; | ||||||||||||||||||||||||||||
| uint16_t b; | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| struct HSV { | ||||||||||||||||||||||||||||
| uint16_t h; | ||||||||||||||||||||||||||||
| uint8_t s; | ||||||||||||||||||||||||||||
| uint8_t v; | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
takuchi17 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||
| * コンストラクタ | ||||||||||||||||||||||||||||
aridome222 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
| * @param port PUPポートID | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
| ColorSensor(Port port) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| pupDevicePointer = pup_color_sensor_get_device(static_cast<pbio_port_id_t>(port)); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||
| * カラーセンサのRGB値を取得する | ||||||||||||||||||||||||||||
| * @param 値を設定するRGB構造体、各色10ビット | ||||||||||||||||||||||||||||
| * @return - | ||||||||||||||||||||||||||||
aridome222 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
| void getRGB(RGB& rgb) const | ||||||||||||||||||||||||||||
|
Comment on lines
+40
to
+44
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 細かいけど説明に引数名がないかな。
Suggested change
|
||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| pup_color_rgb_t pup_rgb = pup_color_sensor_rgb(pupDevicePointer); | ||||||||||||||||||||||||||||
| rgb.r = pup_rgb.r; | ||||||||||||||||||||||||||||
| rgb.g = pup_rgb.g; | ||||||||||||||||||||||||||||
| rgb.b = pup_rgb.b; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||
| * カラーセンサで色を測定する | ||||||||||||||||||||||||||||
| * @param surface trueならば表面の色から、falseならば他の光源の色を検出する | ||||||||||||||||||||||||||||
| * @return 色(hsvによる表現) | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
| void getColor(HSV& hsv, bool surface = true) const | ||||||||||||||||||||||||||||
|
Comment on lines
+53
to
+58
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 引数の説明にhsvがない
Suggested change
|
||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| pup_color_hsv_t pup_hsv = pup_color_sensor_color(pupDevicePointer, surface); | ||||||||||||||||||||||||||||
| hsv.h = pup_hsv.h; | ||||||||||||||||||||||||||||
| hsv.s = pup_hsv.s; | ||||||||||||||||||||||||||||
| hsv.v = pup_hsv.v; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||
| * カラーセンサで色を測定する(近似なし) | ||||||||||||||||||||||||||||
| * @param surface trueならば表面の色から、falseならば他の光源の色を検出する | ||||||||||||||||||||||||||||
| * @return 色(hsvによる表現) | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
|
Comment on lines
+66
to
+71
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ここも引数hsvの説明がないな |
||||||||||||||||||||||||||||
| void getHSV(HSV& hsv, bool surface = true) const | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| pup_color_hsv_t pup_hsv = pup_color_sensor_hsv(pupDevicePointer, surface); | ||||||||||||||||||||||||||||
| hsv.h = pup_hsv.h; | ||||||||||||||||||||||||||||
| hsv.s = pup_hsv.s; | ||||||||||||||||||||||||||||
| hsv.v = pup_hsv.v; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||
| * センサーの発する光を表面がどの程度反射するかを測定する | ||||||||||||||||||||||||||||
aridome222 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
| * @return どの程度反射しているか(%) | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
| int32_t getReflection() const { return pup_color_sensor_reflection(pupDevicePointer); } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||
| * 周囲の光の強度を測定する | ||||||||||||||||||||||||||||
| * @return 周囲の光の強度(%) | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
| int32_t getAmbient() const { return pup_color_sensor_ambient(pupDevicePointer); } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||
| * カラーセンサのライトを設定する | ||||||||||||||||||||||||||||
| * @param bv1 輝度1 | ||||||||||||||||||||||||||||
| * @param bv2 輝度2 | ||||||||||||||||||||||||||||
| * @param bv3 輝度3 | ||||||||||||||||||||||||||||
| * @return - | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
| void setLight(int32_t bv1, int32_t bv2, int32_t bv3) const | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| pup_color_sensor_light_set(pupDevicePointer, bv1, bv2, bv3); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||
| * カラーセンサのライトを点灯する | ||||||||||||||||||||||||||||
| * @param - | ||||||||||||||||||||||||||||
| * @return - | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
| void lightOn() const { pup_color_sensor_light_on(pupDevicePointer); } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||
| * カラーセンサのライトを消灯する | ||||||||||||||||||||||||||||
| * @param - | ||||||||||||||||||||||||||||
| * @return - | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
| void lightOff() const { pup_color_sensor_light_off(pupDevicePointer); } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||
| * カラーセンサが検知する色を設定する | ||||||||||||||||||||||||||||
| * @param size カラーの配列のサイズ | ||||||||||||||||||||||||||||
| * @param colors カラーの配列 | ||||||||||||||||||||||||||||
| * @return - | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
| void setDetectableColors(int32_t size, pup_color_hsv_t* colors) const | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| pup_color_sensor_detectable_colors(size, colors); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
takuchi17 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||
| * インスタンス生成が正常にできたかどうかを確認するための共通メソッド | ||||||||||||||||||||||||||||
| * pupDevicePointerがNULLの場合にtrueとなる | ||||||||||||||||||||||||||||
aridome222 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
| bool hasError() { return pupDevicePointer == 0; } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| private: | ||||||||||||||||||||||||||||
| pup_device_t* pupDevicePointer; | ||||||||||||||||||||||||||||
| }; // class ColorSensor | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /** | ||
| * @file Port.h | ||
| * @brief ポート関連定義 | ||
| * @author HaruArima08 | ||
| */ | ||
|
|
||
| #ifndef PORT_H_ | ||
| #define PORT_H_ | ||
|
||
|
|
||
| #include "spikeapi.h" | ||
| #include "pbio/port.h" | ||
|
|
||
| /** | ||
| * モータ/センサポート関連定義 | ||
| */ | ||
|
|
||
| enum class Port { | ||
| PORT_A = PBIO_PORT_ID_A, /**< SPIKE ポートA */ | ||
| PORT_B = PBIO_PORT_ID_B, /**< SPIKE ポートB */ | ||
| PORT_C = PBIO_PORT_ID_C, /**< SPIKE ポートC */ | ||
| PORT_D = PBIO_PORT_ID_D, /**< SPIKE ポートD */ | ||
| PORT_E = PBIO_PORT_ID_E, /**< SPIKE ポートE */ | ||
| PORT_F = PBIO_PORT_ID_F /**< SPIKE ポートF */ | ||
| }; | ||
|
|
||
| #endif | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,126 @@ | ||||||
| /** | ||||||
| * @file ColorMeasureTest.cpp | ||||||
|
||||||
| * @file ColorMeasureTest.cpp | |
| * @file ColorSensorTest.cpp |
aridome222 marked this conversation as resolved.
Show resolved
Hide resolved
takuchi17 marked this conversation as resolved.
Show resolved
Hide resolved
aridome222 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
aridome222 marked this conversation as resolved.
Show resolved
Hide resolved
aridome222 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
aridome222 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /** | ||
| * @file port.h | ||
| * @brief ポート関連定義(ダミー) | ||
| * @author HaruArima08 | ||
| */ | ||
|
|
||
| #ifndef PORT_H | ||
| #define PORT_H | ||
|
|
||
| // 型定義(ColorSensorで使われる) | ||
| typedef int pbio_port_id_t; | ||
|
|
||
| // ダミーのポートID定数定義 | ||
| #define PBIO_PORT_ID_A 0 | ||
| #define PBIO_PORT_ID_B 1 | ||
| #define PBIO_PORT_ID_C 2 | ||
| #define PBIO_PORT_ID_D 3 | ||
| #define PBIO_PORT_ID_E 4 | ||
| #define PBIO_PORT_ID_F 5 | ||
|
|
||
| #endif // PORT_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この括弧は一個下げた方が気持ちいい