robotology / icub-tutorials

Tutorials on iCub code
19 stars 9 forks source link

IPOPT does not work with iKin #16

Closed linzdg closed 4 years ago

linzdg commented 4 years ago

I Compiled IpOpt 3.12.12, and I haved tested it(~/open/Ipopt-3.12.12/build/Ipopt/examples/WDS$ ./hs071_cpp ) could work.

Environment variable had set: export IPOPT_DIR=/home/ccc/open/Ipopt-3.12.12/build

I run three examples with icub-tutorials/src/

  1. smoke-tests

    ccc@ccc-HP-340-G4:~/open/icub-tutorials/src/smoke-tests$ ./ipopt Ipopt:testing correct installation... Segmentation fault (core dumped)

  2. icub-tutorials/src/iKin/iCubLimbsFwKin which didn't display segmentation fault

    ccc@ccc-HP-340-G4:~/open/icub-tutorials/src/iKin/iCubLimbsFwKin$ ./iCubLimbsFwKin Asked for type "left" Type used "left" kinematics="eye/left" q=( 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000) H= 0.00000 0.00000 -1.00000 -0.06281 1.00000 0.00000 0.00000 -0.03400 0.00000 -1.00000 -0.00000 0.34080 0.00000 0.00000 0.00000 1.00000

  3. icub-tutorials/src/iKin/fwInvKinematics showed segmentation fault at below code // instantiate a IPOPT solver for inverse kinematic // for both translational and rotational part iKinIpOptMin slv(*chain,IKINCTRL_POSE_FULL,1e-3,1e-6,100);

ccc@ccc-HP-340-G4:~/open/icub-tutorials/src/iKin/fwInvKinematics$ ./fwInvKinematics joint 0 in [-95.5,5] set to -45.25 joint 1 in [0,160.8] set to 80.4 joint 2 in [-37,90] set to 26.5 joint 3 in [5.5,106] set to 55.75 joint 4 in [-90,90] set to 0 joint 5 in [-90,0] set to -45 joint 6 in [-20,40] set to 41 Actual joints set to -45.250000 80.400000 26.500000 55.750000 0.000000 -45.000000 40.000000 Torso blocked links at: 0 0 0 Unblocking the first torso joint... 8 DOFs available Blocking the first torso joint again... 7 DOFs available Current arm end-effector pose: -0.205914 0.364357 0.225312 -0.508262 -0.779788 0.365513 2.097540 Segmentation fault (core dumped)

How can I solve this problem? Thanks in advance.

traversaro commented 4 years ago

On which system are you running this tutorial? If you are on Ubuntu, installing coinor-libipopt-dev should be enough to run all the iKin related software. There is any specific reason why you compile your own ipopt? What I suspect is happening is that some libraries or executable are linking the system-installed ipopt, while some other your custom ipopt, and this is creating the segmentation fault errors.

pattacini commented 4 years ago

Hi @linzdg

I think @traversaro is right: it's quite likely that a mixed installation is causing the seg-fault. My recommendation is to try installing the system as per the instructions available in our Wiki: https://wiki.icub.org/wiki/ICub_Software_Installation.

You can click on the badge below and get the latest software running on a Cloud IDE. Ipopt is working as expected along with icub-tutorials.

Open in Gitpod

linzdg commented 4 years ago

On which system are you running this tutorial? If you are on Ubuntu, installing coinor-libipopt-dev should be enough to run all the iKin related software. There is any specific reason why you compile your own ipopt? What I suspect is happening is that some libraries or executable are linking the system-installed ipopt, while some other your custom ipopt, and this is creating the segmentation fault errors.

Now I uninstall IPOPT3.12.12, and installing coinor-libipopt-dev. ICUB_CMAKE_OPTIONS -ICUB_USE_IPOPT = ON, IPOPT_DIR = /usr
It showed that CMake Error at /usr/local/share/cmake-3.16/Modules/FindPackageHandleStandarArgs.cmake:146(could NOT find IPOPT(missing:IPOPT_LIBRARIES))

CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: /home/ccc/open/icub-main/src/libraries/iKin/IPOPT_INCLUDE_DIRS used as include directory in directory

pattacini commented 4 years ago

Unfortunately, troubleshooting installations is not that easy and tends to be way time consuming as many factors play their role quite silently under the hood.

The golden rule of debugging states that we ought to start from a clean condition and this is also our recommendation. Tracing back the problem on your machine might be a long journey − especially if we don't have access to it − forcing our minds to figure out what sort of problem could be causing this stumbling issue and, most of all, leading you to waste possibly plenty of hours unfruitfully.

The easiest solution then is to try out everything from scratch, either by grabbing a new machine or even better by experimenting with Docker containers.

Here are the instructions to install dependencies for icub-tutorials correctly:

# Update apt database
apt update

# Install essentials
apt install -y apt-utils software-properties-common apt-transport-https sudo \
               psmisc lsb-release nano wget curl build-essential gdb git gitk \
               libedit-dev libxml2-dev autoconf

# Install the most recent cmake
apt install -y ca-certificates gnupg
wget -q https://apt.kitware.com/keys/kitware-archive-latest.asc -O- | apt-key add -
apt-add-repository "deb https://apt.kitware.com/ubuntu/ `lsb_release -cs` main"
apt update
apt install -y kitware-archive-keyring
apt-key --keyring /etc/apt/trusted.gpg del C1F34CDD40CD72DA
apt install -y cmake cmake-curses-gui

# Install yarp dependencies
echo "deb http://www.icub.org/ubuntu `lsb_release -cs` contrib/science" > /etc/apt/sources.list.d/icub.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 57A5ACB6110576A6
apt update
apt install -y icub-common

# Download and build Distro 2019.12.feat-02 (see https://wiki.icub.org/wiki/Software_Versioning_Table)

# YCM
git clone https://github.com/robotology/ycm.git -b v0.11.0
cd ycm && mkdir build && cd build
cmake .. \
      -DCMAKE_BUILD_TYPE=Release
make install

# YARP
git clone https://github.com/robotology/yarp.git -b v3.3.0
cd yarp && mkdir build && cd build
cmake .. \
      -DCMAKE_BUILD_TYPE=Release \
      -DYARP_COMPILE_libYARP_math=ON \
      -DYARP_COMPILE_CARRIER_PLUGINS=ON \
      -DYARP_COMPILE_DEVICE_PLUGINS=ON \
      -DYARP_COMPILE_GUIS=ON
make install

# icub-main
git clone https://github.com/robotology/icub-main.git -b v1.14.1
cd icub-main && mkdir build && cd build
cmake .. \ 
      -DCMAKE_BUILD_TYPE=Release \
      -DENABLE_icubmod_cartesiancontrollerserver=ON \
      -DENABLE_icubmod_cartesiancontrollerclient=ON \
      -DENABLE_icubmod_gazecontrollerclient=ON
make install

# icub-contrib-common
git clone https://github.com/robotology/icub-contrib-common.git -b v1.14.0
cd icub-contrib-common && mkdir build && cd build
cmake ..
make install

# Set environmental variables
echo "export YARP_DATA_DIRS=/usr/local/share/yarp:/usr/local/share/iCub:/usr/local/share/ICUBcontrib" >> ~/.bashrc
echo "export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib/yarp" >> ~/.bashrc

Incidentally, these instructions represent a subset of the Docker recipe I used to construct the image underlying the Gitpod snapshot I pointed you at in my earlier post. If you're not familiar with Docker, just go for the instructions detailed above and run them on the cleanest machine you can get.

linzdg commented 4 years ago

I ran them on the new machine and followed the steps. Everything is OK! I really appreciate your help! Thank you very much!

pattacini commented 4 years ago

That's great 👍