File tree Expand file tree Collapse file tree 2 files changed +12
-36
lines changed Expand file tree Collapse file tree 2 files changed +12
-36
lines changed Original file line number Diff line number Diff line change @@ -86,26 +86,14 @@ def acceleration(self):
8686 return (self .x [0 ] * _mult , self .y [0 ] * _mult , self .z [0 ] * _mult )
8787
8888 def roll (self ):
89- self .acceleration ()
90- div = math .sqrt (math .pow (self .y [0 ], 2 ) + math .pow (self .z [0 ], 2 ))
91- if div == 0 :
92- div = 0.01
93- return (180 / 3.14154 ) * math .atan (self .x [0 ] / div )
89+ x ,y ,z = self .acceleration ()
90+ rad = math .atan2 (- x , z )
91+ return (180 / math .pi ) * rad
9492
9593 def pitch (self ):
96- self .acceleration ()
97- if self .z [0 ] == 0 :
98- div = 1
99- else :
100- div = self .z [0 ]
101- return (180 / 3.14154 ) * math .atan (math .sqrt (math .pow (self .x [0 ], 2 ) + math .pow (self .y [0 ], 2 )) / div )
102-
103- def yaw (self ):
104- self .acceleration ()
105- div = math .sqrt (math .pow (self .x [0 ], 2 ) + math .pow (self .z [0 ], 2 ))
106- if div == 0 :
107- div = 0.01
108- return (180 / 3.14154 ) * math .atan (self .y [0 ] / div )
94+ x ,y ,z = self .acceleration ()
95+ rad = - math .atan2 (y , (math .sqrt (x * x + z * z )))
96+ return (180 / math .pi ) * rad
10997
11098 def set_full_scale (self , scale ):
11199 self .i2c .readfrom_mem_into (ACC_I2CADDR , CTRL4_REG , self .reg )
Original file line number Diff line number Diff line change @@ -86,26 +86,14 @@ def acceleration(self):
8686 return (self .x [0 ] * _mult , self .y [0 ] * _mult , self .z [0 ] * _mult )
8787
8888 def roll (self ):
89- self .acceleration ()
90- div = math .sqrt (math .pow (self .y [0 ], 2 ) + math .pow (self .z [0 ], 2 ))
91- if div == 0 :
92- div = 0.01
93- return (180 / 3.14154 ) * math .atan (self .x [0 ] / div )
89+ x ,y ,z = self .acceleration ()
90+ rad = math .atan2 (- x , z )
91+ return (180 / math .pi ) * rad
9492
9593 def pitch (self ):
96- self .acceleration ()
97- if self .z [0 ] == 0 :
98- div = 1
99- else :
100- div = self .z [0 ]
101- return (180 / 3.14154 ) * math .atan (math .sqrt (math .pow (self .x [0 ], 2 ) + math .pow (self .y [0 ], 2 )) / div )
102-
103- def yaw (self ):
104- self .acceleration ()
105- div = math .sqrt (math .pow (self .x [0 ], 2 ) + math .pow (self .z [0 ], 2 ))
106- if div == 0 :
107- div = 0.01
108- return (180 / 3.14154 ) * math .atan (self .y [0 ] / div )
94+ x ,y ,z = self .acceleration ()
95+ rad = - math .atan2 (y , (math .sqrt (x * x + z * z )))
96+ return (180 / math .pi ) * rad
10997
11098 def set_full_scale (self , scale ):
11199 self .i2c .readfrom_mem_into (ACC_I2CADDR , CTRL4_REG , self .reg )
You can’t perform that action at this time.
0 commit comments