ubuntu18.04 docker ros
1.需要一台安装好ubuntu18.04的PC机。
2.需要安装好docker,并在docker中安装好ros环境。(客户提供的docker镜像)
3.需要在ubuntu18.04中安装好ros环境。
注:
(1)以上所有的安装网上应该都有,不过我在亲自安装Ubuntu18.04下的ros环境时,确实走了很多坑,因为和ros教程中的结果不太一样,不过经过不断努力,都还是可以解决的。环境搭建这块就不详细说明了。
(2)会创建docker容器,会容器的基本操作。
(3)会ros基本命令。
下面就说说我是怎么解决的。。。
1.首先需要在Ubuntu18.04的终端下开启ros,还有在创建的容器中开启ros
roscore
2.新建Ubuntu终端,查看ip
ifconfig (或ifconfig -a)
Ubuntu18.04在docker中回放ros的点云数据,并在Ubuntu中不点云(
查看得到宿主机decker0的ip:172.17.0.1
3.新建容器,并进入容器,查看容器ip
ifconfig (或ifconfig -a)
Ubuntu18.04在docker中回放ros的点云数据,并在Ubuntu中不点云(
查看得到容器的ip:172.17.0.2
4.重新开启Ubuntu终端
输入
vim ~/.bashrc (无权限则执行sudo vim ~/.bashrc)
打开文件,添加
export ROS_HOSTNAME=172.17.0.1
export ROS_MASTER_URL=http://172.17.0.2:11311
保存文件,重新source
source ~/.bashrc
5.重新开启容器终端
输入
vim ~/.bashrc (无权限则执行sudo vim ~/.bashrc)
打开文件,添加
export ROS_HOSTNAME=172.17.0.2
export ROS_MASTER_URL=http://172.17.0.2:11311
保存文件,重新source
source ~/.bashrc
6.拷贝回放数据到容器中,在容器中运行回放数据
输入
rosbag play 2020-08-12-07-31-18.bag
我的bag名称是 2020-08-12-07-31-18.bag。以实际为准,回车,能看到数据在回放。
Ubuntu18.04在docker中回放ros的点云数据,并在Ubuntu中不点云(
7.分别开启新的Ubuntu终端和容器终端,执行
rostopic list
能发现有相同节点在目录下 /lidar_points
Ubuntu18.04在docker中回放ros的点云数据,并在Ubuntu中不点云(
8.在Ubuntu终端中执行显示点云窗口
输入
rosrun rviz rviz
在弹出的窗口中,将lidar_points ,add进去。
注:需要将Displays部分的Fixed Frame改成world
Ubuntu18.04在docker中回放ros的点云数据,并在Ubuntu中不点云(
9.点云即可正常显示
Ubuntu18.04在docker中回放ros的点云数据,并在Ubuntu中不点云(
至此一步,点云已经能在docker中回放,在宿主机上显示了。我接手这个环境配置也只有一周时间,这一周,真不知道怎么过来的,搭建docker是坑,搭建ros是坑,配置ROS_MASTER_URL也是坑。。。但是只要坚持,还是都挺过来了,各位小伙伴加油!
假设条件
A电脑中安装了ros, B电脑安装了docker,docker中安装了ros系统。即B电脑为机器人内部使用,B电脑为master,故需采用A电脑进行远程调试与控制。
查看B电脑的当前的IP地址,采用ifconfig命令如下:
pi@raspberrypi:~/docker_ros $ ifconfig
docker0: flags=4099 mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:91:6a:c3:a7 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163 mtu 1500
inet 192.168.1.113 netmask 255.255.255.0 broadcast 192.168.5.255
inet6 fe80::fe56:c579:853d:6e5d prefixlen 64 scopeid 0x20
ether dc:a6:32:80:2c:45 txqueuelen 1000 (Ethernet)
RX packets 354776 bytes 401333083 (382.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 352905 bytes 222508344 (212.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
docker 容器ros网络配置
进入容器后,需要进行配置ros网络参数,进入终端后,先执行
export ROS_MASTER_URI=http://192.168.1.113:11311
export ROS_HOSTNAME=192.168.1.113
Pytorch
模型训练:
optimizer.zero_grad() 清空过往梯度;
loss.backward() 反向传播,计算当前梯度;
optimizer.step() 根据梯度更新网络参数
or
for i in range(num):
loss+=Loss(input,target)
optimizer.zero_grad() 清空过往梯度;
loss.backward() 反向传播,计算当前梯度;
optimizer.step() 根据梯度更新网络参数
例如车道线训练:
def __init__(self):
super(Agent, self).__init__()
self.p = Parameters()
self.lane_detection_network = lane_detection_network()
self.setup_optimizer()
self.current_epoch = 0
self.hard_sampling = hard_sampling.hard_sampling()
print("model parameters: ")
print(self.count_parameters(self.lane_detection_network))
def setup_optimizer(self):
self.lane_detection_optim = torch.optim.Adam(self.lane_detection_network.parameters(), lr=self.p.l_rateweight_decay=self.p.weight_decay)
..........
self.lane_detection_optim.zero_grad()
lane_detection_loss.backward() # divide by batch size
self.lane_detection_optim.step()
Qt qmake問題
問題:
qmake –v
ros 編譯報錯 /usr/lib/x86_64-linux-gnu/qt5/bin/qmake 不存在
辦法:
重新安裝
https://download.qt.io/archive/qt/5.12/5.12.4/single/
下載qt-opensource-linux-x64-5.12.10.run
sudo ./qt-opensource-linux-x64-5.12.10.run
默認安裝在 opt下
目錄在 /opt/Qt5.12.10/5.12.10/gcc_64
但是ubuntu默認路徑在
/usr/lib/x86_64-linux-gnu/qt5
因此建立鏈接 copy文件到上面目錄即可
先把原来的删除:
sudo rm /usr/bin/qmake
连接:
ln -s /opt/Qt5.12.10/5.12.10/gcc_64/bin/qmake /usr/bin/qmake