备份与整理大学期间的笔记:基于匿名凌霄飞控与树莓派的四旋翼无人机在未知复杂度环境的自主探索系统
-
Ubuntu 18.04 的代号
Xenial Xerus
-
Ubuntu 18.04 的代号
bionic
-
Ubuntu 20.04 的代号
focal
-
Ubuntu 22.04 的代号
jammy
-
Ubuntu 24.04 的代号
Noble Numbat
树莓派环境搭建
-
下载树莓派镜像
打开网址Ubuntu 20.04.5 LTS (Focal Fossa)
下滑到底,选择下载:ubuntu-20.04.5-preinstalled-server-arm64+raspi.img.xz.zsync(755M)
-
使用Raspberry Pi Imager烧录
先使用SD Card Formatter格式化SD卡,再烧录,此过程容易失败
-
配置网络(建议先用自己的热点,可以看到是否有连接设备)
sudo vim /etc/netplan/50-cloud-init.yaml
-
生效网络配置
sudo netplan generate
sudo netplan apply
ifconfig
(需要下载,sudo apt-get install net-tools) -
配置国内镜像源
sudo vim /etc/apt/sources.list
将所有地址deb http开头的网址修改
https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/
键入ESC->:->
wq
-
更新系统(约半小时)
sudo apt-get update
sudo apt-get upgrade
-
下载Ubuntu桌面版(约半小时)
sudo apt install ubuntu-desktop
sudo apt install xrdp
-
重启系统
reboot
安装远程桌面(可跳过本步骤,先下一步)
-
下载Nomachine远程桌面
进入网址NoMachine - Download NoMachine for Arm点击下载
上述网址失效:浏览器搜索nomachine_7.6.2_3_arm64.deb ->点击第一个Nomachine-> NoMachine for ARM ARMv8 DEB->Download
将该.deb传输到Ubuntu中
运行下载
sudo dpkg -i nomachine_xxx(按Tab自动补全)
修改nomachine配置
sudo vim /usr/NX/etc/server.cfg
键入ESC->键入GG至文末->键入i编辑
PhysicalDesktopAuthorization 0
AutomaticDisconnection 1
键入ESC->键入:->键入wq保存
重启配置
sudo /usr/NX/bin/nxserver --restart
下载Nomachine的Windows版本->打开->系统自动扫描同一网段的启用该程序设备->输入账号密码连接
ROS基本工作环境搭建
-
ros一键安装工具(注意-O大写)
wget http://fishros.com/install -O fishros && . fishros
-
创建工作空间
mkdir -p ~/catkin_ws/src
-
初始化工作空间
cd ~/catkin_ws/src
catkin_init_workspace
-
编译工作空间
cd ~/catkin_ws/
catkin_make
-
配置环境变量(使终端能正确识别和使用 ROS 的命令和包)
source devel/setup.bash
以上为暂时的,永久配置如下
gedit ~/.bashrc
在末尾添加
source /home/username/catkin_ws/devel/setup.bash
source ~/.bashrc //保存文件后使其生效
启动串口通信(可跳过本步骤,先下一步)
-
下载树莓派硬件交互包
sudo apt install libraspberrypi-bin
-
查看所有串口
dtoverlay -a | grep uart
-
配置串口
sudo gedit /boot/config.txt
文末添加
dtoverlay=uart2
dtoverlay=uart3
dtoverlay=uart4
dtoverlay=uart5
-
重启确认是否生效
reboot
ls /dev/ttyAMA*
若生效会输出AMA0-4设备
UART与GPIO对应关系
GPIO14 = TXD0 -> ttyAMA0 GPIO0 = TXD2 -> ttyAMA1 GPIO4 = TXD3 -> ttyAMA2 GPIO8 = TXD4 -> ttyAMA3 GPIO12 = TXD5 -> ttyAMA4
GPIO15 = RXD0 -> ttyAMA0 GPIO1 = RXD2 -> ttyAMA1 GPIO5 = RXD3 -> ttyAMA2 GPIO9 = RXD4 -> ttyAMA3 GPIO13 = RXD5 -> ttyAMA4
-
使用python测试
pi@raspberrypi:~ $ python3 Python 3.7.3 (default, Jul 25 2020, 13:03:44) [GCC 8.3.0] on linux Type ``"help"``, ``"copyright"``, ``"credits"` `or ``"license"` `for` `more` `information. >>> ``import` `serial >>> ted5 = serial.Serial(port="/dev/ttyAMA4", baudrate=9600) >>> ted5.write("Hello No.5".encode("gbk")) 10 >>> ted5.read(10) b'Hello No.5'
-
打开串口3(连接至雷达)串口5(连接至飞控)
/boot/uEnv/board.txt (board 是你所用的板子的名称)
-
将内存缓冲区中的数据强制写入磁盘并重启
sync
reboot
-
检查是否使能成功
ls /dev/tty*
N10雷达环境搭建
-
编译原始N10包
将lsn10包导入src工作区
下载编译工具
sudo apt-get install libpcap-dev
编译
cd ~/catkin_ws/
catkin_make -DCATKIN_WHITELIST_PACKAGES=lslidar_msgs
catkin_make -DCATKIN_WHITELIST_PACKAGES=lslidar_driver
-
导入CH343驱动
下载ch343ser_linux驱动包,并解压
进入解压后的驱动包的driver目录
cd ./ch343ser_linuxxxx/driver
右键点击Open in Terminal进入此目录终端
查看是否有adc模块
lsmod | grep cdc_acm
有输出的话卸载,否则跳过本步骤
sudo rmmod cdc_acm
编译规则
make
载入模块
sudo make load
将文件安装至指定目录
sudo make install
使系统自动装载该驱动
sudo gedit /etc/modules
重启系统
reboot
查看是否装载
ll /dev | grep ttyCH343USB
-
运行程序
启动雷达
roslaunch lslidar_driver lslidar_serial.launch
启动点云
rivz
修改索引
RVIZ->左上方Displays->Fixed Frame->修改参数为->
laser
添加索引
RVIZ->左下角add->By topic->/scan->LaserScan->OK
SLAM环境搭建
-
GitHub下载对应的hector-mapping包放入src中
git clone https://github.com/tu-darmstadt-ros-pkg/hector_slam
-
调用lslidar_serial.launch
cp ~/catkin_ws/src/lsx10/lslidar_driver/launch/lslidar_serial.launch ~/catkin_ws/src/hector_slam/hector_mapping/launch/laser_ys.launch
-
新建 ROS 节点的配置文件
vim ~/catkin_ws/src/hector_slam/hector_mapping/launch/slam_ys.launch
<?xml version="1.0"?>
<launch> <!-- hector_mapping lidar开启雷达 --> <include file="$(find hector_mapping)/launch/laser_ys.launch" />
<!-- 开启hector建图算法 --> <include file="$(find hector_mapping)/launch/mapping_default.launch" />
<node pkg="tf" type="static_transform_publisher" name="odom_to_base" args="0.0 0.00 0.0 0 0 0 odom_combined base_footprint 100" />
<node pkg="tf" type="static_transform_publisher" name="base_to_laser" args="0.0 0.00 0.0 3.14 0 0 base_footprint laser 100" />
<!--打开rviz--> <node name="rviz" pkg="rviz" type="rviz" args="-d $(find hector_mapping)/rviz/hector.rviz" /> </launch>
-
修改mapping_default.launch配置文件
修改第六行
<arg name="odom_frame" default="odom_combined"/>
保存退出
-
新建rviz配置
vim ~/catkin_ws/src/hector_slam/hector_mapping/rviz/hector.rviz
Panels:
-
Class: rviz/Displays Help Height: 78 Name: Displays Property Tree Widget: Expanded: ~ Splitter Ratio: 0.5 Tree Height: 572
-
Class: rviz/Selection Name: Selection
-
Class: rviz/Tool Properties Expanded:
-
/2D Pose Estimate1
-
/2D Nav Goal1
-
/Publish Point1 Name: Tool Properties Splitter Ratio: 0.5886790156364441
-
-
Class: rviz/Views Expanded:
-
/Current View1 Name: Views Splitter Ratio: 0.5
-
-
Class: rviz/Time Experimental: false Name: Time SyncMode: 0 SyncSource: "" Preferences: PromptSaveOnExit: true Toolbars: toolButtonStyle: 2 Visualization Manager: Class: "" Displays:
-
Alpha: 0.5 Cell Size: 1 Class: rviz/Grid Color: 160; 160; 164 Enabled: true Line Style: Line Width: 0.029999999329447746 Value: Lines Name: Grid Normal Cell Count: 0 Offset: X: 0 Y: 0 Z: 0 Plane: XY Plane Cell Count: 10 Reference Frame: <Fixed Frame> Value: true
-
Class: rviz/TF Enabled: true Frame Timeout: 15 Frames: All Enabled: true base_footprint: Value: true laser: Value: true odom_combined: Value: true Marker Scale: 1 Name: TF Show Arrows: true Show Axes: true Show Names: true Tree: {} Update Interval: 0 Value: true
-
Alpha: 0.699999988079071 Class: rviz/Map Color Scheme: map Draw Behind: false Enabled: true Name: Map Topic: /map Unreliable: false Use Timestamp: false Value: true
-
Alpha: 1 Autocompute Intensity Bounds: true Autocompute Value Bounds: Max Value: 10 Min Value: -10 Value: true Axis: Z Channel Name: intensity Class: rviz/LaserScan Color: 255; 255; 255 Color Transformer: Intensity Decay Time: 0 Enabled: true Invert Rainbow: false Max Color: 255; 255; 255 Max Intensity: 47 Min Color: 0; 0; 0 Min Intensity: 47 Name: LaserScan Position Transformer: XYZ Queue Size: 10 Selectable: true Size (Pixels): 3 Size (m): 0.009999999776482582 Style: Flat Squares Topic: /scan Unreliable: false Use Fixed Frame: true Use rainbow: true Value: true Enabled: true Global Options: Background Color: 48; 48; 48 Default Light: true Fixed Frame: map Frame Rate: 30 Name: root Tools:
-
Class: rviz/Interact Hide Inactive Objects: true
-
Class: rviz/MoveCamera
-
Class: rviz/Select
-
Class: rviz/FocusCamera
-
Class: rviz/Measure
-
Class: rviz/SetInitialPose Theta std deviation: 0.2617993950843811 Topic: /initialpose X std deviation: 0.5 Y std deviation: 0.5
-
Class: rviz/SetGoal Topic: /move_base_simple/goal
-
Class: rviz/PublishPoint Single click: true Topic: /clicked_point Value: true Views: Current: Class: rviz/Orbit Distance: 14.049280166625977 Enable Stereo Rendering: Stereo Eye Separation: 0.05999999865889549 Stereo Focal Distance: 1 Swap Stereo Eyes: false Value: false Focal Point: X: 0 Y: 0 Z: 0 Focal Shape Fixed Size: true Focal Shape Size: 0.05000000074505806 Invert Z Axis: false Name: Current View Near Clip Distance: 0.009999999776482582 Pitch: 1.5697963237762451 Target Frame: <Fixed Frame> Value: Orbit (rviz) Yaw: 1.705397605895996 Saved: ~ Window Geometry: Displays: collapsed: false Height: 869 Hide Left Dock: false Hide Right Dock: false QMainWindow State: 000000ff00000000fd000000040000000000000156000002c7fc0200000008fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000005c00fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000003d000002c7000000c900fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261000000010000010f0000037cfc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a0056006900650077007300000000270000037c000000a400fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000003a00000003efc0100000002fb0000000800540069006d00650100000000000003a0000002eb00fffffffb0000000800540069006d0065010000000000000450000000000000000000000244000002c700000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000 Selection: collapsed: false Time: collapsed: false Tool Properties: collapsed: false Views: collapsed: false Width: 928 X: 562 Y: 108
-
-
-
重新编译工作空间
catkin_make -DCATKIN_WHITELIST_PACKAGES=hector_mapping
-
运行RVIZ视图空间
roslaunch hector_mapping slam_ys.launch
-
添加操作指令
rviz视图左下角ADD
RVIZ->Create visuallzation->By display type->RobotModel
-
修改参数
RVIZ->LaserScan->Size-> 0.07
-
保存地图
安装map_server包
sudo apt-get install ros-noetic-map-server
保存地图
rosrun map_server map_saver -f ~/my_map
-
查看坐标系与话题关系
rosrun tf view_frames
evince frames.pdf
若报错TypeError: cannot use a string pattern on a bytes-like object
sudo gedit /opt/ros/noetic/lib/tf/view_frames
搜索
m = r.search(vstr)
(第89行),在这行前面添加vstr=str(vstr)
即可。再次运行
rosrun tf view_frames
-
hector_mapping运行时的节点和话题关系
rqt_graph
一般会报错,解决方案如下:
sudo apt-get install ros-noetic-rqt sudo apt-get install ros-noetic-rqt-graph sudo apt-get install ros-noetic-rqt-common-plugins
或者使用rqt或rosrun查询话题
rqt
rosrun rqt_graph rqt_graph
查看节点与节点之间的关系
plugins->Introspection / Node Graph
插件可以看到所有与ROS2相关的进程
Introspection / Process Monitor
获取base_link的姿态
rosrun tf tf_echo /map /base_link
实现开机自启
-
安装robot_upstart功能包实现节点开机自启
sudo apt-get install ros-noetic-robot-upstart
-
自启动设置
rosrun robot_upstart install <package_name>/launch/<launch_file>.launch
启动任务,只需要启动功能包的名字<package_name>即可
sudo systemctl daemon-reload && sudo systemctl start <package_name>
sudo service <package_name> start
-
停止任务
sudo service <package_name> stop
-
卸载自启动任务
sudo service <package_name> stop
rosrun robot_upstart uninstall <package_name>
-
如果对launch进行更改,需要重启任务
卸载自启动任务
sudo service <package_name> stop
rosrun robot_upstart uninstall <package_name>
重新设置自启动任务
rosrun robot_upstart install <package_name>/launch/<launch_file>.launch
sudo systemctl daemon-reload && sudo systemctl start <package_name>
sudo service <package_name> start
添加Gazebo仿真
-
运行Gazebo控制空间进行仿真
roslaunch wpr_simulation wpb_stage_slam.launch
-
进入Gazebo
新增参数Gazebo->Modeis->wpb_home->Links->pose窗口
-
测试串口输出数据
串口映射
-
以管理员权限安装 ROS Noetic 版本的指定功能库
sudo apt install ros-noetic-LIBARIES