USC-ACTLab / crazyswarm

A Large Quadcopter Swarm
MIT License
319 stars 316 forks source link

change absolute file path in pycrazyswarm #716

Closed shupx closed 1 year ago

shupx commented 1 year ago

The crazyflie.yaml was read as a relative path in crazyswarm_py.py, which depends on the workspace. We have to navigate to the scripts folder to execute the python scripts there. If we run these python scripts in other directories, the following error will occur: No such file or directory: '../launch/crazyflies.yaml' This is because of the following codes: https://github.com/USC-ACTLab/crazyswarm/blob/ea4a67e57743fb7c8f56270edd96b191876f4057/ros_ws/src/crazyswarm/scripts/pycrazyswarm/crazyswarm_py.py#L39-L42 So I change the '../launch/crazyflies.yaml' in crazyswarm_py.py into an absolute path style which uses os.path.abspath(__file__) to acquire the absolute path of crazyswarm_py.py:

        if crazyflies_yaml is None:
            folder = os.path.dirname(os.path.abspath(__file__)) # absolute path of this file
            folder = os.path.dirname(folder) # up folder
            folder = os.path.dirname(folder) # up folder
            crazyflies_yaml = folder + "/launch/crazyflies.yaml"
        if crazyflies_yaml.endswith(".yaml"):
            crazyflies_yaml = open(crazyflies_yaml, 'r').read()

This change has no conflict with original operations, and makes python scripts that depends on the pycrazyswarm to be able to execute in any directories. Even rosrun is supported. For example: rosrun crazyswarm cmdVelocityCircle.py

Hope this commit can be merged. Thanks!

whoenig commented 1 year ago

Thanks!

vinzenzm commented 1 year ago

When creating a custom ros package as shown here: https://crazyswarm.readthedocs.io/en/latest/howto/howto.html#option-2-custom-ros-package then the wrong "crazyflies.yaml" will be chosen now. (The one inside the crazyswarm package.)

Because you are able to pass the .yaml in the constructor this doesn't break anything, but it's inconvenient and unclear. Please either change this sentence in the How-To-Guide: "In you package, you can have your own launch files, yaml configuration files, and scripts, similar to the folder structure in the crazyswarm package." or revert/rework this change.

shupx commented 1 year ago

@vinzenzm You are right. The "crazyflies.yaml" is always chosen as the one inside the crazyswarm package rather than your own ROS package now since the absolute file path is adopted. And this may be confusing. When I create my own ROS package and python scripts, I prefer copying the pycrazyswarm folder to my 'scripts' folder, so I need not to export the python path of the pycrazyswarm and does not have the problem as you mentioned. But the beginners and most users may follow the document instructions to create their scripts, which leads to the wrong selection of the "crazyflies.yaml" under this commit. Sorry for that, and I would recommend reverting this change to keep consistent with the document.