Skip to content

Commit

Permalink
Merge pull request #319 from IMRCLab/feature_examples_flake8
Browse files Browse the repository at this point in the history
crazyflie_examples: fix flake8 and pep256 issues
  • Loading branch information
whoenig committed Oct 25, 2023
2 parents fd2e4f2 + f08cfa3 commit 13cb67f
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 114 deletions.
16 changes: 16 additions & 0 deletions crazyflie_examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,20 @@ install(DIRECTORY
DESTINATION share/${PROJECT_NAME}/
)

if(BUILD_TESTING)
find_package(ament_cmake_pytest REQUIRED)
set(_pytest_tests
test/test_flake8.py
test/test_pep257.py
)
foreach(_test_path ${_pytest_tests})
get_filename_component(_test_name ${_test_path} NAME_WE)
ament_add_pytest_test(${_test_name} ${_test_path}
APPEND_ENV PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}
TIMEOUT 60
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endforeach()
endif()

ament_package()
11 changes: 7 additions & 4 deletions crazyflie_examples/crazyflie_examples/cmd_full_state.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python

import numpy as np
from pathlib import Path

from crazyflie_py import *
from crazyflie_py import Crazyswarm
from crazyflie_py.uav_trajectory import Trajectory
import numpy as np


def executeTrajectory(timeHelper, cf, trajpath, rate=100, offset=np.zeros(3)):
Expand Down Expand Up @@ -39,12 +39,15 @@ def main():
cf.takeoff(targetHeight=Z, duration=Z+1.0)
timeHelper.sleep(Z+2.0)

executeTrajectory(timeHelper, cf, Path(__file__).parent / "data/figure8.csv", rate, offset=np.array([0, 0, 0.5]))
executeTrajectory(timeHelper, cf,
Path(__file__).parent / 'data/figure8.csv',
rate,
offset=np.array([0, 0, 0.5]))

cf.notifySetpointsStop()
cf.land(targetHeight=0.03, duration=Z+1.0)
timeHelper.sleep(Z+2.0)


if __name__ == "__main__":
if __name__ == '__main__':
main()
9 changes: 5 additions & 4 deletions crazyflie_examples/crazyflie_examples/figure8.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#!/usr/bin/env python

import numpy as np
from pathlib import Path

from crazyflie_py import *
from crazyflie_py import Crazyswarm
from crazyflie_py.uav_trajectory import Trajectory
import numpy as np


def main():
swarm = Crazyswarm()
timeHelper = swarm.timeHelper
allcfs = swarm.allcfs

traj1 = Trajectory()
traj1.loadcsv(Path(__file__).parent / "data/figure8.csv")
traj1.loadcsv(Path(__file__).parent / 'data/figure8.csv')

TRIALS = 1
TIMESCALE = 1.0
Expand All @@ -36,5 +37,5 @@ def main():
timeHelper.sleep(3.0)


if __name__ == "__main__":
if __name__ == '__main__':
main()
3 changes: 1 addition & 2 deletions crazyflie_examples/crazyflie_examples/hello_world.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Takeoff-hover-land for one CF. Useful to validate hardware config."""

# from pycrazyswarm import Crazyswarm
from crazyflie_py import Crazyswarm


Expand All @@ -19,5 +18,5 @@ def main():
timeHelper.sleep(TAKEOFF_DURATION)


if __name__ == "__main__":
if __name__ == '__main__':
main()
11 changes: 6 additions & 5 deletions crazyflie_examples/crazyflie_examples/multi_trajectory.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#!/usr/bin/env python

import numpy as np
from pathlib import Path

from crazyflie_py import *
from crazyflie_py import Crazyswarm
from crazyflie_py.uav_trajectory import Trajectory
import numpy as np


def main():
swarm = Crazyswarm()
timeHelper = swarm.timeHelper
allcfs = swarm.allcfs
trajs = []
n = 2 # number of distinct trajectories
n = 2 # number of distinct trajectories

for i in range(n):
traj = Trajectory()
traj.loadcsv(Path(__file__).parent / f"data/multi_trajectory/traj{i}.csv")
traj.loadcsv(Path(__file__).parent / f'data/multi_trajectory/traj{i}.csv')
trajs.append(traj)

TRIALS = 1
Expand All @@ -38,5 +39,5 @@ def main():
timeHelper.sleep(3.0)


if __name__ == "__main__":
if __name__ == '__main__':
main()
9 changes: 5 additions & 4 deletions crazyflie_examples/crazyflie_examples/nice_hover.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env python

from crazyflie_py import Crazyswarm
import numpy as np
from crazyflie_py import *


def main():
Z = 1.0

swarm = Crazyswarm()
timeHelper = swarm.timeHelper
allcfs = swarm.allcfs
Expand All @@ -17,11 +17,12 @@ def main():
pos = np.array(cf.initialPosition) + np.array([0, 0, Z])
cf.goTo(pos, 0, 1.0)

print("press button to continue...")
print('press button to continue...')
swarm.input.waitUntilButtonPressed()

allcfs.land(targetHeight=0.02, duration=1.0+Z)
timeHelper.sleep(1.0+Z)

if __name__ == "__main__":

if __name__ == '__main__':
main()
10 changes: 4 additions & 6 deletions crazyflie_examples/crazyflie_examples/set_param.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
#!/usr/bin/env python

from crazyflie_py import *
from crazyflie_py import Crazyswarm


def main():
Z = 1.0

swarm = Crazyswarm()
timeHelper = swarm.timeHelper
allcfs = swarm.allcfs

# disable LED (one by one)
for cf in allcfs.crazyflies:
cf.setParam("led.bitmask", 128)
cf.setParam('led.bitmask', 128)
timeHelper.sleep(1.0)

timeHelper.sleep(2.0)

# enable LED (broadcast)
allcfs.setParam("led.bitmask", 0)
allcfs.setParam('led.bitmask', 0)
timeHelper.sleep(5.0)


if __name__ == "__main__":
if __name__ == '__main__':
main()
10 changes: 6 additions & 4 deletions crazyflie_examples/launch/keyboard_velmux_launch.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
import yaml

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node
import yaml


def generate_launch_description():
# load crazyflies
Expand All @@ -29,8 +31,8 @@ def generate_launch_description():
executable='vel_mux.py',
name='vel_mux',
output='screen',
parameters=[{"hover_height": 0.3},
{"incoming_twist_topic": "/cmd_vel"},
{"robot_prefix": "/cf1"}]
parameters=[{'hover_height': 0.3},
{'incoming_twist_topic': '/cmd_vel'},
{'robot_prefix': '/cf1'}]
),
])
47 changes: 23 additions & 24 deletions crazyflie_examples/launch/multiranger_mapping_launch.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import os
import yaml

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch_ros.actions import Node
from launch.conditions import LaunchConfigurationEquals
from launch.launch_description_sources import PythonLaunchDescriptionSource
import yaml


def generate_launch_description():
# load crazyflies
Expand All @@ -32,25 +31,25 @@ def generate_launch_description():
executable='vel_mux.py',
name='vel_mux',
output='screen',
parameters=[{"hover_height": 0.3},
{"incoming_twist_topic": "/cmd_vel"},
{"robot_prefix": "/cf1"}]
parameters=[{'hover_height': 0.3},
{'incoming_twist_topic': '/cmd_vel'},
{'robot_prefix': '/cf1'}]
),
Node(
parameters=[
{'odom_frame': 'odom'},
{'map_frame': 'world'},
{'base_frame': 'cf1'},
{'scan_topic': '/cf1/scan'},
{'use_scan_matching': False},
{'max_laser_range': 3.5},
{'resolution': 0.1},
{'minimum_travel_distance': 0.01},
{'minimum_travel_heading': 0.001},
{'map_update_interval': 0.1}
],
package='slam_toolbox',
executable='async_slam_toolbox_node',
name='slam_toolbox',
output='screen'),
])
parameters=[
{'odom_frame': 'odom'},
{'map_frame': 'world'},
{'base_frame': 'cf1'},
{'scan_topic': '/cf1/scan'},
{'use_scan_matching': False},
{'max_laser_range': 3.5},
{'resolution': 0.1},
{'minimum_travel_distance': 0.01},
{'minimum_travel_heading': 0.001},
{'map_update_interval': 0.1}
],
package='slam_toolbox',
executable='async_slam_toolbox_node',
name='slam_toolbox',
output='screen'),
])
77 changes: 39 additions & 38 deletions crazyflie_examples/launch/multiranger_nav2_launch.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os
import yaml

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch_ros.actions import Node
from launch.conditions import LaunchConfigurationEquals
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch_ros.actions import Node
import yaml


def generate_launch_description():
Expand All @@ -20,64 +20,65 @@ def generate_launch_description():

server_params = crazyflies

cf_examples_dir = get_package_share_directory("crazyflie_examples")
cf_examples_dir = get_package_share_directory('crazyflie_examples')
bringup_dir = get_package_share_directory('nav2_bringup')
bringup_launch_dir = os.path.join(bringup_dir, 'launch')
map_name = "map"

map_name = 'map'

return LaunchDescription([
Node(
package='crazyflie',
executable='crazyflie_server.py',
name='crazyflie_server',
output='screen',
parameters=[{"world_tf_name": 'map'},
parameters=[{'world_tf_name': 'map'},
server_params],
),
Node(
package='crazyflie',
executable='vel_mux.py',
name='vel_mux',
output='screen',
parameters=[{"hover_height": 0.3},
{"incoming_twist_topic": "/cmd_vel"},
{"robot_prefix": "/cf1"}]
parameters=[{'hover_height': 0.3},
{'incoming_twist_topic': '/cmd_vel'},
{'robot_prefix': '/cf1'}]
),
Node(
parameters=[
{'odom_frame': 'odom'},
{'map_frame': 'map'},
{'base_frame': 'cf1'},
{'scan_topic': '/cf1/scan'},
{'use_scan_matching': False},
{'max_laser_range': 3.5},
{'resolution': 0.1},
{'minimum_travel_distance': 0.01},
{'minimum_travel_heading': 0.001},
{'map_update_interval': 0.1},
{'mode': 'localization'},
{"map_file_name": cf_examples_dir + "/data/" + map_name},
{"map_start_pose": [0.0, 0.0, 0.0]} ],
package='slam_toolbox',
executable='async_slam_toolbox_node',
name='slam_toolbox',
output='screen'),
parameters=[
{'odom_frame': 'odom'},
{'map_frame': 'map'},
{'base_frame': 'cf1'},
{'scan_topic': '/cf1/scan'},
{'use_scan_matching': False},
{'max_laser_range': 3.5},
{'resolution': 0.1},
{'minimum_travel_distance': 0.01},
{'minimum_travel_heading': 0.001},
{'map_update_interval': 0.1},
{'mode': 'localization'},
{'map_file_name': cf_examples_dir + '/data/' + map_name},
{'map_start_pose': [0.0, 0.0, 0.0]}],
package='slam_toolbox',
executable='async_slam_toolbox_node',
name='slam_toolbox',
output='screen'),
IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(bringup_launch_dir, 'bringup_launch.py')),
launch_arguments={'slam': 'False',
'use_sim_time': 'false',
'map': cf_examples_dir + "/data/" + map_name + ".yaml",
'params_file': os.path.join(cf_examples_dir, 'nav2_params.yaml'),
'autostart': 'true',
'use_composition': 'true',
'transform_publish_period': '0.02'
}.items()
launch_arguments={
'slam': 'False',
'use_sim_time': 'false',
'map': cf_examples_dir + '/data/' + map_name + '.yaml',
'params_file': os.path.join(cf_examples_dir, 'nav2_params.yaml'),
'autostart': 'true',
'use_composition': 'true',
'transform_publish_period': '0.02'
}.items()
),
IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(bringup_launch_dir, 'rviz_launch.py')),
launch_arguments={
'rviz_config': os.path.join(bringup_dir, 'rviz', 'nav2_default_view.rviz')}.items())
'rviz_config': os.path.join(
bringup_dir, 'rviz', 'nav2_default_view.rviz')}.items())
])
Loading

0 comments on commit 13cb67f

Please sign in to comment.