# DAMAD **Repository Path**: dagoo101-studio/damad ## Basic Information - **Project Name**: DAMAD - **Description**: 无人机辅助的多感知主体自动驾驶决策系统 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-08-24 - **Last Updated**: 2025-04-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # DAMAD #### 介绍 无人机辅助的多感知主体自动驾驶决策系统 #### 软件架构 软件架构说明 #### 安装教程 1.从github上clone源码 `git clone https://github.com/PX4/PX4-Autopilot.git --recursive` 进入PX4-Autopilot文件夹,继续下载未下载完的组件 ``` cd PX4-Autopilot/ git submodule update --init --recursive ``` 继续执行ubuntu.sh脚本 ``` cd .. bash ./PX4-Autopilot/Tools/setup/ubuntu.sh ``` 中间出错的话执行指令 ``` python3 -m pip install --upgrade pip python3 -m pip install --upgrade Pillow ``` 如果过程中有安装失败的地方,可以再用以下命令更新一下,: ``` bash ./PX4-Autopilot/Tools/setup/ubuntu.sh --fix-missing ``` 之后进行编译 ``` make px4_sitl_default gazebo ``` 有gazebo出现后,输入commander takeoff可以看到无人机起飞 tips: E: 无法定位软件包 kconfig-frontends ``` sudo add-apt-repository universe sudo apt-get update sudo apt install kconfig-frontends ``` E: 软件包 libgstreamer-plugins-base1.0-dev 没有可安装候选 尝试更换aliyun软件源 1.5 source相关文件 `gedit ~/.bashrc` 在.bashrc文件最下面写入如下: ``` source ~/PX4-Autopilot/Tools/simulation/gazebo-classic/setup_gazebo.bash ~/PX4-Autopilot ~/PX4-Autopilot/build/px4_sitl_default export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4-Autopilot export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic ``` 输入source ~/.bashrc使上述命令生效 2.安装MAVROS ``` sudo apt-get install ros-noetic-mavros ros-noetic-mavros-extras wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh sudo bash ./install_geographiclib_datasets.sh ``` (这一步往往用时很长) 将`DAMAD/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/models`复制并覆盖`~/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/models` 运行以下命令测试mavros是否安装成功 `roslaunch mavros px4.launch` 在成功打开gazebo仿真界面后输入 `rostopic list` 可查看mavros话题 3.安装gazebo的模型库 将`DAMAD/.gazebo/models` 覆盖 `~/.gazebo/models` 将`DAMAD/PX4-Autopilot/launch`文件夹覆盖`~/PX4-Autopilot/launch`文件夹 将`DAMAD/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/worlds`文件夹覆盖`~/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/worlds` 4.安装无人车 安装无人车依赖 ``` sudo apt install ros-noetic-effort-controllers sudo apt-get install ros-noetic-gazebo-ros-control sudo apt-get install ros-noetic-ackermann-msgs sudo apt-get install ros-noetic-joint-state-controller ``` 安装无人车的包 将uavros_gazebo放入主目录下 在.bashrc文件最下面写入 ``` gedit ~/.bashrc export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/uavros_gazebo source ~/.bashrc ``` 5.安装ros包 将catkin_ws/src下的shipinliu、test_sudu、launch、Yolov8_ros放入你的catkin_ws/src下 `catkin_make` 为了使用yolov8,要创建python3.8的anaconda环境,并下载torch2.0.1,ultralytics 配置好anaconda环境后 ``` 进入Yolov8_ros文件夹 sudo -s conda activate your_env source /opt/ros/noetic/setup.bash catkin_make ``` 5.5.1记得把需要path的文件加上你自己的路径(几乎所有) 5.5.2在主目录下创建用于传输数据的txt文件 ``` touch able_to_start.txt touch actor_x.txt touch car_ready.txt touch if_obstacle_exist.txt touch if_pass.txt touch if_ready.txt touch iris_orientation.txt touch iris_speed.txt touch iris_x.txt touch orientation.txt touch pump.txt touch rplidar_ready.txt touch speed.txt touch state.txt touch time.txt touch time_past.txt touch x.txt touch value.txt touch y.txt ``` 6.测试传统方法 ``` roslaunch px4 mavros_posix_sitl.launch ``` 6.1测试yolov8 进入Yolov8_ros文件夹 ``` sudo -s conda activate your_env source /opt/ros/noetic/setup.bash catkin_make source ./devel/setup.bash roslaunch yolov8_ros yolo_v8.launch ``` 6.2测试无人机传统方法(在打开yolov8的基础上) 在test_sudu文件夹中 `rosrun test_sudu test_sudu` 在看到无人机起飞后 `roslaunch launch all.launch` 6.3测试雷达传统方法(不用打开yolov8) ``` roslaunch launch rplidar.launch ``` 7.测试ddqn 进入shipinliu/src文件夹 ``` sudo -s conda activate your_env source /opt/ros/noetic/setup.bash python3 DDQN_v32_rplidar.py 打开另一个终端 roslaunch launch rplidar_ddqn.launch ``` 其他类似 可能遇到的问题及解决方案: 1. px4仿真环境不能使用虚拟机安装,必须使用双系统 2. 在编译catkin_ws的时候,如果已经正确安装了需要的包,还是提示缺少包的话,需要修改test_sudu中的cmakelist文件,删除引用的多余的库 3. 路径PX4-Autopilot/launch/中的文件”mavros_posix_sitl.launch”中的bl-ver5no_collision.world应修改为bl-ver5.world 4. 在开启mavros_posix_sitl.launch文件时,若遇到命名冲突的问题,可能是多个launch文件同时开启了gazebo建图导致的。可以把uavros_gazebo/launch/rover_laucnh/rover_sitl.launch文件中打开gazebo的部分删掉 5. 若已经安装了rospkg包,仍然报错提示缺少rospkg,除了考虑安装的位置不对(本地or虚拟环境)之外,也可能是存在多个冲突的python版本。只保留一个应该可以解决此问题 # 实车实验参考文档 ## SR5E1E3 引脚定义如下: ``` 1. HardwareBoard myBoard 2. include "platform:/plugin/com.st.stellar.model.lib/lib/SR5E1/SR5E1.gpio_def" version "2.0.0" 3. package E7 4. 5. //CAN 6. CAN1 { 7. in CAN1_RX -> E7_1 as Pin_CAN1_RX_A4 8. IO 9. AFRL4 = 6, 10. IHYSTR4 = 'CMOS', 11. MODER4 = 'Alternate', 12. OSPEEDR4 = 'VeryHigh', 13. OT4 = 'PushPull', 14. PUPDR4 = 'Floating', 15. SFS4 = 'Disabled', 16. SFV4 = 'Low', 17. TR4 = 'Enable' 18. 19. ; 20. out CAN1_TX -> E7_2 as Pin_CAN1_TX_A5 21. IO 22. AFRL5 = 6, 23. IHYSTR5 = 'CMOS', 24. MODER5 = 'Alternate', 25. OSPEEDR5 = 'VeryHigh', 26. OT5 = 'PushPull', 27. PUPDR5 = 'Floating', 28. SFS5 = 'Disabled', 29. SFV5 = 'Low', 30. TR5 = 'Disabled' 31. 32. ; 33. } 34. UART3 { 35. in UART3_RX -> E7_91 as Pin_UART3_RX_E9 36. IO 37. AFRL9 = 7, 38. IHYSTR9 = 'CMOS', 39. MODER9 = 'Alternate', 40. OSPEEDR9 = 'VeryHigh', 41. OT9 = 'PushPull', 42. PUPDR9 = 'Floating', 43. SFS9 = 'Disabled', 44. SFV9 = 'Low', 45. TR9 = 'Enable' 46. 47. ; 48. out UART3_TX -> E7_92 as Pin_UART3_TX_E10 49. IO 50. AFRL10 = 7, 51. IHYSTR10 = 'CMOS', 52. MODER10 = 'Alternate', 53. OSPEEDR10 = 'VeryHigh', 54. OT10 = 'PushPull', 55. PUPDR10 = 'Floating', 56. SFS10 = 'Disabled', 57. SFV10 = 'Low', 58. TR10 = 'Disabled' 59. 60. ; 61. } 62. //PS2手柄 63. GPIO { 64. in GPIO3_12 -> E7_81 as Pin_PS2_DATA_D12 65. IO 66. AFRL12 = 0, 67. IHYSTR12 = 'CMOS', 68. MODER12 = 'Input', 69. OSPEEDR12 = 'VeryHigh', 70. OT12 = 'PushPull', 71. PUPDR12 = 'PullDown', 72. SFS12 = 'Disabled', 73. SFV12 = 'Low', 74. TR12 = 'Disabled' 75. 76. ; 77. out GPIO3_13 -> E7_82 as Pin_PS2_CMD_D13 78. IO 79. AFRL13 = 0, 80. IHYSTR13 = 'CMOS', 81. MODER13 = 'Output', 82. OSPEEDR13 = 'VeryHigh', 83. OT13 = 'PushPull', 84. PUPDR13 = 'Floating', 85. SFS13 = 'Disabled', 86. SFV13 = 'Low', 87. TR13 = 'Disabled' 88. 89. ; 90. out GPIO3_14 -> E7_84 as Pin_PS2_ATT_D14 91. IO 92. AFRL14 = 0, 93. IHYSTR14 = 'CMOS', 94. MODER14 = 'Output', 95. OSPEEDR14 = 'VeryHigh', 96. OT14 = 'PushPull', 97. PUPDR14 = 'Floating', 98. SFS14 = 'Disabled', 99. SFV14 = 'Low', 100. TR14 = 'Disabled' 101. 102. ; 103. out GPIO3_15 -> E7_85 as Pin_PS2_CLK_D15 104. IO 105. AFRL15 = 0, 106. IHYSTR15 = 'CMOS', 107. MODER15 = 'Output', 108. OSPEEDR15 = 'VeryHigh', 109. OT15 = 'PushPull', 110. PUPDR15 = 'Floating', 111. SFS15 = 'Disabled', 112. SFV15 = 'Low', 113. TR15 = 'Disabled' 114. 115. ; 116. } 117. //按键 118. GPIO { 119. in GPI_PB_7 -> E7_26 as Pin_KEY1_B7 120. IO 121. AFRL7 = 0, 122. IHYSTR7 = 'CMOS', 123. MODER7 = 'Input', 124. OSPEEDR7 = 'VeryHigh', 125. OT7 = 'PushPull', 126. PUPDR7 = 'PullDown', 127. SFS7 = 'Disabled', 128. SFV7 = 'Low', 129. TR7 = 'Enable' 130. 131. ; 132. in GPI_PB_8 -> E7_27 as Pin_KEY2_B8 133. IO 134. AFRL8 = 0, 135. IHYSTR8 = 'CMOS', 136. MODER8 = 'Input', 137. OSPEEDR8 = 'VeryHigh', 138. OT8 = 'PushPull', 139. PUPDR8 = 'PullDown', 140. SFS8 = 'Disabled', 141. SFV8 = 'Low', 142. TR8 = 'Enable' 143. 144. ; 145. in GPI_PB_9 -> E7_28 as Pin_KEY3_B9 146. IO 147. AFRL9 = 0, 148. IHYSTR9 = 'CMOS', 149. MODER9 = 'Input', 150. OSPEEDR9 = 'VeryHigh', 151. OT9 = 'PushPull', 152. PUPDR9 = 'PullDown', 153. SFS9 = 'Disabled', 154. SFV9 = 'Low', 155. TR9 = 'Enable' 156. 157. ; 158. } 159. //OLED屏幕,屏幕接口靠左 160. GPIO { 161. out GPIO6_5 -> E7_129 as Pin_OLED_SCL_G5 162. IO 163. AFRL5 = 0, 164. IHYSTR5 = 'CMOS', 165. MODER5 = 'Output', 166. OSPEEDR5 = 'VeryHigh', 167. OT5 = 'PushPull', 168. PUPDR5 = 'Floating', 169. SFS5 = 'Disabled', 170. SFV5 = 'Low', 171. TR5 = 'Disabled' 172. 173. ; 174. out GPIO6_7 -> E7_131 as Pin_OLED_SDA_G7 175. IO 176. AFRL7 = 0, 177. IHYSTR7 = 'CMOS', 178. MODER7 = 'Output', 179. OSPEEDR7 = 'VeryHigh', 180. OT7 = 'PushPull', 181. PUPDR7 = 'Floating', 182. SFS7 = 'Disabled', 183. SFV7 = 'Low', 184. TR7 = 'Disabled' 185. 186. ; 187. out GPIO6_6 -> E7_130 as Pin_OLED_RES_G6 188. IO 189. AFRL6 = 0, 190. IHYSTR6 = 'CMOS', 191. MODER6 = 'Output', 192. OSPEEDR6 = 'VeryHigh', 193. OT6 = 'PushPull', 194. PUPDR6 = 'Floating', 195. SFS6 = 'Disabled', 196. SFV6 = 'Low', 197. TR6 = 'Disabled' 198. 199. ; 200. out GPIO7_1 -> E7_146 as Pin_OLED_DC_H1 201. IO 202. AFRL1 = 0, 203. IHYSTR1 = 'CMOS', 204. MODER1 = 'Output', 205. OSPEEDR1 = 'VeryHigh', 206. OT1 = 'PushPull', 207. PUPDR1 = 'Floating', 208. SFS1 = 'Disabled', 209. SFV1 = 'Low', 210. TR1 = 'Disabled' 211. 212. ; 213. } 214. //电机 215. TIM4 { 216. out TIM4_CH1 -> E7_160 as Pin_MOTOR1_H12 217. IO 218. AFRL12 = 2, 219. IHYSTR12 = 'CMOS', 220. MODER12 = 'Alternate', 221. OSPEEDR12 = 'VeryHigh', 222. OT12 = 'PushPull', 223. PUPDR12 = 'Floating', 224. SFS12 = 'Disabled', 225. SFV12 = 'Low', 226. TR12 = 'Disabled' 227. 228. ; 229. out TIM4_CH2 -> E7_161 as Pin_MOTOR2_H13 230. IO 231. AFRL13 = 2, 232. IHYSTR13 = 'CMOS', 233. MODER13 = 'Alternate', 234. OSPEEDR13 = 'VeryHigh', 235. OT13 = 'PushPull', 236. PUPDR13 = 'Floating', 237. SFS13 = 'Disabled', 238. SFV13 = 'Low', 239. TR13 = 'Disabled' 240. 241. ; 242. } 243. GPIO { 244. out GPIO8_1 -> E7_165 as Pin_MOTOR1_A_I1 245. IO 246. AFRL1 = 0, 247. IHYSTR1 = 'CMOS', 248. MODER1 = 'Output', 249. OSPEEDR1 = 'VeryHigh', 250. OT1 = 'PushPull', 251. PUPDR1 = 'Floating', 252. SFS1 = 'Disabled', 253. SFV1 = 'Low', 254. TR1 = 'Disabled' 255. 256. ; 257. out GPIO8_3 -> E7_168 as Pin_MOTOR1_B_I3 258. IO 259. AFRL3 = 0, 260. IHYSTR3 = 'CMOS', 261. MODER3 = 'Output', 262. OSPEEDR3 = 'VeryHigh', 263. OT3 = 'PushPull', 264. PUPDR3 = 'Floating', 265. SFS3 = 'Disabled', 266. SFV3 = 'Low', 267. TR3 = 'Disabled' 268. 269. ; 270. out GPIO8_4 -> E7_169 as Pin_MOTOR2_A_I4 271. IO 272. AFRL4 = 0, 273. IHYSTR4 = 'CMOS', 274. MODER4 = 'Output', 275. OSPEEDR4 = 'VeryHigh', 276. OT4 = 'PushPull', 277. PUPDR4 = 'Floating', 278. SFS4 = 'Disabled', 279. SFV4 = 'Low', 280. TR4 = 'Disabled' 281. 282. ; 283. out GPIO8_5 -> E7_170 as Pin_MOTOR2_B_I5 284. IO 285. AFRL5 = 0, 286. IHYSTR5 = 'CMOS', 287. MODER5 = 'Output', 288. OSPEEDR5 = 'VeryHigh', 289. OT5 = 'PushPull', 290. PUPDR5 = 'Floating', 291. SFS5 = 'Disabled', 292. SFV5 = 'Low', 293. TR5 = 'Disabled' 294. 295. ; 296. } 297. //编码器 298. GPIO { 299. in GPI_PB_2 -> E7_20 as Pin_BMQ0_B2 300. IO 301. AFRL2 = 0, 302. IHYSTR2 = 'CMOS', 303. MODER2 = 'Input', 304. OSPEEDR2 = 'VeryHigh', 305. OT2 = 'PushPull', 306. PUPDR2 = 'Floating', 307. SFS2 = 'Disabled', 308. SFV2 = 'Low', 309. TR2 = 'Enable' 310. 311. ; 312. in GPI_PB_3 -> E7_21 as Pin_BMQ1_B3 313. IO 314. AFRL3 = 0, 315. IHYSTR3 = 'CMOS', 316. MODER3 = 'Input', 317. OSPEEDR3 = 'VeryHigh', 318. OT3 = 'PushPull', 319. PUPDR3 = 'Floating', 320. SFS3 = 'Disabled', 321. SFV3 = 'Low', 322. TR3 = 'Enable' 323. 324. ; 325. in GPI_PB_4 -> E7_22 as Pin_EIRQ_BMQ0_B4 326. IO 327. AFRL4 = 0, 328. IHYSTR4 = 'CMOS', 329. MODER4 = 'Input', 330. OSPEEDR4 = 'VeryHigh', 331. OT4 = 'PushPull', 332. PUPDR4 = 'Floating', 333. SFS4 = 'Disabled', 334. SFV4 = 'Low', 335. TR4 = 'Enable' 336. 337. ; 338. in GPI_PB_5 -> E7_23 as Pin_EIRQ_BMQ1_B5 339. IO 340. AFRL5 = 0, 341. IHYSTR5 = 'CMOS', 342. MODER5 = 'Input', 343. OSPEEDR5 = 'VeryHigh', 344. OT5 = 'PushPull', 345. PUPDR5 = 'Floating', 346. SFS5 = 'Disabled', 347. SFV5 = 'Low', 348. TR5 = 'Enable' 349. 350. ; 351. } 352. //舵机 353. TIM3 { 354. out TIM3_CH1 -> E7_140 as Pin_SERVO_G14 355. IO 356. AFRL14 = 2, 357. IHYSTR14 = 'CMOS', 358. MODER14 = 'Alternate', 359. OSPEEDR14 = 'VeryHigh', 360. OT14 = 'PushPull', 361. PUPDR14 = 'Floating', 362. SFS14 = 'Disabled', 363. SFV14 = 'Low', 364. TR14 = 'Disabled' 365. 366. ; 367. } 368. //定时器 369. TIM3 { 370. out TIM3_CH2 -> E7_141 as Pin_DingShiQi_G15 371. IO 372. AFRL15 = 2, 373. IHYSTR15 = 'CMOS', 374. MODER15 = 'Alternate', 375. OSPEEDR15 = 'VeryHigh', 376. OT15 = 'PushPull', 377. PUPDR15 = 'Floating', 378. SFS15 = 'Disabled', 379. SFV15 = 'Low', 380. TR15 = 'Disabled' 381. 382. ; 383. } ``` ## 接线 为了方便,给板子分别命名为B1, B2, B3,如图所示。 ![B1](Figure/B1.png) ![B2](Figure/B2.png) ![B3](Figure/B3.png) 电机编码器: 左轮编码器 B1_B2—>B2_D4 左轮外部中断编码器 B1_B4—>B2_D8 右轮编码器 B1_B3—>B2_D2 右轮外部中断编码器 B1_B5—>B2_D7 电机驱动: 右轮: B3_V —>B2_3.3V B3_P2—>B1_H13 B3_A2—>B1_I4 B3_B2—>B1_I5 B3_G —>B2_GND 左轮: B3_V —>B2_3.3V B3_P1—>B1_H12 B3_A1—>B1_I1 B3_B1—>B1_I3 B3_G —>B2_GND 舵机: 舵机白线—>B1_G14 舵机红线—>12V电源正极 舵机黑线—>12V电源负极&B1_GND PS2手柄:(B2的PS2开关往上拨) B1_D12—>B2_A3 B1_D13—>B2_PC_TX B1_D14—>B2_A2 B1_D15—>B2_A1 CAN: USBCAN分析仪L—>B1_CAN_L USBCAN分析仪H—>B1_CAN_H 蓝牙: UART wifi接口 5V&GND TX—>B1_E9 RX—>B1_E10 OLED显示屏: 屏幕接口靠左接 启动开关: JP34跳线帽需要拿掉 黄线 —>B1_GND 黑线 —>B1_3.3V 蓝线&绿线—>B1_B8 切换开关: 黄线 —>B1_GND 黑线 —>B1_3.3V 蓝线&绿线—>B1_B9 急停开关: B1_B7&B1_3.3V任意连接 供电(B1的5V引脚为输入引脚) B1_5V—>B2_5V B1_GND—>B2_GND ## 运行 ![硬件接线图](Figure/hardware.png) 将`d435i.py`,`esp32_detect_person.py`和`control.py`放在同一目录下 分别新建终端运行以下文件 ``` python3 d435i.py ``` ``` python3 esp32_detect_person.py ``` 待以上两个程序初始化完成后运行以下程序 ``` python3 control.py ``` ## 结果 ![视频预览](Figure/real_world_expriment.gif)