当前位置:   article > 正文

阿克曼结构移动机器人的gazebo仿真(二)_阿克曼结构机器人

阿克曼结构机器人

阿克曼结构移动机器人的gazebo仿真(二)

第二章、配置xacro文件

0.前言

上一节已经将urdf导出来了,这一节需要配置一下xacro文件。先看一下导出的功能包在gazebo以及rviz中显示的效果。

将功能包放进工作空间进行编译,source一下环境,先看gazebo:

roslaunch tianracer_description gazebo.launch
  • 1

请添加图片描述

可以看到模型已经加载到gazebo中的empty_world中了,此时模型还是白板,稍后可对颜色进行配置。

再看rviz,先修改tianracer_description/launch中的 arg name=“gui” default="False"改为arg name=“gui” default=“True”

 roslaunch tianracer_description display.launch 
  • 1

在这里插入图片描述

此时左侧会出现joint_state_publisher的可视化窗口,拖动上边的动态条即可控制小车的每个关节。

1.添加传动装置

新建tianracer_description.xacro文件,将urdf文件中的代码复制过来,并对其进行修改。

<?xml version="1.0" encoding="utf-8"?>
<robot name="tianracer"  xmlns:xacro="http://ros.org/wiki/xacro">

 <link name="base_link">
</link>

<link name="chassis">
    <inertial>
      <origin
        xyz="0.0623235722457065 0.0014584636628485 0.0350371599032402"
        rpy="0 0 0" />
      <mass
        value="5" />
     <inertia ixx="0.010609" ixy="0"          ixz="0"
                          iyy="0.050409"   iyz="0"
                                           izz="0.05865" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh filename="package://tianracer_description/meshes/base_link.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="0.792156862745098 0.819607843137255 0.933333333333333 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://tianracer_description/meshes/base_link.STL" />
      </geometry>
    </collision>
  </link>
  <joint name="base_link_joint" type="fixed">
        <origin xyz="0 0 0" rpy="0 0 0" />        
        <parent link="base_link"/>
        <child link="chassis" />
    </joint>  




  <link
    name="left_steering_hinge">
    <inertial>
      <origin
        xyz="0.00160901052986848 0.00421500740928921 0.000999991873067492"
        rpy="0 0 0" />
      <mass
        value="0.34" />
      <inertia
        ixx="4E-06"
        ixy="0"
        ixz="0"
        iyy="4E-06"
        iyz="0"
        izz="4E-06" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://tianracer_description/meshes/left_steering_hinge.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="1 1 1 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://tianracer_description/meshes/left_steering_hinge.STL" />
      </geometry>
    </collision>
  </link>



  <joint
    name="left_steering_hinge_joint"
    type="revolute">
    <origin
      xyz="0.1237 0.070647 0.0235"
      rpy="0 0 0" />
    <parent
      link="base_link" />
    <child
      link="left_steering_hinge" />
    <axis
      xyz="0 0 1" />
    <limit
      lower="-0.6"
      upper="0.6"
      effort="10"
      velocity="1000" />
  </joint>



  <link
    name="left_front_wheel">
    <inertial>
      <origin
        xyz="-1.16652756898539E-10 0.000722301233977055 -0.000982991824011559"
        rpy="0 0 0" />
      <mass
        value="0.7" />
     <inertia ixx="0.00026046" ixy="0"          ixz="0"
                            iyy="0.00026046" iyz="0"
                                             izz="0.00041226" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://tianracer_description/meshes/left_front_wheel.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="0.792156862745098 0.819607843137255 0.933333333333333 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://tianracer_description/meshes/left_front_wheel.STL" />
      </geometry>
    </collision>
  </link>

  <joint
    name="left_front_wheel_joint"
    type="continuous">
    <origin
      xyz="0 0.015649 0"
      rpy="0 0 0" />
    <parent
      link="left_steering_hinge" />
    <child
      link="left_front_wheel" />
    <axis
      xyz="0 1 0" />
  </joint>


  <link
    name="right_steering_hinge">
    <inertial>
      <origin
        xyz="0.00160901052986852 -0.00421500740928916 0.00100000812693248"
        rpy="0 0 0" />
      <mass
        value="0.34" />
      <inertia
         ixx="4E-06"
        ixy="0"
        ixz="0"
        iyy="4E-06"
        iyz="0"
        izz="4E-06" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://tianracer_description/meshes/right_steering_hinge.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="1 1 1 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://tianracer_description/meshes/right_steering_hinge.STL" />
      </geometry>
    </collision>
  </link>


  <joint
    name="right_steering_hinge_joint"
    type="revolute">
    <origin
      xyz="0.12626 -0.065953 0.0235"
      rpy="0 0 0" />
    <parent
      link="base_link" />
    <child
      link="right_steering_hinge" />
    <axis
      xyz="0 0 1" />
    <limit
      lower="-0.6"
      upper="0.6"
      effort="10"
      velocity="1000" />
  </joint>


  <link
    name="right_front_wheel">
    <inertial>
      <origin
        xyz="1.16652479342783E-10 -0.000722301233976874 -0.000982991824011684"
        rpy="0 0 0" />
      <mass
        value="0.7" />
      <inertia ixx="0.00026046" ixy="0"          ixz="0"
                            iyy="0.00026046" iyz="0"
                                             izz="0.00041226" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://tianracer_description/meshes/right_front_wheel.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="0.792156862745098 0.819607843137255 0.933333333333333 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://tianracer_description/meshes/right_front_wheel.STL" />
      </geometry>
    </collision>
  </link>


  <joint
    name="right_front_wheel_joint"
    type="continuous">
    <origin
      xyz="0 -0.015649 0"
      rpy="0 0 0" />
    <parent
      link="right_steering_hinge" />
    <child
      link="right_front_wheel" />
    <axis
      xyz="0 1 0" />
  </joint>



  <link
    name="left_rear_wheel">
    <inertial>
      <origin
        xyz="-6.22009417952651E-06 0.000722301233977513 1.58299866985546E-05"
        rpy="0 0 0" />
      <mass
        value="0.7" />
     <inertia ixx="0.00026046" ixy="0"          ixz="0"
                            iyy="0.00026046" iyz="0"
                                             izz="0.00041226" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://tianracer_description/meshes/left_rear_wheel.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="0.792156862745098 0.819607843137255 0.933333333333333 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://tianracer_description/meshes/left_rear_wheel.STL" />
      </geometry>
    </collision>
  </link>



  <joint
    name="left_rear_wheel_joint"
    type="continuous">
    <origin
      xyz="-0.12626 0.081602 0.0225"
      rpy="0 0 0" />
    <parent
      link="base_link" />
    <child
      link="left_rear_wheel" />
    <axis
      xyz="0 1 0" />
  </joint>




  <link
    name="right_rear_wheel">
    <inertial>
      <origin
        xyz="5.49312575473526E-06 -0.000722301233977277 1.60966959317256E-05"
        rpy="0 0 0" />
      <mass
        value="0.7" />
        <inertia ixx="0.00026046" ixy="0"          ixz="0"
                            iyy="0.00026046" iyz="0"
                                             izz="0.00041226" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh  filename="package://tianracer_description/meshes/right_rear_wheel.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="0.792156862745098 0.819607843137255 0.933333333333333 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://tianracer_description/meshes/right_rear_wheel.STL" />
      </geometry>
    </collision>
  </link>


  <joint
    name="right_rear_wheel_joint"
    type="continuous">
    <origin
      xyz="-0.1237 -0.086296 0.0225"
      rpy="0 0 0" />
    <parent
      link="base_link" />
    <child
      link="right_rear_wheel" />
    <axis
      xyz="0 1 0" />
  </joint>



  <link
    name="lidar">
    <inertial>
      <origin
        xyz="-0.0120919804823413 0.0023160815953297 -0.0191850779635995"
        rpy="0 0 0" />
      <mass
        value="0.0792224121739075" />
      <inertia
        ixx="2.10579541640659E-05"
        ixy="-1.189626176555E-07"
        ixz="4.23690141563745E-07"
        iyy="2.51190032657276E-05"
        iyz="-7.86831091483644E-09"
        izz="4.38241306407012E-05" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://tianracer_description/meshes/lidar.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="0.792156862745098 0.819607843137255 0.933333333333333 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://tianracer_description/meshes/lidar.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="lidar_joint"
    type="fixed">
    <origin
      xyz="0.093603 -8.284E-05 0.12377"
      rpy="0 0 0" />
    <parent
      link="base_link" />
    <child
      link="lidar" />
    <axis
      xyz="0 0 0" />
  </joint>
  <link
    name="camera">
    <inertial>
      <origin
        xyz="-0.00831465204525364 0.000297862545499916 -0.000809694900417546"
        rpy="0 0 0" />
      <mass
        value="0.0203878842392581" />
      <inertia
        ixx="4.0787812214101E-06"
        ixy="-1.28709200468823E-08"
        ixz="-1.65865223773842E-08"
        iyy="3.17565570823081E-06"
        iyz="-1.52713816393124E-08"
        izz="2.98536150732633E-06" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://tianracer_description/meshes/camera.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="0.43921568627451 0.43921568627451 0.43921568627451 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://tianracer_description/meshes/camera.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="camera_joint"
    type="fixed">
    <origin
      xyz="0.14851 0.0022137 0.0975"
      rpy="0 0 0" />
    <parent
      link="base_link" />
    <child
      link="camera" />
    <axis
      xyz="0 0 0" />
  </joint>
  <link
    name="real_sense">
    <inertial>
      <origin
        xyz="-0.00975078931607951 0.00306064913353049 -7.04374991291334E-05"
        rpy="0 0 0" />
      <mass
        value="0.103311749598955" />
      <inertia
        ixx="7.35323632954531E-05"
        ixy="3.0437488683846E-06"
        ixz="2.08538534427428E-08"
        iyy="7.40427481540393E-06"
        iyz="-1.93018760531168E-08"
        izz="7.2832884533889E-05" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://tianracer_description/meshes/real_sense.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="0.666666666666667 0.698039215686274 0.768627450980392 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://tianracer_description/meshes/real_sense.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="real_sense_joint"
    type="fixed">
    <origin
      xyz="0.19864 0.0038046 0.052021"
      rpy="0 0 0" />
    <parent
      link="base_link" />
    <child
      link="real_sense" />
    <axis
      xyz="0 0 0" />
  </joint>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
  • 376
  • 377
  • 378
  • 379
  • 380
  • 381
  • 382
  • 383
  • 384
  • 385
  • 386
  • 387
  • 388
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • 397
  • 398
  • 399
  • 400
  • 401
  • 402
  • 403
  • 404
  • 405
  • 406
  • 407
  • 408
  • 409
  • 410
  • 411
  • 412
  • 413
  • 414
  • 415
  • 416
  • 417
  • 418
  • 419
  • 420
  • 421
  • 422
  • 423
  • 424
  • 425
  • 426
  • 427
  • 428
  • 429
  • 430
  • 431
  • 432
  • 433
  • 434
  • 435
  • 436
  • 437
  • 438
  • 439
  • 440
  • 441
  • 442
  • 443
  • 444
  • 445
  • 446
  • 447
  • 448
  • 449
  • 450
  • 451
  • 452
  • 453
  • 454
  • 455
  • 456
  • 457
  • 458
  • 459
  • 460
  • 461
  • 462
  • 463
  • 464
  • 465
  • 466
  • 467
  • 468
  • 469
  • 470
  • 471
  • 472
  • 473
  • 474
  • 475
  • 476
  • 477
  • 478
  • 479
  • 480
  • 481
  • 482
  • 483
  • 484
  • 485
  • 486
  • 487
  • 488
  • 489
  • 490
  • 491
  • 492
  • 493
  • 494
  • 495
  • 496
  • 497
  • 498
  • 499
  • 500
  • 501
  • 502
  • 503
  • 504
  • 505
  • 506
  • 507
  • 508
  • 509
  • 510
  • 511
  • 512
  • 513
  • 514
  • 515
  • 516
  • 517
  • 518
  • 519
  • 520
  • 521
  • 522
  • 523
  • 524
  • 525
  • 526
  • 527
  • 528
  • 529
  • 530
  • 531
  • 532
  • 533
  • 534
  • 535
  • 536
  • 537
  • 538
  • 539
  • 540
  • 541
  • 542
  • 543
  • 544
  • 545
  • 546
  • 547
  • 548
  • 549

上边主要修改的内容是第一句修改为xacro声明:

<?xml version="1.0" encoding="utf-8"?>
<robot name="tianracer"  xmlns:xacro="http://ros.org/wiki/xacro">
  • 1
  • 2

以及一些惯性参数的修改。

本次项目做的是基于twist消息的阿克曼转向移动机器人,为实现该机器人的运动学,我们给两个后轮以及连接两个前轮的steer添加传动装置。为使用ROS控制驱动机器人,需要在模型中加入transmission元素,将传动装置与joint绑定。

<transmission name="right_steering_hinge_joint_trans">
		<type>transmission_interface/SimpleTransmission</type>
		<joint name="right_steering_hinge_joint" >
			<hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
		</joint>
		<actuator name="right_steering_hinge_joint_motor">
			<hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
			<mechanicalReduction>1</mechanicalReduction>
			<motorTorqueConstant>100</motorTorqueConstant>
		</actuator>
	</transmission>	
	
	<transmission name="left_steering_hinge_joint_trans">
		<type>transmission_interface/SimpleTransmission</type>
		<joint name="left_steering_hinge_joint" >
			<hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
		</joint>
		<actuator name="left_steering_hinge_joint_motor">
			<hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
			<mechanicalReduction>1</mechanicalReduction>
			<motorTorqueConstant>100</motorTorqueConstant>
		</actuator>
	</transmission>


	<transmission name="right_rear_wheel_joint_trans">
		<type>transmission_interface/SimpleTransmission</type>
		<joint name="right_rear_wheel_joint" >
			<hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
		</joint>
		<actuator name="right_rear_wheel_joint_motor">
			<hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
			<mechanicalReduction>1</mechanicalReduction>
		</actuator>
	</transmission>			
	
	<transmission name="left_rear_wheel_joint_trans">
		<type>transmission_interface/SimpleTransmission</type>
		<joint name="left_rear_wheel_joint" >
			<hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
		</joint>
		<actuator name="left_rear_wheel_joint_motor">
			<hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
			<mechanicalReduction>1</mechanicalReduction>
		</actuator>
	</transmission>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47

2.添加插件

在与tianracer_description.xacro路径相同路径下新建tianracer.gazebo文件

添加gazebo插件

由于车轮实际上会接触地面,因此会与地面发生物理相互作用,将各个link添加部件材料的附加信息,并且定义各个link的颜色信息。参考:gazebo官网

<gazebo reference="chassis">
  <mu1 value="0.0"/>
  <mu2 value="0.0"/>
  <kp  value="10000000.0" />
  <kd  value="1.0" />
  <material>Gazebo/Red</material>
</gazebo>

<gazebo reference="left_steering_hinge">
  <mu1 value="2.0"/>
  <mu2 value="2.0"/>
  <kp  value="10000000.0" />
  <kd  value="1.0" />
  <fdir1 value="1 0 0"/>
  <material>Gazebo/Grey</material>
</gazebo>

<gazebo reference="left_rear_wheel">
  <mu1 value="2.0"/>
  <mu2 value="2.0"/>
  <kp  value="10000000.0" />
  <kd  value="1.0" />
  <fdir1 value="1 0 0"/>
  <material>Gazebo/Black</material>
</gazebo>

<gazebo reference="right_steering_hinge">
  <mu1 value="2.0"/>
  <mu2 value="2.0"/>
  <kp  value="10000000.0" />
  <kd  value="1.0" />
  <fdir1 value="1 0 0"/>
  <material>Gazebo/Grey</material>
</gazebo>

<gazebo reference="right_rear_wheel">
  <mu1 value="2.0"/>
  <mu2 value="2.0"/>
  <kp  value="10000000.0" />
  <kd  value="1.0" />
  <fdir1 value="1 0 0"/>
  <material>Gazebo/Black</material>
</gazebo>

<gazebo reference="left_front_wheel">
  <mu1 value="2.0"/>
  <mu2 value="2.0"/>
  <kp  value="10000000.0" />
  <kd  value="1.0" />
  <fdir1 value="0 0 1"/>
  <material>Gazebo/Black</material>
</gazebo>

<gazebo reference="right_front_wheel">
  <mu1 value="2.0"/>
  <mu2 value="2.0"/>
  <kp  value="10000000.0" />
  <kd  value="1.0" />
  <fdir1 value="0 0 1"/>
  <material>Gazebo/Black</material>
</gazebo>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3zZNP6y0-1648997167602)(/home/zyx/blog/二/3.png)]

添加ros_control插件

由于gazebo并没阿克曼车型的插件,要链接gazebo与ros,我们先添加ros_control插件,它读取所有transmission标记,以及joint_state_publisher插件

<gazebo>
  <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
    <robotNamespace>/tianracer</robotNamespace>
    <robotParam>robot_description</robotParam>
    <robotSimType>gazebo_ros_control/DefaultRobotHWSim</robotSimType>
    <legacyModeNS>true</legacyModeNS>
  </plugin>
</gazebo>

<gazebo>
    <plugin name="joint_state_publisher" filename="libgazebo_ros_joint_state_publisher.so">
      <jointName>left_rear_wheel_joint, right_rear_wheel_joint, left_steering_hinge_joint, right_steering_hinge_joint, right_front_wheel_joint,left_ front_wheel_joint</jointName>
      <updateRate>50.0</updateRate>
      <robotNamespace>/tianracer</robotNamespace>
      <alwaysOn>true</alwaysOn>
    </plugin>
  </gazebo>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
添加传感器插件

添加二维激光雷达插件

<!-- hokuyo -->
<xacro:unless value="$(optenv DISABLE_GAZEBO_LASER false)">
  <gazebo reference="lidar">
    <material>Gazebo/Grey</material>
    <sensor type="ray" name="hokuyo_sensor">
      <pose>0 0 0.0124 0 0 0</pose>
      <visualize>false</visualize>
      <update_rate>40</update_rate>
      <ray>
        <scan>
          <horizontal>
            <samples>1081</samples>
            <resolution>1</resolution>
            <min_angle>-2.3561944902</min_angle>
            <max_angle>2.3561944902</max_angle>
          </horizontal>
        </scan>
        <range>
          <min>0.1</min>
          <max>10.0</max>
          <resolution>0.01</resolution>
        </range>
        <noise>
          <mean>0.0</mean>
          <stddev>0.01</stddev>
        </noise>
      </ray>
      <plugin name="gazebo_ros_hokuyo_controller" filename="libgazebo_ros_laser.so">
        <topicName>/scan</topicName>
        <frameName>lidar</frameName>
      </plugin>
    </sensor>
  </gazebo>
</xacro:unless>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

注意雷达的名字需要与link名对应上。

添加单目摄像头以及深度摄像头插件


<!-- camera -->
  <gazebo reference="camera">
  <material>Gazebo/Grey</material>
    <sensor type="camera" name="camera1">
      <update_rate>30.0</update_rate>
      <camera name="head">
        <horizontal_fov>1.3962634</horizontal_fov>
        <image>
          <width>800</width>
          <height>800</height>
          <format>R8G8B8</format>
        </image>
        <clip>
          <near>0.02</near>
          <far>300</far>
        </clip>
        <noise>
          <type>gaussian</type>
          <!-- Noise is sampled independently per pixel on each frame.
               That pixel's noise value is added to each of its color
               channels, which at that point lie in the range [0,1]. -->
          <mean>0.0</mean>
          <stddev>0.007</stddev>
        </noise>
      </camera>
      <plugin name="camera_controller" filename="libgazebo_ros_camera.so">
        <alwaysOn>true</alwaysOn>
        <updateRate>0.0</updateRate>
        <cameraName>rrbot/camera1</cameraName>
        <imageTopicName>image_raw</imageTopicName>
        <cameraInfoTopicName>camera_info</cameraInfoTopicName>
        <frameName>camera</frameName>
        <hackBaseline>0.07</hackBaseline>
        <distortionK1>0.0</distortionK1>
        <distortionK2>0.0</distortionK2>
        <distortionK3>0.0</distortionK3>
        <distortionT1>0.0</distortionT1>
        <distortionT2>0.0</distortionT2>
      </plugin>
    </sensor>
    </gazebo>

<gazebo reference="real_sense">
            <sensor type="depth" name="real_sense">
                <always_on>true</always_on>
                <update_rate>20.0</update_rate>
                <camera>
                    <horizontal_fov>${60.0*3.14/180.0}</horizontal_fov>
                    <image>
                        <format>R8G8B8</format>
                        <width>640</width>
                        <height>480</height>
                    </image>
                    <clip>
                        <near>0.05</near>
                        <far>8.0</far>
                    </clip>
                </camera>
                <plugin name="kinect_real_sense_controller" filename="libgazebo_ros_openni_kinect.so">
                    <cameraName>real_sense</cameraName>
                    <alwaysOn>true</alwaysOn>
                    <updateRate>10</updateRate>
                    <imageTopicName>rgb/image_raw</imageTopicName>
                    <depthImageTopicName>depth/image_raw</depthImageTopicName>
                    <pointCloudTopicName>depth/points</pointCloudTopicName>
                    <cameraInfoTopicName>rgb/camera_info</cameraInfoTopicName>
                    <depthImageCameraInfoTopicName>depth/camera_info</depthImageCameraInfoTopicName>
                    <frameName>real_sense</frameName>
                    <baseline>0.1</baseline>
                    <distortion_k1>0.0</distortion_k1>
                    <distortion_k2>0.0</distortion_k2>
                    <distortion_k3>0.0</distortion_k3>
                    <distortion_t1>0.0</distortion_t1>
                    <distortion_t2>0.0</distortion_t2>
                    <pointCloudCutoff>0.4</pointCloudCutoff>
                </plugin>
            </sensor>
        </gazebo>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79

这里深度摄像头的插件用kinect的插件代替。

最后将tianracer.gazebo添加到tianracer_description.xacro文件里边:

<xacro:include filename="$(find tianracer_description)/urdf/tianracer.gazebo" />
  • 1

小结

至此,我们已经配置好小车的各个link的颜色以及传感器的插件,但我们仍无法让小车运动起来,因为我们还未配置小车的controllers。下一节通过配置controllers让小车动起来。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-96xz2D3Y-1648997167603)(/home/zyx/Pictures/4.png)]

参考资料

1.古月老师的<<ROS机器人开发实践>>

2.从零开始自动驾驶

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/443928
推荐阅读
相关标签
  

闽ICP备14008679号