-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathCmdVelSubscriber.cs
More file actions
36 lines (33 loc) · 1.13 KB
/
CmdVelSubscriber.cs
File metadata and controls
36 lines (33 loc) · 1.13 KB
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
using UnityEngine;
using Unity.Robotics.ROSTCPConnector;
// 各種ROSトピック形式
using TwistMsg = RosMessageTypes.Geometry.TwistMsg;
/// <summary>
/// CmdVel(TwistMsg)を受信するためのクラス
/// 主にデバッグ用に使うことを想定
/// </summary>
public class CmdVelSubscriber : MonoBehaviour
{
// 受信するROSのトピック名
[SerializeField] string rosTopicName = "cmd_vel";
// デバッグモードとするかどうか(デバッグモードではコンソールにログを出力)
[SerializeField] bool isDebugMode = true;
/// <summary>
/// 初期化用のイベント関数
/// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html
/// </summary>
void Start()
{
ROSConnection.GetOrCreateInstance().Subscribe<TwistMsg>(rosTopicName, CmdVelUpdate);
}
/// <summary>
/// ROSトピックを受け取った際に呼ばれるコールバック関数
/// </summary>
void CmdVelUpdate(TwistMsg twistMessage)
{
if (isDebugMode)
{
Debug.Log(twistMessage);
}
}
}