@@ -61,7 +61,7 @@ TABS.motors.initialize = function (callback) {
6161
6262 function initSensorData ( ) {
6363 for ( var i = 0 ; i < 3 ; i ++ ) {
64- SENSOR_DATA . accelerometer [ i ] = 0 ;
64+ SENSOR_DATA . gyroscope [ i ] = 0 ;
6565 }
6666 }
6767
@@ -207,12 +207,10 @@ TABS.motors.initialize = function (callback) {
207207 initSensorData ( ) ;
208208
209209 // Setup variables
210- var samples_accel_i = 0 ,
211- accel_data = initDataArray ( 3 ) ,
212- accelHelpers = initGraphHelpers ( '#accel' , samples_accel_i , [ - 2 , 2 ] ) ,
213- accel_max_read = [ 0 , 0 , 0 ] ,
214- accel_offset = [ 0 , 0 , 0 ] ,
215- accel_offset_established = false ;
210+ var samples_gyro_i = 0 ,
211+ gyro_data = initDataArray ( 3 ) ,
212+ gyroHelpers = initGraphHelpers ( '#gyro' , samples_gyro_i , [ - 2 , 2 ] ) ,
213+ gyro_max_read = [ 0 , 0 , 0 ] ;
216214
217215 var raw_data_text_ements = {
218216 x : [ ] ,
@@ -235,10 +233,10 @@ TABS.motors.initialize = function (callback) {
235233 } ) ;
236234
237235 // set refresh speeds according to configuration saved in storage
238- chrome . storage . local . get ( 'motors_tab_accel_settings ' , function ( result ) {
239- if ( result . motors_tab_accel_settings ) {
240- $ ( '.tab-motors select[name="accel_refresh_rate "]' ) . val ( result . motors_tab_accel_settings . rate ) ;
241- $ ( '.tab-motors select[name="accel_scale "]' ) . val ( result . motors_tab_accel_settings . scale ) ;
236+ chrome . storage . local . get ( 'motors_tab_gyro_settings ' , function ( result ) {
237+ if ( result . motors_tab_gyro_settings ) {
238+ $ ( '.tab-motors select[name="gyro_refresh_rate "]' ) . val ( result . motors_tab_gyro_settings . rate ) ;
239+ $ ( '.tab-motors select[name="gyro_scale "]' ) . val ( result . motors_tab_gyro_settings . scale ) ;
242240
243241 // start polling data by triggering refresh rate change event
244242 $ ( '.tab-motors .rate select:first' ) . change ( ) ;
@@ -249,63 +247,54 @@ TABS.motors.initialize = function (callback) {
249247 } ) ;
250248
251249 $ ( '.tab-motors .rate select, .tab-motors .scale select' ) . change ( function ( ) {
252- var rate = parseInt ( $ ( '.tab-motors select[name="accel_refresh_rate "]' ) . val ( ) , 10 ) ;
253- var scale = parseFloat ( $ ( '.tab-motors select[name="accel_scale "]' ) . val ( ) ) ;
250+ var rate = parseInt ( $ ( '.tab-motors select[name="gyro_refresh_rate "]' ) . val ( ) , 10 ) ;
251+ var scale = parseFloat ( $ ( '.tab-motors select[name="gyro_scale "]' ) . val ( ) ) ;
254252
255253 // store current/latest refresh rates in the storage
256- chrome . storage . local . set ( { 'motors_tab_accel_settings ' : { 'rate' : rate , 'scale' : scale } } ) ;
254+ chrome . storage . local . set ( { 'motors_tab_gyro_settings ' : { 'rate' : rate , 'scale' : scale } } ) ;
257255
258- accelHelpers = initGraphHelpers ( '#accel ' , samples_accel_i , [ - scale , scale ] ) ;
256+ gyroHelpers = initGraphHelpers ( '#gyro ' , samples_gyro_i , [ - scale , scale ] ) ;
259257
260258 // timer initialization
261259 GUI . interval_kill_all ( [ 'motor_and_status_pull' ] ) ;
262260
263261 GUI . interval_add ( 'IMU_pull' , function imu_data_pull ( ) {
264- MSP . send_message ( MSPCodes . MSP_RAW_IMU , false , false , update_accel_graph ) ;
262+ MSP . send_message ( MSPCodes . MSP_RAW_IMU , false , false , update_gyro_graph ) ;
265263 } , rate , true ) ;
266264
267- function update_accel_graph ( ) {
268- if ( ! accel_offset_established ) {
269- for ( var i = 0 ; i < 3 ; i ++ ) {
270- accel_offset [ i ] = SENSOR_DATA . accelerometer [ i ] * - 1 ;
271- }
272-
273- accel_offset_established = true ;
274- }
275-
276- var accel_with_offset = [
277- accel_offset [ 0 ] + SENSOR_DATA . accelerometer [ 0 ] ,
278- accel_offset [ 1 ] + SENSOR_DATA . accelerometer [ 1 ] ,
279- accel_offset [ 2 ] + SENSOR_DATA . accelerometer [ 2 ]
265+ function update_gyro_graph ( ) {
266+ var gyro = [
267+ SENSOR_DATA . gyroscope [ 0 ] ,
268+ SENSOR_DATA . gyroscope [ 1 ] ,
269+ SENSOR_DATA . gyroscope [ 2 ]
280270 ] ;
281271
282- updateGraphHelperSize ( accelHelpers ) ;
283- samples_accel_i = addSampleToData ( accel_data , samples_accel_i , accel_with_offset ) ;
284- drawGraph ( accelHelpers , accel_data , samples_accel_i ) ;
272+ updateGraphHelperSize ( gyroHelpers ) ;
273+ samples_gyro_i = addSampleToData ( gyro_data , samples_gyro_i , gyro ) ;
274+ drawGraph ( gyroHelpers , gyro_data , samples_gyro_i ) ;
285275
286- // Compute RMS of acceleration in displayed period of time
276+ // Compute RMS of gyroscope readings in displayed period of time
287277 // This is particularly useful for motor balancing as it
288278 // eliminates the need for external tools
289279 var sum = 0.0 ;
290- for ( var j = 0 ; j < accel_data . length ; j ++ )
291- for ( var k = 0 ; k < accel_data [ j ] . length ; k ++ )
292- sum += accel_data [ j ] [ k ] [ 1 ] * accel_data [ j ] [ k ] [ 1 ] ;
293- var rms = Math . sqrt ( sum / ( accel_data [ 0 ] . length + accel_data [ 1 ] . length + accel_data [ 2 ] . length ) ) ;
294-
295- raw_data_text_ements . x [ 0 ] . text ( accel_with_offset [ 0 ] . toFixed ( 2 ) + ' (' + accel_max_read [ 0 ] . toFixed ( 2 ) + ')' ) ;
296- raw_data_text_ements . y [ 0 ] . text ( accel_with_offset [ 1 ] . toFixed ( 2 ) + ' (' + accel_max_read [ 1 ] . toFixed ( 2 ) + ')' ) ;
297- raw_data_text_ements . z [ 0 ] . text ( accel_with_offset [ 2 ] . toFixed ( 2 ) + ' (' + accel_max_read [ 2 ] . toFixed ( 2 ) + ')' ) ;
280+ for ( var j = 0 ; j < gyro_data . length ; j ++ )
281+ for ( var k = 0 ; k < gyro_data [ j ] . length ; k ++ )
282+ sum += gyro_data [ j ] [ k ] [ 1 ] * gyro_data [ j ] [ k ] [ 1 ] ;
283+ var rms = Math . sqrt ( sum / ( gyro_data [ 0 ] . length + gyro_data [ 1 ] . length + gyro_data [ 2 ] . length ) ) ;
284+
285+ raw_data_text_ements . x [ 0 ] . text ( gyro [ 0 ] . toFixed ( 2 ) + ' (' + gyro_max_read [ 0 ] . toFixed ( 2 ) + ')' ) ;
286+ raw_data_text_ements . y [ 0 ] . text ( gyro [ 1 ] . toFixed ( 2 ) + ' (' + gyro_max_read [ 1 ] . toFixed ( 2 ) + ')' ) ;
287+ raw_data_text_ements . z [ 0 ] . text ( gyro [ 2 ] . toFixed ( 2 ) + ' (' + gyro_max_read [ 2 ] . toFixed ( 2 ) + ')' ) ;
298288 raw_data_text_ements . rms [ 0 ] . text ( rms . toFixed ( 4 ) ) ;
299289
300290 for ( var i = 0 ; i < 3 ; i ++ ) {
301- if ( Math . abs ( accel_with_offset [ i ] ) > Math . abs ( accel_max_read [ i ] ) ) accel_max_read [ i ] = accel_with_offset [ i ] ;
291+ if ( Math . abs ( gyro [ i ] ) > Math . abs ( gyro_max_read [ i ] ) ) gyro_max_read [ i ] = gyro [ i ] ;
302292 }
303293 }
304294 } ) ;
305295
306296 $ ( 'a.reset_accel_max' ) . click ( function ( ) {
307- accel_max_read = [ 0 , 0 , 0 ] ;
308- accel_offset_established = false ;
297+ gyro_max_read = [ 0 , 0 , 0 ] ;
309298 } ) ;
310299
311300 var number_of_valid_outputs = ( MOTOR_DATA . indexOf ( 0 ) > - 1 ) ? MOTOR_DATA . indexOf ( 0 ) : 8 ;
0 commit comments