Skip to content

Commit e97923d

Browse files
committed
added filter
1 parent a36cb24 commit e97923d

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/Arduino_AlvikCarrier.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ Arduino_AlvikCarrier::Arduino_AlvikCarrier(){
7979
zl = 0;
8080
zh = 0;
8181
tilt_time = 0;
82+
tmp_tilt_status = 0;
83+
tilt_filter = 0;
8284

8385
// version
8486
version_high = VERSION_BYTE_HIGH;
@@ -714,13 +716,24 @@ void Arduino_AlvikCarrier::updateImu(){
714716
imu->Get_6D_Orientation_ZL(&zl);
715717
imu->Get_6D_Orientation_ZH(&zh);
716718

717-
tilt_status = 0;
718-
tilt_status |= xl<<4;
719-
tilt_status |= xh<<5;
720-
tilt_status |= zl<<7;
721-
tilt_status |= zh<<6;
722-
tilt_status |= yh<<3;
723-
tilt_status |= yl<<2;
719+
tmp_tilt_status = 0;
720+
tmp_tilt_status |= xl<<4;
721+
tmp_tilt_status |= xh<<5;
722+
tmp_tilt_status |= zl<<7;
723+
tmp_tilt_status |= zh<<6;
724+
tmp_tilt_status |= yh<<3;
725+
tmp_tilt_status |= yl<<2;
726+
727+
if (tilt_status == tmp_tilt_status){
728+
tilt_filter++;
729+
}else{
730+
tilt_filter = 0;
731+
}
732+
733+
if (tilt_filter>20){
734+
tilt_status = tmp_tilt_status;
735+
}
736+
724737
}
725738

726739
}

src/Arduino_AlvikCarrier.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class Arduino_AlvikCarrier{
7373
uint8_t tilt_status;
7474
uint8_t xl, xh, yl, yh, zl, zh;
7575
unsigned long tilt_time;
76+
uint8_t tilt_filter;
77+
uint8_t tmp_tilt_status;
7678

7779
uint8_t version_high;
7880
uint8_t version_mid;

0 commit comments

Comments
 (0)