Commit c7b26111 authored by Marlene Böhmer's avatar Marlene Böhmer

update scripts, PRRT, cflib

parent 550cf702
Subproject commit b9612f7d1905e98d4d22fa2367f144c6cd5c0ad0 Subproject commit b3ef5eb222f83f71a5d0a6e7ab29965783e51523
#!/usr/bin/env python #!/usr/bin/env python3
import logging import logging
import sys import sys
...@@ -176,4 +176,3 @@ if __name__ == '__main__': ...@@ -176,4 +176,3 @@ if __name__ == '__main__':
except KeyboardInterrupt: except KeyboardInterrupt:
print('\n') print('\n')
bridge.stop() bridge.stop()
""" #!/usr/bin/env python3
This script shows a simple scripted flight path using the MotionCommander class.
Simple example that connects to the crazyflie at `URI` and runs a
sequence. Change the URI variable to your Crazyflie configuration.
"""
import logging import logging
import time import time
import sys
import cflib.crtp import cflib.crtp
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.positioning.motion_commander import MotionCommander from cflib.positioning.motion_commander import MotionCommander
URI = 'radio://0/80/2M' URI = ''
if len(sys.argv) >= 2:
if sys.argv[1] == 'radio':
URI = 'radio://0/80/2M'
elif sys.argv[1] == 'prrt':
URI = 'prrt://10.8.0.208:5000'
elif sys.argv[1] == 'serial':
URI = 'serial://pi'
else:
sys.exit('Give a valid argument.')
else:
sys.exit('Give a commandline argument.')
# Only output errors from the logging framework # Only output errors from the logging framework
logging.basicConfig(level=logging.ERROR) logging.basicConfig(level=logging.ERROR)
...@@ -21,43 +30,44 @@ if __name__ == '__main__': ...@@ -21,43 +30,44 @@ if __name__ == '__main__':
cflib.crtp.init_drivers(enable_debug_driver=False) cflib.crtp.init_drivers(enable_debug_driver=False)
with SyncCrazyflie(URI) as scf: with SyncCrazyflie(URI) as scf:
# n_points = 16 radius = 0.4 circle_time = 4
with MotionCommander(scf) as mc: with MotionCommander(scf) as mc:
mc.up(0.4) mc.up(0.4)
time.sleep(1.5) time.sleep(1.5)
for i in range(2): for i in range(2):
mc.start_linear_motion(0.0, -0.12179274798194117, 0.6122934917841437) mc.start_linear_motion(0.0, -0.121792748 , 0.6122934918 )
time.sleep(0.25) time.sleep( 0.25 )
mc.start_linear_motion(0.0, -0.34683640211958267, 0.5190773581143323) mc.start_linear_motion(0.0, -0.3468364021 , 0.5190773581 )
time.sleep(0.25) time.sleep( 0.25 )
mc.start_linear_motion(0.0, -0.5190773581143324, 0.3468364021195829) mc.start_linear_motion(0.0, -0.5190773581 , 0.3468364021 )
time.sleep(0.25) time.sleep( 0.25 )
mc.start_linear_motion(0.0, -0.6122934917841437, 0.12179274798194117) mc.start_linear_motion(0.0, -0.6122934918 , 0.121792748 )
time.sleep(0.25) time.sleep( 0.25 )
mc.start_linear_motion(0.0, -0.6122934917841437, -0.12179274798194117) mc.start_linear_motion(0.0, -0.6122934918 , -0.121792748 )
time.sleep(0.25) time.sleep( 0.25 )
mc.start_linear_motion(0.0, -0.5190773581143324, -0.34683640211958267) mc.start_linear_motion(0.0, -0.5190773581 , -0.3468364021 )
time.sleep(0.25) time.sleep( 0.25 )
mc.start_linear_motion(0.0, -0.3468364021195829, -0.5190773581143324) mc.start_linear_motion(0.0, -0.3468364021 , -0.5190773581 )
time.sleep(0.25) time.sleep( 0.25 )
mc.start_linear_motion(0.0, -0.12179274798194117, -0.6122934917841436) mc.start_linear_motion(0.0, -0.121792748 , -0.6122934918 )
time.sleep(0.25) time.sleep( 0.25 )
mc.start_linear_motion(0.0, 0.12179274798194095, -0.6122934917841437) mc.start_linear_motion(0.0, 0.121792748 , -0.6122934918 )
time.sleep(0.25) time.sleep( 0.25 )
mc.start_linear_motion(0.0, 0.3468364021195829, -0.5190773581143325) mc.start_linear_motion(0.0, 0.3468364021 , -0.5190773581 )
time.sleep(0.25) time.sleep( 0.25 )
mc.start_linear_motion(0.0, 0.5190773581143316, -0.34683640211958244) mc.start_linear_motion(0.0, 0.5190773581 , -0.3468364021 )
time.sleep(0.25) time.sleep( 0.25 )
mc.start_linear_motion(0.0, 0.6122934917841443, -0.12179274798194162) mc.start_linear_motion(0.0, 0.6122934918 , -0.121792748 )
time.sleep(0.25) time.sleep( 0.25 )
mc.start_linear_motion(0.0, 0.6122934917841444, 0.1217927479819414) mc.start_linear_motion(0.0, 0.6122934918 , 0.121792748 )
time.sleep(0.25) time.sleep( 0.25 )
mc.start_linear_motion(0.0, 0.5190773581143318, 0.34683640211958244) mc.start_linear_motion(0.0, 0.5190773581 , 0.3468364021 )
time.sleep(0.25) time.sleep( 0.25 )
mc.start_linear_motion(0.0, 0.34683640211958267, 0.5190773581143315) mc.start_linear_motion(0.0, 0.3468364021 , 0.5190773581 )
time.sleep(0.25) time.sleep( 0.25 )
mc.start_linear_motion(0.0, 0.12179274798194162, 0.6122934917841443) mc.start_linear_motion(0.0, 0.121792748 , 0.6122934918 )
time.sleep(0.25) time.sleep( 0.25 )
mc.stop() mc.stop()
time.sleep(1.5) time.sleep(1.5)
"""
This script shows a simple scripted flight path using the MotionCommander class.
Simple example that connects to the crazyflie at `URI` and runs a
sequence. Change the URI variable to your Crazyflie configuration.
"""
import logging
import time
import cflib.crtp
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.positioning.motion_commander import MotionCommander
URI = 'radio://0/80/2M'
# Only output errors from the logging framework
logging.basicConfig(level=logging.ERROR)
if __name__ == '__main__':
# Initialize the low-level drivers (don't list the debug drivers)
cflib.crtp.init_drivers(enable_debug_driver=False)
with SyncCrazyflie(URI) as scf:
# We take off when the commander is created
with MotionCommander(scf) as mc:
print('Taking off!')
time.sleep(1)
# There is a set of functions that move a specific distance
# We can move in all directions
print('Moving forward 0.5m')
mc.forward(0.5)
# Wait a bit
time.sleep(1)
print('Moving up 0.2m')
mc.up(0.2)
# Wait a bit
time.sleep(1)
print('Doing a 180deg circle')
mc.circle_right(0.1, velocity=0.1, angle_degrees=180)
print('Moving down 0.2m')
mc.down(0.2)
# Wait a bit
time.sleep(1)
print('Moving forward 0.5m')
mc.forward(0.5)
# We land when the MotionCommander goes out of scope
print('Landing!')
""" #!/usr/bin/env python3
This script shows a simple scripted flight path using the MotionCommander class.
Simple example that connects to the crazyflie at `URI` and runs a
sequence. Change the URI variable to your Crazyflie configuration.
"""
import logging import logging
import time import time
import sys
import cflib.crtp import cflib.crtp
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.positioning.motion_commander import MotionCommander from cflib.positioning.motion_commander import MotionCommander
URI = 'serial://pi' URI = ''
if len(sys.argv) >= 2:
if sys.argv[1] == 'radio':
URI = 'radio://0/80/2M'
elif sys.argv[1] == 'prrt':
URI = 'prrt://10.8.0.208:5000'
elif sys.argv[1] == 'serial':
URI = 'serial://pi'
else:
sys.exit('Give a valid argument.')
else:
sys.exit('Give a commandline argument.')
# Only output errors from the logging framework # Only output errors from the logging framework
logging.basicConfig(level=logging.ERROR) logging.basicConfig(level=logging.ERROR)
...@@ -21,9 +30,18 @@ if __name__ == '__main__': ...@@ -21,9 +30,18 @@ if __name__ == '__main__':
cflib.crtp.init_drivers(enable_debug_driver=False) cflib.crtp.init_drivers(enable_debug_driver=False)
with SyncCrazyflie(URI) as scf: with SyncCrazyflie(URI) as scf:
# We take off when the commander is created # n_points = 2 radius = 0.25 circle_time = 2
with MotionCommander(scf) as mc: with MotionCommander(scf) as mc:
print('Taking off!') time.sleep(1.5)
time.sleep(0.1)
# We land when the MotionCommander goes out of scope for i in range(5):
print('Landing!') mc.start_linear_motion(0.0, -0.5 , 0.0 )
time.sleep( 1.0 )
mc.stop()
time.sleep(0.2)
mc.start_linear_motion(0.0, 0.5 , -0.0 )
time.sleep( 1.0 )
mc.stop()
time.sleep(0.2)
time.sleep(1.3)
""" #!/usr/bin/env python3
This script shows a simple scripted flight path using the MotionCommander class.
Simple example that connects to the crazyflie at `URI` and runs a
sequence. Change the URI variable to your Crazyflie configuration.
"""
import logging import logging
import time import time
import sys
import cflib.crtp import cflib.crtp
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.positioning.motion_commander import MotionCommander from cflib.positioning.motion_commander import MotionCommander
URI = 'prrt://10.8.0.208:5000' URI = ''
if len(sys.argv) >= 2:
if sys.argv[1] == 'radio':
URI = 'radio://0/80/2M'
elif sys.argv[1] == 'prrt':
URI = 'prrt://10.8.0.208:5000'
elif sys.argv[1] == 'serial':
URI = 'serial://pi'
else:
sys.exit('Give a valid argument.')
else:
sys.exit('Give a commandline argument.')
# Only output errors from the logging framework # Only output errors from the logging framework
logging.basicConfig(level=logging.ERROR) logging.basicConfig(level=logging.ERROR)
...@@ -21,9 +30,22 @@ if __name__ == '__main__': ...@@ -21,9 +30,22 @@ if __name__ == '__main__':
cflib.crtp.init_drivers(enable_debug_driver=False) cflib.crtp.init_drivers(enable_debug_driver=False)
with SyncCrazyflie(URI) as scf: with SyncCrazyflie(URI) as scf:
# We take off when the commander is created
with MotionCommander(scf) as mc: with MotionCommander(scf) as mc:
print('Taking off!') print('Taking off!')
time.sleep(0.1) time.sleep(0.5)
# We land when the MotionCommander goes out of scope
print('Moving forward')
mc.forward(0.3)
time.sleep(0.5)
print('Moving up')
mc.up(0.2)
print('Turn left')
mc.turn_left(90)
print('Moving left')
mc.left(0.3)
time.sleep(0.5)
print('Landing!') print('Landing!')
""" #!/usr/bin/env python3
This script shows a simple scripted flight path using the MotionCommander class.
Simple example that connects to the crazyflie at `URI` and runs a
sequence. Change the URI variable to your Crazyflie configuration.
"""
import logging import logging
import time import time
import sys
import cflib.crtp import cflib.crtp
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.positioning.motion_commander import MotionCommander from cflib.positioning.motion_commander import MotionCommander
URI = 'radio://0/80/2M' URI = ''
if len(sys.argv) >= 2:
if sys.argv[1] == 'radio':
URI = 'radio://0/80/2M'
elif sys.argv[1] == 'prrt':
URI = 'prrt://10.8.0.208:5000'
elif sys.argv[1] == 'serial':
URI = 'serial://pi'
else:
sys.exit('Give a valid argument.')
else:
sys.exit('Give a commandline argument.')
# Only output errors from the logging framework # Only output errors from the logging framework
logging.basicConfig(level=logging.ERROR) logging.basicConfig(level=logging.ERROR)
......
"""
This script shows a simple scripted flight path using the MotionCommander class.
Simple example that connects to the crazyflie at `URI` and runs a
sequence. Change the URI variable to your Crazyflie configuration.
"""
import logging
import time
import cflib.crtp
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.positioning.motion_commander import MotionCommander
URI = 'serial://pi'
# Only output errors from the logging framework
logging.basicConfig(level=logging.ERROR)
if __name__ == '__main__':
# Initialize the low-level drivers (don't list the debug drivers)
cflib.crtp.init_drivers(enable_debug_driver=False)
with SyncCrazyflie(URI) as scf:
# We take off when the commander is created
with MotionCommander(scf) as mc:
print('Taking off!')
time.sleep(1)
# There is a set of functions that move a specific distance
# We can move in all directions
print('Moving forward 0.5m')
mc.forward(0.5)
# Wait a bit
time.sleep(1)
print('Moving up 0.2m')
mc.up(0.2)
# Wait a bit
time.sleep(1)
print('Doing a 180deg circle')
mc.circle_right(0.1, velocity=0.1, angle_degrees=180)
print('Moving down 0.2m')
mc.down(0.2)
# Wait a bit
time.sleep(1)
print('Moving forward 0.5m')
mc.forward(0.5)
# We land when the MotionCommander goes out of scope
print('Landing!')
\ No newline at end of file
import numpy as np import numpy as np
n_points = 16 n_points = 2
radius = 0.4 radius = 0.25
time_for_segment = 4/n_points circle_time = 2
time_for_segment = circle_time/n_points
y_points = np.arange(n_points+1, dtype=np.float64) y_points = np.arange(n_points+1, dtype=np.float64)
z_points = np.arange(n_points+1, dtype=np.float64) z_points = np.arange(n_points+1, dtype=np.float64)
...@@ -13,8 +14,8 @@ z_points = [x * 2*np.pi/n_points for x in z_points] ...@@ -13,8 +14,8 @@ z_points = [x * 2*np.pi/n_points for x in z_points]
y_points = [np.cos(x) for x in y_points] y_points = [np.cos(x) for x in y_points]
z_points = [np.sin(x) for x in z_points] z_points = [np.sin(x) for x in z_points]
y_points = [x * 0.4 for x in y_points] y_points = [x * radius for x in y_points]
z_points = [x * 0.4 for x in z_points] z_points = [x * radius for x in z_points]
y_diff = [y_points[i+1]-y_points[i] for i in range(n_points)] y_diff = [y_points[i+1]-y_points[i] for i in range(n_points)]
z_diff = [z_points[i+1]-z_points[i] for i in range(n_points)] z_diff = [z_points[i+1]-z_points[i] for i in range(n_points)]
...@@ -22,5 +23,8 @@ z_diff = [z_points[i+1]-z_points[i] for i in range(n_points)] ...@@ -22,5 +23,8 @@ z_diff = [z_points[i+1]-z_points[i] for i in range(n_points)]
y_velocity = [y_diff[i]/time_for_segment for i in range(n_points)] y_velocity = [y_diff[i]/time_for_segment for i in range(n_points)]
z_velocity = [z_diff[i]/time_for_segment for i in range(n_points)] z_velocity = [z_diff[i]/time_for_segment for i in range(n_points)]
y_velocity = np.around(y_velocity, 10)
z_velocity = np.around(z_velocity, 10)
for i in range(n_points): for i in range(n_points):
print("mc.start_linear_motion(0.0,", y_velocity[i], ",", z_velocity[i], ")\ntime.sleep(", time_for_segment, ")") print("mc.start_linear_motion(0.0,", y_velocity[i], ",", z_velocity[i], ")\ntime.sleep(", time_for_segment, ")")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment