Skip to content

Commit dcda6cc

Browse files
committed
refactoring and new string formatting
1 parent b2fbce5 commit dcda6cc

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

examples/lsm303_accel_inclinometer.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,18 @@
1212

1313

1414
def vector_2_degrees(x, y):
15-
radians = atan2(y, x)
16-
degrees_calc = degrees(radians)
17-
if degrees_calc < 0:
18-
degrees_calc = 360 + degrees_calc
19-
return degrees_calc
15+
angle = degrees(atan2(y, x))
16+
if angle < 0:
17+
angle += 360
18+
return angle
2019

2120

2221
def get_inclination(_sensor):
23-
return get_inclination_respect_x(_sensor), get_inclination_respect_y(_sensor)
24-
25-
26-
def get_inclination_respect_x(_sensor):
27-
accel_axis_data = _sensor.acceleration
28-
return vector_2_degrees(accel_axis_data[0], accel_axis_data[2])
29-
30-
31-
def get_inclination_respect_y(_sensor):
32-
accel_axis_data = _sensor.acceleration
33-
return vector_2_degrees(accel_axis_data[1], accel_axis_data[2])
22+
x, y, z = _sensor.acceleration
23+
return vector_2_degrees(x, z), vector_2_degrees(y, z)
3424

3525

3626
while True:
37-
print("inclination: (%s, %s)" % (get_inclination(sensor)))
27+
inclination = get_inclination(sensor)
28+
print("XZ angle = {:6.2f}deg YZ angle = {:6.2f}deg".format(inclination[0],inclination[1]))
3829
time.sleep(0.2)

0 commit comments

Comments
 (0)