日常小坑记录
ROS
安装rosdep
正常步骤
melodic在Ubuntu18.04上的安装
$ sudo rosdep init
ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down.
问题是域名没办法正确解析,方法是在IP查询域名对应可用的ip,我的IP查询结果
raw.githubusercontent.com服务器iP:
当前解析:
日本 东京151.101.108.133
日本 东京151.101.228.133
美国151.101.128.133
美国151.101.0.133
美国151.101.192.133
保留地址0.0.0.0
中国 香港151.101.76.133
尝试ping 中国香港的IP,是通的,然后在/etc/hosts中增加对应ip
sudo vim /etc/hosts
# insert
151.101.76.133 raw.githubusercontent.com
接着就该
rosdep update
不出意外,又出现了错误
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
ERROR: error loading sources list:
('The read operation timed out',)
rosdep update timeout
从结尾可以看出是超时了, 解决方法看其他方法,基本就是4种:
- 更新时间设长一点,可以看参考2;
- 多试几次 or 切手机热点或者其他网络试试;
- 科学上网;
- 把加载的文件提前下载下来.
推荐方法4,一劳永逸,从源头解决问题
- 方法1
在我更新的几次中,发现 进度条是向前的,也就是不是卡在一个文件上更新不了,所以文件还是可以获取的.
有两次卡在了同一个地方
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Add distro "dashing"
Add distro "eloquent"
ERROR: error loading sources list:
('The read operation timed out',)
尝试第一种方法,加大超时时长,可以接着更新了.
我将timeout改成了150,试了大概5,6次后成功了,如果看到进度条一直卡在一个地方可以试试其他方法.
参考1–rosdep init error
参考2–rosdep update
- 方法4
改超时时间简单, 但是不一定有效, 下面来尝试终极的方法4, 将从raw.githubusercontent.com获取内容的方式变成先下载文件, 再替换文件的方式, 具体的步骤为
注意: 替换your_host为自己的用户名
比如 /home/admin/
# 建立一个位置存放资源文件
cd ~ && mkdir repo && cd repo
# 记录当前文件位置, 应该为/home/your_host/repo
pwd
# 从源获取文件
git clone https://github.com/ros/rosdistro.git
# 修改rep3.py文件
sudo vi /usr/lib/python2.7/dist-packages/rosdep2/rep3.py
# 将'https://raw.githubusercontent.com/ros/rosdistro/master/releases/targets.yaml'
# 替换为 'file:///home/your_host/repo/rosdistro/releases/targets.yaml'
# 修改__init__.py文件
sudo vi /usr/lib/python2.7/dist-packages/rosdistro/__init__.py
# 将'https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'
# 替换为 'file:///home/cwj/Repo/rosdistro/index-v4.yaml'
# 生成20-default.list
suod rosdep init
# 如果已经init过,则会提示已有该文件
# 修改20-default.list
sudo vi /etc/ros/rosdep/sources.list.d/20-default.list
# 替换所有的https://raw.githubusercontent.com/ros/rosdistro/master
# 为 file:///home/your_host/repo/rosdistro
rosdep update
OpenCV
OpenCV_contrib使用
Version
OpenCV & OpenCV_contrib 3.4.6
Reason
由于不可抗力,需要使用fast_line_detector模块,所以需要使用ximgproc功能,编译OpenCV时遇到一点小问题,记录在这里
cmake
直接阅读OpenCV_contrib的README会提示在cmake命令行中加入modules选项,但是我不需要完全安装,只需要两个模块就OK了,解决也很简单,直接试了试就好了
在CMakeLists.txt中修改一行
# 路径不对可以试试绝对路径
set(OPENCV_EXTRA_MODULES_PATH "${HOME}/repo/opencv_contrib/modules/line_descriptor;${HOME}/repo/opencv_contrib/modules/ximgproc" CACHE PATH "Where to look for additional OpenCV modules (can be ;-separated list of paths)")
# 增加一个flag
set(OPENCV_ENABLE_NONFREE "True")
Could not find JNI
sudo apt-get install -y openjdk-8-jdk
sudo apt-get install -y default-jdk
# 如果是arch的话,最好用tab补全一下最后的文件目录
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
# 还可以设置几个选项在cmakelists.txt中,具体那几个,查查应该有
video.h No such file or directory
sudo apt install libv4l-devel
sudo ln -s /usr/include/libv4l1-videodev.h /usr/include/linux/videodev.h
ROS2
dashing
写dashing的launch文件的时候,遇到一个很奇怪的东西,语法大概是
Node(
parameters=[{
"foo": "good",
"bar": "111"
}]
)
其中bar是一个string类型,但是读取后实际上是以int型使用的,就报了一个错
terminate called after throwing an instance of 'rclcpp::ParameterTypeException'
what(): expected [string] got [integer]
其实是一个python的“”, ‘’ 也就是双引号和单引号的配合使用,如果要将111表示不被类型推导转化的字符串,需要" ‘111’ "。
官方的Guide里是有举例的。