(三)从零搭建unity3d机器人仿真:使用WheelCollider实现turtlebot轮子差速运动
通常使用ArticulationBody就能实现机器人运动,但是如果WheelCollider进行控制能对机器人进行拓展,比如可以扩展到汽车上。本文通过WheelCollider实现turtlebot轮子差速运动。
(1)使用urdf inport导入机器人
注意,导入后将原来的ArticulationBody和脚本全部删除。
(2)选中机器人加入RigidBody
(3)选中机器人的左右轮加入WheelCollider部件
并且设置相关参数。
主要参数有重量Mass,
轮子半径Radius等
其中小车的重量Mass=1.38
其中轮子的WheelCollider配置参数如下
(4)加入控制代码
新建DiffWheelControll.cs如下
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class DiffWheelControll : MonoBehaviour
{// Start is called before the first frame updatepublic WheelCollider[] my_wheels;public float my_speed;void Start(){}// Update is called once per framevoid Update(){for (int i = 0; i < my_wheels.Length; i++){my_wheels[i].motorTorque = my_speed;}if (Input.GetKeyDown(KeyCode.W)){Debug.Log("Hello, w!"); my_speed = 1;}if (Input.GetKeyDown(KeyCode.S)){Debug.Log("Hello, s!"); my_speed = -1;}}
}
加入后绑定车轮
(5)运行
运行后发现机器人很抖,并且发送1m的速度机器人只能稍微运动。TODO
参考
(二)从零搭建unity3d机器人仿真:驱动turtlebot轮子运动