質問編集履歴

3

文字の修正

2016/06/11 08:23

投稿

northpotato
northpotato

スコア38

test CHANGED
File without changes
test CHANGED
@@ -20,9 +20,9 @@
20
20
 
21
21
 
22
22
 
23
- 2016. 6. 11
23
+
24
-
24
+
25
- アドバイスを受け、下記のように修正し、希望の機能を実現できました。
25
+ 頂いたアドバイスを元に、下記のように修正し、希望の機能を実現できました。
26
26
 
27
27
 
28
28
 

2

アラート内での、傾斜計測・デバイスの補正

2016/06/11 08:23

投稿

northpotato
northpotato

スコア38

test CHANGED
File without changes
test CHANGED
@@ -17,3 +17,207 @@
17
17
 
18
18
 
19
19
  ![イメージ説明](f3e21bf681597a161c7636272f7df4bd.png)
20
+
21
+
22
+
23
+ 2016. 6. 11
24
+
25
+ アドバイスを受け、下記のように修正し、希望の機能を実現できました。
26
+
27
+
28
+
29
+ ```
30
+
31
+ // ボタン押下時に Alert-1 を表示する
32
+
33
+ - (IBAction)Button_comp:(UIButton *)sender {
34
+
35
+ // 補正変数の初期化
36
+
37
+ angle_comp_1 =0;
38
+
39
+ angle_comp_2 =0;
40
+
41
+ angle_comp =0;
42
+
43
+
44
+
45
+ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"補正(ステップ1/2)"
46
+
47
+ message:@"補正しますか?"
48
+
49
+ preferredStyle:UIAlertControllerStyleAlert];
50
+
51
+ // addActionした順に左から右にボタンが配置される
52
+
53
+ [alertController addAction:[UIAlertAction actionWithTitle:@"いいえ" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
54
+
55
+ // 「いいえ」ボタンが押された時の処理
56
+
57
+ [self cancelButtonPushed];
58
+
59
+ }]];
60
+
61
+
62
+
63
+ [alertController addAction:[UIAlertAction actionWithTitle:@"はい" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
64
+
65
+ // 「はい」ボタンが押された時の処理
66
+
67
+ [self otherButtonPushed];
68
+
69
+ }]];
70
+
71
+
72
+
73
+ // 画面に表示します
74
+
75
+ [self presentViewController:alertController animated:YES completion:nil];
76
+
77
+ }
78
+
79
+
80
+
81
+ // アラートの「はい」ボタン押下処理
82
+
83
+ - (void)otherButtonPushed {
84
+
85
+ // 定期的に実行するハンドラを設定
86
+
87
+ CMAccelerometerHandler handler = ^(CMAccelerometerData *angle_data, NSError *error){
88
+
89
+ [self animation:angle_data];
90
+
91
+ };
92
+
93
+
94
+
95
+ // 加速度センサーの利用を開始
96
+
97
+ [motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue]withHandler:handler];
98
+
99
+ CMAccelerometerData *angle_data = motionManager.accelerometerData;
100
+
101
+ xac = angle_data.acceleration.x; // X 軸: 加速度G
102
+
103
+ yac = angle_data.acceleration.y; // Y 軸: 加速度G
104
+
105
+ angle_comp_1 = atan2(yac, xac) * - 180.0 / M_PI;
106
+
107
+
108
+
109
+ // 傾斜角を小数点以下1桁の実数表示
110
+
111
+ self.Incl_Label.text = [NSString stringWithFormat:@"%4.1f", angle];
112
+
113
+ self.black.transform = CGAffineTransformMakeRotation(M_PI * angle / 180);
114
+
115
+ [self alert_2];
116
+
117
+ }
118
+
119
+
120
+
121
+ // アラートの「いいえ」ボタン押下処理
122
+
123
+ - (void)cancelButtonPushed {
124
+
125
+ NSLog(@"いいえ!");
126
+
127
+ }
128
+
129
+
130
+
131
+ - (void)alert_2{
132
+
133
+ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"補正(ステップ2/2)"
134
+
135
+ message:@"180度、水平反転してください。"
136
+
137
+ preferredStyle:UIAlertControllerStyleAlert];
138
+
139
+
140
+
141
+ // addActionした順に左から右にボタンが配置される
142
+
143
+ [alertController addAction:[UIAlertAction actionWithTitle:@"キャンセル" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
144
+
145
+ // 「いいえ」ボタンが押された時の処理
146
+
147
+ [self cancelButtonPushed];
148
+
149
+ }]];
150
+
151
+ [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
152
+
153
+ // 「はい」ボタンが押された時の処理
154
+
155
+ [self otherButtonPushed_2];
156
+
157
+ }]];
158
+
159
+
160
+
161
+ // 画面に表示します
162
+
163
+ [self presentViewController:alertController animated:YES completion:nil];
164
+
165
+ }
166
+
167
+
168
+
169
+ // アラートの「はい」ボタン押下処理
170
+
171
+ - (void)otherButtonPushed_2 {
172
+
173
+ // 傾斜角を小数点以下1桁の実数表示
174
+
175
+ self.Incl_Label.text = [NSString stringWithFormat:@"%4.1f", angle];
176
+
177
+ self.black.transform = CGAffineTransformMakeRotation(M_PI * angle / 180);
178
+
179
+ CMAccelerometerData *angle_data = motionManager.accelerometerData;
180
+
181
+ xac = angle_data.acceleration.x; // X 軸: 加速度G
182
+
183
+ yac = angle_data.acceleration.y; // Y 軸: 加速度G
184
+
185
+ angle_comp_2 = atan2(yac, xac) * - 180.0 / M_PI;
186
+
187
+
188
+
189
+ angle_comp = (angle_comp_1 + angle_comp_2)/2 ;
190
+
191
+ self.comp_value.text = [NSString stringWithFormat:@"%4.1f", angle_comp];
192
+
193
+
194
+
195
+ // 角度計測を停止する
196
+
197
+ [motionManager stopAccelerometerUpdates];
198
+
199
+
200
+
201
+ //angle_ar[] の初期化
202
+
203
+ int i;
204
+
205
+ for (i=0; i <500; i++) {angle_ar[i] = 0; }
206
+
207
+
208
+
209
+ // angle_disp[] 初期化
210
+
211
+ for (i=0; i<10; i++) { angle_disp[i] = 0;}
212
+
213
+
214
+
215
+ // jcount の 初期化
216
+
217
+ jcount =0;
218
+
219
+ }
220
+
221
+
222
+
223
+ ```

1

angle_data の定義部分

2016/06/11 08:12

投稿

northpotato
northpotato

スコア38

test CHANGED
File without changes
test CHANGED
@@ -10,6 +10,10 @@
10
10
 
11
11
 
12
12
 
13
+ ![イメージ説明](cc3ca547e9bdaf6ed58d12f9e9ec33dc.png)
14
+
15
+
16
+
13
17
 
14
18
 
15
19
  ![イメージ説明](f3e21bf681597a161c7636272f7df4bd.png)