• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン1896 (tree)
日時2010-09-06 22:51:49
作者satofumi

ログメッセージ

両輪の PWM 指定による回転を確認

変更サマリ

差分

--- branches/tsukuba_2010/libs/run_drive/encoder_control.c (revision 1895)
+++ branches/tsukuba_2010/libs/run_drive/encoder_control.c (nonexistent)
@@ -1,59 +0,0 @@
1-/*!
2- \file
3- \brief エンコーダ制御
4-
5- \author Satofumi KAMIMURA
6-
7- $Id$
8-*/
9-
10-#include "encoder_control.h"
11-
12-
13-static void encoder_initialize_device(int device_id)
14-{
15- if (device_id == 0) {
16- // !!!
17- } else if (device_id == 1) {
18- // !!!
19- }
20-}
21-
22-
23-static unsigned short encoder_count(int device_id)
24-{
25- if (device_id == 0) {
26- // !!!
27- return -1;
28-
29- } else if (device_id == 1) {
30- // !!!
31- return -1;
32- }
33-
34- return -1;
35-}
36-
37-
38-void encoder_initialize(encoder_t *encoder, int device_id)
39-{
40- encoder_initialize_device(device_id);
41-
42- encoder->device_id = device_id;
43- encoder->previous_count = encoder_count(device_id);
44-}
45-
46-
47-void encoder_update(encoder_t *encoder)
48-{
49- unsigned short current_count = encoder_count(encoder->device_id);
50-
51- encoder->difference = current_count - encoder->previous_count;
52- encoder->previous_count = current_count;
53-}
54-
55-
56-unsigned short encoder_difference(encoder_t *encoder)
57-{
58- return encoder->difference;
59-}
Deleted: svn:keywords
## -1 +0,0 ##
-Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/encoder_control.h (revision 1895)
+++ branches/tsukuba_2010/libs/run_drive/encoder_control.h (nonexistent)
@@ -1,44 +0,0 @@
1-#ifndef QRK_ENCODER_CONTROL_H
2-#define QRK_ENCODER_CONTROL_H
3-
4-/*!
5- \file
6- \brief エンコーダ制御
7-
8- \author Satofumi KAMIMURA
9-
10- $Id$
11-*/
12-
13-
14-#include "encoder_t.h"
15-
16-
17-//! 初期化
18-extern void encoder_initialize(encoder_t *encoder, int device_id);
19-
20-//! エンコーダ値の更新
21-extern void encoder_update(encoder_t *encoder);
22-
23-//! エンコーダ変位の取得
24-extern unsigned short encoder_difference(encoder_t *encoder);
25-
26-#endif /* !QRK_ENCODER_CONTROL_H */
27-
28-
29-/*!
30- \page encoder_control_h_page エンコーダ制御
31-
32- エンコーダの値を定期的に読み取り、前回に読み出した値との差を取ることでエンコーダの変位量を計算する。 \n
33- エンコーダが 16 [bit] 幅の場合、エンコーダ変位量の差分は、以下のコードで計算できる。
34-
35- \code
36- // unsigned short current_counter; // 今回読み出したのエンコーダ値
37- // unsigned short previous_counter; // 前回読み出したエンコーダ値
38-
39- short diff = current_counter - previous_counter; // エンコーダ変位
40- \endcode
41- \n
42-
43- エンコーダの値を定期的に読み出すには、優先度を高めに設定した割り込みを用いること。
44-*/
Deleted: svn:keywords
## -1 +0,0 ##
-Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/encoder_reader.c (nonexistent)
+++ branches/tsukuba_2010/libs/run_drive/encoder_reader.c (revision 1896)
@@ -0,0 +1,62 @@
1+/*!
2+ \file
3+ \brief エンコーダ制御
4+
5+ \author Satofumi KAMIMURA
6+
7+ $Id$
8+*/
9+
10+#include "encoder_reader.h"
11+#include "mtu2_initialize.h"
12+
13+
14+static void encoder_initialize_device(int device_id)
15+{
16+ mtu2_initialize();
17+
18+ if (device_id == 0) {
19+ // !!!
20+ } else if (device_id == 1) {
21+ // !!!
22+ }
23+}
24+
25+
26+static unsigned short encoder_count(int device_id)
27+{
28+ if (device_id == 0) {
29+ // !!!
30+ return -1;
31+
32+ } else if (device_id == 1) {
33+ // !!!
34+ return -1;
35+ }
36+
37+ return -1;
38+}
39+
40+
41+void encoder_initialize(encoder_t *encoder, int device_id)
42+{
43+ encoder_initialize_device(device_id);
44+
45+ encoder->device_id = device_id;
46+ encoder->previous_count = encoder_count(device_id);
47+}
48+
49+
50+void encoder_update(encoder_t *encoder)
51+{
52+ unsigned short current_count = encoder_count(encoder->device_id);
53+
54+ encoder->difference = current_count - encoder->previous_count;
55+ encoder->previous_count = current_count;
56+}
57+
58+
59+unsigned short encoder_difference(encoder_t *encoder)
60+{
61+ return encoder->difference;
62+}
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/encoder_reader.h (nonexistent)
+++ branches/tsukuba_2010/libs/run_drive/encoder_reader.h (revision 1896)
@@ -0,0 +1,44 @@
1+#ifndef QRK_ENCODER_CONTROL_H
2+#define QRK_ENCODER_CONTROL_H
3+
4+/*!
5+ \file
6+ \brief エンコーダ制御
7+
8+ \author Satofumi KAMIMURA
9+
10+ $Id$
11+*/
12+
13+
14+#include "encoder_t.h"
15+
16+
17+//! 初期化
18+extern void encoder_initialize(encoder_t *encoder, int device_id);
19+
20+//! エンコーダ値の更新
21+extern void encoder_update(encoder_t *encoder);
22+
23+//! エンコーダ変位の取得
24+extern unsigned short encoder_difference(encoder_t *encoder);
25+
26+#endif /* !QRK_ENCODER_CONTROL_H */
27+
28+
29+/*!
30+ \page encoder_control_h_page エンコーダ制御
31+
32+ エンコーダの値を定期的に読み取り、前回に読み出した値との差を取ることでエンコーダの変位量を計算する。 \n
33+ エンコーダが 16 [bit] 幅の場合、エンコーダ変位量の差分は、以下のコードで計算できる。
34+
35+ \code
36+ // unsigned short current_counter; // 今回読み出したのエンコーダ値
37+ // unsigned short previous_counter; // 前回読み出したエンコーダ値
38+
39+ short diff = current_counter - previous_counter; // エンコーダ変位
40+ \endcode
41+ \n
42+
43+ エンコーダの値を定期的に読み出すには、優先度を高めに設定した割り込みを用いること。
44+*/
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/mtu2_initialize.c (nonexistent)
+++ branches/tsukuba_2010/libs/run_drive/mtu2_initialize.c (revision 1896)
@@ -0,0 +1,27 @@
1+/*!
2+ \file
3+ \brief MTU2 モジュールのスタンバイ解除
4+
5+ \author Satofumi KAMIMURA
6+
7+ $Id$
8+*/
9+
10+#include "mtu2_initialize.h"
11+#include <stdbool.h>
12+#include <7125S.H>
13+
14+
15+void mtu2_initialize(void)
16+{
17+ static bool initialized = false;
18+
19+ if (initialized) {
20+ return;
21+ }
22+
23+ // スタンバイ解除
24+ STB.CR4.BYTE &= ~0x40;
25+
26+ initialized = true;
27+}
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/mtu2_initialize.h (nonexistent)
+++ branches/tsukuba_2010/libs/run_drive/mtu2_initialize.h (revision 1896)
@@ -0,0 +1,16 @@
1+#ifndef MTU2_INITIALIZE_H
2+#define MTU2_INITIALIZE_H
3+
4+/*!
5+ \file
6+ \brief MTU2 モジュールのスタンバイ解除
7+
8+ \author Satofumi KAMIMURA
9+
10+ $Id$
11+*/
12+
13+
14+extern void mtu2_initialize(void);
15+
16+#endif /* !MTU2_INITIALIZE_H */
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/Makefile (revision 1895)
+++ branches/tsukuba_2010/libs/run_drive/Makefile (revision 1896)
@@ -27,7 +27,7 @@
2727
2828 .PHONY : all clean html upload
2929 ######################################################################
30-run_drive.mot : run_drive.o initialize_state.o control_state.o pause_state.o clock_initialize.o imask_control.o communication_handler.o protocol_handler.o sci_control.o emergency_io_control.o timer_control.o path_handler.o position_handler.o velocity_handler.o body_handler.o wheel_handler.o motor_velocity.o motor_pwm.o encoder_control.o odometry_calculate.o
30+run_drive.mot : run_drive.o initialize_state.o control_state.o pause_state.o clock_initialize.o imask_control.o communication_handler.o protocol_handler.o sci_control.o emergency_io_control.o timer_control.o path_handler.o position_handler.o velocity_handler.o body_handler.o wheel_handler.o motor_velocity.o motor_pwm.o encoder_reader.o odometry_calculate.o mtu2_initialize.o
3131
3232 # DO NOT DELETE
3333
@@ -34,7 +34,7 @@
3434 body_handler.o: wheel_t.h encoder_t.h
3535 control_state.o: run_t.h controller_config.h odometry_t.h path_t.h wheel_t.h
3636 control_state.o: encoder_t.h
37-encoder_control.o: encoder_t.h
37+encoder_reader.o: encoder_t.h
3838 initialize_state.o: run_t.h controller_config.h odometry_t.h path_t.h
3939 initialize_state.o: wheel_t.h encoder_t.h
4040 odometry_calculate.o: odometry_t.h
@@ -54,9 +54,9 @@
5454 control_state.o: control_state.h run_t.h controller_config.h odometry_t.h
5555 control_state.o: path_t.h wheel_t.h encoder_t.h pause_state.h
5656 control_state.o: emergency_io_control.h timer_control.h protocol_handler.h
57-control_state.o: encoder_control.h odometry_calculate.h path_handler.h
57+control_state.o: encoder_reader.h odometry_calculate.h path_handler.h
5858 emergency_io_control.o: emergency_io_control.h
59-encoder_control.o: encoder_control.h encoder_t.h
59+encoder_reader.o: encoder_reader.h encoder_t.h mtu2_initialize.h
6060 imask_control.o: imask_control.h
6161 initialize_state.o: initialize_state.h run_t.h controller_config.h
6262 initialize_state.o: odometry_t.h path_t.h wheel_t.h encoder_t.h
@@ -64,8 +64,9 @@
6464 initialize_state.o: emergency_io_control.h odometry_calculate.h
6565 initialize_state.o: path_handler.h wheel_handler.h protocol_handler.h
6666 initialize_state.o: interrupt_priority.h
67-motor_pwm.o: motor_pwm.h
67+motor_pwm.o: motor_pwm.h mtu2_initialize.h
6868 motor_velocity.o: motor_velocity.h
69+mtu2_initialize.o: mtu2_initialize.h
6970 odometry_calculate.o: odometry_calculate.h odometry_t.h
7071 path_handler.o: path_t.h position_handler.h
7172 pause_state.o: pause_state.h run_t.h controller_config.h odometry_t.h
--- branches/tsukuba_2010/libs/run_drive/control_state.c (revision 1895)
+++ branches/tsukuba_2010/libs/run_drive/control_state.c (revision 1896)
@@ -12,7 +12,7 @@
1212 #include "emergency_io_control.h"
1313 #include "timer_control.h"
1414 #include "protocol_handler.h"
15-#include "encoder_control.h"
15+#include "encoder_reader.h"
1616 #include "odometry_calculate.h"
1717 #include "path_handler.h"
1818 #include <stddef.h>
--- branches/tsukuba_2010/libs/run_drive/motor_pwm.c (revision 1895)
+++ branches/tsukuba_2010/libs/run_drive/motor_pwm.c (revision 1896)
@@ -36,20 +36,23 @@
3636 */
3737
3838 #include "motor_pwm.h"
39+#include "mtu2_initialize.h"
3940 #include <7125S.H>
4041
4142 typedef enum {
42- Lo = 0,
43- Hi = 1,
43+ LO = 0,
44+ HI = 1,
4445 } io_state_t;
4546
4647
4748 static void set_pe8(io_state_t state)
4849 {
49- if (state == Hi) {
50- // !!!
50+ PFC.PECRL3.WORD &= ~0x0007;
51+ PFC.PEIORL.WORD |= 0x0100;
52+ if (state == HI) {
53+ PE.DRL.WORD |= 0x0100;
5154 } else {
52- // !!!
55+ PE.DRL.WORD &= ~0x0100;
5356 }
5457 }
5558
@@ -56,13 +59,12 @@
5659
5760 void set_pe10(io_state_t state)
5861 {
59- (void)state;
60- // !!!
61-
62- if (state == Hi) {
63- // !!!
62+ PFC.PECRL3.WORD &= ~0x0700;
63+ PFC.PEIORL.WORD |= 0x0400;
64+ if (state == HI) {
65+ PE.DRL.WORD |= 0x0400;
6466 } else {
65- // !!!
67+ PE.DRL.WORD &= ~0x0400;
6668 }
6769 }
6870
@@ -69,27 +71,26 @@
6971
7072 static void set_pe8_pwm(unsigned char duty)
7173 {
72- (void)duty;
73- // !!!
74+ PFC.PECRL3.WORD |= 0x0001;
75+ MTU23.TGRB = duty;
7476 }
7577
7678
7779 static void set_pe10_pwm(unsigned char duty)
7880 {
79- (void)duty;
80- // !!!
81+ PFC.PECRL3.WORD |= 0x0100;
82+ MTU23.TGRD = duty;
8183 }
8284
8385
8486 static void set_pe12(io_state_t state)
8587 {
86- (void)state;
87- // !!!
88-
89- if (state == Hi) {
90- // !!!
88+ PFC.PECRL4.WORD &= ~0x0007;
89+ PFC.PEIORL.WORD |= 0x1000;
90+ if (state == HI) {
91+ PE.DRL.WORD |= 0x1000;
9192 } else {
92- // !!!
93+ PE.DRL.WORD &= ~0x1000;
9394 }
9495 }
9596
@@ -96,13 +97,12 @@
9697
9798 static void set_pe14(io_state_t state)
9899 {
99- (void)state;
100- // !!!
101-
102- if (state == Hi) {
103- // !!!
100+ PFC.PECRL4.WORD &= ~0x0700;
101+ PFC.PEIORL.WORD |= 0x4000;
102+ if (state == HI) {
103+ PE.DRL.WORD |= 0x4000;
104104 } else {
105- // !!!
105+ PE.DRL.WORD &= ~0x4000;
106106 }
107107 }
108108
@@ -109,27 +109,28 @@
109109
110110 static void set_pe12_pwm(unsigned char duty)
111111 {
112- (void)duty;
113- // !!!
112+ PFC.PECRL4.WORD |= 0x0001;
113+ MTU24.TGRB = duty;
114114 }
115115
116116
117117 static void set_pe14_pwm(unsigned char duty)
118118 {
119- (void)duty;
120- // !!!
119+ PFC.PECRL4.WORD |= 0x0100;
120+ MTU24.TGRD = duty;
121121 }
122122
123123
124124 static void set_cw(int device_id, unsigned char duty)
125125 {
126+ // PWM 出力が Lo のときに回転するので、指定された duty をここで反転させる
126127 if (device_id == 0) {
127- set_pe10(Hi);
128- set_pe8_pwm(duty);
128+ set_pe8(HI);
129+ set_pe10_pwm(255 - duty);
129130
130131 } else if (device_id == 1) {
131- set_pe14(Hi);
132- set_pe12_pwm(duty);
132+ set_pe12(HI);
133+ set_pe14_pwm(255 - duty);
133134 }
134135 }
135136
@@ -136,15 +137,14 @@
136137
137138 static void set_ccw(int device_id, unsigned char duty)
138139 {
140+ // PWM 出力が Lo のときに回転するので、指定された duty をここで反転させる
139141 if (device_id == 0) {
140- // PE8: Hi, PE10: PWM
141- set_pe8(Hi);
142- set_pe10_pwm(duty);
142+ set_pe10(HI);
143+ set_pe8_pwm(255 - duty);
143144
144145 } else if (device_id == 1) {
145- // PE12: Hi, PE14: PWM
146- set_pe12(Hi);
147- set_pe14_pwm(duty);
146+ set_pe14(HI);
147+ set_pe12_pwm(255 - duty);
148148 }
149149 }
150150
@@ -151,6 +151,8 @@
151151
152152 void motor_pwm_initialize(int device_id)
153153 {
154+ mtu2_initialize();
155+
154156 if (device_id == 0) {
155157 // PE8/TIOC3A, PI10/TIOC3C 側
156158
@@ -174,12 +176,8 @@
174176 MTU23.TMDR.BYTE = 0x02;
175177
176178 // TIOC3C(PE10), TIOC3A(PE8) 出力設定
177- PFC.PEIORL.WORD &= ~0x0f00;
178179 PFC.PEIORL.WORD |= 0x0500;
179180
180- // 初期状態では、"正転 <-> ブレーキ" に設定し、duty 比をゼロにする
181- set_cw(device_id, 0);
182-
183181 // TCNT のスタート
184182 MTU2.TSTR.BYTE |= 0x40;
185183
@@ -190,7 +188,7 @@
190188 MTU2.TSTR.BYTE &= ~0x80;
191189
192190 // 出力設定
193- MTU2.TOER.BYTE |= 0xc0 | 0x12;
191+ MTU2.TOER.BYTE |= 0x12;
194192
195193 // 周期を TGRA に設定
196194 MTU24.TCR.BYTE = 0x25;
@@ -209,15 +207,14 @@
209207 MTU24.TMDR.BYTE = 0x02;
210208
211209 // TIOC4C(PE14), TIOC4A(PE12) 出力設定
212- PFC.PEIORL.WORD &= ~0xf000;
213210 PFC.PEIORL.WORD |= 0x5000;
214211
215- // 初期状態では、"正転 <-> ブレーキ" に設定し、duty 比をゼロにする
216- set_cw(device_id, 0);
217-
218212 // TCNT のスタート
219213 MTU2.TSTR.BYTE |= 0x80;
220214 }
215+
216+ // 初期状態では、"正転 <-> ブレーキ" に設定し、duty 比をゼロにする
217+ set_cw(device_id, 0);
221218 }
222219
223220
--- branches/tsukuba_2010/libs/run_drive/samples/motor_velocity.c (revision 1895)
+++ branches/tsukuba_2010/libs/run_drive/samples/motor_velocity.c (nonexistent)
@@ -1,5 +0,0 @@
1-int main(void)
2-{
3- // !!!
4- return 0;
5-}
Deleted: svn:keywords
## -1 +0,0 ##
-Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/samples/motor_pwm.c (revision 1895)
+++ branches/tsukuba_2010/libs/run_drive/samples/motor_pwm.c (nonexistent)
@@ -1,16 +0,0 @@
1-/*!
2- \example モータの PWM 出力サンプル
3-
4- \author Satofumi KAMIMURA
5-
6- $Id$
7-*/
8-
9-#include "motor_pwm.h"
10-
11-
12-int main(void)
13-{
14- // !!!
15- return 0;
16-}
Deleted: svn:keywords
## -1 +0,0 ##
-Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/samples/motor_velocity_out.c (nonexistent)
+++ branches/tsukuba_2010/libs/run_drive/samples/motor_velocity_out.c (revision 1896)
@@ -0,0 +1,16 @@
1+/*!
2+ \example motor_velocity_out.c モータの速度制御サンプル
3+
4+ \author Satofumi KAMIMURA
5+
6+ $Id$
7+*/
8+
9+#include "motor_velocity.h"
10+
11+
12+int main(void)
13+{
14+ // !!!
15+ return 0;
16+}
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/samples/motor_pwm_out.c (nonexistent)
+++ branches/tsukuba_2010/libs/run_drive/samples/motor_pwm_out.c (revision 1896)
@@ -0,0 +1,30 @@
1+/*!
2+ \example motor_pwm_out.c モータの PWM 出力サンプル
3+
4+ \author Satofumi KAMIMURA
5+
6+ $Id$
7+*/
8+
9+#include "clock_initialize.h"
10+#include "motor_pwm.h"
11+
12+
13+int main(void)
14+{
15+ enum {
16+ DUTY = 32,
17+ };
18+ int i;
19+
20+ clock_initialize();
21+
22+ for (i = 0; i < 2; ++i) {
23+ motor_pwm_initialize(i);
24+ motor_pwm_set_duty(i, MOTOR_PWM_CW, DUTY);
25+ }
26+
27+ while (1) {
28+ ;
29+ }
30+}
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/samples/Makefile (revision 1895)
+++ branches/tsukuba_2010/libs/run_drive/samples/Makefile (revision 1896)
@@ -1,7 +1,7 @@
11 # taiyaki/sample
22
33 ARCH = sh-elf
4-SOURCE_DIR = ../
4+SOURCE_DIR = ..
55 include $(SOURCE_DIR)/build_rule.mk
66
77 CFLAGS_FOR_BUILD = -DHOST_COMPILE -m2 -Wall -Werror -W $(INCLUDES_FOR_BUILD)
@@ -18,8 +18,8 @@
1818 sci_write.mot \
1919 sci_echoback.mot \
2020 timer_1sec.mot \
21- motor_pwm.mot \
22- motor_velocity.mot \
21+ motor_pwm_out.mot \
22+ motor_velocity_out.mot \
2323 encoder_print.mot \
2424
2525 all : $(TARGET)
@@ -32,14 +32,14 @@
3232
3333 .PHONY : all clean depend
3434 ######################################################################
35-BASE_OBJ = $(SOURCE_DIR)/clock_initialize.o $(SOURCE_DIR)/imask_control.o $(SOURCE_DIR)/sci_control.o
35+BASE_OBJ = $(SOURCE_DIR)/clock_initialize.o $(SOURCE_DIR)/imask_control.o $(SOURCE_DIR)/sci_control.o $(SOURCE_DIR)/mtu2_initialize.o
3636
3737 sci_write.mot : sci_write.o $(BASE_OBJ)
3838 sci_echoback.mot : sci_echoback.o $(BASE_OBJ)
3939 timer_1sec.mot : timer_1sec.o $(BASE_OBJ) $(SOURCE_DIR)/timer_control.o itoa.o $(SOURCE_DIR)/std_string.o
4040 encoder_print.mot : encoder_print.o
41-motor_pwm.mot : motor_pwm.o
42-motor_velocity.mot : motor_velocity.o
41+motor_pwm_out.mot : motor_pwm_out.o $(BASE_OBJ) $(SOURCE_DIR)/motor_pwm.o
42+motor_velocity_out.mot : motor_velocity_out.o
4343 pwm_output.mot : pwm_output.o $(SOURCE_DIR)/pwm_control.o
4444 servo_free.mot : servo_free.o
4545
@@ -46,6 +46,8 @@
4646 # DO NOT DELETE
4747
4848 itoa.o: itoa.h
49+motor_pwm_out.o: ../clock_initialize.h ../motor_pwm.h
50+motor_velocity_out.o: ../motor_velocity.h
4951 sci_echoback.o: ../clock_initialize.h ../imask_control.h ../sci_control.h
5052 sci_echoback.o: ../interrupt_priority.h
5153 sci_write.o: ../clock_initialize.h ../imask_control.h ../sci_control.h
旧リポジトリブラウザで表示