• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン1922 (tree)
日時2010-09-20 07:30:11
作者satofumi

ログメッセージ

htoi.c の間違いを修正

変更サマリ

差分

--- branches/tsukuba_2010/libs/run_drive/initialize_state.c (revision 1921)
+++ branches/tsukuba_2010/libs/run_drive/initialize_state.c (nonexistent)
@@ -1,43 +0,0 @@
1-/*!
2- \file
3- \brief 初期化の状態
4-
5- \author Satofumi KAMIMURA
6-
7- $Id$
8-*/
9-
10-#include "initialize_state.h"
11-#include "imask.h"
12-#include "clock_initialize.h"
13-#include "timer_control.h"
14-#include "run_system.h"
15-#include "emergency_io_control.h"
16-#include "odometry_calculate.h"
17-#include "path_follow.h"
18-#include "wheel_velocity.h"
19-#include "protocol_handler.h"
20-#include "interrupt_priority.h"
21-
22-
23-void initialize_state(run_t *run)
24-{
25- int i;
26-
27- // システム
28- imask_initialize();
29- clock_initialize();
30- timer_initialize(INTERRUPT_PRIORITY_TIMER);
31-
32- // 走行モジュール
33- run_system_initialize(&run->run_system);
34- emergency_io_initialize();
35- odometry_initialize(&run->odometry);
36- path_follow_initialize(&run->path);
37- for (i = 0; i < NUMBER_OF_WHEELS; ++i) {
38- wheel_initialize(&run->wheel[i], i);
39- }
40-
41- // 通信
42- protocol_initialize();
43-}
Deleted: svn:keywords
## -1 +0,0 ##
-Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/initialize_state.h (revision 1921)
+++ branches/tsukuba_2010/libs/run_drive/initialize_state.h (nonexistent)
@@ -1,28 +0,0 @@
1-#ifndef QRK_INITIALIZE_STATE_H
2-#define QRK_INITIALIZE_STATE_H
3-
4-/*!
5- \file
6- \brief 初期化の状態
7-
8- \author Satofumi KAMIMURA
9-
10- $Id$
11-*/
12-
13-#include "run_t.h"
14-
15-
16-//! 初期化の状態
17-extern void initialize_state(run_t *run);
18-
19-#endif /* !QRK_INITIALIZE_STATE_H */
20-
21-
22-/*!
23- \page initialize_state_h_page 初期化
24-
25- CPU モジュールの初期化と走行モジュールの初期化を行う。
26-
27- \section initialize_state_
28-*/
Deleted: svn:keywords
## -1 +0,0 ##
-Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/Makefile (revision 1921)
+++ branches/tsukuba_2010/libs/run_drive/Makefile (revision 1922)
@@ -11,10 +11,10 @@
1111
1212 START_UP_FOR_BUILD = $(SOURCE_DIR)/crt0.S
1313 LD_LOAD_FOR_BUILD = $(SOURCE_DIR)/aki_sh7125_load.x
14-#LD_ROM_FOR_BUILD = $(SOURCE_DIR)/aki_sh7125_rom.x
14+LD_ROM_FOR_BUILD = $(SOURCE_DIR)/aki_sh7125_rom.x
1515
1616
17-TARGET = run_drive.mot
17+TARGET = run_drive.mot run_drive.rom
1818 all : $(TARGET)
1919
2020 clean :
@@ -28,7 +28,7 @@
2828
2929 .PHONY : all clean html upload
3030 ######################################################################
31-run_drive.mot : run_drive.o initialize_state.o control_state.o pause_state.o clock_initialize.o imask.o run_system.o connection.o connection_utilities.o protocol_handler.o sci_interrupt_read_write.o emergency_io_control.o timer_control.o path_follow.o position_handler.o velocity_handler.o body_handler.o wheel_velocity.o motor_velocity.o motor_pwm.o encoder_reader.o odometry_calculate.o mtu2_initialize.o ring_buffer.o run_commands.o htoi.o
31+run_drive.mot run_drive.rom : run_drive.o setup_state.o control_state.o pause_state.o clock_initialize.o imask.o run_system.o connection.o connection_utilities.o protocol_handler.o sci_interrupt_read_write.o emergency_io_control.o timer_control.o path_follow.o position_handler.o velocity_handler.o body_handler.o wheel_velocity.o motor_velocity.o motor_pwm.o encoder_reader.o odometry_calculate.o mtu2_initialize.o ring_buffer.o run_commands.o htoi.o
3232
3333 # DO NOT DELETE
3434
@@ -36,8 +36,6 @@
3636 control_state.o: run_t.h controller_config.h run_system_t.h odometry_t.h
3737 control_state.o: path_t.h wheel_t.h encoder_t.h motor_t.h
3838 encoder_reader.o: encoder_t.h
39-initialize_state.o: run_t.h controller_config.h run_system_t.h odometry_t.h
40-initialize_state.o: path_t.h wheel_t.h encoder_t.h motor_t.h
4139 motor_velocity.o: motor_t.h
4240 odometry_calculate.o: odometry_t.h
4341 path_follow.o: path_t.h
@@ -45,9 +43,13 @@
4543 pause_state.o: path_t.h wheel_t.h encoder_t.h motor_t.h
4644 protocol_handler.o: run_t.h controller_config.h run_system_t.h odometry_t.h
4745 protocol_handler.o: path_t.h wheel_t.h encoder_t.h motor_t.h
46+run_commands.o: run_t.h controller_config.h run_system_t.h odometry_t.h
47+run_commands.o: path_t.h wheel_t.h encoder_t.h motor_t.h
4848 run_system.o: run_system_t.h
4949 run_t.o: controller_config.h run_system_t.h odometry_t.h path_t.h wheel_t.h
5050 run_t.o: encoder_t.h motor_t.h
51+setup_state.o: run_t.h controller_config.h run_system_t.h odometry_t.h
52+setup_state.o: path_t.h wheel_t.h encoder_t.h motor_t.h
5153 wheel_t.o: encoder_t.h motor_t.h
5254 wheel_velocity.o: wheel_t.h encoder_t.h motor_t.h
5355 body_handler.o: body_handler.h wheel_t.h encoder_t.h motor_t.h
@@ -63,13 +65,8 @@
6365 control_state.o: wheel_velocity.h
6466 emergency_io_control.o: emergency_io_control.h
6567 encoder_reader.o: encoder_reader.h encoder_t.h mtu2_initialize.h
68+htoi.o: htoi.h
6669 imask.o: imask.h
67-initialize_state.o: initialize_state.h run_t.h controller_config.h
68-initialize_state.o: run_system_t.h odometry_t.h path_t.h wheel_t.h
69-initialize_state.o: encoder_t.h motor_t.h imask.h clock_initialize.h
70-initialize_state.o: timer_control.h run_system.h emergency_io_control.h
71-initialize_state.o: odometry_calculate.h path_follow.h wheel_velocity.h
72-initialize_state.o: protocol_handler.h interrupt_priority.h
7370 motor_pwm.o: motor_pwm.h mtu2_initialize.h
7471 motor_velocity.o: motor_velocity.h motor_t.h robot_parameter.h motor_pwm.h
7572 motor_velocity.o: encoder_reader.h encoder_t.h
@@ -83,9 +80,12 @@
8380 protocol_handler.o: protocol_handler.h run_t.h controller_config.h
8481 protocol_handler.o: run_system_t.h odometry_t.h path_t.h wheel_t.h
8582 protocol_handler.o: encoder_t.h motor_t.h connection.h connection_utilities.h
86-protocol_handler.o: std_string.h
83+protocol_handler.o: run_commands.h std_string.h
8784 ring_buffer.o: ring_buffer.h
88-run_drive.o: initialize_state.h run_t.h controller_config.h run_system_t.h
85+run_commands.o: run_commands.h run_t.h controller_config.h run_system_t.h
86+run_commands.o: odometry_t.h path_t.h wheel_t.h encoder_t.h motor_t.h htoi.h
87+run_commands.o: wheel_velocity.h connection.h
88+run_drive.o: setup_state.h run_t.h controller_config.h run_system_t.h
8989 run_drive.o: odometry_t.h path_t.h wheel_t.h encoder_t.h motor_t.h
9090 run_drive.o: control_state.h
9191 run_system.o: run_system.h run_system_t.h
@@ -93,6 +93,11 @@
9393 sci_interrupt_read_write.o: ring_buffer.h
9494 sci_read_write.o: sci_read_write.h cpu_clock.h
9595 sci_utilities.o: sci_utilities.h sci_read_write.h
96+setup_state.o: setup_state.h run_t.h controller_config.h run_system_t.h
97+setup_state.o: odometry_t.h path_t.h wheel_t.h encoder_t.h motor_t.h imask.h
98+setup_state.o: clock_initialize.h timer_control.h run_system.h
99+setup_state.o: emergency_io_control.h odometry_calculate.h path_follow.h
100+setup_state.o: wheel_velocity.h protocol_handler.h interrupt_priority.h
96101 std_string.o: std_string.h
97102 timer_control.o: timer_control.h cpu_clock.h
98103 velocity_handler.o: velocity_handler.h
--- branches/tsukuba_2010/libs/run_drive/run_drive.c (revision 1921)
+++ branches/tsukuba_2010/libs/run_drive/run_drive.c (revision 1922)
@@ -7,7 +7,7 @@
77 $Id$
88 */
99
10-#include "initialize_state.h"
10+#include "setup_state.h"
1111 #include "control_state.h"
1212
1313
@@ -17,7 +17,7 @@
1717
1818 int main(void)
1919 {
20- initialize_state(&run_);
20+ setup_state(&run_);
2121 control_state(&run_);
2222
2323 return 0;
--- branches/tsukuba_2010/libs/run_drive/setup_state.c (nonexistent)
+++ branches/tsukuba_2010/libs/run_drive/setup_state.c (revision 1922)
@@ -0,0 +1,43 @@
1+/*!
2+ \file
3+ \brief 初期化の状態
4+
5+ \author Satofumi KAMIMURA
6+
7+ $Id$
8+*/
9+
10+#include "setup_state.h"
11+#include "imask.h"
12+#include "clock_initialize.h"
13+#include "timer_control.h"
14+#include "run_system.h"
15+#include "emergency_io_control.h"
16+#include "odometry_calculate.h"
17+#include "path_follow.h"
18+#include "wheel_velocity.h"
19+#include "protocol_handler.h"
20+#include "interrupt_priority.h"
21+
22+
23+void setup_state(run_t *run)
24+{
25+ int i;
26+
27+ // システム
28+ imask_initialize();
29+ clock_initialize();
30+ timer_initialize(INTERRUPT_PRIORITY_TIMER);
31+
32+ // 走行モジュール
33+ run_system_initialize(&run->run_system);
34+ emergency_io_initialize();
35+ odometry_initialize(&run->odometry);
36+ path_follow_initialize(&run->path);
37+ for (i = 0; i < NUMBER_OF_WHEELS; ++i) {
38+ wheel_initialize(&run->wheel[i], i);
39+ }
40+
41+ // 通信
42+ protocol_initialize();
43+}
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/setup_state.h (nonexistent)
+++ branches/tsukuba_2010/libs/run_drive/setup_state.h (revision 1922)
@@ -0,0 +1,28 @@
1+#ifndef QRK_SETUP_STATE_H
2+#define QRK_SETUP_STATE_H
3+
4+/*!
5+ \file
6+ \brief 初期化の状態
7+
8+ \author Satofumi KAMIMURA
9+
10+ $Id$
11+*/
12+
13+#include "run_t.h"
14+
15+
16+//! 初期化の状態
17+extern void setup_state(run_t *run);
18+
19+#endif /* !QRK_SETUP_STATE_H */
20+
21+
22+/*!
23+ \page setup_state_h_page 初期化
24+
25+ CPU モジュールの初期化と走行モジュールの初期化を行う。
26+
27+ !!!
28+*/
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/protocol_handler.c (revision 1921)
+++ branches/tsukuba_2010/libs/run_drive/protocol_handler.c (revision 1922)
@@ -32,7 +32,7 @@
3232
3333 static command_packet_t command_packets_[] = {
3434 // !!!
35- { WV_Command, "WV", 2, 5, },
35+ { WV_Command, "WV", 2, 7, },
3636 };
3737
3838
--- branches/tsukuba_2010/libs/run_drive/test/Run_commands_test.cpp (nonexistent)
+++ branches/tsukuba_2010/libs/run_drive/test/Run_commands_test.cpp (revision 1922)
@@ -0,0 +1,77 @@
1+/*!
2+ \file
3+ \brief run_commands.c のテスト
4+
5+ \author Satofumi KAMIMURA
6+
7+ $Id$
8+*/
9+
10+#include "Run_commands_test.h"
11+#include "host_connection.h"
12+#include "connection_utilities.h"
13+#include "connection.h"
14+#include "protocol_handler.h"
15+#include <string>
16+
17+using namespace std;
18+
19+CPPUNIT_TEST_SUITE_REGISTRATION(Run_commands_test);
20+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Run_commands_test, "Run_commands_test");
21+
22+
23+namespace {
24+ run_t run_;
25+}
26+
27+
28+void Run_commands_test::setUp(void)
29+{
30+ for (int i = 0; i < 2; ++i) {
31+ run_.wheel[i].target_velocity = 0;
32+ }
33+}
34+
35+
36+void wheel_set_velocity(wheel_t *wheel, int mm_per_sec)
37+{
38+ wheel->target_velocity = mm_per_sec;
39+}
40+
41+
42+void Run_commands_test::wv_command_test(void)
43+{
44+ // テストに使う変数を初期化
45+ for (int i = 0; i < 2; ++i) {
46+ run_.wheel[0].target_velocity = 0;
47+ }
48+
49+ connection_initialize();
50+
51+ // 応答が返されるかのテスト
52+ send_command("WV00000\n");
53+ protocol_update(&run_);
54+ string reply_line = receive_response_line();
55+ CPPUNIT_ASSERT_EQUAL(string("WV0\n"), reply_line);
56+ CPPUNIT_ASSERT_EQUAL(0, run_.wheel[0].target_velocity);
57+
58+ // 値が適切に設定されるかのテスト
59+ send_command("WV00001\n");
60+ protocol_update(&run_);
61+ reply_line = receive_response_line();
62+ CPPUNIT_ASSERT_EQUAL(string("WV0\n"), reply_line);
63+ CPPUNIT_ASSERT_EQUAL(1, run_.wheel[0].target_velocity);
64+
65+ send_command("WV10001\n");
66+ protocol_update(&run_);
67+ reply_line = receive_response_line();
68+ CPPUNIT_ASSERT_EQUAL(string("WV0\n"), reply_line);
69+ CPPUNIT_ASSERT_EQUAL(1, run_.wheel[1].target_velocity);
70+
71+ send_command("WV0ffff\n");
72+ protocol_update(&run_);
73+ reply_line = receive_response_line();
74+ CPPUNIT_ASSERT_EQUAL(string("WV0\n"), reply_line);
75+ CPPUNIT_ASSERT_EQUAL(-1, run_.wheel[0].target_velocity);
76+}
77+
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/test/Connection_utilities_test.cpp (revision 1921)
+++ branches/tsukuba_2010/libs/run_drive/test/Connection_utilities_test.cpp (revision 1922)
@@ -39,4 +39,11 @@
3939 send_command("\n");
4040 n =connection_readline(buffer, CONNECTION_READLINE_BUFFER_SIZE);
4141 CPPUNIT_ASSERT_EQUAL(0, n);
42+
43+ // 再度、改行までの文字列が返されるかのテスト
44+ send_command("123\n");
45+ n =connection_readline(buffer, CONNECTION_READLINE_BUFFER_SIZE);
46+ CPPUNIT_ASSERT_EQUAL(3, n);
47+ CPPUNIT_ASSERT_EQUAL(string("123"), string(buffer));
48+
4249 }
--- branches/tsukuba_2010/libs/run_drive/test/Run_commands_test.h (nonexistent)
+++ branches/tsukuba_2010/libs/run_drive/test/Run_commands_test.h (revision 1922)
@@ -0,0 +1,28 @@
1+#ifndef QRK_RUN_COMMANDS_TEST_H
2+#define QRK_RUN_COMMANDS_TEST_H
3+
4+/*!
5+ \file
6+ \brief run_commands.c のテスト
7+
8+ \author Satofumi KAMIMURA
9+
10+ $Id$
11+*/
12+
13+#include <cppunit/extensions/HelperMacros.h>
14+
15+
16+//! run_commands.c のテストクラス
17+class Run_commands_test : public CppUnit::TestFixture
18+{
19+ CPPUNIT_TEST_SUITE(Run_commands_test);
20+ CPPUNIT_TEST(wv_command_test);
21+ CPPUNIT_TEST_SUITE_END();
22+
23+public:
24+ void setUp(void);
25+ void wv_command_test(void);
26+};
27+
28+#endif /* !QRK_RUN_COMMANDS_TEST_H */
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/test/connection_dummy.cpp (revision 1921)
+++ branches/tsukuba_2010/libs/run_drive/test/connection_dummy.cpp (revision 1922)
@@ -61,6 +61,13 @@
6161 for (int i = 0; i < data_size; ++i) {
6262 sensor_sent_buffer_.push_back(data[i]);
6363 }
64+
65+ size_t n = sensor_sent_buffer_.size();
66+ for (size_t i = 0; i < n; ++i) {
67+ sensor_sent_data_.push_back(sensor_sent_buffer_[i]);
68+ }
69+ sensor_sent_buffer_.clear();
70+
6471 return data_size;
6572 }
6673
--- branches/tsukuba_2010/libs/run_drive/test/Makefile (revision 1921)
+++ branches/tsukuba_2010/libs/run_drive/test/Makefile (revision 1922)
@@ -18,7 +18,7 @@
1818 ./all_test
1919
2020 ######################################################################
21-TEST_OBJS = all_test.o Connection_utilities_test.o connection_dummy.o connection_utilities.o std_string.o
21+TEST_OBJS = all_test.o Connection_utilities_test.o connection_dummy.o connection_utilities.o std_string.o Run_commands_test.o protocol_handler.o run_commands.o htoi.o
2222
2323 all_test : $(TEST_OBJS)
2424 $(CXX) $(CXXFLAGS) $(TEST_OBJS) -o $@ `cppunit-config --libs` $(TEST_LDLIBS)
@@ -29,11 +29,29 @@
2929 connection_utilities.o : ../connection_utilities.c
3030 $(CXX) $(CXXFLAGS) $< -c -o $@
3131
32+protocol_handler.o : ../protocol_handler.c
33+ $(CXX) $(CXXFLAGS) $< -c -o $@
34+
35+run_commands.o : ../run_commands.c
36+ $(CXX) $(CXXFLAGS) $< -c -o $@
37+
3238 std_string.o : ../std_string.c
3339 $(CXX) $(CXXFLAGS) $< -c -o $@
3440
41+htoi.o : ../htoi.c
42+ $(CXX) $(CXXFLAGS) $< -c -o $@
43+
3544 # DO NOT DELETE
3645
46+Connection_utilities_test.o: Connection_utilities_test.h
47+Connection_utilities_test.o: ../connection_utilities.h host_connection.h
48+Connection_utilities_test.o: ../connection.h
49+Run_commands_test.o: Run_commands_test.h host_connection.h
50+Run_commands_test.o: ../connection_utilities.h ../connection.h
51+Run_commands_test.o: ../protocol_handler.h ../run_t.h ../controller_config.h
52+Run_commands_test.o: ../run_system_t.h ../odometry_t.h ../path_t.h
53+Run_commands_test.o: ../wheel_t.h ../encoder_t.h ../motor_t.h
54+connection_dummy.o: ../connection.h
3755 wheel_velocity_test.o: ../wheel_velocity.c ../wheel_velocity.h ../wheel_t.h
3856 wheel_velocity_test.o: ../encoder_t.h ../motor_t.h ../robot_parameter.h
3957 wheel_velocity_test.o: ../encoder_reader.h ../motor_velocity.h ../motor_pwm.h
--- branches/tsukuba_2010/libs/run_drive/htoi.c (revision 1921)
+++ branches/tsukuba_2010/libs/run_drive/htoi.c (revision 1922)
@@ -17,6 +17,8 @@
1717
1818 for (i = 0; i < data_size; ++i) {
1919 char ch = hex_data[i];
20+ value <<= 4;
21+
2022 if ((ch >= '0') && (ch <= '9')) {
2123 value += ch - '0';
2224 } else if ((ch >= 'a') && (ch <= 'f')) {
@@ -24,7 +26,6 @@
2426 } else if ((ch >= 'A') && (ch <= 'F')) {
2527 value += (ch - 'A') + 10;
2628 }
27- value <<= 4;
2829 }
2930
3031 return value;
--- branches/tsukuba_2010/libs/run_drive/samples/Makefile (revision 1921)
+++ branches/tsukuba_2010/libs/run_drive/samples/Makefile (revision 1922)
@@ -53,13 +53,13 @@
5353
5454 encoder_print.o: ../imask.h ../clock_initialize.h ../interrupt_priority.h
5555 encoder_print.o: ../encoder_reader.h ../encoder_t.h ../sci_read_write.h
56-encoder_print.o: ../sci_utilities.h
56+encoder_print.o: ../sci_utilities.h ../motor_pwm.h
5757 itoa.o: itoa.h
5858 motor_pwm_out.o: ../clock_initialize.h ../motor_pwm.h
5959 motor_velocity_run.o: ../clock_initialize.h ../imask.h
6060 motor_velocity_run.o: ../interrupt_priority.h ../motor_velocity.h
6161 motor_velocity_run.o: ../motor_t.h ../timer_control.h ../encoder_reader.h
62-motor_velocity_run.o: ../encoder_t.h
62+motor_velocity_run.o: ../encoder_t.h ../robot_parameter.h
6363 sci_echoback.o: ../clock_initialize.h ../imask.h ../sci_read_write.h
6464 sci_echoback.o: ../interrupt_priority.h
6565 sci_interrupt_echoback.o: ../clock_initialize.h ../imask.h
@@ -77,3 +77,4 @@
7777 wheel_velocity_run.o: ../interrupt_priority.h ../wheel_velocity.h
7878 wheel_velocity_run.o: ../wheel_t.h ../encoder_t.h ../motor_t.h
7979 wheel_velocity_run.o: ../encoder_reader.h ../timer_control.h
80+wheel_velocity_run.o: ../robot_parameter.h
--- branches/tsukuba_2010/libs/run_drive/run_commands.c (revision 1921)
+++ branches/tsukuba_2010/libs/run_drive/run_commands.c (revision 1922)
@@ -10,12 +10,14 @@
1010 #include "run_commands.h"
1111 #include "htoi.h"
1212 #include "wheel_velocity.h"
13+#include "connection.h"
1314
1415
1516 void handle_WV_command(run_t *run, const char *line_buffer)
1617 {
1718 int id;
18- long velocity;
19+ short velocity;
20+ char response[] = "WV0\n";
1921
2022 // パラメータの読み出し
2123 id = htoi(&line_buffer[2], 1);
@@ -25,8 +27,11 @@
2527
2628 if ((id == 0) || (id == 1)) {
2729 wheel_set_velocity(&run->wheel[id], velocity);
30+ run->run_system.mode = DIRECT_WHEEL_CONTROL;
2831 } else {
29- return;
32+ // ID 範囲外のエラー
33+ response[2] = '1';
3034 }
31- run->run_system.mode = DIRECT_WHEEL_CONTROL;
35+
36+ connection_write(response, 4);
3237 }
旧リポジトリブラウザで表示