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.
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.
It seems that .bashrc will be edited, so let's check the contents for the time being. The following parts have been added.
When reading ROS with .bashrc, the following warning is displayed when `` `conda init```.
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.
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.
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.
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?
To solve this, I edited CMakeLists.txt as follows.
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.
I've written so far, but let's move to ROS2, which can use Python3, as soon as possible!
Recommended Posts