ARピタゴラスイッチのプログラム実装メモ(Arduino×Processing)
どうも、こんにちわ。たっきーです。
ちょっとけんきうの息抜きにARピタゴラスイッチを作ってみたのでメモ。
はじめに
1個下の学生さんが課題でARピタゴラスイッチなるものを作らなきゃいけないらしく面白そうやんけwって感じでプログラム周りを手伝ったのでそのメモ。
半日足らずで書いたので雑クオリティなの許してください。
ARピタゴラスイッチとは
こんなやつ。
拡張現実ピタゴラ装置って呼ばれたりもする(?)
動画見てめっちゃ面白そうやんけってなってモチベ爆上げ。
実行環境と使用機器
- macOS Sierra 10.12.5
- Arduino 1.8.3
- Arduino UNO
- Processing 3.3.5
- サーボモータ GWSサーボ MICRO/STD/F(フタバ)
- タクトスイッチ
- ミニブレッドボード
- その他小物
Arduinoをはじめよう 初心者実験 キット 基本部品セット20in1 UNO R3互換ボード(Arduino学習キット基本版)
- 出版社/メーカー: vership
- メディア: おもちゃ&ホビー
- この商品を含むブログ (1件) を見る
Amazonベーシック USB2.0ケーブル 1.8m Aオス-Bオス 7HUA
- 出版社/メーカー: AmazonBasics
- メディア: Personal Computers
- この商品を含むブログを見る
参考にしたサイト・本
たのしい電子工作 Arduinoで電子工作をはじめよう![第2版]
- 作者: 高橋隆雄
- 出版社/メーカー: 秀和システム
- 発売日: 2014/08/12
- メディア: Kindle版
- この商品を含むブログを見る
ブレッドボード図
こういうの得意じゃないので間違ってるかも(?)
とりあえず、こんな感じ
スイッチ部分
全体像
Arduinoスケッチ
こんな感じ。
スイッチが押されたらシリアルボードに'a'と書き込んで、指定時間遅らせてからサーボを回し、終わるタイミングで'b'を書き込むってだけのスケッチ。
Processingのプログラム
こんな感じ。
↓を追加する必要あり。
Arduino Playground - Processing
Arduinoから受け取った信号に対応してアニメーション開始したり音出したりする。
↑からダウンロードして、oh.wavって名前で保存して、.pdeファイルと同じディレクトリ内に入れる。
実行動画
深夜2時にピタゴラスイッチ作ってワイワイするおじさん達の動画です pic.twitter.com/GevqtrcVEO
— たっきー (@tacky0612) 2017年7月25日
声がウザいのは気にしない。
上手いこと行ってよかった()
最後に
ARピタゴラスイッチめちゃ面白い(語彙)
Arduinoの制御、Processingの使い方の初歩的な部分を学ぶことができるのでオヌヌメです。
もっと他のセンサーとか使ってギミックを追加してみたさ深い。
たのしい電子工作 Arduinoで電子工作をはじめよう![第2版]
- 作者: 高橋隆雄
- 出版社/メーカー: 秀和システム
- 発売日: 2014/08/12
- メディア: Kindle版
- この商品を含むブログを見る
らぼの日常
ベイブレードがたった!! pic.twitter.com/8aB81EN5jx
— たっきー (@tacky0612) 2017年7月25日
初心者による初心者の為のTensorFlowを使用したMNIST for ML Beginnersを解説。
はじめに
MNISTとは
TensorFlowの処理の流れ
- TensorFlow読み込み
- 式を立てる(モデル)
- セッションを開始
- 式を実行(run)
機械学習の3ステップ
- 現象をモデル化する
- モデルを最適化するパラメータを求める
- 学習したモデルを使用して推定・分類
このチュートリアルで何をするか
実装
from tensorflow.examples.tutorials.mnist import input_datamnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
import tensorflow as tf
x = tf.placeholder(tf.float32, [None, 784])
placeholder(shape=None, #与えられる行列の形状(オプション)。形状が指定されていない場合は、任意の形状のテンソルを供給することができます。name=None #操作の名前(オプション)。)
次に、変数を定義。
W = tf.Variable(tf.zeros([784, 10]))b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x, W) + b)
y_ = tf.placeholder(tf.float32, [None, 10])
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
https://www.tensorflow.org/api_guides/python/train#optimizers
)sess = tf.InteractiveSession()tf.global_variables_initializer().run()
for _ in range(1000):batch_xs, batch_ys = mnist.train.next_batch(100)sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))
だがしかしこれはまだ深層学習ではない
TensorFlowで学ぶディープラーニング入門 ~畳み込みニューラルネットワーク徹底解説~
- 作者: 中井悦司
- 出版社/メーカー: マイナビ出版
- 発売日: 2016/09/27
- メディア: 単行本(ソフトカバー)
- この商品を含むブログ (1件) を見る
最後に
Is that good? Well, not really. In fact, it's pretty bad. This is because we're using a very simple model. With some small changes, we can get to 97%. The best models can get to over 99.7% accuracy!
そういや今年の6月は雨が少ないですね。
初心者による初心者の為のTensorFlowを使用したHello,Worldまでを解説してみるって話。
TensorFlowで学ぶディープラーニング入門?畳み込みニューラルネットワーク徹底解説
- 作者: 中井悦司
- 出版社/メーカー: マイナビ出版
- 発売日: 2016/09/28
- メディア: Kindle版
- この商品を含むブログを見る
環境
TensorFlowとは
Anacondaとは
The Anaconda installation is community supported, not officially supported.
Tensorflowの導入
$ python —version
$ conda create -n tensorflow python=3.5
$ source activate tensorflow
必要なライブラリのインストール
$ conda install -c conda-forge tensorflow
いよいよTensorflowで”Hello, world!”
$ python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
折角なので、簡単な四則演算も実行してみる
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print(sess.run(a + b))
>>> print(sess.run(a * b))
>>> print(sess.run(a - b))
>>> print(sess.run(a / b))
はい、想定通りですね。
終了方法
>>> exit()
$ source deactivate tensorflow
最後に
ゼロから作るDeep Learning ―Pythonで学ぶディープラーニングの理論と実装
- 作者: 斎藤康毅
- 出版社/メーカー: オライリージャパン
- 発売日: 2016/09/24
- メディア: 単行本(ソフトカバー)
- この商品を含むブログ (15件) を見る
詳解 ディープラーニング ~TensorFlow・Kerasによる時系列データ処理~
- 作者: 巣籠悠輔
- 出版社/メーカー: マイナビ出版
- 発売日: 2017/05/30
- メディア: 単行本(ソフトカバー)
- この商品を含むブログを見る
呟き。
Pyてょnのイメージって蛇のアイコンだし、インタラクティブシェルで実行してると蛇使いになった気分になれる(厨二)
— たっきー.py (@tacky0612) 2017年5月30日