Why my “print” function is ptinting the triplle of values of variable “g” and “ag” instead of only 1 value for ag and 3 for ag?
When O run y code, I have this as the result:
72
(0.15401078760623932, -0.9237408638000488, -0.35069024562835693)
72
(0.15401078760623932, -0.9237408638000488, -0.35069024562835693)
72
(0.15401078760623932, -0.9237408638000488, -0.35069024562835693)
My code:
'''This script records your device's orientation (accelerometer data) for 5 seconds, and then renders a simple plot of the gravity vector, using matplotlib.'''
import numpy as np
import sys
import motion
import matplotlib.pyplot as plt
from time import sleep
import console
g=0;
ag=0;
data=0;
data_ag=0;
del g
del ag
del data
del data_ag
fs=100;
duration=5;
def main():
console.alert('Motion Plot', 'When you tap Continue, accelerometer (motion) data will be recorded for 5 seconds.', 'Continue')
motion.start_updates()
sleep(0.2)
print('Capturing motion data...')
num_samples = fs*duration;
data = []
data_ag = []
for i in range(num_samples):
sleep(1/fs)
ag=motion.get_user_acceleration();
g = motion.get_gravity();
#a=motion.get_gravity()
#motion.get_attitude()
#motion.get_magnetic_field()
data.append(g);
data_ag.append(ag);
motion.stop_updates()
print('Capture finished, plotting...')
x_values = [x/fs for x in range(num_samples)]
for i, color, label in zip(range(3), 'rgb', 'XYZ'):
plt.plot(x_values, [g[i] for g in data], color, label=label, lw=2)
szg=sys.getsizeof(g)
print(szg)
print(g)
plt.grid(True)
plt.xlabel('t')
plt.ylabel('G')
plt.gca().set_ylim([-1.0, 1.0])
plt.legend()
plt.show()
if name == 'main':
main()