Skip to content

Commit 6e93153

Browse files
authored
Merge pull request #334 from bitcraze/examples-fix
example fixes
2 parents af031ea + b9a2612 commit 6e93153

File tree

10 files changed

+47
-42
lines changed

10 files changed

+47
-42
lines changed

examples/autonomy/autonomousSequence.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@
4545
# Change the sequence according to your setup
4646
# x y z YAW
4747
sequence = [
48-
(2.5, 2.5, 1.2, 0),
49-
(1.5, 2.5, 1.2, 0),
50-
(2.5, 2.0, 1.2, 0),
51-
(3.5, 2.5, 1.2, 0),
52-
(2.5, 3.0, 1.2, 0),
53-
(2.5, 2.5, 1.2, 0),
54-
(2.5, 2.5, 0.4, 0),
48+
(0.0, 0.0, 0.4, 0),
49+
(0.0, 0.0, 1.2, 0),
50+
(0.5, -0.5, 1.2, 0),
51+
(0.5, 0.5, 1.2, 0),
52+
(-0.5, 0.5, 1.2, 0),
53+
(-0.5, -0.5, 1.2, 0),
54+
(0.0, 0.0, 1.2, 0),
55+
(0.0, 0.0, 0.4, 0),
5556
]
5657

5758

examples/basicLedmemSync.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656
# Get LED memory and write to it
5757
mem = cf.mem.get_mems(MemoryElement.TYPE_DRIVER_LED)
5858
if len(mem) > 0:
59-
mem[0].leds[0].set(r=0, g=100, b=0)
60-
mem[0].leds[3].set(r=0, g=0, b=100)
61-
mem[0].leds[6].set(r=100, g=0, b=0)
59+
mem[0].leds[0].set(r=0, g=100, b=0)
60+
mem[0].leds[3].set(r=0, g=0, b=100)
61+
mem[0].leds[6].set(r=100, g=0, b=0)
6262
mem[0].leds[9].set(r=100, g=100, b=100)
6363
mem[0].write_data(None)
6464

examples/basicLedparamSync.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@
6666
# Set fade time i seconds
6767
cf.param.set_value('ring.fadeTime', '1.0')
6868
# Set the RGB values in one uint32 0xRRGGBB
69-
cf.param.set_value('ring.fadeColor', '0x0000A0')
69+
cf.param.set_value('ring.fadeColor', int('0000A0', 16))
7070
time.sleep(1)
71-
cf.param.set_value('ring.fadeColor', '0x00A000')
71+
cf.param.set_value('ring.fadeColor', int('00A000', 16))
7272
time.sleep(1)
73-
cf.param.set_value('ring.fadeColor', '0xA00000')
73+
cf.param.set_value('ring.fadeColor', int('A00000', 16))
7474
time.sleep(1)

examples/lighthouse/lighthouse_openvr_multigrab.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
from cflib.crazyflie.syncLogger import SyncLogger
1616

1717
# URI to the Crazyflie to connect to
18-
uri0 = 'radio://0/80/2M'
19-
uri1 = 'radio://0/80/2M/E7E7E7E701'
18+
uri0 = 'radio://0/80/2M/E7E7E7E701'
19+
uri1 = 'radio://0/80/2M/E7E7E7E702'
2020

2121
print('Opening')
2222
vr = openvr.init(openvr.VRApplication_Other)
@@ -127,8 +127,8 @@ def run_sequence(scf0, scf1):
127127
openvr.TrackingUniverseStanding, 0, openvr.k_unMaxTrackedDeviceCount)
128128
controller_pose = poses[controllerId]
129129
pose = controller_pose.mDeviceToAbsoluteTracking
130-
setpoints = [[-1*pose[2][3], -1*pose[0][3] - 0.5, pose[1][3] + 0.3],
131-
[-1*pose[2][3], -1*pose[0][3] + 0.5, pose[1][3] + 0.3]]
130+
setpoints = [[-1 * pose[2][3], -1 * pose[0][3] - 0.5, pose[1][3] + 0.3],
131+
[-1 * pose[2][3], -1 * pose[0][3] + 0.5, pose[1][3] + 0.3]]
132132

133133
closest = 0
134134

@@ -149,7 +149,7 @@ def run_sequence(scf0, scf1):
149149

150150
if not grabbed and trigger:
151151
print('Grab started')
152-
grab_controller_start = [-1*pose[2][3], -1*pose[0][3], pose[1][3]]
152+
grab_controller_start = [-1 * pose[2][3], -1 * pose[0][3], pose[1][3]]
153153

154154
dist0 = vector_norm(vector_subtract(grab_controller_start,
155155
setpoints[0]))
@@ -169,7 +169,7 @@ def run_sequence(scf0, scf1):
169169
grabbed = trigger
170170

171171
if trigger:
172-
curr = [-1*pose[2][3], -1*pose[0][3], pose[1][3]]
172+
curr = [-1 * pose[2][3], -1 * pose[0][3], pose[1][3]]
173173
setpoints[closest] = vector_add(
174174
grab_setpoint_start, vector_subtract(curr,
175175
grab_controller_start))

examples/lighthouse/read_lighthouse_mem.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from cflib.crazyflie import Crazyflie
3131
from cflib.crazyflie.mem import LighthouseMemHelper
3232
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
33+
from cflib.utils import uri_helper
3334

3435
# Only output errors from the logging framework
3536
logging.basicConfig(level=logging.ERROR)
@@ -67,7 +68,7 @@ def _calib_read_ready(self, calib_data):
6768

6869
if __name__ == '__main__':
6970
# URI to the Crazyflie to connect to
70-
uri = 'radio://0/80'
71+
uri = uri_helper.uri_from_env(default='radio://0/80/2M/E7E7E7E7E7')
7172

7273
# Initialize the low-level drivers
7374
cflib.crtp.init_drivers()

examples/lighthouse/write_lighthouse_mem.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from cflib.crazyflie.mem import LighthouseBsGeometry
3333
from cflib.crazyflie.mem import LighthouseMemHelper
3434
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
35+
from cflib.utils import uri_helper
3536

3637
# Only output errors from the logging framework
3738
logging.basicConfig(level=logging.ERROR)
@@ -63,7 +64,7 @@ def _data_written(self, success):
6364

6465
if __name__ == '__main__':
6566
# URI to the Crazyflie to connect to
66-
uri = 'radio://0/80'
67+
uri = uri_helper.uri_from_env(default='radio://0/80/2M/E7E7E7E7E7')
6768

6869
# Initialize the low-level drivers
6970
cflib.crtp.init_drivers()

examples/positioning/initial_position.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@
4141
from cflib.crazyflie.log import LogConfig
4242
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
4343
from cflib.crazyflie.syncLogger import SyncLogger
44+
from cflib.utils import uri_helper
4445

4546
# URI to the Crazyflie to connect to
46-
uri = 'radio://0/80/2M'
47+
uri = uri_helper.uri_from_env(default='radio://0/80/2M/E7E7E7E7E7')
4748

4849
# Change the sequence according to your setup
4950
# x y z

examples/radio/scan.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@
2222
# You should have received a copy of the GNU General Public License
2323
# along with this program. If not, see <https://www.gnu.org/licenses/>.
2424
"""
25-
Simple example that scans for available Crazyflies and lists them.
25+
Simple example that scans for available Crazyflies with a certain address and lists them.
2626
"""
2727
import cflib.crtp
2828

2929
# Initiate the low level drivers
3030
cflib.crtp.init_drivers()
3131

3232
print('Scanning interfaces for Crazyflies...')
33-
available = cflib.crtp.scan_interfaces()
33+
available = cflib.crtp.scan_interfaces(address=int('E7E7E7E7E7', 16)
34+
)
3435
print('Crazyflies found:')
3536
for i in available:
3637
print(i[0])

examples/step-by-step/sbs_motion_commander.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def param_deck_flow(_, value_str):
127127

128128
logconf.start()
129129

130-
# take_off_simple(scf)
130+
take_off_simple(scf)
131131
# move_linear_simple(scf)
132132
# move_box_limit(scf)
133-
# logconf.stop()
133+
logconf.stop()

examples/tuning/PID_controller_tuner.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def __init__(self, master):
6161
self.master = master
6262
self.master.title('PID tuner Crazyflie')
6363

64-
self.figplot = plt.Figure(figsize=(5, 4), dpi=100)
64+
self.figplot = plt.Figure(figsize=(2, 1), dpi=100)
6565
self.ax2 = self.figplot.add_subplot(111)
6666
self.line2 = FigureCanvasTkAgg(self.figplot, self.master)
6767
self.line2.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
@@ -191,12 +191,12 @@ def send_pid_gains(self):
191191
'position PID controller: Kp: ' +
192192
str(self.pid_gui.scale_Kp.get()) +
193193
', Ki: ' + str(self.pid_gui.scale_Ki.get()) +
194-
', Kd: '+str(self.pid_gui.scale_Ki.get()))
195-
cf.param.set_value(self.unit_choice+'CtlPid.'+self.axis_choice +
194+
', Kd: ' + str(self.pid_gui.scale_Kd.get()))
195+
cf.param.set_value(self.unit_choice + 'CtlPid.' + self.axis_choice +
196196
'Kp', self.pid_gui.scale_Kp.get())
197-
cf.param.set_value(self.unit_choice+'CtlPid.'+self.axis_choice +
197+
cf.param.set_value(self.unit_choice + 'CtlPid.' + self.axis_choice +
198198
'Ki', self.pid_gui.scale_Ki.get())
199-
cf.param.set_value(self.unit_choice+'CtlPid.'+self.axis_choice +
199+
cf.param.set_value(self.unit_choice + 'CtlPid.' + self.axis_choice +
200200
'Kd', self.pid_gui.scale_Kd.get())
201201
cf.param.set_value('posCtlPid.xVelMax', self.pid_gui.scale_vMax.get())
202202
cf.param.set_value('posCtlPid.yVelMax', self.pid_gui.scale_vMax.get())
@@ -240,11 +240,11 @@ def do_step(self):
240240
# print(sp_history)
241241
self.pid_gui.draw_plot(time_history, pos_history, sp_history)
242242
if self.axis_choice == 'z':
243-
self.commander.go_to(0, 0, -1*STEP_SIZE, 0, 1.0, relative=True)
243+
self.commander.go_to(0, 0, -1 * STEP_SIZE, 0, 1.0, relative=True)
244244
elif self.axis_choice == 'x':
245-
self.commander.go_to(-1*STEP_SIZE, 0, 0, 0, 1.0, relative=True)
245+
self.commander.go_to(-1 * STEP_SIZE, 0, 0, 0, 1.0, relative=True)
246246
elif self.axis_choice == 'y':
247-
self.commander.go_to(0, -1*STEP_SIZE, 0, 0, 1.0, relative=True)
247+
self.commander.go_to(0, -1 * STEP_SIZE, 0, 0, 1.0, relative=True)
248248
else:
249249
print('WRONG CHOICE?!?!')
250250
self.stop_gui()
@@ -256,7 +256,7 @@ def stop_gui(self):
256256
# parameter update
257257
def change_param_axis_callback(self, value_axis):
258258
#
259-
print(self.unit_choice + 'CtlPid.'+value_axis)
259+
print(self.unit_choice + 'CtlPid.' + value_axis)
260260

261261
groupname = self.unit_choice + 'CtlPid'
262262
self.cf.param.remove_update_callback(
@@ -277,9 +277,9 @@ def change_param_axis_callback(self, value_axis):
277277
group=groupname, name=value_axis +
278278
'Kd', cb=self.param_updated_callback_Kd)
279279

280-
self.cf.param.request_param_update(groupname+'.'+value_axis+'Kp')
281-
self.cf.param.request_param_update(groupname+'.'+value_axis+'Ki')
282-
self.cf.param.request_param_update(groupname+'.'+value_axis+'Kd')
280+
self.cf.param.request_param_update(groupname + '.' + value_axis + 'Kp')
281+
self.cf.param.request_param_update(groupname + '.' + value_axis + 'Ki')
282+
self.cf.param.request_param_update(groupname + '.' + value_axis + 'Kd')
283283
time.sleep(0.1)
284284

285285
self.update_scale_info()
@@ -311,13 +311,13 @@ def change_param_unit_callback(self, value_unit):
311311
group=groupname_new, name=self.axis_choice +
312312
'Kd', cb=self.param_updated_callback_Kd)
313313

314-
print(groupname_new+'.'+self.axis_choice+'Kp')
314+
print(groupname_new + '.' + self.axis_choice + 'Kp')
315315
self.cf.param.request_param_update(
316-
groupname_new+'.'+self.axis_choice+'Kp')
316+
groupname_new + '.' + self.axis_choice + 'Kp')
317317
self.cf.param.request_param_update(
318-
groupname_new+'.'+self.axis_choice+'Ki')
318+
groupname_new + '.' + self.axis_choice + 'Ki')
319319
self.cf.param.request_param_update(
320-
groupname_new+'.'+self.axis_choice+'Kd')
320+
groupname_new + '.' + self.axis_choice + 'Kd')
321321
time.sleep(0.1)
322322

323323
self.update_scale_info()

0 commit comments

Comments
 (0)