初めましてよろしくお願いします。raspberry piとL3G4200Dというジャイロセンサーを使って角度の検出をしたいです。pythonを使用しています。現在では下記のURLを参考にして角速度の検出までできるようになりました。角度の検出を行うにあたって質問がいくつかあります。
使用しているジャイロセンサーには200,500,2000dpsの3つのレンジを選択することができます。プログラムから使用しているレンジは2000dpsだと予想しています。このプログラムでは2000dpsを使用しているということでよろしいのでしょうか。また、角度に変換するときには×0.070をしたほうがいいのでしょうか。
角度への変換は台数公式を使用する予定です。角度への変換でオススメのものや参考URLなどがありましたら、教えていただけるとありがたいです。
初歩的な質問ですがよろしくお願いします。
レンジの参考URL
https://strawberry-linux.com/pub/l3gd20-manual.pdf
プログラムの参考URL
https://github.com/bashardawood/L3G4200D-Python/blob/master/gyro.py
プログラム
from time import sleep
#import smbus to access i2c port
import smbus
import string
#converts 16 bit two's compliment reading to signed int
def getSignedNumber(number):
if number & (1 << 15):
return number | ~65535
else:
return number & 65535
#open /dev/i2c-1
i2c_bus=smbus.SMBus(1)
#i2c slave address of the L3G4200D
i2c_address=0x69
#initialise the L3G4200D
#normal mode and all axes on to control reg1
i2c_bus.write_byte_data(i2c_address,0x20,0x0F)
#full 2000dps to control reg4
i2c_bus.write_byte_data(i2c_address,0x23,0x20)
#read lower and upper bytes, combine and display
while True:
i2c_bus.write_byte(i2c_address,0x28) X_L = i2c_bus.read_byte(i2c_address) i2c_bus.write_byte(i2c_address,0x29) X_H = i2c_bus.read_byte(i2c_address) X = X_H << 8 | X_L i2c_bus.write_byte(i2c_address,0x2A) Y_L = i2c_bus.read_byte(i2c_address) i2c_bus.write_byte(i2c_address,0x2B) Y_H = i2c_bus.read_byte(i2c_address) Y = Y_H << 8 | Y_L i2c_bus.write_byte(i2c_address,0x2C) Z_L = i2c_bus.read_byte(i2c_address) i2c_bus.write_byte(i2c_address,0x2D) Z_H = i2c_bus.read_byte(i2c_address) Z = Z_H << 8 | Z_L X = getSignedNumber(X) Y = getSignedNumber(Y) Z = getSignedNumber(Z) print string.rjust(`X`, 10), print string.rjust(`Y`, 10), print string.rjust(`Z`, 10) sleep(0.02)
あなたの回答
tips
プレビュー