Crazyswarm: weird behavior with rospy on ROS Melodic

asked 2018-09-26 17:38:22 -0600

TheSS gravatar image

updated 2018-09-27 07:20:45 -0600

gvdhoorn gravatar image

Hi,

I'm using ROS Melodic on Ubuntu Linux 18.04 on an x86_64 machine.

While using the Crazyswarm package I bumped into an error with rospy.

I have a script that imports the modules from the package. The modules then import rospy. My script:

from __future__ import print_function
import numpy as np
import os
import sys
from pycrazyswarm import *

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

    # hover drones
    allcfs.takeoff(targetHeight=0.5, duration=2.0)
    timeHelper.sleep(2.5)

    allcfs.land(targetHeight=0.05, duration=2.0)
    timeHelper.sleep(3.0)

if __name__ == "__main__":

    main()

When I run this, I get the following error:

Traceback (most recent call last):
  File "cga_cfa_cst_acc.py", line 65, in <module>
    main()
  File "cga_cfa_cst_acc.py", line 39, in main
    swarm = Crazyswarm()
  File "/home/tylersummers/ssh_cs_ws_3/crazyswarm/ros_ws/src/crazyswarm/scripts/pycrazyswarm/crazyswarm.py", line 19, in __init__
    import crazyflie
  File "/home/tylersummers/ssh_cs_ws_3/crazyswarm/ros_ws/src/crazyswarm/scripts/pycrazyswarm/crazyflie.py", line 5, in <module>
    import rospy
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/__init__.py", line 49, in <module>
    from .client import spin, myargv, init_node, \
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/client.py", line 52, in <module>
    import roslib
  File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/__init__.py", line 50, in <module>
    from roslib.launcher import load_manifest
  File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/launcher.py", line 42, in <module>
    import rospkg
  File "/usr/lib/python2.7/dist-packages/rospkg/__init__.py", line 42, in <module>
    from .rospack import expand_to_packages, get_package_name, \
  File "/usr/lib/python2.7/dist-packages/rospkg/rospack.py", line 35, in <module>
    from xml.etree.cElementTree import ElementTree
  File "/usr/lib/python2.7/xml/etree/cElementTree.py", line 3, in <module>
    from _elementtree import *
ImportError: PyCapsule_Import could not import module "pyexpat"

When I add import rospy to my script, the script runs normally and the error is gone.

If it helps, my ROS environment variables are:

ROS_ETC_DIR=/opt/ros/melodic/etc/ros
ROS_ROOT=/opt/ros/melodic/share/ros
ROS_MASTER_URI=http://localhost:11311
ROS_VERSION=1
ROS_PYTHON_VERSION=2
ROS_PACKAGE_PATH=/home/tylersummers/ssh_cs_ws_3/crazyswarm/ros_ws/src:/opt/ros/melodic/share
ROSLISP_PACKAGE_DIRECTORIES=/home/tylersummers/ssh_cs_ws_3/crazyswarm/ros_ws/devel/share/common-lisp
ROS_DISTRO=melodic

And my python path is:

/home/tylersummers/ssh_cs_ws_3/crazyswarm/ros_ws/devel/lib/python2.7/dist-packages:/opt/ros/melodic/lib/python2.7/dist-packages

Thank you

edit retag flag offensive close merge delete