Use Olympe from a ROS program

Hello,

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:

  1. Run ROS in an Olympe environment
    or
  2. Import Olympe functions into the global python environments.

Thank you for your help/ suggestions in advance. :slight_smile:

Hello,

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.

Regards

Nicolas

Hello,

Thank you very much for the reply. This seems to be exactly what I am after, specifically Option 2.

  • How can we populate the PYTHONPATH variable to add olympe and its dependencies?
    : Can you please provide a sample script that does this?

Thank you very much for your time.

Hi!

  1. 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"
  1. Activate your Python virtual environment (or edit the script above to activate your environment from it).
  2. Source the script into your current shell source ./olympe_custom_env.sh

Hello,

Thanks for the reply again. When I follow step 3, my current shell window closes out. Here’s what I am doing exactly:

  1. I’ve created a shell file named “olympe_custom_env.sh” in my ~/code/parrot-groundsdk folder
  2. The ROS projects use the default python interpreter, so in my shell I run #!/usr/bin/env python
  3. From the ~/code/parrot-groundsdk folder, I run the command source ./olympe_custom_env.sh in the shell in which I ran step-2.

When i run step 3, the shell exits out, and I am starting over. Am I following the steps correctly ?

How can I import Olympe without activating a virtual environment? (I am trying to use Olympe with AWS Greengrass).

Hi,

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).

Could you please retry now? Thanks

1 Like

Hi @jonsl0,

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.

Hello,

This worked with a small edit to your script. I used
export PYTHONPATH="${PYTHONPATH}:/$GSDK_DIR/out/olympe-linux/final/usr/lib/python/site-packages"

instead of

export PYTHONPATH="$GSDK_DIR/out/olympe-linux/final/usr/lib/python/site-packages"

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+ ?

Once again, thank you very much for the replies.

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!!!

1 Like

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"

Courtesy of the original script: @ndessart.

  1. Install ROS packages for python 3 using pip3 install rospkg

  2. Source the script using source ./olympe_custom_env.sh.

  3. Now a Python3 program executed from this terminal can import both Olympe and ROS packages.

2 Likes