-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #515 from bitcraze/Aris/Single_Drone_Reset_Estimator
Replaced reset estimator in single drone examples
- Loading branch information
Showing
13 changed files
with
74 additions
and
573 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import time | ||
|
||
from cflib.crazyflie.log import LogConfig | ||
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie | ||
from cflib.crazyflie.syncLogger import SyncLogger | ||
|
||
|
||
def reset_estimator(crazyflie): | ||
if isinstance(crazyflie, SyncCrazyflie): | ||
cf = crazyflie.cf | ||
else: | ||
cf = crazyflie | ||
cf.param.set_value('kalman.resetEstimation', '1') | ||
time.sleep(0.1) | ||
cf.param.set_value('kalman.resetEstimation', '0') | ||
|
||
_wait_for_position_estimator(cf) | ||
|
||
|
||
def _wait_for_position_estimator(cf): | ||
print('Waiting for estimator to find position...', end='\r') | ||
|
||
log_config = LogConfig(name='Kalman Variance', period_in_ms=500) | ||
log_config.add_variable('kalman.varPX', 'float') | ||
log_config.add_variable('kalman.varPY', 'float') | ||
log_config.add_variable('kalman.varPZ', 'float') | ||
|
||
var_y_history = [1000] * 10 | ||
var_x_history = [1000] * 10 | ||
var_z_history = [1000] * 10 | ||
|
||
threshold = 0.001 | ||
|
||
with SyncLogger(cf, log_config) as logger: | ||
for log_entry in logger: | ||
data = log_entry[1] | ||
|
||
var_x_history.append(data['kalman.varPX']) | ||
var_x_history.pop(0) | ||
var_y_history.append(data['kalman.varPY']) | ||
var_y_history.pop(0) | ||
var_z_history.append(data['kalman.varPZ']) | ||
var_z_history.pop(0) | ||
|
||
min_x = min(var_x_history) | ||
max_x = max(var_x_history) | ||
min_y = min(var_y_history) | ||
max_y = max(var_y_history) | ||
min_z = min(var_z_history) | ||
max_z = max(var_z_history) | ||
|
||
if (max_x - min_x) < threshold and ( | ||
max_y - min_y) < threshold and ( | ||
max_z - min_z) < threshold: | ||
print('Waiting for estimator to find position...success!') | ||
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.