I am trying to implement a feedback based reference tracking controller for a physical ANAFI drone. I have a motion tracking system which gives the inertial pose of the drone using a ROS based driver. The goal is to compute a correction based on these measurements and issue these commands to the drone in real time.
The issue I am currently facing is that, in order to control ANAFI, the olympe environment needs to be activated using source ~/code/parrot-groundsdk/./products/olympe/linux/env/shell which appears to be an environment of its own. However, the environment does not recognize ROS, or any ROS functions. Can anyone please suggest how to either:
Run ROS in an Olympe environment
or
Import Olympe functions into the global python environments.
Option #1:Run ROS in an Olympe environment
I am not familiar with ROS or its installation procedure but, once you have your Olympe Python environment setup and activated, you should be able to pip install everything you need inside it.
OR
Option #2:Import Olympe functions into the global python environments
Running Olympe in another Python environment should be possible. It’s just a matter of populating your PYTHONPATH environment variable correctly to add Olympe and its dependencies from the groundsdk workspace to your python environment. Then you should just source ./out/olympe-linux/final/native-wrapper.sh. This script modifies the LD_LIBRARY_PATH of your current shell so that Olympe can find its compiled C dependencies.
Add the following script ( olympe_custom_env.sh ) in your GroundSDK workspace root directory (ex: ~/code/groundsdk if you’ve followed the user guide closely) :
#!/bin/bash
[[ $0 != $BASH_SOURCE ]] && \
SCRIPT_PATH=$(realpath $BASH_SOURCE) || \
SCRIPT_PATH="`readlink -f "$0"`"
GSDK_DIR="`dirname "$SCRIPT_PATH"`"
# TODO: activate your python environment here. For example:
# source ~/code/ros_project/env/bin/activate
# The following line installs Olympe Python dependencies into your Python
# virtual environement. It should only be necessary the first time and can
# be commented out after that.
pip3 install -r "$GSDK_DIR/packages/olympe/requirements.txt"
# Add Olympe and GSDK Python dependencies to your PYTHONPATH
export PYTHONPATH="${PYTHONPATH}:/$GSDK_DIR/out/olympe-linux/final/usr/lib/python/site-packages"
# Add Olympe GSDK C dependencies to LD_LIBRARY_PATH
source "$GSDK_DIR/out/olympe-linux/final/native-wrapper.sh"
Activate your Python virtual environment (or edit the script above to activate your environment from it).
Source the script into your current shell source ./olympe_custom_env.sh
My apologies, you should remove the set -e line at the beginning of the script. I’ve edited my post above. This is a bash directive that exits the current shell process when a command returns a non-zero error code. This option is useful for a script that you’re executing (the script ends when an error occurs) but should be avoided for scripts that are meant to be sourced because in this option exits your current interactive shell session if the script fails or if you later try to execute a command that fails…
I’ve also corrected the PYTHONPATH variable (there was an extra “:” at the beginning).
You should be able to source the above script in your global Python environment without using a virtual environment. Just make sure to use pip3 instead of pip and python3 instead of python if your linux distribution default Python version is still Python 2.7.
And that retained all the command line functionalities of ROS. The only issue now seems to be that my Olympe runs on Python 3.6.8, while ROS libraries are available for Python 2.7.15+. I guess this is a different issue, but is there a way to install import olympe into Python 2.7.15+ ?
Unfortunately, we have already completely dropped support for Python 2.
At some point during our Python2/Python3 migration Olympe worked for both Python2 and Python3 (this is why you’ll find some “from future import” here and there in the Olympe codebase. But since we have completely stopped using Olympe in Python 2 I don’t think it still works…
Never mind, got ROS to use work on python3 using pip3 install rospkg, and it works!! Now ROS, and Olympe are able to run from the same Pythton3 code. Thank you!!!
Just to summarize, in case anyone else is struggling with a similar issue on how to use Olympe in a global python3 environment with ROS, this is what worked for me:
1.Create the following script with name olympe_custom_env.sh in your olympe’s directory. (Ex: ~/code/parrot-groundsdk/
#!/bin/bash
[[ $0 != $BASH_SOURCE ]] && \
SCRIPT_PATH=$(realpath $BASH_SOURCE) || \
SCRIPT_PATH="`readlink -f "$0"`"
GSDK_DIR="`dirname "$SCRIPT_PATH"`"
# TODO: activate your python environment here. For example:
# source ~/code/ros_project/env/bin/activate
# The following line installs Olympe Python dependencies into your Python
# virtual environement. It should only be necessary the first time and can
# be commented out after that.
pip install -r "$GSDK_DIR/packages/olympe/requirements.txt"
# Add Olympe and GSDK Python dependencies to your PYTHONPATH
export PYTHONPATH="${PYTHONPATH}:/$GSDK_DIR/out/olympe-linux/final/usr/lib/python/site-packages"
# Add Olympe GSDK C dependencies to LD_LIBRARY_PATH
source "$GSDK_DIR/out/olympe-linux/final/native-wrapper.sh"
Hi, the solution runs very well, thank you very much. However, I have a trivial problem. There is lots of log information in my terminal, which is not I’m expected. As a result, I can not find my own information printed. How can I solve it?
There may be a very small issue for some people who are using ROS Kinetic with Python 3. Since the ROS Kinetic is running under Python 2.7, the command