forked from ev3dev/ev3dev
-
Notifications
You must be signed in to change notification settings - Fork 0
HiTechnic NXT Gyro Sensor (NGY1044)
David Lechner edited this page Feb 26, 2014
·
3 revisions
This sensor uses the msensor device class.
Value | |
---|---|
type_id |
3 * |
# Modes | 1 |
Connection | Analog/NXT |
* Not unique. |
Mode 0 | |
---|---|
mode
|
NXT-ANALOG-0
|
Description | Rotational speed |
num_values
|
1
|
value0
|
Raw sensor voltage |
Min |
0
|
Max |
4883 (4.882 V)
|
units
|
V
|
dp (decimal places)
|
3
|
Since this is an NXT Analog sensor and the exact type cannot be autodetected, we have to use a generic sensor interface. This sensor measures rotational speed in degrees/second. Nominally, 0.00V == -540 deg/sec and 4.88V == 400 deg/sec. However, depending on temperature, there is a small offset, so we have to calibrate the sensor to accommodate this.
Sample usage:
#!/bin/bash
# Sample the raw sensor voltage 10 times and get an average value.
# Sensor should be held perfectly still for this.
total=0
for i in {1..10}
do
total=$(($total + $(cat value0)))
# if you are using a compiled language, you will want a delay here (~10msec is good)
done
average=$(($total / $i))
# Set scaling that includes offset from average
# 1.953V is proportional to 400 deg/sec
raw_min=$average
raw_max=$(($average + 1953))
scaled_min=0
scaled_max=400
# Now move the sensor around
watch -n 0.1 echo '$((($(cat value0) - '$raw_min')
* ('$scaled_max' - '$scaled_min')
/ ('$raw_max' - '$raw_min') + '$scaled_min'))'