Skip to content

Commit

Permalink
Merge pull request #334 from bitcraze/examples-fix
Browse files Browse the repository at this point in the history
example fixes
  • Loading branch information
knmcguire committed May 11, 2022
2 parents af031ea + b9a2612 commit 6e93153
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 42 deletions.
15 changes: 8 additions & 7 deletions examples/autonomy/autonomousSequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]


Expand Down
6 changes: 3 additions & 3 deletions examples/basicLedmemSync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions examples/basicLedparamSync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 6 additions & 6 deletions examples/lighthouse/lighthouse_openvr_multigrab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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]))
Expand All @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion examples/lighthouse/read_lighthouse_mem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion examples/lighthouse/write_lighthouse_mem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion examples/positioning/initial_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions examples/radio/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
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

# Initiate the low level drivers
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])
4 changes: 2 additions & 2 deletions examples/step-by-step/sbs_motion_commander.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
32 changes: 16 additions & 16 deletions examples/tuning/PID_controller_tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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_Ki.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())
Expand Down Expand Up @@ -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()
Expand All @@ -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(
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 6e93153

Please sign in to comment.