このディレクトリにはLED、スイッチ、ブザーなどのRaspberryPiMouseの周辺機器を使うサンプルコードがあります。
This directory contains examples how to use RaspberryPiMouse's peripherals like LEDs, switches, buzzer, etc.
このディレクトリはApache 2.0ライセンスで公開されています。詳細はSampleProgram / LICENSEを確認してください。
This directory is licensed under the Apache 2.0 License, see SampleProgram / LICENSE.
各機能ごとにShell Script、C、Pythonで書かれたサンプルコードを用意しています。
Each peripheral example has sample code files written Shell Script, C and Python.
RT Software Tutorialsでは動画つきで説明しています。
https://rt-net.github.io/tutorials/raspimouse/driver/samples.html
$ bash step1.sh
Ctrl-c を押して終了してください。
Press [Ctrl-c] to terminate.サンプル実行前に、gccでコンパイルします。
Compile an example code via gcc command before execution.
$ gcc step1.c -o step1
$ ./step1
Ctrl-c を押して終了してください。
Press [Ctrl-c] to terminate.$ python3 step1.py
Ctrl-c を押して終了してください。
Press [Ctrl-c] to terminate.LED0~LED3が点滅します。
The LED0 ~ LED3 blinks.
キーボード入力でブザーを鳴らします。 入力キーと音階のペアは./SCALEを参照してください。
'0'を入力するとブザーが止まります。 'c'を入力するとプログラムが終了します。(Shell ScriptではCtrl-cで終了します。)
Beep the buzzer with keyboard input. Refer to the ./SCALE file for the pairs of input characters and scales.
Press '0' to stop beeping. Press 'c' to terminate the program. (Press Ctrl-c for the Shell Script.)
スイッチを押してLEDを点消灯します。 組み合わせは次のとおりです。
Turn on/off LEDs by the switches. The combination of LEDs and switches are defined as bellow.
- SW0 : LED3
- SW1 : LED1 & LED2
- SW2 : LED0
モータを回して右旋回、左旋回します。
Drive the motors to rotate clockwise and counter-clockwise.
ライトセンサの値を読み込みます。
Read the lightsensors values.
モータを回して、パルスカウンタの値を読み込みます。
Drive the motors and read the pulse counters values.
車体速度
サンプルでは車体速度と車体角速度を指定しての移動が実装されています。
ホイールの直径を
左右のモータへの制御信号を
このときのそれぞれの関係は以下のように表現できます。
旋回方向についても同様に考えます。
車体が1回転するときのホイールが円弧を描くように移動する距離は
左右のモータへの制御信号をそれぞれ
このときのそれぞれの関係は以下のように表現できます。
これらを整理するとモータ制御信号は以下の2つの式にまとめられます。