如何调用通过Arduino调用MPU6050板块实现,将四元数数据传输到Unity并控制物体的姿态
Arduino如何获取MPU6050的姿态数据已经在前面的文章说说过了,有需要的看前面的文章。
ROSsharp的
PoseStampedSubscriber脚本使用
再自己定义一个动作脚本放在场景中调用PoseStampedSubscriber脚本,然后订阅arduino那边的发送的MPU6050板块的数据(不发全部,我这里值发送了四元数数据,(我的话题名为/pose_data)),这里的代码的odmo,在Unity界面绑定ROSconnecter的PoseStampedSubscriber的脚本。
public PoseStampedSubscriber odmo;
public GameObject base_link;
public Text text;
// Start is called before the first frame update
void Start()
{
text.text = "陀螺仪数据接收 就绪";
}
// Update is called once per frame
void FixedUpdate()
{
base_link.transform.rotation = odmo.rotation;
}