-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatom.xml
7527 lines (5929 loc) · 485 KB
/
atom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><![CDATA[九州工業大学 CIR-KIT Blog]]></title>
<link href="http://cir-kit.github.io/atom.xml" rel="self"/>
<link href="http://cir-kit.github.io/"/>
<updated>2016-07-07T04:41:42+09:00</updated>
<id>http://cir-kit.github.io/</id>
<author>
<name><![CDATA[CIR-KIT Members]]></name>
</author>
<generator uri="http://octopress.org/">Octopress</generator>
<entry>
<title type="html"><![CDATA[New_machine]]></title>
<link href="http://cir-kit.github.io/blog/2016/07/06/new-machine/"/>
<updated>2016-07-06T19:38:47+09:00</updated>
<id>http://cir-kit.github.io/blog/2016/07/06/new-machine</id>
<content type="html"><![CDATA[<h5>概要</h5>
<p>[新メンバ向け]新機材の導入について</p>
<!--more-->
<h5>目録</h5>
<p>・ CIRKIT-5の制作についての記述<br/>
・ YP-Spurについての記述<br/>
・ 開発環境の導入についての記述<br/>
-Linux(Ubuntu)<br/>
-Git<br/>
-GitHub<br/>
-ROS<br/>
-Octpress(このブログの書き方)<br/>
・ 当面の目標についての記述</p>
<h1>CIRKIT-5についての記述 </h1>
<p>CIRKIT-5は独立して回転する2つの車輪を以って自律駆動し,街中を自律走行する.
電源は鉛蓄電池を搭載.センサーとしてカメラ,LRFを予定する.
開発内容としては <em>ROS</em> 使用が前提となっている</p>
<h1>YP-Spurについての記述 </h1>
<p>T-frog社のi-Cart Mini <a href="http://t-frog.com/products/icart_mini/">http://t-frog.com/products/icart_mini/</a><br/>
公式をまず参照.<br/>
さらにここ↓<br/>
<a href="http://www.roboken.iit.tsukuba.ac.jp/platform/wiki/yp-spur/how-to-install">http://www.roboken.iit.tsukuba.ac.jp/platform/wiki/yp-spur/how-to-install</a><br/>
からサンプルを以って学習.</p>
<p>のドライバ. ハードソフト両面共に非常に扱いやすい(前年度比)</p>
<h1>開発環境の導入についての記述 </h1>
<h2>Linux(Ubuntu)</h2>
<p>Bootメディアが工房内にあるので,それを使ってインストールすれば良い
すべてのタスクのために必要になる(Windowsではむづかしい.)CIR-KIT/ARC標準OSシステム.<br/>
基本的にUbuntu16.04を導入してもらいたい.<br/>
当分は工房のUbuntu14.04マシンで作業することができる.<br/>
生協PC,ネットブックなどではHDD容量不足などの問題が生じる人が要るかもしれない. 外付けHDD導入,アップグレードなどで対処されたい.
大丈夫,なんとでもなる</p>
<h2>Git</h2>
<p>Ubuntuに標準装備されている.
<em>バージョン管理ツール</em> つまるところ,
1. 作業マシンのディレクトリ内の変化を追跡する<br/>
2. 変化のあった事項を遠隔サーバーにアップロードする<br/>
3. 任意のタイミングのソースコードを手元に返す<br/>
が行える. <em>早めに使い慣れておくと煩雑な管理作業から開放されうる</em></p>
<h2>GitHub</h2>
<p>上に述べたGitのアップロード先として提案されるサービス.GitHHub Pages という機能がOctpressにおいても必要</p>
<h2>ROS</h2>
<p>ネットから落として入れる
<em>ロボット開発用のミドルウェア</em><br/>
各々の書いたコードを <em>ノード</em> という形式で実行する.これらは相互に通信を行う必要がある場合,ROS越しでそれを行うことができる.つまりプログラム相互の通信規定,プロトコルについてはるかに作業が削減される.<br/>
サンプルやデモ,チュートリアルがたくさんある.ここの過去記事にも既出であるが,各々興味の湧く分野で試行錯誤してみること.</p>
<h2>Octpress(このブログの書き方)</h2>
<p>GitHubを導入する際に使用可能にする(<em>Ask!</em>)<br/>
できたことを報告したり見せたりするのにガンガン使っていきたい・・・行きましょう</p>
<h1>当面の目標についての記述 </h1>
<p>上記の遠足の準備にとりかかる.<br/>
借りの機体を修復し,実働試験を行う<br/>
コードを書いて,ロボットを動かす.<br/>
<em>ROS</em> を活用してみる.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[CIR-KITロゴ 完成!]]></title>
<link href="http://cir-kit.github.io/blog/2015/04/04/logo/"/>
<updated>2015-04-04T23:05:02+09:00</updated>
<id>http://cir-kit.github.io/blog/2015/04/04/logo</id>
<content type="html"><![CDATA[<h1>CIR-KITのロゴが完成しました</h1>
<!--more-->
<p>CIR-KITのロゴが完成しました。横長の物と正方形の2種類です。</p>
<p>今後ともよろしくお願いします。</p>
<p><img src="http://cir-kit.github.io/images/2015-04-04-logo/CIR-KIT_ver17.png" alt="symbol1" /></p>
<p><img src="http://cir-kit.github.io/images/2015-04-04-logo/CIR-KIT_square3.png" alt="symbol2" /></p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[ジョイスティックで亀を泳がせる(機動編)]]></title>
<link href="http://cir-kit.github.io/blog/2015/03/15/make-turtlesim-teleop/"/>
<updated>2015-03-15T19:10:46+09:00</updated>
<id>http://cir-kit.github.io/blog/2015/03/15/make-turtlesim-teleop</id>
<content type="html"><![CDATA[<h1>ジョイスティックで亀を泳がせる</h1>
<h2>概要</h2>
<p>ROSのチュートリアルで使用したturtlesimの亀をジョイスティックで動かします。<a href="http://wiki.ros.org/joy/Tutorials">joy_tutorial</a>で行っていることをやりますので、原文はそちらへどうぞ。</p>
<h2>検証情報</h2>
<h3>日時</h3>
<p>03/13/2015 (Fri)</p>
<!--more-->
<h3>スペック</h3>
<table>
<thead>
<tr>
<th style="text-align:center;">パーツ</th>
<th style="text-align:center;">スペック</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center;">PC</td>
<td style="text-align:center;">CLEVO M76T</td>
</tr>
<tr>
<td style="text-align:center;">Prosessor</td>
<td style="text-align:center;">CeleronDualCore T3000 1.80GHz×2</td>
</tr>
<tr>
<td style="text-align:center;">RAM</td>
<td style="text-align:center;">4GB</td>
</tr>
<tr>
<td style="text-align:center;">OS</td>
<td style="text-align:center;">Ubuntu 14.04.2 LTS 64bit</td>
</tr>
<tr>
<td style="text-align:center;">ROS</td>
<td style="text-align:center;">indigo 1.11.10</td>
</tr>
<tr>
<td style="text-align:center;">joystick_drivers</td>
<td style="text-align:center;">1.10.0</td>
</tr>
</tbody>
</table>
<h2>使用したもの</h2>
<table>
<thead>
<tr>
<th style="text-align:left;"></th>
<th style="text-align:left;">参考</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">ROS</td>
<td style="text-align:left;"><a href="http://cir-kit.github.io/blog/2015/02/25/we-have-get-to-work-when-install-ubuntu">CIR-KITメンバーが必ずすべきこと</a></td>
</tr>
<tr>
<td style="text-align:left;">DualShock3</td>
<td style="text-align:left;"><a href="http://www.jp.playstation.com/ps3/peripheral/cechzc2j.html">PlayStation.com</a></td>
</tr>
<tr>
<td style="text-align:left;">joystick_driver</td>
<td style="text-align:left;"><a href="http://wiki.ros.org/joy">ROS.org</a></td>
</tr>
<tr>
<td style="text-align:left;">PC</td>
<td style="text-align:left;"><a href="http://shopap.lenovo.com/jp/notebooks/thinkpad/x-series/x250/?cid=jp:sem:q2xyf9&#tab-customize">ご自由に</a></td>
</tr>
<tr>
<td style="text-align:left;">USBケーブル</td>
<td style="text-align:left;"><a href="http://www.amazon.co.jp/%E3%82%BD%E3%83%8B%E3%83%BC%E3%83%BB%E3%82%B3%E3%83%B3%E3%83%94%E3%83%A5%E3%83%BC%E3%82%BF%E3%82%A8%E3%83%B3%E3%82%BF%E3%83%86%E3%82%A4%E3%83%B3%E3%83%A1%E3%83%B3%E3%83%88-USB-%E3%82%B1%E3%83%BC%E3%83%96%E3%83%AB-2-8m/dp/B00462Q5ZW/ref=sr_1_1?ie=UTF8&qid=1426232234&sr=8-1&keywords=usb%E3%82%B1%E3%83%BC%E3%83%96%E3%83%AB+Dualshock">適宜用意</a></td>
</tr>
</tbody>
</table>
<h2>新しいパッケージを作る</h2>
<p>亀を動かすためのパッケージを作ります。<code>catkin_ws</code>に移動して以下のコマンドを実行して下さい。</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>catkin_create_pkg learning_joy roscpp turtlesim joy
</span></code></pre></td></tr></table></div></figure>
<p>これで<code>roscpp</code> <code>turtlesim</code> <code>joy</code>を依存関係に持つ<code>learnig_joy</code>というパッケージが出来ました。</p>
<p>次は中身を作ります。</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nb">cd </span>src/learning_joy/src
</span><span class='line'>emacs turtle_teleop_joy.cpp
</span></code></pre></td></tr></table></div></figure>
<p>以下のソースをコピーして下さい。</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
<span class='line-number'>39</span>
<span class='line-number'>40</span>
<span class='line-number'>41</span>
<span class='line-number'>42</span>
<span class='line-number'>43</span>
<span class='line-number'>44</span>
<span class='line-number'>45</span>
<span class='line-number'>46</span>
<span class='line-number'>47</span>
<span class='line-number'>48</span>
<span class='line-number'>49</span>
<span class='line-number'>50</span>
<span class='line-number'>51</span>
<span class='line-number'>52</span>
<span class='line-number'>53</span>
<span class='line-number'>54</span>
<span class='line-number'>55</span>
<span class='line-number'>56</span>
<span class='line-number'>57</span>
</pre></td><td class='code'><pre><code class='cpp'><span class='line'><span class="cp">#include <ros/ros.h></span>
</span><span class='line'><span class="cp">#include <geometry_msgs/Twist.h></span>
</span><span class='line'><span class="cp">#include <sensor_msgs/Joy.h></span>
</span><span class='line'>
</span><span class='line'>
</span><span class='line'><span class="k">class</span> <span class="nc">TeleopTurtle</span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'><span class="k">public</span><span class="o">:</span>
</span><span class='line'> <span class="n">TeleopTurtle</span><span class="p">();</span>
</span><span class='line'>
</span><span class='line'><span class="k">private</span><span class="o">:</span>
</span><span class='line'> <span class="kt">void</span> <span class="n">joyCallback</span><span class="p">(</span><span class="k">const</span> <span class="n">sensor_msgs</span><span class="o">::</span><span class="n">Joy</span><span class="o">::</span><span class="n">ConstPtr</span><span class="o">&</span> <span class="n">joy</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'> <span class="n">ros</span><span class="o">::</span><span class="n">NodeHandle</span> <span class="n">nh_</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'> <span class="kt">int</span> <span class="n">linear_</span><span class="p">,</span> <span class="n">angular_</span><span class="p">;</span>
</span><span class='line'> <span class="kt">double</span> <span class="n">l_scale_</span><span class="p">,</span> <span class="n">a_scale_</span><span class="p">;</span>
</span><span class='line'> <span class="n">ros</span><span class="o">::</span><span class="n">Publisher</span> <span class="n">twist_pub_</span><span class="p">;</span>
</span><span class='line'> <span class="n">ros</span><span class="o">::</span><span class="n">Subscriber</span> <span class="n">joy_sub_</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'><span class="p">};</span>
</span><span class='line'>
</span><span class='line'>
</span><span class='line'><span class="n">TeleopTurtle</span><span class="o">::</span><span class="n">TeleopTurtle</span><span class="p">()</span><span class="o">:</span>
</span><span class='line'> <span class="n">linear_</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span>
</span><span class='line'> <span class="n">angular_</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'>
</span><span class='line'> <span class="n">nh_</span><span class="p">.</span><span class="n">param</span><span class="p">(</span><span class="s">"axis_linear"</span><span class="p">,</span> <span class="n">linear_</span><span class="p">,</span> <span class="n">linear_</span><span class="p">);</span>
</span><span class='line'> <span class="n">nh_</span><span class="p">.</span><span class="n">param</span><span class="p">(</span><span class="s">"axis_angular"</span><span class="p">,</span> <span class="n">angular_</span><span class="p">,</span> <span class="n">angular_</span><span class="p">);</span>
</span><span class='line'> <span class="n">nh_</span><span class="p">.</span><span class="n">param</span><span class="p">(</span><span class="s">"scale_angular"</span><span class="p">,</span> <span class="n">a_scale_</span><span class="p">,</span> <span class="n">a_scale_</span><span class="p">);</span>
</span><span class='line'> <span class="n">nh_</span><span class="p">.</span><span class="n">param</span><span class="p">(</span><span class="s">"scale_linear"</span><span class="p">,</span> <span class="n">l_scale_</span><span class="p">,</span> <span class="n">l_scale_</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'>
</span><span class='line'> <span class="n">twist_pub_</span> <span class="o">=</span> <span class="n">nh_</span><span class="p">.</span><span class="n">advertise</span><span class="o"><</span><span class="n">geometry_msgs</span><span class="o">::</span><span class="n">Twist</span><span class="o">></span><span class="p">(</span><span class="s">"turtle1/cmd_vel"</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'>
</span><span class='line'> <span class="n">joy_sub_</span> <span class="o">=</span> <span class="n">nh_</span><span class="p">.</span><span class="n">subscribe</span><span class="o"><</span><span class="n">sensor_msgs</span><span class="o">::</span><span class="n">Joy</span><span class="o">></span><span class="p">(</span><span class="s">"joy"</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="o">&</span><span class="n">TeleopTurtle</span><span class="o">::</span><span class="n">joyCallback</span><span class="p">,</span> <span class="k">this</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="kt">void</span> <span class="n">TeleopTurtle</span><span class="o">::</span><span class="n">joyCallback</span><span class="p">(</span><span class="k">const</span> <span class="n">sensor_msgs</span><span class="o">::</span><span class="n">Joy</span><span class="o">::</span><span class="n">ConstPtr</span><span class="o">&</span> <span class="n">joy</span><span class="p">)</span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'> <span class="n">geometry_msgs</span><span class="o">::</span><span class="n">Twist</span> <span class="n">twist</span><span class="p">;</span>
</span><span class='line'> <span class="n">twist</span><span class="p">.</span><span class="n">angular</span><span class="p">.</span><span class="n">z</span> <span class="o">=</span> <span class="n">a_scale_</span><span class="o">*</span><span class="n">joy</span><span class="o">-></span><span class="n">axes</span><span class="p">[</span><span class="n">angular_</span><span class="p">];</span>
</span><span class='line'> <span class="n">twist</span><span class="p">.</span><span class="n">linear</span><span class="p">.</span><span class="n">x</span> <span class="o">=</span> <span class="n">l_scale_</span><span class="o">*</span><span class="n">joy</span><span class="o">-></span><span class="n">axes</span><span class="p">[</span><span class="n">linear_</span><span class="p">];</span>
</span><span class='line'> <span class="n">twist_pub_</span><span class="p">.</span><span class="n">publish</span><span class="p">(</span><span class="n">twist</span><span class="p">);</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'>
</span><span class='line'><span class="kt">int</span> <span class="n">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span><span class="o">**</span> <span class="n">argv</span><span class="p">)</span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'> <span class="n">ros</span><span class="o">::</span><span class="n">init</span><span class="p">(</span><span class="n">argc</span><span class="p">,</span> <span class="n">argv</span><span class="p">,</span> <span class="s">"teleop_turtle"</span><span class="p">);</span>
</span><span class='line'> <span class="n">TeleopTurtle</span> <span class="n">teleop_turtle</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'> <span class="n">ros</span><span class="o">::</span><span class="n">spin</span><span class="p">();</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>
<p>このソースは既にIndigoで動くように所々書き換えられています。よって、Indigo以外のディストリビューションの方は原文のページを参考にして下さい。</p>
<p>次に、<code>CMakeLists.txt</code>を書き換えます。</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nb">cd</span> ..
</span><span class='line'>emacs CMakeLists.txt
</span></code></pre></td></tr></table></div></figure>
<p>以下の行を<code>CMakeLists.txt</code>の最後に追加して下さい。</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>add_executable<span class="o">(</span>turtle_teleop_joy src/turtle_teleop_joy.cpp<span class="o">)</span>
</span><span class='line'>target_link_libraries<span class="o">(</span>turtle_teleop_joy <span class="k">${</span><span class="nv">catkin_LIBRARIES</span><span class="k">}</span><span class="o">)</span>
</span></code></pre></td></tr></table></div></figure>
<p>また、以下の部分を探してコメントアウトを外して下さい。</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>CATKIN_DEPENDS joy roscpp turtlesim
</span></code></pre></td></tr></table></div></figure>
<h2>launchファイルを作る</h2>
<p>joy_nodeやturtlesimを一斉に起動するlaunchファイルを作ります。</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>mkdir launch
</span><span class='line'><span class="nb">cd </span>launch
</span><span class='line'>emacs turtle_joy.launch
</span></code></pre></td></tr></table></div></figure>
<p>以下のソースをコピーして下さい。</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
</pre></td><td class='code'><pre><code class='cpp'><span class='line'><span class="o"><</span><span class="n">launch</span><span class="o">></span>
</span><span class='line'>
</span><span class='line'> <span class="o"><!--</span> <span class="n">Turtlesim</span> <span class="n">Node</span><span class="o">--></span>
</span><span class='line'> <span class="o"><</span><span class="n">node</span> <span class="n">pkg</span><span class="o">=</span><span class="s">"turtlesim"</span> <span class="n">type</span><span class="o">=</span><span class="s">"turtlesim_node"</span> <span class="n">name</span><span class="o">=</span><span class="s">"sim"</span><span class="o">/></span>
</span><span class='line'>
</span><span class='line'>
</span><span class='line'> <span class="o"><!--</span> <span class="n">joy</span> <span class="n">node</span> <span class="o">--></span>
</span><span class='line'> <span class="o"><</span><span class="n">node</span> <span class="n">respawn</span><span class="o">=</span><span class="s">"true"</span> <span class="n">pkg</span><span class="o">=</span><span class="s">"joy"</span>
</span><span class='line'> <span class="n">type</span><span class="o">=</span><span class="s">"joy_node"</span> <span class="n">name</span><span class="o">=</span><span class="s">"turtle_joy"</span> <span class="o">></span>
</span><span class='line'> <span class="o"><</span><span class="n">param</span> <span class="n">name</span><span class="o">=</span><span class="s">"dev"</span> <span class="n">type</span><span class="o">=</span><span class="s">"string"</span> <span class="n">value</span><span class="o">=</span><span class="s">"/dev/input/js0"</span> <span class="o">/></span>
</span><span class='line'> <span class="o"><</span><span class="n">param</span> <span class="n">name</span><span class="o">=</span><span class="s">"deadzone"</span> <span class="n">value</span><span class="o">=</span><span class="s">"0.12"</span> <span class="o">/></span>
</span><span class='line'> <span class="o"></</span><span class="n">node</span><span class="o">></span>
</span><span class='line'>
</span><span class='line'> <span class="o"><!--</span> <span class="n">Axes</span> <span class="o">--></span>
</span><span class='line'> <span class="o"><</span><span class="n">param</span> <span class="n">name</span><span class="o">=</span><span class="s">"axis_linear"</span> <span class="n">value</span><span class="o">=</span><span class="s">"1"</span> <span class="n">type</span><span class="o">=</span><span class="s">"int"</span><span class="o">/></span>
</span><span class='line'> <span class="o"><</span><span class="n">param</span> <span class="n">name</span><span class="o">=</span><span class="s">"axis_angular"</span> <span class="n">value</span><span class="o">=</span><span class="s">"0"</span> <span class="n">type</span><span class="o">=</span><span class="s">"int"</span><span class="o">/></span>
</span><span class='line'> <span class="o"><</span><span class="n">param</span> <span class="n">name</span><span class="o">=</span><span class="s">"scale_linear"</span> <span class="n">value</span><span class="o">=</span><span class="s">"2"</span> <span class="n">type</span><span class="o">=</span><span class="s">"double"</span><span class="o">/></span>
</span><span class='line'> <span class="o"><</span><span class="n">param</span> <span class="n">name</span><span class="o">=</span><span class="s">"scale_angular"</span> <span class="n">value</span><span class="o">=</span><span class="s">"2"</span> <span class="n">type</span><span class="o">=</span><span class="s">"double"</span><span class="o">/></span>
</span><span class='line'>
</span><span class='line'> <span class="o"><</span><span class="n">node</span> <span class="n">pkg</span><span class="o">=</span><span class="s">"leaning_joy"</span> <span class="n">type</span><span class="o">=</span><span class="s">"turtle_teleop_joy"</span> <span class="n">name</span><span class="o">=</span><span class="s">"teleop"</span><span class="o">/></span>
</span><span class='line'>
</span><span class='line'><span class="o"></</span><span class="n">launch</span><span class="o">></span>
</span></code></pre></td></tr></table></div></figure>
<p>例によって、Indigo用に書き換えてあります。</p>
<p>保存したら、<code>catkin_ws</code>に移動して以下のコマンドを実行して下さい。</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>catkin_make install
</span></code></pre></td></tr></table></div></figure>
<p>これは依存関係をすべて整えてグローバルインストールします。つまり、困ったらコレ的な便利コマンドです。</p>
<p>DualShock3を繋いで許可を出し、トピックが配信されることを確認しましょう。</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>ls -l /dev/input/js0
</span><span class='line'>sudo chmod a+rw /dev/input/js0
</span><span class='line'>rostopic <span class="nb">echo </span>joy
</span></code></pre></td></tr></table></div></figure>
<p>確認ができたら以下のコマンドを実行して下さい。turtlesimが起動して、DualShock3で動かせるようになっているはずです。</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>roslaunch learning_joy turtle_joy.launch
</span></code></pre></td></tr></table></div></figure>
<h2>最後に</h2>
<p>今回は自分が誤字で依存関係がうまく構築できなかったり、DualShock3からうまく情報が取れなかったりと色々ありました。が、とりあえず動いたので満足です。</p>
<p>間違っているところがあればコメントお願いします。</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[CIR-KITの1号機ドライバ作成 on ROS]]></title>
<link href="http://cir-kit.github.io/blog/2015/03/15/make-first-robot-driver-on-ros/"/>
<updated>2015-03-15T03:00:00+09:00</updated>
<id>http://cir-kit.github.io/blog/2015/03/15/make-first-robot-driver-on-ros</id>
<content type="html"><![CDATA[<h1>1号機の新しいドライバについて</h1>
<h2>概要</h2>
<p>ROSを利用して1号機のドライバを再度作成した際に
決定した仕様や,変更した仕様などをまとめた.
また,Arduinoによる制御において考えるべき要素を記す.</p>
<h2>検証情報</h2>
<h3>日時</h3>
<p>03/13/2015 (Fri)</p>
<!--more-->
<h3>スペック</h3>
<table>
<thead>
<tr>
<th style="text-align:center;">パーツ</th>
<th style="text-align:center;">スペック</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center;">PC</td>
<td style="text-align:center;">Panasonic Let’s note CF-LX3TG7TC</td>
</tr>
<tr>
<td style="text-align:center;">Prosessor</td>
<td style="text-align:center;">Intel core i7-4500U (1.8GHz)</td>
</tr>
<tr>
<td style="text-align:center;">RAM</td>
<td style="text-align:center;">DDR3 SDRAM(PC3-12800) 4GB</td>
</tr>
<tr>
<td style="text-align:center;">OS</td>
<td style="text-align:center;">Ubuntu 14.04.2 LTS 64bit</td>
</tr>
<tr>
<td style="text-align:center;">Kernel</td>
<td style="text-align:center;">3.13.0-46-generic</td>
</tr>
<tr>
<td style="text-align:center;">ROS</td>
<td style="text-align:center;">indigo 1.11.10</td>
</tr>
<tr>
<td style="text-align:center;">Arduino</td>
<td style="text-align:center;">Arduino UNO</td>
</tr>
<tr>
<td style="text-align:center;">rosserial</td>
<td style="text-align:center;">0.6.3</td>
</tr>
</tbody>
</table>
<h2>新しいドライバの過去からの変更点</h2>
<p>レスポンス速度を過去のものより高速化した.ただし無駄を改良仕切ったわけではない.
前身はloopを最速で回す前提かつdelayで一時処理がとまるプログラムだったので,一部だけだが,それらに依らない改良を行った.</p>
<h2>ドライバ仕様</h2>
<p>Topic</p>
<table>
<thead>
<tr>
<th style="text-align:center;">名称</th>
<th style="text-align:center;">使用法</th>
<th style="text-align:center;">型</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center;">moter_driver</td>
<td style="text-align:center;">subscribe</td>
<td style="text-align:center;">geometry_msgs/Twist</td>
</tr>
</tbody>
</table>
<p>Msg:geometry_msgs/Twist</p>
<table>
<thead>
<tr>
<th style="text-align:center;">要素</th>
<th style="text-align:center;">関連物</th>
<th style="text-align:center;">想定条件</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center;">linear.x</td>
<td style="text-align:center;">前後移動速度</td>
<td style="text-align:center;">-1.0 ~ 1.0</td>
</tr>
<tr>
<td style="text-align:center;">angular.z</td>
<td style="text-align:center;">左右操舵条件</td>
<td style="text-align:center;">ステッピングモータのステップ数</td>
</tr>
</tbody>
</table>
<p>geometry_msgs/Twist メッセージを受け取り,linear.xを前後移動速度,angular.zを左右操舵条件としてモータを制御します.</p>
<p>linear.xの絶対値は速度になります.また,1.0は最大速度を示します.
負の値を受け取った時はバックします.yとzは使用しません.</p>
<p>angular.zが正の値で左,負の値で右へ操舵します.0の場合,現在の操舵状態を保持します.angularにステッピングモータのステップ数を入れるよう推奨しているのはジオメトリ出力として入力しやすいと考えたからです.なお,xとyは使用しません.</p>
<h2>ソース</h2>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
<span class='line-number'>39</span>
<span class='line-number'>40</span>
<span class='line-number'>41</span>
<span class='line-number'>42</span>
<span class='line-number'>43</span>
<span class='line-number'>44</span>
<span class='line-number'>45</span>
<span class='line-number'>46</span>
<span class='line-number'>47</span>
<span class='line-number'>48</span>
<span class='line-number'>49</span>
<span class='line-number'>50</span>
<span class='line-number'>51</span>
<span class='line-number'>52</span>
<span class='line-number'>53</span>
<span class='line-number'>54</span>
<span class='line-number'>55</span>
<span class='line-number'>56</span>
<span class='line-number'>57</span>
<span class='line-number'>58</span>
<span class='line-number'>59</span>
<span class='line-number'>60</span>
<span class='line-number'>61</span>
<span class='line-number'>62</span>
<span class='line-number'>63</span>
<span class='line-number'>64</span>
<span class='line-number'>65</span>
<span class='line-number'>66</span>
<span class='line-number'>67</span>
<span class='line-number'>68</span>
<span class='line-number'>69</span>
<span class='line-number'>70</span>
<span class='line-number'>71</span>
<span class='line-number'>72</span>
<span class='line-number'>73</span>
<span class='line-number'>74</span>
<span class='line-number'>75</span>
<span class='line-number'>76</span>
<span class='line-number'>77</span>
<span class='line-number'>78</span>
<span class='line-number'>79</span>
<span class='line-number'>80</span>
<span class='line-number'>81</span>
<span class='line-number'>82</span>
<span class='line-number'>83</span>
<span class='line-number'>84</span>
<span class='line-number'>85</span>
<span class='line-number'>86</span>
<span class='line-number'>87</span>
<span class='line-number'>88</span>
<span class='line-number'>89</span>
<span class='line-number'>90</span>
<span class='line-number'>91</span>
<span class='line-number'>92</span>
<span class='line-number'>93</span>
<span class='line-number'>94</span>
<span class='line-number'>95</span>
<span class='line-number'>96</span>
<span class='line-number'>97</span>
<span class='line-number'>98</span>
<span class='line-number'>99</span>
<span class='line-number'>100</span>
<span class='line-number'>101</span>
<span class='line-number'>102</span>
<span class='line-number'>103</span>
<span class='line-number'>104</span>
<span class='line-number'>105</span>
<span class='line-number'>106</span>
<span class='line-number'>107</span>
<span class='line-number'>108</span>
<span class='line-number'>109</span>
<span class='line-number'>110</span>
<span class='line-number'>111</span>
<span class='line-number'>112</span>
<span class='line-number'>113</span>
<span class='line-number'>114</span>
<span class='line-number'>115</span>
<span class='line-number'>116</span>
<span class='line-number'>117</span>
<span class='line-number'>118</span>
<span class='line-number'>119</span>
<span class='line-number'>120</span>
<span class='line-number'>121</span>
<span class='line-number'>122</span>
<span class='line-number'>123</span>
<span class='line-number'>124</span>
<span class='line-number'>125</span>
<span class='line-number'>126</span>
<span class='line-number'>127</span>
<span class='line-number'>128</span>
<span class='line-number'>129</span>
<span class='line-number'>130</span>
<span class='line-number'>131</span>
<span class='line-number'>132</span>
<span class='line-number'>133</span>
<span class='line-number'>134</span>
<span class='line-number'>135</span>
<span class='line-number'>136</span>
<span class='line-number'>137</span>
<span class='line-number'>138</span>
<span class='line-number'>139</span>
<span class='line-number'>140</span>
<span class='line-number'>141</span>
<span class='line-number'>142</span>
<span class='line-number'>143</span>
<span class='line-number'>144</span>
<span class='line-number'>145</span>
<span class='line-number'>146</span>
<span class='line-number'>147</span>
<span class='line-number'>148</span>
<span class='line-number'>149</span>
<span class='line-number'>150</span>
<span class='line-number'>151</span>
<span class='line-number'>152</span>
</pre></td><td class='code'><pre><code class='cpp'><span class='line'><span class="cm">/**</span>
</span><span class='line'><span class="cm">Copyright (c) 2015, Yusuke Doi</span>
</span><span class='line'><span class="cm">All rights reserved.</span>
</span><span class='line'>
</span><span class='line'><span class="cm">Redistribution and use in source and binary forms, with or without</span>
</span><span class='line'><span class="cm">modification, are permitted provided that the following conditions are met: </span>
</span><span class='line'>
</span><span class='line'><span class="cm">1. Redistributions of source code must retain the above copyright notice,</span>
</span><span class='line'><span class="cm"> this list of conditions and the following disclaimer. </span>
</span><span class='line'><span class="cm">2. Redistributions in binary form must reproduce the above copyright notice,</span>
</span><span class='line'><span class="cm"> this list of conditions and the following disclaimer in the documentation</span>
</span><span class='line'><span class="cm"> and/or other materials provided with the distribution. </span>
</span><span class='line'>
</span><span class='line'><span class="cm">THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND</span>
</span><span class='line'><span class="cm">ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED</span>
</span><span class='line'><span class="cm">WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE</span>
</span><span class='line'><span class="cm">DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR</span>
</span><span class='line'><span class="cm">ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES</span>
</span><span class='line'><span class="cm">(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;</span>
</span><span class='line'><span class="cm">LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND</span>
</span><span class='line'><span class="cm">ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span>
</span><span class='line'><span class="cm">(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS</span>
</span><span class='line'><span class="cm">SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
</span><span class='line'>
</span><span class='line'><span class="cm">The views and conclusions contained in the software and documentation are those</span>
</span><span class='line'><span class="cm">of the authors and should not be interpreted as representing official policies, </span>
</span><span class='line'><span class="cm">either expressed or implied, of the FreeBSD Project.</span>
</span><span class='line'><span class="cm">*/</span>
</span><span class='line'><span class="cp">#include <ros.h> </span><span class="c1">// Use ros_lib.</span>
</span><span class='line'><span class="cp">#include <geometry_msgs/Twist.h> </span><span class="c1">// Use Twist.msg. -> [linear(x,y,z), angular(x,y,z)]</span>
</span><span class='line'>
</span><span class='line'><span class="cm">/* Define pin numbers. */</span>
</span><span class='line'><span class="cp">#define ACCEL 9</span>
</span><span class='line'><span class="cp">#define BACK_GEAR 8</span>
</span><span class='line'><span class="cp">#define CW 3</span>
</span><span class='line'><span class="cp">#define CCW 4</span>
</span><span class='line'><span class="cm">/* Define pulse width time of the stepping motor. */</span>
</span><span class='line'><span class="cp">#define PULSE_WIDTH_MICRO_SECOND 500</span>
</span><span class='line'><span class="cm">/* Define max speed to 220. */</span>
</span><span class='line'><span class="cp">#define MAX_SPEED 220</span>
</span><span class='line'><span class="cm">/* Define direction of angular z. */</span>
</span><span class='line'><span class="cp">#define LEFT 0</span>
</span><span class='line'><span class="cp">#define RIGHT 1</span>
</span><span class='line'><span class="cp">#define KEEP 2</span>
</span><span class='line'><span class="cm">/* Define direction of back gear. */</span>
</span><span class='line'><span class="cp">#define FORWARD 0</span>
</span><span class='line'><span class="cp">#define BACK 1</span>
</span><span class='line'>
</span><span class='line'><span class="cm">/* Declare proto type functions. */</span>
</span><span class='line'><span class="kt">void</span> <span class="nf">steer</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="n">direction</span><span class="p">);</span> <span class="c1">// Write pulse to the stepping motor.</span>
</span><span class='line'><span class="kt">void</span> <span class="nf">setGear</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="n">direction</span><span class="p">);</span> <span class="c1">// Set direction to the back gear pin.</span>
</span><span class='line'><span class="kt">unsigned</span> <span class="kt">char</span> <span class="nf">getSpeed</span><span class="p">(</span><span class="kt">float</span> <span class="n">speed</span><span class="p">);</span> <span class="c1">// Get speed what fit the robot model.</span>
</span><span class='line'><span class="kt">void</span> <span class="nf">motorCb</span><span class="p">(</span><span class="k">const</span> <span class="n">geometry_msgs</span><span class="o">::</span><span class="n">Twist</span><span class="o">&</span> <span class="n">msg</span><span class="p">);</span> <span class="c1">// Call back function of the motor_driver topic.</span>
</span><span class='line'>
</span><span class='line'><span class="cm">/* Declare global constants. */</span>
</span><span class='line'><span class="k">const</span> <span class="kt">unsigned</span> <span class="kt">int</span> <span class="n">PULSE_FREQUENCY</span> <span class="o">=</span> <span class="mi">1000l</span> <span class="o">*</span> <span class="mi">1000</span> <span class="o">/</span> <span class="p">(</span><span class="n">PULSE_WIDTH_MICRO_SECOND</span> <span class="o">*</span> <span class="mi">2</span><span class="p">);</span> <span class="c1">// Get frequency of pulse.</span>
</span><span class='line'><span class="cm">/* Declare global variables. */</span>
</span><span class='line'><span class="n">ros</span><span class="o">::</span><span class="n">NodeHandle</span> <span class="n">nh</span><span class="p">;</span> <span class="c1">// The nodeHandle.</span>
</span><span class='line'><span class="n">ros</span><span class="o">::</span><span class="n">Subscriber</span><span class="o"><</span><span class="n">geometry_msgs</span><span class="o">::</span><span class="n">Twist</span><span class="o">></span> <span class="n">sub</span><span class="p">(</span><span class="s">"motor_driver"</span><span class="p">,</span> <span class="o">&</span><span class="n">motorCb</span><span class="p">);</span> <span class="c1">// Set subscribe the motor_driver topic.</span>
</span><span class='line'>
</span><span class='line'><span class="kt">void</span> <span class="nf">setup</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'> <span class="cm">/* Set pins Mode. */</span>
</span><span class='line'> <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="n">CCW</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">ACCEL</span><span class="o">+</span><span class="mi">1</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// 3: CCW, 4: CW, 5: C0, 6:C2, 7:HOFF 8: BACK_GEAR 9: ACCEL</span>
</span><span class='line'> <span class="n">pinMode</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">OUTPUT</span><span class="p">);</span>
</span><span class='line'> <span class="n">digitalWrite</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">LOW</span><span class="p">);</span> <span class="c1">// Default pin status is LOW.</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'> <span class="cm">/* Node handle setting. */</span>
</span><span class='line'> <span class="n">nh</span><span class="p">.</span><span class="n">initNode</span><span class="p">();</span> <span class="c1">// First setup the node handle.</span>
</span><span class='line'> <span class="n">nh</span><span class="p">.</span><span class="n">subscribe</span><span class="p">(</span><span class="n">sub</span><span class="p">);</span> <span class="c1">// Start subscribe the motor_driver topic.</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="kt">void</span> <span class="nf">loop</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'> <span class="n">nh</span><span class="p">.</span><span class="n">spinOnce</span><span class="p">();</span> <span class="c1">// Check topic and if change it, run the call back function.</span>
</span><span class='line'> <span class="n">delay</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="cm">/**</span>
</span><span class='line'><span class="cm"> * Call back function of the motor_driver topic.</span>
</span><span class='line'><span class="cm"> * This funcion is moter driver unit.</span>
</span><span class='line'><span class="cm"> *</span>
</span><span class='line'><span class="cm"> * @author "Yusuke Doi"</span>
</span><span class='line'><span class="cm"> * @param msg This param is msg object of the motor_driver topic.</span>
</span><span class='line'><span class="cm"> */</span>
</span><span class='line'><span class="kt">void</span> <span class="nf">motorCb</span><span class="p">(</span><span class="k">const</span> <span class="n">geometry_msgs</span><span class="o">::</span><span class="n">Twist</span><span class="o">&</span> <span class="n">msg</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="cm">/* gear change task */</span>
</span><span class='line'> <span class="k">if</span> <span class="p">(</span><span class="n">msg</span><span class="p">.</span><span class="n">linear</span><span class="p">.</span><span class="n">x</span> <span class="o"><</span> <span class="mi">0</span> <span class="o">&&</span> <span class="o">!</span><span class="n">digitalRead</span><span class="p">(</span><span class="n">BACK_GEAR</span><span class="p">))</span> <span class="c1">// Go to back, but gear setting is forward now.</span>
</span><span class='line'> <span class="n">setGear</span><span class="p">(</span><span class="n">BACK</span><span class="p">);</span> <span class="c1">// Set back to back gear.</span>
</span><span class='line'> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">msg</span><span class="p">.</span><span class="n">linear</span><span class="p">.</span><span class="n">x</span> <span class="o">></span> <span class="mi">0</span> <span class="o">&&</span> <span class="n">digitalRead</span><span class="p">(</span><span class="n">BACK_GEAR</span><span class="p">))</span> <span class="c1">// Go to forward, but gear setting is back now.</span>
</span><span class='line'> <span class="n">setGear</span><span class="p">(</span><span class="n">FORWARD</span><span class="p">);</span> <span class="c1">// Set forward to back gear.</span>
</span><span class='line'> <span class="cm">/* steer task */</span>
</span><span class='line'> <span class="k">if</span> <span class="p">(</span><span class="n">msg</span><span class="p">.</span><span class="n">angular</span><span class="p">.</span><span class="n">z</span> <span class="o"><</span> <span class="mi">0</span><span class="p">)</span> <span class="n">steer</span><span class="p">(</span><span class="n">RIGHT</span><span class="p">);</span> <span class="c1">// Minus mean CCW or right.</span>
</span><span class='line'> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">msg</span><span class="p">.</span><span class="n">angular</span><span class="p">.</span><span class="n">z</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> <span class="n">steer</span><span class="p">(</span><span class="n">LEFT</span><span class="p">);</span> <span class="c1">// Plus mean CW or left.</span>
</span><span class='line'> <span class="k">else</span> <span class="n">steer</span><span class="p">(</span><span class="n">KEEP</span><span class="p">);</span> <span class="c1">// Zero mean keep steer.</span>
</span><span class='line'> <span class="cm">/* move task */</span>
</span><span class='line'> <span class="n">analogWrite</span><span class="p">(</span><span class="n">ACCEL</span><span class="p">,</span> <span class="n">getSpeed</span><span class="p">(</span><span class="n">msg</span><span class="p">.</span><span class="n">linear</span><span class="p">.</span><span class="n">x</span><span class="p">));</span> <span class="c1">// Write speed to accel pin.</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="cm">/**</span>
</span><span class='line'><span class="cm"> * Set back gear by direction.</span>
</span><span class='line'><span class="cm"> *</span>
</span><span class='line'><span class="cm"> * @author "Yusuke Doi"</span>
</span><span class='line'><span class="cm"> * @param direction Set this into back gear.</span>
</span><span class='line'><span class="cm"> */</span>
</span><span class='line'><span class="kt">void</span> <span class="nf">setGear</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="n">direction</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="n">analogWrite</span><span class="p">(</span><span class="n">ACCEL</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span> <span class="c1">// Stop the DC motor.</span>
</span><span class='line'> <span class="k">switch</span> <span class="p">(</span><span class="n">direction</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="k">case</span> <span class="nl">FORWARD</span><span class="p">:</span>
</span><span class='line'> <span class="n">delay</span><span class="p">(</span><span class="mi">700</span><span class="p">);</span> <span class="c1">// Wait to stop the DC motor perfectly.</span>
</span><span class='line'> <span class="n">digitalWrite</span><span class="p">(</span><span class="n">BACK_GEAR</span><span class="p">,</span> <span class="n">LOW</span><span class="p">);</span> <span class="c1">// Change back gear to back.</span>
</span><span class='line'> <span class="n">delay</span><span class="p">(</span><span class="mi">400</span><span class="p">);</span> <span class="c1">// Wait to change back gear perfectly.</span>
</span><span class='line'> <span class="k">break</span><span class="p">;</span>
</span><span class='line'> <span class="k">case</span> <span class="nl">BACK</span><span class="p">:</span>
</span><span class='line'> <span class="n">delay</span><span class="p">(</span><span class="mi">500</span><span class="p">);</span> <span class="c1">// Wait to stop the DC motor perfectly.</span>
</span><span class='line'> <span class="n">digitalWrite</span><span class="p">(</span><span class="n">BACK_GEAR</span><span class="p">,</span> <span class="n">HIGH</span><span class="p">);</span> <span class="c1">// Change back gear to back.</span>
</span><span class='line'> <span class="n">delay</span><span class="p">(</span><span class="mi">500</span><span class="p">);</span> <span class="c1">// Wait to change back gear perfectly.</span>
</span><span class='line'> <span class="k">break</span><span class="p">;</span>
</span><span class='line'> <span class="k">default</span><span class="o">:</span>
</span><span class='line'> <span class="n">setGear</span><span class="p">(</span><span class="n">FORWARD</span><span class="p">);</span> <span class="c1">// Run this function, and set FORWARD.</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="cm">/**</span>
</span><span class='line'><span class="cm"> * Steering function of the stepping motor.</span>
</span><span class='line'><span class="cm"> *</span>
</span><span class='line'><span class="cm"> * @author "Yusuke Doi"</span>
</span><span class='line'><span class="cm"> * @param direction Steer to direction.</span>
</span><span class='line'><span class="cm"> */</span>
</span><span class='line'><span class="kt">void</span> <span class="nf">steer</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="n">direction</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="k">switch</span> <span class="p">(</span><span class="n">direction</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="k">case</span> <span class="nl">LEFT</span><span class="p">:</span> <span class="c1">// Task steer left.</span>
</span><span class='line'> <span class="n">noTone</span><span class="p">(</span><span class="n">CW</span><span class="p">);</span> <span class="c1">// Unset tone. If don't running tone, not happen.</span>
</span><span class='line'> <span class="n">digitalWrite</span><span class="p">(</span><span class="n">CW</span><span class="p">,</span> <span class="n">HIGH</span><span class="p">);</span> <span class="c1">// Set high to CW.</span>
</span><span class='line'> <span class="n">tone</span><span class="p">(</span><span class="n">CCW</span><span class="p">,</span> <span class="n">PULSE_FREQUENCY</span><span class="p">);</span> <span class="c1">// Write pulse to CCW pin. turn to CW.</span>
</span><span class='line'> <span class="k">break</span><span class="p">;</span>
</span><span class='line'> <span class="k">case</span> <span class="nl">RIGHT</span><span class="p">:</span> <span class="c1">// Task steer right.</span>
</span><span class='line'> <span class="n">noTone</span><span class="p">(</span><span class="n">CCW</span><span class="p">);</span> <span class="c1">// Unset tone. If don't running tone, not happen.</span>
</span><span class='line'> <span class="n">digitalWrite</span><span class="p">(</span><span class="n">CCW</span><span class="p">,</span> <span class="n">HIGH</span><span class="p">);</span> <span class="c1">// Set high to CCW.</span>
</span><span class='line'> <span class="n">tone</span><span class="p">(</span><span class="n">CW</span><span class="p">,</span> <span class="n">PULSE_FREQUENCY</span><span class="p">);</span> <span class="c1">// Write pulse to CW pin. turn to CCW.</span>
</span><span class='line'> <span class="k">break</span><span class="p">;</span>
</span><span class='line'> <span class="k">case</span> <span class="nl">KEEP</span><span class="p">:</span> <span class="k">default</span><span class="o">:</span> <span class="c1">// set CW and CCW to low.</span>
</span><span class='line'> <span class="n">noTone</span><span class="p">(</span><span class="n">CW</span><span class="p">);</span> <span class="c1">// Unset tone. If don't running tone, not happen.</span>
</span><span class='line'> <span class="n">noTone</span><span class="p">(</span><span class="n">CCW</span><span class="p">);</span> <span class="c1">// Unset tone. If don't running tone, not happen.</span>
</span><span class='line'> <span class="n">digitalWrite</span><span class="p">(</span><span class="n">CW</span><span class="p">,</span> <span class="n">LOW</span><span class="p">);</span>
</span><span class='line'> <span class="n">digitalWrite</span><span class="p">(</span><span class="n">CCW</span><span class="p">,</span> <span class="n">LOW</span><span class="p">);</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="kt">unsigned</span> <span class="kt">char</span> <span class="nf">getSpeed</span><span class="p">(</span><span class="kt">float</span> <span class="n">baseSpeed</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="kt">float</span> <span class="n">speed</span> <span class="o">=</span> <span class="n">abs</span><span class="p">(</span><span class="n">baseSpeed</span> <span class="o">*</span> <span class="n">MAX_SPEED</span><span class="p">);</span> <span class="c1">// Cast to 0~MAX_SPEED. so baseSpeed width is -1.0~1.0.</span>
</span><span class='line'> <span class="k">if</span> <span class="p">(</span><span class="n">speed</span> <span class="o">></span> <span class="n">MAX_SPEED</span><span class="p">)</span> <span class="n">speed</span> <span class="o">=</span> <span class="n">MAX_SPEED</span><span class="p">;</span> <span class="c1">// Limit max speed to 220.</span>
</span><span class='line'> <span class="k">return</span> <span class="p">(</span><span class="kt">unsigned</span> <span class="kt">char</span><span class="p">)</span><span class="n">speed</span><span class="p">;</span> <span class="c1">// Cast to unsigned char.</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>
<h3>解説など</h3>
<p>トピックにメッセージが来たらコールバック関数joyCbを呼び出します.この関数は受け取ったメッセージを解析して,操舵,ギアチェンジ,モータ制御を行います.詳しくはソースのコメントを呼んでください.</p>
<h3>加えられた改良について</h3>
<h4>操舵</h4>
<p>今回の一番の改良点は操舵にtone関数を採用した点です.これによりarduinoは操舵にCPUを専有されることがなくなります.toneは指定ピンに指定周波数のデューティー比50%PWMを出力します.
この関数はPWM用のタイマを利用するので3番ピンと11番ピンのanalogWriteを阻害します.よって現在の構成には影響しません.</p>
<h4>無意味なコピペ削除</h4>
<p>いままでのソースは分岐後に全く同じ動作をする部分が多すぎたため,それらをまとめ可読性を上げました.</p>
<h3>課題点</h3>
<h4>ギアチェンジ</h4>
<p>ギアチェンジ用の関数は未だにdelayが使用されています.このためこのドライバはギアチェンジ中の1秒以上操作不可能に陥ります.</p>
<p>私ははギアチェンジフラグを作成し,DCモータへのアクセスを禁止することでこれを解決しようと考えています.</p>
<h4>多量のマクロ及び関数</h4>
<p>C++を採用しているにも関わらず,CIR-KITでは古いC言語ライクの文が蔓延っています.それは,例えば定数として無意味にマクロを用いたり,1つのソース内からすべての変数にアクセスできることです.</p>
<p>私はクラスを利用してオブジェクト化することでこれら問題を解決すべきと考えています.</p>
<h2>Arduinoプログラムに求められること</h2>
<h3>最低基準:常時反応性</h3>
<p>ここまでのことからまず,最低限マイコンに求められることがあります.
それは常時反応性です.つまり,右を向けと指示を出して,すぐにそれを感知してタスクを実行し始めることが重要です.もし,右に向けと指示を出したのにずっとギアチェンジのタスクに掛かり切りなら,右に向くのはずっと後になります.ギアチェンジのタスク中は停止しているようにすら見えるでしょう.</p>
<p>つまり,マルチタスクをする場合でも,入力受付を常時行うことが必要です.そして,動いてはいけない場合は場合分けで対応するべきです.</p>
<h4>達成方法</h4>
<p>多くのマイコンにはタイマやsoftwareで一度指示を出せばバックグラウンドに処理をしてくれる機能が場合ついています.これらに継続的処理をすべて任せることでプログラマは情報の処理に集中でき,更に常時入力性を保つことができます.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[ジョイスティックで亀を泳がせる(準備編)]]></title>
<link href="http://cir-kit.github.io/blog/2015/03/13/turtlesim-with-joystick/"/>
<updated>2015-03-13T13:02:00+09:00</updated>
<id>http://cir-kit.github.io/blog/2015/03/13/turtlesim-with-joystick</id>
<content type="html"><![CDATA[<h1>ジョイスティックで亀を泳がせる</h1>
<h2>概要</h2>
<p>ROSのチュートリアルで使用したturtlesimの亀をジョイスティックで動かします。<a href="http://wiki.ros.org/joy/Tutorials">joy_tutorial</a>で行っていることをやりますので、原文はそちらへどうぞ。</p>
<h2>検証情報</h2>
<h3>日時</h3>
<p>03/13/2015 (Fri)</p>
<h3>スペック</h3>
<table>
<thead>
<tr>
<th style="text-align:center;">パーツ</th>
<th style="text-align:center;">スペック</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center;">PC</td>
<td style="text-align:center;">CLEVO M76T</td>
</tr>
<tr>
<td style="text-align:center;">Prosessor</td>
<td style="text-align:center;">CeleronDualCore T3000 1.80GHz×2</td>
</tr>
<tr>
<td style="text-align:center;">RAM</td>
<td style="text-align:center;">4GB</td>
</tr>
<tr>
<td style="text-align:center;">OS</td>
<td style="text-align:center;">Ubuntu 14.04.2 LTS 64bit</td>
</tr>