Building a conda environment for ROS users

When you want to do machine learning that is popular these days, it is difficult to build an environment with Python. The local environment is also dirty ... I often see materials that use Anaconda or Miniconda as teaching materials that allow you to learn machine learning while moving the code. And when creating these environments, ROS users often have a lot of trouble, but surprisingly there are few articles, so I decided to leave it here. The environment is as follows.

Miniconda installation

Download the 64-bit version of Python 3.7 from here

$ cd ~/Downloads
$ bash Miniconda3-latest-Linux-x86_64.sh

Execute the above command and proceed with the installation according to the instructions of the terminal. Finally, you will be asked if you want to execute `` `conda init```, so if you answer yes, the environment construction will be completed.

See below for what happens when you run conda init if the installation is successful.

Screenshot from 2019-11-24 15-35-37 (コピー).png

It seems that .bashrc will be edited, so let's check the contents for the time being. The following parts have been added.

Screenshot from 2019-11-24 15-38-05.png

Be careful here!

When reading ROS with .bashrc, the following warning is displayed when `` `conda init```.

Screenshot from 2019-11-21 14-29-54 (コピー).png

When loading the ROS environment, PYTHONPATH now points to /opt/ros/melodic/lib/python2.7/dist-packages. So, let's disable ROS loading before installation.

Building a ROS environment using conda

Just type the following command

$ conda create --name ros --channel conda-forge ros-core ros-actionlib ros-dynamic-reconfigure python=2.7
$ conda activate ros

With this alone, it is convenient to create a ROS environment on the virtual environment of conda. You can use basic commands such as roscore, rosrun, and roslaunch.

Self-made package

When running ROS in a virtual environment using conda, it is a self-made package that is worrisome. Since ROS1 is used this time, catkin_make is required when creating packages etc. in C ++.

https://github.com/nakano16180/roscpp_practice I used the package linked above this time.

Stuck point

Originally, you can clone the github package and catkin_make to start it with rosrun. But this time I got stuck here. It seems that the path to pthread does not pass?

Screenshot from 2019-11-28 16-50-24.png

To solve this, I edited CMakeLists.txt as follows.

CMakeLists.txt

CMakeLists.txt


cmake_minimum_required(VERSION 2.8.3)
project(roscpp_practice)

## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
  rosbag
)

## System dependencies are found with CMake's conventions
find_package(Boost REQUIRED COMPONENTS system)
find_package(Threads REQUIRED)  #Added here


## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()

###########
## Build ##
###########

## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
# include
  ${catkin_INCLUDE_DIRS}
)

## Declare a C++ library
# add_library(${PROJECT_NAME}
#   src/${PROJECT_NAME}/roscpp_practice.cpp
# )

## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
# add_executable(${PROJECT_NAME}_node src/roscpp_practice_node.cpp)
add_executable(talker src/talker.cpp)
add_executable(listener src/listener.cpp)
add_executable(bag_write src/bag_write.cpp)
add_executable(bag_read src/bag_read.cpp)

## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")

## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Specify libraries to link a library or executable target against
# target_link_libraries(${PROJECT_NAME}_node
#   ${catkin_LIBRARIES}
# )
target_link_libraries(talker
  ${catkin_LIBRARIES}
  Threads::Threads  ##Postscript
)
target_link_libraries(listener
  ${catkin_LIBRARIES}
  Threads::Threads  ##Postscript
)
target_link_libraries(bag_write
  ${catkin_LIBRARIES}
  Threads::Threads  ##Postscript
)
target_link_libraries(bag_read
  ${catkin_LIBRARIES}
  Threads::Threads  ##Postscript
)

By editing as above, I was able to build and execute it safely. Screenshot from 2019-11-30 14-20-03.png

Finally

I've written so far, but let's move to ROS2, which can use Python3, as soon as possible!

Recommended Posts

Building a conda environment for ROS users
[Mac] Building a virtual environment for Python
Building a Python development environment for AI development
Building a virtual environment for Mayavi dedicated to Python 3.6, Anaconda, Spyder users
Building a Python environment for pyenv, pyenv-virtualenv, Anaconda (Miniconda)
Recommendation of building a portable Python environment with conda
Building a Docker working environment for R and Python
Building a training environment for penetration testing using Naumachia
Procedure for building a CDK environment on Windows (Python)
conda memorandum: Building a Python environment with supercomputer ITO
Building a Python environment for programming beginners (Mac OS)
Building a Python virtual environment
Memo for building a machine learning environment using Python
Building a python environment for artificial intelligence (Chainer / TensorFlow / CSLAIER)
Building a development environment for Android apps-creating Android apps in Python
Building a Hy environment for Lisper who hasn't touched Python
Building a kubernetes environment with ansible 2
Building a Python environment on Mac
Building a Python environment on Ubuntu
Building a virtual environment with Python 3
Building a kubernetes environment with ansible 1
Building a Docker working environment for R and Python 2: Japanese support
How about Anaconda for building a machine learning environment in Python?
Building a Windows 7 environment for getting started with machine learning with Python
[Pyenv] Building a python environment with ubuntu 16.04
Building a Python3 environment with Amazon Linux2
Building a virtual environment using homebrew + pyenv-virtualenv
Building a LaTeX environment on Chrome OS
Let's create a virtual environment for Python
Build a TOP screen for Django users
Building a Python 3.6 environment with Windows + PowerShell
ROS course 107 Make a client for rosblidge
Creating a development environment for machine learning
Building an environment for "Tello_Video" on Raspbian
Building an environment for "Tello_Video" on Windows
Procedure for building a kube environment on amazon linux2 (aws) ~ (with bonus)
Selenium + WebDriver (Chrome) + Python | Building environment for scraping
Prepare a programming language environment for data analysis
Building a python environment with virtualenv and direnv
Building an environment for executing Python scripts (for mac)
Building an Anaconda environment for Python with pyenv
Building a Python environment with WLS2 + Anaconda + PyCharm
I created a Dockerfile for Django's development environment
ROS environment setup ①
Building an environment for matplotlib + cartopy on Mac
[Python] Web development preparation (building a virtual environment)
Think about building a Python 3 environment in a Mac environment
Commands for creating a python3 environment with virtualenv
Build a Kubernetes environment for development on Ubuntu
Procedure for creating a Python quarantine environment (venv environment)
Try building an environment for MayaPython with VisualStudioCode
A memo for creating a python environment by a beginner
Building a Python environment on a Sakura VPS server
Build a mruby development environment for ESP32 (Linux)
Procedure when building Ubuntu as a virtual environment with Vagrant + Virtualbox for LPIC Level 1.
Build a local development environment for Laravel6.X on Mac
Building an environment for "Tello_Video" on Mac OS X
Build a python environment for each directory with pyenv-virtualenv
Building a TensorFlow environment that uses GPU on Windows 10
Building an environment for natural language processing with Python
Building and enabling a python virtual environment, etc. (venv)