Skip to content

Commit

Permalink
(#159) fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
knmcguire committed Jul 29, 2020
1 parent 3bf5b47 commit a212e92
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/user-guides/sbs_motion_commander.md
Original file line number Diff line number Diff line change
Expand Up @@ -513,4 +513,4 @@ You're done! The full code of this tutorial can be found in the example/step-by-

# What is next ?

Now you are able to send velocity commands to the Crazyflie and react upon logging and parameters variables, so one step closer to writing your own application with the Crazyflie python library! Check out the motion_commander_demo.py in the example folder of the cflib if you would like to see what the commander can do.
Now you are able to send velocity commands to the Crazyflie and react upon logging and parameters variables, so one step closer to writing your own application with the Crazyflie python library! Check out the motion_commander_demo.py in the example folder of the cflib if you would like to see what the commander can do.
46 changes: 24 additions & 22 deletions examples/step-by-step/sbs_motion_commander.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.

import logging
import time

import cflib.crtp
from cflib.crazyflie import Crazyflie
from cflib.crazyflie.log import LogConfig
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.positioning.motion_commander import MotionCommander
from cflib.crazyflie.log import LogConfig


URI = 'radio://0/80/2M/E7E7E7E7E7'
Expand All @@ -42,13 +41,14 @@

logging.basicConfig(level=logging.ERROR)

position_estimate = [0,0]
position_estimate = [0, 0]


def move_box_limit(scf):
with MotionCommander(scf, default_height=DEFAULT_HEIGHT) as mc:
body_x_cmd = 0.2;
body_y_cmd = 0.1;
max_vel = 0.2;
body_x_cmd = 0.2
body_y_cmd = 0.1
max_vel = 0.2

while (1):
'''if position_estimate[0] > BOX_LIMIT:
Expand All @@ -58,18 +58,17 @@ def move_box_limit(scf):
'''

if position_estimate[0] > BOX_LIMIT:
body_x_cmd=-max_vel
body_x_cmd = -max_vel
elif position_estimate[0] < -BOX_LIMIT:
body_x_cmd=max_vel
body_x_cmd = max_vel
if position_estimate[1] > BOX_LIMIT:
body_y_cmd=-max_vel
body_y_cmd = -max_vel
elif position_estimate[1] < -BOX_LIMIT:
body_y_cmd=max_vel
body_y_cmd = max_vel

mc.start_linear_motion(body_x_cmd, body_y_cmd, 0)

time.sleep(0.1)

time.sleep(0.1)


def move_linear_simple(scf):
Expand All @@ -82,35 +81,38 @@ def move_linear_simple(scf):
mc.forward(0.5)
time.sleep(1)


def take_off_simple(scf):
with MotionCommander(scf, default_height=DEFAULT_HEIGHT) as mc:
time.sleep(3)
mc.stop()


def log_pos_callback(timestamp, data, logconf):
print(data)
global postion_estimate
position_estimate[0] = data["stateEstimate.x"]
position_estimate[1] = data["stateEstimate.y"]
position_estimate[0] = data['stateEstimate.x']
position_estimate[1] = data['stateEstimate.y']


def param_deck_flow(name, value):
global is_deck_attached
print(value)
if value:
is_deck_attached = True
print("Deck is attached!")
print('Deck is attached!')
else:
is_deck_attached = False
print("Deck is NOT attached!")
print('Deck is NOT attached!')


if __name__ == '__main__':
cflib.crtp.init_drivers(enable_debug_driver=False)


with SyncCrazyflie(URI, cf=Crazyflie(rw_cache='./cache')) as scf:

scf.cf.param.add_update_callback(group="deck", name="bcFlow2",
cb=param_deck_flow)
scf.cf.param.add_update_callback(group='deck', name='bcFlow2',
cb=param_deck_flow)
time.sleep(1)

logconf = LogConfig(name='Position', period_in_ms=10)
Expand All @@ -122,7 +124,7 @@ def param_deck_flow(name, value):
if is_deck_attached:
logconf.start()

#take_off_simple(scf)
#move_linear_simple(scf)
# take_off_simple(scf)
# move_linear_simple(scf)
move_box_limit(scf)
logconf.stop()
logconf.stop()

0 comments on commit a212e92

Please sign in to comment.