From 933a1d074bfda6303d8fd5c1cde4c75d9f370520 Mon Sep 17 00:00:00 2001 From: knmcguire Date: Tue, 10 May 2022 13:23:52 +0200 Subject: [PATCH 1/5] reduce square flown autonomousSequence --- examples/autonomy/autonomousSequence.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/autonomy/autonomousSequence.py b/examples/autonomy/autonomousSequence.py index a4e03e96d..e7353a8c0 100644 --- a/examples/autonomy/autonomousSequence.py +++ b/examples/autonomy/autonomousSequence.py @@ -45,13 +45,14 @@ # Change the sequence according to your setup # x y z YAW sequence = [ - (2.5, 2.5, 1.2, 0), - (1.5, 2.5, 1.2, 0), - (2.5, 2.0, 1.2, 0), - (3.5, 2.5, 1.2, 0), - (2.5, 3.0, 1.2, 0), - (2.5, 2.5, 1.2, 0), - (2.5, 2.5, 0.4, 0), + (0.0, 0.0, 0.4, 0), + (0.0, 0.0, 1.2, 0), + (0.5, -0.5, 1.2, 0), + (0.5, 0.5, 1.2, 0), + (-0.5, 0.5, 1.2, 0), + (-0.5, -0.5, 1.2, 0), + (0.0, 0.0, 1.2, 0), + (0.0, 0.0, 0.4, 0), ] From c40316d2841e7775b81612cd9ad889dea6901199 Mon Sep 17 00:00:00 2001 From: knmcguire Date: Tue, 10 May 2022 16:48:11 +0200 Subject: [PATCH 2/5] more scripts with several updates and improvements --- examples/basicLedparamSync.py | 6 +++--- examples/lighthouse/lighthouse_openvr_multigrab.py | 4 ++-- examples/lighthouse/read_lighthouse_mem.py | 3 ++- examples/lighthouse/write_lighthouse_mem.py | 3 ++- examples/positioning/initial_position.py | 3 ++- examples/radio/scan.py | 5 +++-- examples/step-by-step/sbs_motion_commander.py | 4 ++-- examples/tuning/PID_controller_tuner.py | 4 ++-- 8 files changed, 18 insertions(+), 14 deletions(-) diff --git a/examples/basicLedparamSync.py b/examples/basicLedparamSync.py index a205a2812..49c018fb6 100644 --- a/examples/basicLedparamSync.py +++ b/examples/basicLedparamSync.py @@ -66,9 +66,9 @@ # Set fade time i seconds cf.param.set_value('ring.fadeTime', '1.0') # Set the RGB values in one uint32 0xRRGGBB - cf.param.set_value('ring.fadeColor', '0x0000A0') + cf.param.set_value('ring.fadeColor', int('0000A0',16)) time.sleep(1) - cf.param.set_value('ring.fadeColor', '0x00A000') + cf.param.set_value('ring.fadeColor', int('00A000',16)) time.sleep(1) - cf.param.set_value('ring.fadeColor', '0xA00000') + cf.param.set_value('ring.fadeColor', int('A00000',16)) time.sleep(1) diff --git a/examples/lighthouse/lighthouse_openvr_multigrab.py b/examples/lighthouse/lighthouse_openvr_multigrab.py index a1fa69a05..fcd57b911 100644 --- a/examples/lighthouse/lighthouse_openvr_multigrab.py +++ b/examples/lighthouse/lighthouse_openvr_multigrab.py @@ -15,8 +15,8 @@ from cflib.crazyflie.syncLogger import SyncLogger # URI to the Crazyflie to connect to -uri0 = 'radio://0/80/2M' -uri1 = 'radio://0/80/2M/E7E7E7E701' +uri0 = 'radio://0/80/2M/E7E7E7E701' +uri1 = 'radio://0/80/2M/E7E7E7E702' print('Opening') vr = openvr.init(openvr.VRApplication_Other) diff --git a/examples/lighthouse/read_lighthouse_mem.py b/examples/lighthouse/read_lighthouse_mem.py index 7f46d160f..42b85dcea 100644 --- a/examples/lighthouse/read_lighthouse_mem.py +++ b/examples/lighthouse/read_lighthouse_mem.py @@ -30,6 +30,7 @@ from cflib.crazyflie import Crazyflie from cflib.crazyflie.mem import LighthouseMemHelper from cflib.crazyflie.syncCrazyflie import SyncCrazyflie +from cflib.utils import uri_helper # Only output errors from the logging framework logging.basicConfig(level=logging.ERROR) @@ -67,7 +68,7 @@ def _calib_read_ready(self, calib_data): if __name__ == '__main__': # URI to the Crazyflie to connect to - uri = 'radio://0/80' + uri = uri_helper.uri_from_env(default='radio://0/80/2M/E7E7E7E7E7') # Initialize the low-level drivers cflib.crtp.init_drivers() diff --git a/examples/lighthouse/write_lighthouse_mem.py b/examples/lighthouse/write_lighthouse_mem.py index 5bc331e5c..c35e99651 100644 --- a/examples/lighthouse/write_lighthouse_mem.py +++ b/examples/lighthouse/write_lighthouse_mem.py @@ -32,6 +32,7 @@ from cflib.crazyflie.mem import LighthouseBsGeometry from cflib.crazyflie.mem import LighthouseMemHelper from cflib.crazyflie.syncCrazyflie import SyncCrazyflie +from cflib.utils import uri_helper # Only output errors from the logging framework logging.basicConfig(level=logging.ERROR) @@ -63,7 +64,7 @@ def _data_written(self, success): if __name__ == '__main__': # URI to the Crazyflie to connect to - uri = 'radio://0/80' + uri = uri_helper.uri_from_env(default='radio://0/80/2M/E7E7E7E7E7') # Initialize the low-level drivers cflib.crtp.init_drivers() diff --git a/examples/positioning/initial_position.py b/examples/positioning/initial_position.py index cbe324abe..6ab9a4f1a 100644 --- a/examples/positioning/initial_position.py +++ b/examples/positioning/initial_position.py @@ -41,9 +41,10 @@ from cflib.crazyflie.log import LogConfig from cflib.crazyflie.syncCrazyflie import SyncCrazyflie from cflib.crazyflie.syncLogger import SyncLogger +from cflib.utils import uri_helper # URI to the Crazyflie to connect to -uri = 'radio://0/80/2M' +uri = uri_helper.uri_from_env(default='radio://0/80/2M/E7E7E7E7E7') # Change the sequence according to your setup # x y z diff --git a/examples/radio/scan.py b/examples/radio/scan.py index 6dd200d13..e67d79bfe 100644 --- a/examples/radio/scan.py +++ b/examples/radio/scan.py @@ -22,7 +22,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ -Simple example that scans for available Crazyflies and lists them. +Simple example that scans for available Crazyflies with a certain address and lists them. """ import cflib.crtp @@ -30,7 +30,8 @@ cflib.crtp.init_drivers() print('Scanning interfaces for Crazyflies...') -available = cflib.crtp.scan_interfaces() +available = cflib.crtp.scan_interfaces(address=int('E7E7E7E7E7', 16) +) print('Crazyflies found:') for i in available: print(i[0]) diff --git a/examples/step-by-step/sbs_motion_commander.py b/examples/step-by-step/sbs_motion_commander.py index 9e3b420cb..376d0b0d1 100644 --- a/examples/step-by-step/sbs_motion_commander.py +++ b/examples/step-by-step/sbs_motion_commander.py @@ -127,7 +127,7 @@ def param_deck_flow(_, value_str): logconf.start() - # take_off_simple(scf) + take_off_simple(scf) # move_linear_simple(scf) # move_box_limit(scf) - # logconf.stop() + logconf.stop() diff --git a/examples/tuning/PID_controller_tuner.py b/examples/tuning/PID_controller_tuner.py index 449d68639..ccbae9ea4 100644 --- a/examples/tuning/PID_controller_tuner.py +++ b/examples/tuning/PID_controller_tuner.py @@ -61,7 +61,7 @@ def __init__(self, master): self.master = master self.master.title('PID tuner Crazyflie') - self.figplot = plt.Figure(figsize=(5, 4), dpi=100) + self.figplot = plt.Figure(figsize=(2, 1), dpi=100) self.ax2 = self.figplot.add_subplot(111) self.line2 = FigureCanvasTkAgg(self.figplot, self.master) self.line2.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1) @@ -191,7 +191,7 @@ def send_pid_gains(self): 'position PID controller: Kp: ' + str(self.pid_gui.scale_Kp.get()) + ', Ki: ' + str(self.pid_gui.scale_Ki.get()) + - ', Kd: '+str(self.pid_gui.scale_Ki.get())) + ', Kd: '+str(self.pid_gui.scale_Kd.get())) cf.param.set_value(self.unit_choice+'CtlPid.'+self.axis_choice + 'Kp', self.pid_gui.scale_Kp.get()) cf.param.set_value(self.unit_choice+'CtlPid.'+self.axis_choice + From 0ca693a54b899801ff9ec40246ada42716d74dd2 Mon Sep 17 00:00:00 2001 From: knmcguire Date: Tue, 10 May 2022 17:10:21 +0200 Subject: [PATCH 3/5] autopep8 fixes --- examples/basicLedmemSync.py | 6 ++-- .../lighthouse/lighthouse_openvr_multigrab.py | 8 ++--- examples/radio/scan.py | 2 +- examples/tuning/PID_controller_tuner.py | 30 +++++++++---------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/examples/basicLedmemSync.py b/examples/basicLedmemSync.py index dec847798..57defadd8 100644 --- a/examples/basicLedmemSync.py +++ b/examples/basicLedmemSync.py @@ -56,9 +56,9 @@ # Get LED memory and write to it mem = cf.mem.get_mems(MemoryElement.TYPE_DRIVER_LED) if len(mem) > 0: - mem[0].leds[0].set(r=0, g=100, b=0) - mem[0].leds[3].set(r=0, g=0, b=100) - mem[0].leds[6].set(r=100, g=0, b=0) + mem[0].leds[0].set(r=0, g=100, b=0) + mem[0].leds[3].set(r=0, g=0, b=100) + mem[0].leds[6].set(r=100, g=0, b=0) mem[0].leds[9].set(r=100, g=100, b=100) mem[0].write_data(None) diff --git a/examples/lighthouse/lighthouse_openvr_multigrab.py b/examples/lighthouse/lighthouse_openvr_multigrab.py index fcd57b911..d4d2377f2 100644 --- a/examples/lighthouse/lighthouse_openvr_multigrab.py +++ b/examples/lighthouse/lighthouse_openvr_multigrab.py @@ -127,8 +127,8 @@ def run_sequence(scf0, scf1): openvr.TrackingUniverseStanding, 0, openvr.k_unMaxTrackedDeviceCount) controller_pose = poses[controllerId] pose = controller_pose.mDeviceToAbsoluteTracking - setpoints = [[-1*pose[2][3], -1*pose[0][3] - 0.5, pose[1][3] + 0.3], - [-1*pose[2][3], -1*pose[0][3] + 0.5, pose[1][3] + 0.3]] + setpoints = [[-1 * pose[2][3], -1 * pose[0][3] - 0.5, pose[1][3] + 0.3], + [-1 * pose[2][3], -1 * pose[0][3] + 0.5, pose[1][3] + 0.3]] closest = 0 @@ -149,7 +149,7 @@ def run_sequence(scf0, scf1): if not grabbed and trigger: print('Grab started') - grab_controller_start = [-1*pose[2][3], -1*pose[0][3], pose[1][3]] + grab_controller_start = [-1 * pose[2][3], -1 * pose[0][3], pose[1][3]] dist0 = vector_norm(vector_subtract(grab_controller_start, setpoints[0])) @@ -169,7 +169,7 @@ def run_sequence(scf0, scf1): grabbed = trigger if trigger: - curr = [-1*pose[2][3], -1*pose[0][3], pose[1][3]] + curr = [-1 * pose[2][3], -1 * pose[0][3], pose[1][3]] setpoints[closest] = vector_add( grab_setpoint_start, vector_subtract(curr, grab_controller_start)) diff --git a/examples/radio/scan.py b/examples/radio/scan.py index e67d79bfe..055feab3e 100644 --- a/examples/radio/scan.py +++ b/examples/radio/scan.py @@ -31,7 +31,7 @@ print('Scanning interfaces for Crazyflies...') available = cflib.crtp.scan_interfaces(address=int('E7E7E7E7E7', 16) -) + ) print('Crazyflies found:') for i in available: print(i[0]) diff --git a/examples/tuning/PID_controller_tuner.py b/examples/tuning/PID_controller_tuner.py index ccbae9ea4..917db4eb4 100644 --- a/examples/tuning/PID_controller_tuner.py +++ b/examples/tuning/PID_controller_tuner.py @@ -191,12 +191,12 @@ def send_pid_gains(self): 'position PID controller: Kp: ' + str(self.pid_gui.scale_Kp.get()) + ', Ki: ' + str(self.pid_gui.scale_Ki.get()) + - ', Kd: '+str(self.pid_gui.scale_Kd.get())) - cf.param.set_value(self.unit_choice+'CtlPid.'+self.axis_choice + + ', Kd: ' + str(self.pid_gui.scale_Kd.get())) + cf.param.set_value(self.unit_choice + 'CtlPid.' + self.axis_choice + 'Kp', self.pid_gui.scale_Kp.get()) - cf.param.set_value(self.unit_choice+'CtlPid.'+self.axis_choice + + cf.param.set_value(self.unit_choice + 'CtlPid.' + self.axis_choice + 'Ki', self.pid_gui.scale_Ki.get()) - cf.param.set_value(self.unit_choice+'CtlPid.'+self.axis_choice + + cf.param.set_value(self.unit_choice + 'CtlPid.' + self.axis_choice + 'Kd', self.pid_gui.scale_Kd.get()) cf.param.set_value('posCtlPid.xVelMax', self.pid_gui.scale_vMax.get()) cf.param.set_value('posCtlPid.yVelMax', self.pid_gui.scale_vMax.get()) @@ -240,11 +240,11 @@ def do_step(self): # print(sp_history) self.pid_gui.draw_plot(time_history, pos_history, sp_history) if self.axis_choice == 'z': - self.commander.go_to(0, 0, -1*STEP_SIZE, 0, 1.0, relative=True) + self.commander.go_to(0, 0, -1 * STEP_SIZE, 0, 1.0, relative=True) elif self.axis_choice == 'x': - self.commander.go_to(-1*STEP_SIZE, 0, 0, 0, 1.0, relative=True) + self.commander.go_to(-1 * STEP_SIZE, 0, 0, 0, 1.0, relative=True) elif self.axis_choice == 'y': - self.commander.go_to(0, -1*STEP_SIZE, 0, 0, 1.0, relative=True) + self.commander.go_to(0, -1 * STEP_SIZE, 0, 0, 1.0, relative=True) else: print('WRONG CHOICE?!?!') self.stop_gui() @@ -256,7 +256,7 @@ def stop_gui(self): # parameter update def change_param_axis_callback(self, value_axis): # - print(self.unit_choice + 'CtlPid.'+value_axis) + print(self.unit_choice + 'CtlPid.' + value_axis) groupname = self.unit_choice + 'CtlPid' self.cf.param.remove_update_callback( @@ -277,9 +277,9 @@ def change_param_axis_callback(self, value_axis): group=groupname, name=value_axis + 'Kd', cb=self.param_updated_callback_Kd) - self.cf.param.request_param_update(groupname+'.'+value_axis+'Kp') - self.cf.param.request_param_update(groupname+'.'+value_axis+'Ki') - self.cf.param.request_param_update(groupname+'.'+value_axis+'Kd') + self.cf.param.request_param_update(groupname + '.' + value_axis + 'Kp') + self.cf.param.request_param_update(groupname + '.' + value_axis + 'Ki') + self.cf.param.request_param_update(groupname + '.' + value_axis + 'Kd') time.sleep(0.1) self.update_scale_info() @@ -311,13 +311,13 @@ def change_param_unit_callback(self, value_unit): group=groupname_new, name=self.axis_choice + 'Kd', cb=self.param_updated_callback_Kd) - print(groupname_new+'.'+self.axis_choice+'Kp') + print(groupname_new + '.' + self.axis_choice + 'Kp') self.cf.param.request_param_update( - groupname_new+'.'+self.axis_choice+'Kp') + groupname_new + '.' + self.axis_choice + 'Kp') self.cf.param.request_param_update( - groupname_new+'.'+self.axis_choice+'Ki') + groupname_new + '.' + self.axis_choice + 'Ki') self.cf.param.request_param_update( - groupname_new+'.'+self.axis_choice+'Kd') + groupname_new + '.' + self.axis_choice + 'Kd') time.sleep(0.1) self.update_scale_info() From 997ef866ee1625433e35a34d1d4aef8b25c4b89b Mon Sep 17 00:00:00 2001 From: knmcguire Date: Tue, 10 May 2022 17:28:35 +0200 Subject: [PATCH 4/5] added callback check to basic param script --- examples/basicLedparamSync.py | 6 +++--- examples/parameters/basicparam.py | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/basicLedparamSync.py b/examples/basicLedparamSync.py index 49c018fb6..bb4326372 100644 --- a/examples/basicLedparamSync.py +++ b/examples/basicLedparamSync.py @@ -66,9 +66,9 @@ # Set fade time i seconds cf.param.set_value('ring.fadeTime', '1.0') # Set the RGB values in one uint32 0xRRGGBB - cf.param.set_value('ring.fadeColor', int('0000A0',16)) + cf.param.set_value('ring.fadeColor', int('0000A0', 16)) time.sleep(1) - cf.param.set_value('ring.fadeColor', int('00A000',16)) + cf.param.set_value('ring.fadeColor', int('00A000', 16)) time.sleep(1) - cf.param.set_value('ring.fadeColor', int('A00000',16)) + cf.param.set_value('ring.fadeColor', int('A00000', 16)) time.sleep(1) diff --git a/examples/parameters/basicparam.py b/examples/parameters/basicparam.py index 6dc18b713..7f874ddfc 100644 --- a/examples/parameters/basicparam.py +++ b/examples/parameters/basicparam.py @@ -125,6 +125,8 @@ def _param_callback(self, name, value): self._cf.param.set_value('pid_attitude.pitch_kd', '{:.2f}'.format(pkd)) + self._cf.param.request_param_update('pid_attitude.pitch_kd') + def _a_pitch_kd_callback(self, name, value): """Callback for pid_attitude.pitch_kd""" print('Readback: {0}={1}'.format(name, value)) From b9a26120286ac1e250d2d755aaf169745ca399ed Mon Sep 17 00:00:00 2001 From: knmcguire Date: Wed, 11 May 2022 10:34:55 +0200 Subject: [PATCH 5/5] remove update param example --- examples/parameters/basicparam.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/parameters/basicparam.py b/examples/parameters/basicparam.py index 7f874ddfc..6dc18b713 100644 --- a/examples/parameters/basicparam.py +++ b/examples/parameters/basicparam.py @@ -125,8 +125,6 @@ def _param_callback(self, name, value): self._cf.param.set_value('pid_attitude.pitch_kd', '{:.2f}'.format(pkd)) - self._cf.param.request_param_update('pid_attitude.pitch_kd') - def _a_pitch_kd_callback(self, name, value): """Callback for pid_attitude.pitch_kd""" print('Readback: {0}={1}'.format(name, value))