• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン1925 (tree)
日時2010-09-25 04:07:26
作者satofumi

ログメッセージ

URG データを記録するプログラムを作成

変更サマリ

差分

--- branches/tsukuba_2010/programs/run_wired_controller/Makefile (revision 1924)
+++ branches/tsukuba_2010/programs/run_wired_controller/Makefile (revision 1925)
@@ -25,4 +25,5 @@
2525 cd $(@D)/ && $(MAKE) $(@F)
2626
2727 run_wired_controller : $(REQUIRE_LIBS)
28+
2829 # DO NOT DELETE
--- branches/tsukuba_2010/programs/urg_auto_recorder/urg_auto_recorder.cpp (nonexistent)
+++ branches/tsukuba_2010/programs/urg_auto_recorder/urg_auto_recorder.cpp (revision 1925)
@@ -0,0 +1,133 @@
1+/*!
2+ \example urg_auto_recorder.cpp URG データの記録
3+
4+ \author Satofumi KAMIMURA
5+
6+ $Id$
7+*/
8+
9+extern "C" {
10+#include "urg_sensor.h"
11+#include "urg_utils.h"
12+}
13+#include <string>
14+#include <iostream>
15+#include <fstream>
16+#include <cstdlib>
17+#include <sys/stat.h>
18+
19+
20+using namespace std;
21+
22+
23+namespace
24+{
25+ int file_id_ = 0;
26+
27+
28+ int parse_args(int argc, char *argv[])
29+ {
30+ if (argc >= 2) {
31+ return atoi(argv[1]);
32+ } else {
33+ return 0;
34+ }
35+ }
36+
37+
38+ string crate_record_directory()
39+ {
40+ enum { Buffer_size = 80 };
41+ char buffer[Buffer_size];
42+ time_t t = time(NULL);
43+ struct tm *tm = localtime(&t);
44+ strftime(buffer, Buffer_size, "%F_%H_%M_%S", tm);
45+
46+ mkdir(buffer, 0755);
47+
48+ return buffer;
49+ }
50+
51+
52+ string create_save_file_name(const string& save_directory)
53+ {
54+ // ファイル名の作成
55+ enum { Buffer_size = 80 };
56+ char buffer[Buffer_size];
57+ snprintf(buffer, Buffer_size, "data_%06d.csv", file_id_);
58+ ++file_id_;
59+
60+ return save_directory + "/" + buffer;
61+ }
62+
63+
64+ bool save_csv_data(const urg_t& urg,
65+ long data[], int data_size, const string& file_name)
66+ {
67+ ofstream fout(file_name.c_str());//, ios::out);
68+ if (!fout.is_open()) {
69+ return false;
70+ }
71+
72+ for (int i = 0; i < data_size; ++i) {
73+ fout << i << ","
74+ << data[i] << ","
75+ << urg_index2rad(&urg, i) << endl;
76+ }
77+
78+ return true;
79+ }
80+
81+
82+ void record_urg_data(urg_t& urg, int record_interval,
83+ const string& save_directory)
84+ {
85+ // 計測の開始
86+ urg_start_measurement(&urg, URG_DISTANCE,
87+ URG_SCAN_INFINITY, record_interval);
88+
89+ long* data = new long[urg_max_data_size(&urg)];
90+ while (true) {
91+ // URG からのデータ取得
92+ int data_size = urg_get_distance(&urg, data, NULL);
93+ if (data_size <= 0) {
94+ break;
95+ }
96+
97+ // ファイルに CSV 形式で保存
98+ string file_name = create_save_file_name(save_directory);
99+ if (!save_csv_data(urg, data, data_size, file_name)) {
100+ fprintf(stderr, "b\n");
101+ break;
102+ }
103+ }
104+ cout << "urg_get_distance: " << urg_error(&urg) << endl;
105+
106+ delete data;
107+ }
108+}
109+
110+
111+int main(int argc, char *argv[])
112+{
113+ // URG センサと接続
114+ enum { URG_DEVICE_BAUDRATE = 115200 };
115+ const char *device = "/dev/ttyACM0";
116+
117+ urg_t urg;
118+ if (urg_open(&urg, URG_SERIAL, device, URG_DEVICE_BAUDRATE) < 0) {
119+ cout << "urg_open: " << device << ": " << urg_error(&urg) << endl;
120+ return 1;
121+ }
122+
123+ // 記録するデータ間隔の読み出し
124+ int record_interval = parse_args(argc, argv);
125+
126+ // 記録するディレクトリの作成
127+ string save_directory = crate_record_directory();
128+
129+ // 記録
130+ record_urg_data(urg, record_interval, save_directory);
131+
132+ return 0;
133+}
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- branches/tsukuba_2010/programs/urg_auto_recorder/Makefile (nonexistent)
+++ branches/tsukuba_2010/programs/urg_auto_recorder/Makefile (revision 1925)
@@ -0,0 +1,28 @@
1+# programs/urg_auto_recorder
2+
3+LIBS_DIR = ../../libs
4+
5+CXXFLAGS = -g -O0 -Wall -Werror -W $(INCLUDES) `urg_c-config --cflags`
6+INCLUDES =
7+LDFLAGS =
8+LDLIBS = `urg_c-config --libs`
9+
10+TARGET = urg_auto_recorder
11+
12+all : $(TARGET)
13+
14+clean :
15+ $(RM) $(TARGET) *.o
16+
17+depend :
18+ makedepend -Y -- $(INCLUDES_FOR_BUILD) -- $(wildcard *.h *.cpp)
19+
20+.PHONY : all clean depend
21+######################################################################
22+REQUIRE_LIBS =
23+
24+$(REQUIRE_LIBS) :
25+ cd $(@D)/ && $(MAKE) $(@F)
26+
27+urg_auto_recorder : $(REQUIRE_LIBS)
28+# DO NOT DELETE
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- branches/tsukuba_2010/programs/Makefile (revision 1924)
+++ branches/tsukuba_2010/programs/Makefile (revision 1925)
@@ -4,8 +4,10 @@
44 cd run_path_recorder/ && $(MAKE)
55 cd run_path_follower/ && $(MAKE)
66 cd run_wired_controller/ && $(MAKE)
7+ cd urg_auto_recorder/ && $(MAKE)
78
89 clean :
910 cd run_path_recorder/ && $(MAKE) clean
1011 cd run_path_follower/ && $(MAKE) clean
1112 cd run_wired_controller/ && $(MAKE) clean
13+ cd urg_auto_recorder/ && $(MAKE) clean
旧リポジトリブラウザで表示