diff --git a/.github/scripts/sync_scripts.sh b/.github/scripts/sync_scripts.sh new file mode 100755 index 0000000..9bf16ca --- /dev/null +++ b/.github/scripts/sync_scripts.sh @@ -0,0 +1,7 @@ +#/bin/bash -eu + +SRC_DIR=$(cd $(dirname ${BASH_SOURCE:-$0})/../../; pwd) +echo "Run sync script in $SRC_DIR" +rsync -av --delete $SRC_DIR/MobileRobotUITutorialProject/Assets/Scripts/ $SRC_DIR/UnityScripts/Scripts +rsync -av --delete $SRC_DIR/MobileRobotUITutorialProject/Assets/OdometryViewer/ $SRC_DIR/UnityScripts/OdometryViewer +rsync -av --delete $SRC_DIR/MobileRobotUITutorialProject/Assets/PointCloud/ $SRC_DIR/UnityScripts/PointCloud diff --git a/.github/workflows/check_tutorial_files.yaml b/.github/workflows/check_tutorial_files.yaml new file mode 100644 index 0000000..64d6e4b --- /dev/null +++ b/.github/workflows/check_tutorial_files.yaml @@ -0,0 +1,18 @@ +name: Check for the tutorial update + +on: + pull_request: + paths: + - "MobileRobotUITutorialProject/**" + - "UnityScripts/**" + +jobs: + check-tutorial-files: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: File sync + run: | + ./.github/scripts/sync_scripts.sh + git status | grep "working tree clean" && exit 0 || git status; exit 1; diff --git a/MobileRobotUITutorialProject/Assets/JoyStick/Scripts/OnScreenStickCmdVelPublisher.cs b/MobileRobotUITutorialProject/Assets/JoyStick/Scripts/OnScreenStickCmdVelPublisher.cs new file mode 100644 index 0000000..c081b17 --- /dev/null +++ b/MobileRobotUITutorialProject/Assets/JoyStick/Scripts/OnScreenStickCmdVelPublisher.cs @@ -0,0 +1,61 @@ +using UnityEngine; +using UnityEngine.InputSystem; +using Unity.Robotics.ROSTCPConnector; +using TwistMsg = RosMessageTypes.Geometry.TwistMsg; + +public class OnScreenStickCmdVelPublisher : MonoBehaviour +{ + [SerializeField] private InputAction _moveAction; + + [SerializeField] string topicName = "cmd_vel"; + private ROSConnection ros; + private TwistMsg cmdVelMessage = new TwistMsg(); + + private void Start() + { + ros = ROSConnection.GetOrCreateInstance(); + ros.RegisterPublisher(topicName); + StopPublish(); + + _moveAction.performed += _ => + { + var value = _moveAction.ReadValue(); + Debug.Log($"Move: ({value.x}, {value.y})"); + cmdVelMessage.linear.x = value.y * 0.2f; + cmdVelMessage.angular.z = value.x * -1.0f; + Publish(); + }; + + _moveAction.canceled += _ => + { + StopPublish(); + }; + } + + private void OnEnable() + { + _moveAction.Enable(); + } + + private void OnDisable() + { + _moveAction.Disable(); + } + + private void OnDestroy() + { + _moveAction.Dispose(); + } + + private void StopPublish() + { + cmdVelMessage.linear.x = 0.0f; + cmdVelMessage.angular.z = 0.0f; + Publish(); + } + + private void Publish() + { + ros.Publish(topicName, cmdVelMessage); + } +} diff --git a/MobileRobotUITutorialProject/Assets/JoyStick/Textures/white_circle.png b/MobileRobotUITutorialProject/Assets/JoyStick/Textures/white_circle.png new file mode 100644 index 0000000..74142f4 Binary files /dev/null and b/MobileRobotUITutorialProject/Assets/JoyStick/Textures/white_circle.png differ diff --git a/MobileRobotUITutorialProject/Assets/Models/maze.dae.meta b/MobileRobotUITutorialProject/Assets/Models/maze.dae.meta index 36528ea..eb05fe7 100644 --- a/MobileRobotUITutorialProject/Assets/Models/maze.dae.meta +++ b/MobileRobotUITutorialProject/Assets/Models/maze.dae.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 guid: 6b9104e2ac3a81ae584c1b2e4433d1cb ModelImporter: - serializedVersion: 20200 + serializedVersion: 21202 internalIDToNameTable: [] externalObjects: {} materials: @@ -14,6 +14,7 @@ ModelImporter: bakeSimulation: 0 resampleCurves: 1 optimizeGameObjects: 0 + removeConstantScaleCurves: 0 motionNodeName: rigImportErrors: rigImportWarnings: @@ -43,6 +44,7 @@ ModelImporter: importBlendShapes: 1 importCameras: 0 importLights: 0 + nodeNameCollisionStrategy: 0 fileIdsGeneration: 2 swapUVChannels: 0 generateSecondaryUV: 0 @@ -54,6 +56,7 @@ ModelImporter: skinWeightsMode: 0 maxBonesPerVertex: 4 minBoneWeight: 0.001 + optimizeBones: 1 meshOptimizationFlags: -1 indexFormat: 0 secondaryUVAngleDistortion: 8 diff --git a/MobileRobotUITutorialProject/Assets/OdometryViewer/Scripts/OdometryViewer.cs b/MobileRobotUITutorialProject/Assets/OdometryViewer/Scripts/OdometryViewer.cs index b1ec1ec..7a16865 100644 --- a/MobileRobotUITutorialProject/Assets/OdometryViewer/Scripts/OdometryViewer.cs +++ b/MobileRobotUITutorialProject/Assets/OdometryViewer/Scripts/OdometryViewer.cs @@ -1,80 +1,80 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using Unity.Robotics.ROSTCPConnector; -using OdometryMsg = RosMessageTypes.Nav.OdometryMsg; -using PointMsg = RosMessageTypes.Geometry.PointMsg; -using QuaternionMsg = RosMessageTypes.Geometry.QuaternionMsg; - -// This script is adapted from https://github.com/YusukeKato/raspimouse_odometry_tuning_unity/blob/master/Assets/Scripts/OdometryTuner.cs -// which is released under the MIT License. -// Copyright (c) 2018 YusukeKato - -/// -/// オドメトリ位置を可視化するためのクラス -/// (可視化のみを行い、座標変換を含むオドメトリの位置計算は予め行っている前提) -/// -public class OdometryViewer : MonoBehaviour -{ - - [SerializeField] bool isDebugMode = true; - [SerializeField] int lengthOfHistory = 10; - [SerializeField] float odometryDistanceThreshold = 0.03f; - [SerializeField] GameObject subscriberGameObject; - - [SerializeField] GameObject arrowPrefab; - - private List arrowList; - - private Vector3 previousRobotPosition = new Vector3(); - - /// - /// 初期化用のイベント関数 - /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html - /// ここで点群(オドメトリの矢印)用の配列を初期化 - /// - void Start() - { - arrowList = new List(lengthOfHistory); - - } - - /// - /// 1フレーム毎に呼び出されるイベント関数 - /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html - /// ここで点群の描画位置を決定 - /// - void Update() - { - Vector3 currentRobotPosition = subscriberGameObject.GetComponent().GetRobotPosition(); - Quaternion currentRobotPosture = subscriberGameObject.GetComponent().GetRobotPosture(); - - if (isDebugMode) - { - Debug.Log("diff: " + Vector3.Distance(currentRobotPosition, previousRobotPosition)); - } - if (Vector3.Distance(currentRobotPosition, previousRobotPosition) > odometryDistanceThreshold) - { - GameObject arrow = Instantiate(arrowPrefab); - arrow.transform.parent = gameObject.transform; - arrow.transform.position = currentRobotPosition; - arrow.transform.rotation = currentRobotPosture; - arrow.transform.Rotate(0, 180, 0); // ロボットの向きに合わせて矢印を回転 - if (arrowList.Count >= lengthOfHistory) { - Destroy(arrowList[0]); - arrowList.RemoveRange(0, 1); - } - arrowList.Add(arrow); - previousRobotPosition = currentRobotPosition; - - if (isDebugMode) - { - Debug.Log("arrow list length: " + arrowList.Count); - } - } - - - } - - +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Unity.Robotics.ROSTCPConnector; +using OdometryMsg = RosMessageTypes.Nav.OdometryMsg; +using PointMsg = RosMessageTypes.Geometry.PointMsg; +using QuaternionMsg = RosMessageTypes.Geometry.QuaternionMsg; + +// This script is adapted from https://github.com/YusukeKato/raspimouse_odometry_tuning_unity/blob/master/Assets/Scripts/OdometryTuner.cs +// which is released under the MIT License. +// Copyright (c) 2018 YusukeKato + +/// +/// オドメトリ位置を可視化するためのクラス +/// (可視化のみを行い、座標変換を含むオドメトリの位置計算は予め行っている前提) +/// +public class OdometryViewer : MonoBehaviour +{ + + [SerializeField] bool isDebugMode = true; + [SerializeField] int lengthOfHistory = 10; + [SerializeField] float odometryDistanceThreshold = 0.03f; + [SerializeField] GameObject subscriberGameObject; + + [SerializeField] GameObject arrowPrefab; + + private List arrowList; + + private Vector3 previousRobotPosition = new Vector3(); + + /// + /// 初期化用のイベント関数 + /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html + /// ここで点群(オドメトリの矢印)用の配列を初期化 + /// + void Start() + { + arrowList = new List(lengthOfHistory); + + } + + /// + /// 1フレーム毎に呼び出されるイベント関数 + /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html + /// ここで点群の描画位置を決定 + /// + void Update() + { + Vector3 currentRobotPosition = subscriberGameObject.GetComponent().GetRobotPosition(); + Quaternion currentRobotPosture = subscriberGameObject.GetComponent().GetRobotPosture(); + + if (isDebugMode) + { + Debug.Log("diff: " + Vector3.Distance(currentRobotPosition, previousRobotPosition)); + } + if (Vector3.Distance(currentRobotPosition, previousRobotPosition) > odometryDistanceThreshold) + { + GameObject arrow = Instantiate(arrowPrefab); + arrow.transform.parent = gameObject.transform; + arrow.transform.position = currentRobotPosition; + arrow.transform.rotation = currentRobotPosture; + arrow.transform.Rotate(0, 180, 0); // ロボットの向きに合わせて矢印を回転 + if (arrowList.Count >= lengthOfHistory) { + Destroy(arrowList[0]); + arrowList.RemoveRange(0, 1); + } + arrowList.Add(arrow); + previousRobotPosition = currentRobotPosition; + + if (isDebugMode) + { + Debug.Log("arrow list length: " + arrowList.Count); + } + } + + + } + + } \ No newline at end of file diff --git a/MobileRobotUITutorialProject/Assets/Resources/GeometryCompassSettings.asset b/MobileRobotUITutorialProject/Assets/Resources/GeometryCompassSettings.asset new file mode 100644 index 0000000..205dae2 --- /dev/null +++ b/MobileRobotUITutorialProject/Assets/Resources/GeometryCompassSettings.asset @@ -0,0 +1,15 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6ad8cf01110e54df290b36a418e91285, type: 3} + m_Name: GeometryCompassSettings + m_EditorClassIdentifier: + m_ZAxisDirection: 0 diff --git a/MobileRobotUITutorialProject/Assets/RosMessages.meta b/MobileRobotUITutorialProject/Assets/Resources/GeometryCompassSettings.asset.meta similarity index 52% rename from MobileRobotUITutorialProject/Assets/RosMessages.meta rename to MobileRobotUITutorialProject/Assets/Resources/GeometryCompassSettings.asset.meta index 3a9294e..707d072 100644 --- a/MobileRobotUITutorialProject/Assets/RosMessages.meta +++ b/MobileRobotUITutorialProject/Assets/Resources/GeometryCompassSettings.asset.meta @@ -1,8 +1,8 @@ fileFormatVersion: 2 -guid: bebd0eca66928a942830017627c7d481 -folderAsset: yes -DefaultImporter: +guid: d96801ebff8a5e641be96e7345c80a27 +NativeFormatImporter: externalObjects: {} + mainObjectFileID: 11400000 userData: assetBundleName: assetBundleVariant: diff --git a/MobileRobotUITutorialProject/Assets/Resources/ROSConnectionPrefab.prefab b/MobileRobotUITutorialProject/Assets/Resources/ROSConnectionPrefab.prefab index 1619049..db04414 100644 --- a/MobileRobotUITutorialProject/Assets/Resources/ROSConnectionPrefab.prefab +++ b/MobileRobotUITutorialProject/Assets/Resources/ROSConnectionPrefab.prefab @@ -28,6 +28,7 @@ Transform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} m_RootOrder: 0 @@ -51,6 +52,9 @@ MonoBehaviour: m_NetworkTimeoutSeconds: 2 m_SleepTimeSeconds: 0.01 m_ShowHUD: 1 + m_TFTopics: + - /tf + listenForTFMessages: 1 --- !u!114 &304769177554254289 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/MobileRobotUITutorialProject/Assets/RosMessages/Tf2.meta b/MobileRobotUITutorialProject/Assets/RosMessages/Tf2.meta deleted file mode 100644 index b2879da..0000000 --- a/MobileRobotUITutorialProject/Assets/RosMessages/Tf2.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 37682d1b76a9107e2aa9a96967e7ffb3 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/MobileRobotUITutorialProject/Assets/RosMessages/Tf2/msg.meta b/MobileRobotUITutorialProject/Assets/RosMessages/Tf2/msg.meta deleted file mode 100644 index 43e9705..0000000 --- a/MobileRobotUITutorialProject/Assets/RosMessages/Tf2/msg.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 4668b3e1665f205feac2d07b7f8f1c77 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/MobileRobotUITutorialProject/Assets/RosMessages/Tf2/msg/TFMessageMsg.cs b/MobileRobotUITutorialProject/Assets/RosMessages/Tf2/msg/TFMessageMsg.cs deleted file mode 100644 index 82416a6..0000000 --- a/MobileRobotUITutorialProject/Assets/RosMessages/Tf2/msg/TFMessageMsg.cs +++ /dev/null @@ -1,57 +0,0 @@ -//Do not edit! This file was generated by Unity-ROS MessageGeneration. -using System; -using System.Linq; -using System.Collections.Generic; -using System.Text; -using Unity.Robotics.ROSTCPConnector.MessageGeneration; - -namespace RosMessageTypes.Tf2 -{ - [Serializable] - public class TFMessageMsg : Message - { - public const string k_RosMessageName = "tf2_msgs/TFMessage"; - public override string RosMessageName => k_RosMessageName; - - public Geometry.TransformStampedMsg[] transforms; - - public TFMessageMsg() - { - this.transforms = new Geometry.TransformStampedMsg[0]; - } - - public TFMessageMsg(Geometry.TransformStampedMsg[] transforms) - { - this.transforms = transforms; - } - - public static TFMessageMsg Deserialize(MessageDeserializer deserializer) => new TFMessageMsg(deserializer); - - private TFMessageMsg(MessageDeserializer deserializer) - { - deserializer.Read(out this.transforms, Geometry.TransformStampedMsg.Deserialize, deserializer.ReadLength()); - } - - public override void SerializeTo(MessageSerializer serializer) - { - serializer.WriteLength(this.transforms); - serializer.Write(this.transforms); - } - - public override string ToString() - { - return "TFMessageMsg: " + - "\ntransforms: " + System.String.Join(", ", transforms.ToList()); - } - -#if UNITY_EDITOR - [UnityEditor.InitializeOnLoadMethod] -#else - [UnityEngine.RuntimeInitializeOnLoadMethod] -#endif - public static void Register() - { - MessageRegistry.Register(k_RosMessageName, Deserialize); - } - } -} diff --git a/MobileRobotUITutorialProject/Assets/RosMessages/Tf2/msg/TFMessageMsg.cs.meta b/MobileRobotUITutorialProject/Assets/RosMessages/Tf2/msg/TFMessageMsg.cs.meta deleted file mode 100644 index 2c867db..0000000 --- a/MobileRobotUITutorialProject/Assets/RosMessages/Tf2/msg/TFMessageMsg.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: dc85b05bfc22047559c16f98c5b4881f -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/MobileRobotUITutorialProject/Assets/Scripts/CmdVelPublisher.cs b/MobileRobotUITutorialProject/Assets/Scripts/CmdVelPublisher.cs index 8a12f74..7fb560c 100644 --- a/MobileRobotUITutorialProject/Assets/Scripts/CmdVelPublisher.cs +++ b/MobileRobotUITutorialProject/Assets/Scripts/CmdVelPublisher.cs @@ -1,92 +1,93 @@ -using UnityEngine; -using Unity.Robotics.ROSTCPConnector; -// 各種ROSトピック形式 -using TwistMsg = RosMessageTypes.Geometry.TwistMsg; - -/// -/// CmdVel(TwistMsg)を送信するためのクラス -/// UIから各関数を呼び出して使うことを想定 -/// -public class CmdVelPublisher : MonoBehaviour -{ - // Variables required for ROS communication - // 送信するROSのトピック名 - [SerializeField] string topicName = "cmd_vel"; - - // 送信する速度指令の基準となる値(各関数でこの速度に所定の倍率をかける) - [SerializeField] float linearVel; - - // 送信する角速度指令の基準となる値(各関数でこの角速度に所定の倍率をかける) - [SerializeField] float angularVel; - - // ROS Connector - private ROSConnection ros; - - private TwistMsg cmdVelMessage = new TwistMsg(); - - /// - /// 初期化用のイベント関数 - /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html - /// - void Start() - { - // Get ROS connection static instance - ros = ROSConnection.instance; - SetStopVel(); - Publish(); - } - - /// - /// 前進方向の速度指令を設定 - /// - /// 指令する速度の倍率 - public void SetForwardVel(float ratio=1.0f) - { - cmdVelMessage.linear.x = linearVel * ratio; - } - - /// - /// 後進方向の速度指令を設定 - /// - /// 指令する速度の倍率 - public void SetBackwardVel(float ratio=1.0f) - { - cmdVelMessage.linear.x = -linearVel * ratio; - } - - /// - /// 右旋回の角速度指令を設定 - /// - /// 指令する角速度の倍率 - public void SetRightTurnVel(float ratio=1.0f) - { - cmdVelMessage.angular.z = -angularVel * ratio; - } - - /// - /// 左旋回の角速度指令を設定 - /// - /// 指令する角速度の倍率 - public void SetLeftTurnVel(float ratio=1.0f) - { - cmdVelMessage.angular.z = angularVel * ratio; - } - - /// - /// 停止の速度指令、角速度指令を設定 - /// - public void SetStopVel() - { - cmdVelMessage.linear.x = 0; - cmdVelMessage.angular.z = 0; - } - - /// - /// 速度指令、角速度指令を送信 - /// - public void Publish() - { - // ROSのros_tcp_endpointのdefault_server_endpoint.pyにメッセージを送信 - ros.Send(topicName, cmdVelMessage); - } -} +using UnityEngine; +using Unity.Robotics.ROSTCPConnector; +// 各種ROSトピック形式 +using TwistMsg = RosMessageTypes.Geometry.TwistMsg; + +/// +/// CmdVel(TwistMsg)を送信するためのクラス +/// UIから各関数を呼び出して使うことを想定 +/// +public class CmdVelPublisher : MonoBehaviour +{ + // Variables required for ROS communication + // 送信するROSのトピック名 + [SerializeField] string topicName = "cmd_vel"; + + // 送信する速度指令の基準となる値(各関数でこの速度に所定の倍率をかける) + [SerializeField] float linearVel; + + // 送信する角速度指令の基準となる値(各関数でこの角速度に所定の倍率をかける) + [SerializeField] float angularVel; + + // ROS Connector + private ROSConnection ros; + + private TwistMsg cmdVelMessage = new TwistMsg(); + + /// + /// 初期化用のイベント関数 + /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html + /// + void Start() + { + // Get ROS connection static instance + ros = ROSConnection.GetOrCreateInstance(); + ros.RegisterPublisher(topicName); + SetStopVel(); + Publish(); + } + + /// + /// 前進方向の速度指令を設定 + /// + /// 指令する速度の倍率 + public void SetForwardVel(float ratio=1.0f) + { + cmdVelMessage.linear.x = linearVel * ratio; + } + + /// + /// 後進方向の速度指令を設定 + /// + /// 指令する速度の倍率 + public void SetBackwardVel(float ratio=1.0f) + { + cmdVelMessage.linear.x = -linearVel * ratio; + } + + /// + /// 右旋回の角速度指令を設定 + /// + /// 指令する角速度の倍率 + public void SetRightTurnVel(float ratio=1.0f) + { + cmdVelMessage.angular.z = -angularVel * ratio; + } + + /// + /// 左旋回の角速度指令を設定 + /// + /// 指令する角速度の倍率 + public void SetLeftTurnVel(float ratio=1.0f) + { + cmdVelMessage.angular.z = angularVel * ratio; + } + + /// + /// 停止の速度指令、角速度指令を設定 + /// + public void SetStopVel() + { + cmdVelMessage.linear.x = 0; + cmdVelMessage.angular.z = 0; + } + + /// + /// 速度指令、角速度指令を送信 + /// + public void Publish() + { + // ROSのros_tcp_endpointのdefault_server_endpoint.pyにメッセージを送信 + ros.Publish(topicName, cmdVelMessage); + } +} diff --git a/MobileRobotUITutorialProject/Assets/Scripts/CmdVelSubscriber.cs b/MobileRobotUITutorialProject/Assets/Scripts/CmdVelSubscriber.cs index e3bba37..9ca0e3f 100644 --- a/MobileRobotUITutorialProject/Assets/Scripts/CmdVelSubscriber.cs +++ b/MobileRobotUITutorialProject/Assets/Scripts/CmdVelSubscriber.cs @@ -1,36 +1,36 @@ -using UnityEngine; -using Unity.Robotics.ROSTCPConnector; -// 各種ROSトピック形式 -using TwistMsg = RosMessageTypes.Geometry.TwistMsg; - -/// -/// CmdVel(TwistMsg)を受信するためのクラス -/// 主にデバッグ用に使うことを想定 -/// -public class CmdVelSubscriber : MonoBehaviour -{ - // 受信するROSのトピック名 - [SerializeField] string rosTopicName = "cmd_vel"; - // デバッグモードとするかどうか(デバッグモードではコンソールにログを出力) - [SerializeField] bool isDebugMode = true; - - /// - /// 初期化用のイベント関数 - /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html - /// - void Start() - { - ROSConnection.instance.Subscribe(rosTopicName, CmdVelUpdate); - } - - /// - /// ROSトピックを受け取った際に呼ばれるコールバック関数 - /// - void CmdVelUpdate(TwistMsg twistMessage) - { - if (isDebugMode) - { - Debug.Log(twistMessage); - } - } +using UnityEngine; +using Unity.Robotics.ROSTCPConnector; +// 各種ROSトピック形式 +using TwistMsg = RosMessageTypes.Geometry.TwistMsg; + +/// +/// CmdVel(TwistMsg)を受信するためのクラス +/// 主にデバッグ用に使うことを想定 +/// +public class CmdVelSubscriber : MonoBehaviour +{ + // 受信するROSのトピック名 + [SerializeField] string rosTopicName = "cmd_vel"; + // デバッグモードとするかどうか(デバッグモードではコンソールにログを出力) + [SerializeField] bool isDebugMode = true; + + /// + /// 初期化用のイベント関数 + /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html + /// + void Start() + { + ROSConnection.GetOrCreateInstance().Subscribe(rosTopicName, CmdVelUpdate); + } + + /// + /// ROSトピックを受け取った際に呼ばれるコールバック関数 + /// + void CmdVelUpdate(TwistMsg twistMessage) + { + if (isDebugMode) + { + Debug.Log(twistMessage); + } + } } \ No newline at end of file diff --git a/MobileRobotUITutorialProject/Assets/Scripts/ImageSubscriber.cs b/MobileRobotUITutorialProject/Assets/Scripts/ImageSubscriber.cs index 10692f4..1d72ab0 100644 --- a/MobileRobotUITutorialProject/Assets/Scripts/ImageSubscriber.cs +++ b/MobileRobotUITutorialProject/Assets/Scripts/ImageSubscriber.cs @@ -1,81 +1,81 @@ -using UnityEngine; -using UnityEngine.UI; -using Unity.Robotics.ROSTCPConnector; -using CompressedImageMsg = RosMessageTypes.Sensor.CompressedImageMsg; - -/// -/// カメラデータ(CompressedImageMsg)を受信し、描画するためのクラス -/// -public class ImageSubscriber : MonoBehaviour -{ - // 受信するROSのトピック名 - [SerializeField] string rosTopicName = "webcam/image_raw/compressed"; - // デバッグモードとするかどうか(デバッグモードではコンソールにログを出力) - [SerializeField] bool isDebugMode = true; - // カメラデータを貼り付けるRawImageオブジェクト - [SerializeField] RawImage rawImage; - - private Texture2D texture2D; - private CameraImage cameraImage = new CameraImage(); - private bool isMessageReceived; - - /// - /// 初期化用のイベント関数 - /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html - /// - void Start() - { - ROSConnection.instance.Subscribe(rosTopicName, ImageMsgUpdate); - texture2D = new Texture2D(1, 1); - } - - /// - /// 1フレーム毎に呼び出されるイベント関数 - /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html - /// - void Update() - { - if (isMessageReceived) - { - ProcessMessage(); - } - } - - /// - /// ROSトピックを受け取った際に呼ばれるコールバック関数 - /// - void ImageMsgUpdate(CompressedImageMsg rawImage) - { - lock (cameraImage) - { - cameraImage.imageData = rawImage.data; - if (isDebugMode) - { - Debug.Log("rawImage recieved. length :" + System.Buffer.ByteLength(cameraImage.imageData)); - } - } - isMessageReceived = true; - } - - /// - /// ImageMsgのデータをTextureに反映する関数 - /// - void ProcessMessage() - { - lock (cameraImage) - { - texture2D.LoadImage(cameraImage.imageData); - texture2D.Apply(); - } - rawImage.texture = texture2D; - isMessageReceived = false; - } -} - -/// -/// アクセス制限用のカメライメージデータ格納配列 -/// -class CameraImage -{ - public byte[] imageData { get; set; } +using UnityEngine; +using UnityEngine.UI; +using Unity.Robotics.ROSTCPConnector; +using CompressedImageMsg = RosMessageTypes.Sensor.CompressedImageMsg; + +/// +/// カメラデータ(CompressedImageMsg)を受信し、描画するためのクラス +/// +public class ImageSubscriber : MonoBehaviour +{ + // 受信するROSのトピック名 + [SerializeField] string rosTopicName = "webcam/image_raw/compressed"; + // デバッグモードとするかどうか(デバッグモードではコンソールにログを出力) + [SerializeField] bool isDebugMode = true; + // カメラデータを貼り付けるRawImageオブジェクト + [SerializeField] RawImage rawImage; + + private Texture2D texture2D; + private CameraImage cameraImage = new CameraImage(); + private bool isMessageReceived; + + /// + /// 初期化用のイベント関数 + /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html + /// + void Start() + { + ROSConnection.GetOrCreateInstance().Subscribe(rosTopicName, ImageMsgUpdate); + texture2D = new Texture2D(1, 1); + } + + /// + /// 1フレーム毎に呼び出されるイベント関数 + /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html + /// + void Update() + { + if (isMessageReceived) + { + ProcessMessage(); + } + } + + /// + /// ROSトピックを受け取った際に呼ばれるコールバック関数 + /// + void ImageMsgUpdate(CompressedImageMsg rawImage) + { + lock (cameraImage) + { + cameraImage.imageData = rawImage.data; + if (isDebugMode) + { + Debug.Log("rawImage recieved. length :" + System.Buffer.ByteLength(cameraImage.imageData)); + } + } + isMessageReceived = true; + } + + /// + /// ImageMsgのデータをTextureに反映する関数 + /// + void ProcessMessage() + { + lock (cameraImage) + { + texture2D.LoadImage(cameraImage.imageData); + texture2D.Apply(); + } + rawImage.texture = texture2D; + isMessageReceived = false; + } +} + +/// +/// アクセス制限用のカメライメージデータ格納配列 +/// +class CameraImage +{ + public byte[] imageData { get; set; } } \ No newline at end of file diff --git a/MobileRobotUITutorialProject/Assets/Scripts/LaserScanSubscriber.cs b/MobileRobotUITutorialProject/Assets/Scripts/LaserScanSubscriber.cs index 7723743..50733d1 100644 --- a/MobileRobotUITutorialProject/Assets/Scripts/LaserScanSubscriber.cs +++ b/MobileRobotUITutorialProject/Assets/Scripts/LaserScanSubscriber.cs @@ -1,73 +1,73 @@ -using UnityEngine; -using Unity.Robotics.ROSTCPConnector; -// 座標変換用 -using Unity.Robotics.ROSTCPConnector.ROSGeometry; -// 各種ROSトピック形式 -using LaserScanMsg = RosMessageTypes.Sensor.LaserScanMsg; - -/// -/// LiDARスキャンデータ(LaserScanMsg)を受信するためのクラス -/// 主にスキャンデータの取得および座標変換に使い、描画は別のスクリプトを用意することを想定 -/// -public class LaserScanSubscriber : MonoBehaviour -{ - - // 受信するROSのトピック名 - [SerializeField] string rosTopicName = "scan"; - // デバッグモードとするかどうか(デバッグモードではコンソールにログを出力) - [SerializeField] bool isDebugMode = true; - - private float[] scanRangesArray; - private float scanAngleMin = 0; - private float scanAngleMax = 0; - - /// - /// 初期化用のイベント関数 - /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html - /// - void Start() - { - ROSConnection.instance.Subscribe(rosTopicName, ScanUpdate); - } - - - /// - /// ROSトピックを受け取った際に呼ばれるコールバック関数 - /// - void ScanUpdate(LaserScanMsg scanMessage) - { - if (isDebugMode) - { - Debug.Log(scanMessage); - } - - scanRangesArray = scanMessage.ranges; - scanAngleMax = scanMessage.angle_max; - scanAngleMin = scanMessage.angle_min; - } - - /// - /// 外部からスキャン結果の配列にアクセスするための関数 - /// - public float[] GetScanRanges() - { - return scanRangesArray; - - } - - /// - /// 外部からスキャン結果にアクセスするための関数 - /// - public float GetScanAngleMin() - { - return scanAngleMin; - } - - /// - /// 外部からスキャン結果にアクセスするための関数 - /// - public float GetScanAngleMax() - { - return scanAngleMax; - } +using UnityEngine; +using Unity.Robotics.ROSTCPConnector; +// 座標変換用 +using Unity.Robotics.ROSTCPConnector.ROSGeometry; +// 各種ROSトピック形式 +using LaserScanMsg = RosMessageTypes.Sensor.LaserScanMsg; + +/// +/// LiDARスキャンデータ(LaserScanMsg)を受信するためのクラス +/// 主にスキャンデータの取得および座標変換に使い、描画は別のスクリプトを用意することを想定 +/// +public class LaserScanSubscriber : MonoBehaviour +{ + + // 受信するROSのトピック名 + [SerializeField] string rosTopicName = "scan"; + // デバッグモードとするかどうか(デバッグモードではコンソールにログを出力) + [SerializeField] bool isDebugMode = true; + + private float[] scanRangesArray; + private float scanAngleMin = 0; + private float scanAngleMax = 0; + + /// + /// 初期化用のイベント関数 + /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html + /// + void Start() + { + ROSConnection.GetOrCreateInstance().Subscribe(rosTopicName, ScanUpdate); + } + + + /// + /// ROSトピックを受け取った際に呼ばれるコールバック関数 + /// + void ScanUpdate(LaserScanMsg scanMessage) + { + if (isDebugMode) + { + Debug.Log(scanMessage); + } + + scanRangesArray = scanMessage.ranges; + scanAngleMax = scanMessage.angle_max; + scanAngleMin = scanMessage.angle_min; + } + + /// + /// 外部からスキャン結果の配列にアクセスするための関数 + /// + public float[] GetScanRanges() + { + return scanRangesArray; + + } + + /// + /// 外部からスキャン結果にアクセスするための関数 + /// + public float GetScanAngleMin() + { + return scanAngleMin; + } + + /// + /// 外部からスキャン結果にアクセスするための関数 + /// + public float GetScanAngleMax() + { + return scanAngleMax; + } } \ No newline at end of file diff --git a/MobileRobotUITutorialProject/Assets/Scripts/OdomSubscriber.cs b/MobileRobotUITutorialProject/Assets/Scripts/OdomSubscriber.cs index ff81d84..3ed3110 100644 --- a/MobileRobotUITutorialProject/Assets/Scripts/OdomSubscriber.cs +++ b/MobileRobotUITutorialProject/Assets/Scripts/OdomSubscriber.cs @@ -1,70 +1,70 @@ -using UnityEngine; -using Unity.Robotics.ROSTCPConnector; -// 座標変換用 -using Unity.Robotics.ROSTCPConnector.ROSGeometry; -// 各種ROSトピック形式 -using OdometryMsg = RosMessageTypes.Nav.OdometryMsg; -using PointMsg = RosMessageTypes.Geometry.PointMsg; -using QuaternionMsg = RosMessageTypes.Geometry.QuaternionMsg; - -/// -/// オドメトリデータ(OdometryMsg)を受信するためのクラス -/// 主にオドメトリデータの取得および座標変換に使い、描画は別のスクリプトを用意することを想定 -/// -public class OdomSubscriber : MonoBehaviour -{ - - [SerializeField] string rosTopicName = "odom"; - [SerializeField] bool isDebugMode = true; - - private Vector3 robotPosition = new Vector3(); - private Quaternion robotPosture = new Quaternion(); - - /// - /// 初期化用のイベント関数 - /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html - /// - void Start() - { - ROSConnection.instance.Subscribe(rosTopicName, OdomUpdate); - } - - /// - /// ROSトピックを受け取った際に呼ばれるコールバック関数 - /// - void OdomUpdate(OdometryMsg odomMessage) - { - if (isDebugMode) - { - Debug.Log(odomMessage); - } - - PointMsg rosOdomPositionMsg = odomMessage.pose.pose.position; - QuaternionMsg rosOdomPostureMsg = odomMessage.pose.pose.orientation; - - // OdomのTwist情報も使う場合は以下を使用 - // Vector3Msg rosOdomTwistLinearMsg = odomMessage.twist.linear; - // Vector3Msg rosOdomTwistAngularMsg = odomMessage.twist.angular; - - // 座標変換 - robotPosition = rosOdomPositionMsg.From(); - robotPosture = rosOdomPostureMsg.From(); - } - - /// - /// 外部からオドメトリ(ROS上のオドメトリ情報をUnity座標に変換したもの)の位置情報にアクセスするための関数 - /// - public Vector3 GetRobotPosition() - { - return robotPosition; - - } - - /// - /// 外部からオドメトリ(ROS上のオドメトリ情報をUnity座標に変換したもの)の姿勢情報にアクセスするための関数 - /// - public Quaternion GetRobotPosture() - { - return robotPosture; - } +using UnityEngine; +using Unity.Robotics.ROSTCPConnector; +// 座標変換用 +using Unity.Robotics.ROSTCPConnector.ROSGeometry; +// 各種ROSトピック形式 +using OdometryMsg = RosMessageTypes.Nav.OdometryMsg; +using PointMsg = RosMessageTypes.Geometry.PointMsg; +using QuaternionMsg = RosMessageTypes.Geometry.QuaternionMsg; + +/// +/// オドメトリデータ(OdometryMsg)を受信するためのクラス +/// 主にオドメトリデータの取得および座標変換に使い、描画は別のスクリプトを用意することを想定 +/// +public class OdomSubscriber : MonoBehaviour +{ + + [SerializeField] string rosTopicName = "odom"; + [SerializeField] bool isDebugMode = true; + + private Vector3 robotPosition = new Vector3(); + private Quaternion robotPosture = new Quaternion(); + + /// + /// 初期化用のイベント関数 + /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html + /// + void Start() + { + ROSConnection.GetOrCreateInstance().Subscribe(rosTopicName, OdomUpdate); + } + + /// + /// ROSトピックを受け取った際に呼ばれるコールバック関数 + /// + void OdomUpdate(OdometryMsg odomMessage) + { + if (isDebugMode) + { + Debug.Log(odomMessage); + } + + PointMsg rosOdomPositionMsg = odomMessage.pose.pose.position; + QuaternionMsg rosOdomPostureMsg = odomMessage.pose.pose.orientation; + + // OdomのTwist情報も使う場合は以下を使用 + // Vector3Msg rosOdomTwistLinearMsg = odomMessage.twist.linear; + // Vector3Msg rosOdomTwistAngularMsg = odomMessage.twist.angular; + + // 座標変換 + robotPosition = rosOdomPositionMsg.From(); + robotPosture = rosOdomPostureMsg.From(); + } + + /// + /// 外部からオドメトリ(ROS上のオドメトリ情報をUnity座標に変換したもの)の位置情報にアクセスするための関数 + /// + public Vector3 GetRobotPosition() + { + return robotPosition; + + } + + /// + /// 外部からオドメトリ(ROS上のオドメトリ情報をUnity座標に変換したもの)の姿勢情報にアクセスするための関数 + /// + public Quaternion GetRobotPosture() + { + return robotPosture; + } } \ No newline at end of file diff --git a/MobileRobotUITutorialProject/Assets/Scripts/TfSubscriber.cs b/MobileRobotUITutorialProject/Assets/Scripts/TfSubscriber.cs index 6410eb3..941f7cf 100644 --- a/MobileRobotUITutorialProject/Assets/Scripts/TfSubscriber.cs +++ b/MobileRobotUITutorialProject/Assets/Scripts/TfSubscriber.cs @@ -1,125 +1,125 @@ -using UnityEngine; -using Unity.Robotics.ROSTCPConnector; -// 座標変換用 -using Unity.Robotics.ROSTCPConnector.ROSGeometry; - -// 各種ROSトピック形式 -using RosMessageTypes.Geometry; -using Tf = RosMessageTypes.Tf2.TFMessageMsg; -using RosPosVector3 = Unity.Robotics.ROSTCPConnector.ROSGeometry.Vector3; -using RosQuaternion = Unity.Robotics.ROSTCPConnector.ROSGeometry.Quaternion; - -/// -/// ロボットの位置姿勢データ(TFMessageMsg)を受信するためのクラス -/// 位置姿勢データの取得、座標変換を行い、指定したGameObjectの位置姿勢を指定する用途を想定 -/// -public class TfSubscriber : MonoBehaviour -{ - // Variables required for ROS communication - [SerializeField] string rosTopicName = "tf"; - - [SerializeField] GameObject mobileRobot; - - [SerializeField] bool isDebugMode = true; - - private int numRobotLinks = 4; - - private Transform[] robotLinkPositions; - - /// - /// 初期化用のイベント関数 - /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html - /// - void Start() - { - // // Get ROS connection static instance - ROSConnection.instance.Subscribe(rosTopicName, TfUpdate); - - robotLinkPositions = new Transform[numRobotLinks]; - - string footprint_link = "base_footprint"; - robotLinkPositions[0] = mobileRobot.transform.Find(footprint_link).transform; - - string body_link = footprint_link + "/base_link"; - robotLinkPositions[1] = mobileRobot.transform.Find(body_link).transform; - - string right_wheel_link = body_link + "/right_wheel_link"; - robotLinkPositions[2] = mobileRobot.transform.Find(right_wheel_link).transform; - - string left_wheel_link = body_link + "/left_wheel_link"; - robotLinkPositions[3] = mobileRobot.transform.Find(left_wheel_link).transform; - - - if (isDebugMode) - { - Debug.Log(robotLinkPositions[1].position + " " + robotLinkPositions[1].rotation); - } - } - - /// - /// デバッグ時の文字列生成用関数 - /// - string Vector3ToString(Vector3 vec, string titile = "") - { - return titile + " (" + vec[0] + ", " + vec[1] + ", " + vec[2] + ")"; - } - - /// - /// デバッグ時の文字列生成用関数 - /// - string RosPosVector3ToString(RosPosVector3 vec, string titile = "") - { - return titile + " (" + vec.x + ", " + vec.y + ", " + vec.z + ")"; - } - - /// - /// ROSトピックを受け取った際に呼ばれるコールバック関数 - /// - void TfUpdate(Tf tfMessage) - { - for (int i = 0; i < tfMessage.transforms.Length; i++) - { - if (tfMessage.transforms[i].child_frame_id == "base_footprint") - { - - Vector3Msg rosPosMsg = tfMessage.transforms[i].transform.translation; - QuaternionMsg rosQuaternionMsg = tfMessage.transforms[i].transform.rotation; - - // 座標変換 - // 座標変換に関するのドキュメント - // https://github.com/Unity-Technologies/ROS-TCP-Connector/blob/v0.5.0/ROSGeometry.md - // 上記ドキュメントの実装箇所 - // https://github.com/Unity-Technologies/ROS-TCP-Connector/blob/v0.5.0/com.unity.robotics.ros-tcp-connector/Runtime/ROSGeometry/CoordinateSpaces.cs - RosPosVector3 rosPos = rosPosMsg.As(); - Vector3 unityPos = rosPos.toUnity; - if (isDebugMode) - { - Debug.Log(RosPosVector3ToString(rosPos, "tf(ros)") + " --> " + Vector3ToString(unityPos, "tf(unity)")); - } - - RosQuaternion rosQuaternion = rosQuaternionMsg.As(); - Quaternion unityQuaternion = rosQuaternion.toUnity; - - // 座標変換はこちらでもOK (1) - // Vector3 unityPos = tfMessage.transforms[i].transform.translation.From(); - // Quaternion unityQuaternion = tfMessage.transforms[i].transform.rotation.From(); - - // 座標変換はこちらでもOK (2) - // Vector3 unityPos = new Vector3((float)-tfMessage.transforms[i].transform.translation.y, - // (float)tfMessage.transforms[i].transform.translation.z, - // (float)tfMessage.transforms[i].transform.translation.x); - // Quaternion unityQuaternion = new Quaternion((float)-tfMessage.transforms[i].transform.rotation.y, - // (float)tfMessage.transforms[i].transform.rotation.z, - // (float)tfMessage.transforms[i].transform.rotation.x, - // (float)-tfMessage.transforms[i].transform.rotation.w); - - robotLinkPositions[0].position = unityPos; - robotLinkPositions[0].rotation = unityQuaternion; - if (isDebugMode) - { - Debug.Log(Vector3ToString(unityPos, "pos")); - } - } - } - } -} +using UnityEngine; +using Unity.Robotics.ROSTCPConnector; +// 座標変換用 +using Unity.Robotics.ROSTCPConnector.ROSGeometry; + +// 各種ROSトピック形式 +using RosMessageTypes.Geometry; +using Tf = RosMessageTypes.Tf2.TFMessageMsg; +using RosPosVector3 = Unity.Robotics.ROSTCPConnector.ROSGeometry.Vector3; +using RosQuaternion = Unity.Robotics.ROSTCPConnector.ROSGeometry.Quaternion; + +/// +/// ロボットの位置姿勢データ(TFMessageMsg)を受信するためのクラス +/// 位置姿勢データの取得、座標変換を行い、指定したGameObjectの位置姿勢を指定する用途を想定 +/// +public class TfSubscriber : MonoBehaviour +{ + // Variables required for ROS communication + [SerializeField] string rosTopicName = "tf"; + + [SerializeField] GameObject mobileRobot; + + [SerializeField] bool isDebugMode = true; + + private int numRobotLinks = 4; + + private Transform[] robotLinkPositions; + + /// + /// 初期化用のイベント関数 + /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html + /// + void Start() + { + // // Get ROS connection static instance + ROSConnection.GetOrCreateInstance().Subscribe(rosTopicName, TfUpdate); + + robotLinkPositions = new Transform[numRobotLinks]; + + string footprint_link = "base_footprint"; + robotLinkPositions[0] = mobileRobot.transform.Find(footprint_link).transform; + + string body_link = footprint_link + "/base_link"; + robotLinkPositions[1] = mobileRobot.transform.Find(body_link).transform; + + string right_wheel_link = body_link + "/right_wheel_link"; + robotLinkPositions[2] = mobileRobot.transform.Find(right_wheel_link).transform; + + string left_wheel_link = body_link + "/left_wheel_link"; + robotLinkPositions[3] = mobileRobot.transform.Find(left_wheel_link).transform; + + + if (isDebugMode) + { + Debug.Log(robotLinkPositions[1].position + " " + robotLinkPositions[1].rotation); + } + } + + /// + /// デバッグ時の文字列生成用関数 + /// + string Vector3ToString(Vector3 vec, string titile = "") + { + return titile + " (" + vec[0] + ", " + vec[1] + ", " + vec[2] + ")"; + } + + /// + /// デバッグ時の文字列生成用関数 + /// + string RosPosVector3ToString(RosPosVector3 vec, string titile = "") + { + return titile + " (" + vec.x + ", " + vec.y + ", " + vec.z + ")"; + } + + /// + /// ROSトピックを受け取った際に呼ばれるコールバック関数 + /// + void TfUpdate(Tf tfMessage) + { + for (int i = 0; i < tfMessage.transforms.Length; i++) + { + if (tfMessage.transforms[i].child_frame_id == "base_footprint") + { + + Vector3Msg rosPosMsg = tfMessage.transforms[i].transform.translation; + QuaternionMsg rosQuaternionMsg = tfMessage.transforms[i].transform.rotation; + + // 座標変換 + // 座標変換に関するのドキュメント + // https://github.com/Unity-Technologies/ROS-TCP-Connector/blob/v0.5.0/ROSGeometry.md + // 上記ドキュメントの実装箇所 + // https://github.com/Unity-Technologies/ROS-TCP-Connector/blob/v0.5.0/com.unity.robotics.ros-tcp-connector/Runtime/ROSGeometry/CoordinateSpaces.cs + RosPosVector3 rosPos = rosPosMsg.As(); + Vector3 unityPos = rosPos.toUnity; + if (isDebugMode) + { + Debug.Log(RosPosVector3ToString(rosPos, "tf(ros)") + " --> " + Vector3ToString(unityPos, "tf(unity)")); + } + + RosQuaternion rosQuaternion = rosQuaternionMsg.As(); + Quaternion unityQuaternion = rosQuaternion.toUnity; + + // 座標変換はこちらでもOK (1) + // Vector3 unityPos = tfMessage.transforms[i].transform.translation.From(); + // Quaternion unityQuaternion = tfMessage.transforms[i].transform.rotation.From(); + + // 座標変換はこちらでもOK (2) + // Vector3 unityPos = new Vector3((float)-tfMessage.transforms[i].transform.translation.y, + // (float)tfMessage.transforms[i].transform.translation.z, + // (float)tfMessage.transforms[i].transform.translation.x); + // Quaternion unityQuaternion = new Quaternion((float)-tfMessage.transforms[i].transform.rotation.y, + // (float)tfMessage.transforms[i].transform.rotation.z, + // (float)tfMessage.transforms[i].transform.rotation.x, + // (float)-tfMessage.transforms[i].transform.rotation.w); + + robotLinkPositions[0].position = unityPos; + robotLinkPositions[0].rotation = unityQuaternion; + if (isDebugMode) + { + Debug.Log(Vector3ToString(unityPos, "pos")); + } + } + } + } +} diff --git a/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/body/RasPiMouse_body.dae.meta b/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/body/RasPiMouse_body.dae.meta index 0ebe0e7..651dadc 100644 --- a/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/body/RasPiMouse_body.dae.meta +++ b/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/body/RasPiMouse_body.dae.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 guid: 5e03af72d6aa3ff489b0582393d7f92c ModelImporter: - serializedVersion: 20200 + serializedVersion: 21202 internalIDToNameTable: [] externalObjects: {} materials: @@ -14,6 +14,7 @@ ModelImporter: bakeSimulation: 0 resampleCurves: 1 optimizeGameObjects: 0 + removeConstantScaleCurves: 0 motionNodeName: rigImportErrors: rigImportWarnings: @@ -43,6 +44,7 @@ ModelImporter: importBlendShapes: 1 importCameras: 0 importLights: 0 + nodeNameCollisionStrategy: 0 fileIdsGeneration: 2 swapUVChannels: 0 generateSecondaryUV: 0 @@ -54,6 +56,7 @@ ModelImporter: skinWeightsMode: 0 maxBonesPerVertex: 4 minBoneWeight: 0.001 + optimizeBones: 1 meshOptimizationFlags: -1 indexFormat: 0 secondaryUVAngleDistortion: 8 diff --git a/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/body/raspimouse_camera_mount.dae.meta b/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/body/raspimouse_camera_mount.dae.meta index 2f629b7..9f66235 100644 --- a/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/body/raspimouse_camera_mount.dae.meta +++ b/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/body/raspimouse_camera_mount.dae.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 guid: d072c67c50d6d90498d64f71e77c545e ModelImporter: - serializedVersion: 20200 + serializedVersion: 21202 internalIDToNameTable: [] externalObjects: {} materials: @@ -14,6 +14,7 @@ ModelImporter: bakeSimulation: 0 resampleCurves: 1 optimizeGameObjects: 0 + removeConstantScaleCurves: 0 motionNodeName: rigImportErrors: rigImportWarnings: @@ -43,6 +44,7 @@ ModelImporter: importBlendShapes: 1 importCameras: 0 importLights: 0 + nodeNameCollisionStrategy: 0 fileIdsGeneration: 2 swapUVChannels: 0 generateSecondaryUV: 0 @@ -54,6 +56,7 @@ ModelImporter: skinWeightsMode: 0 maxBonesPerVertex: 4 minBoneWeight: 0.001 + optimizeBones: 1 meshOptimizationFlags: -1 indexFormat: 0 secondaryUVAngleDistortion: 8 diff --git a/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/body/raspimouse_top_plate.dae.meta b/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/body/raspimouse_top_plate.dae.meta index 76baab9..1aef980 100644 --- a/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/body/raspimouse_top_plate.dae.meta +++ b/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/body/raspimouse_top_plate.dae.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 guid: 24bc2ccaa83d8734683894a9865c06ea ModelImporter: - serializedVersion: 20200 + serializedVersion: 21202 internalIDToNameTable: [] externalObjects: {} materials: @@ -14,6 +14,7 @@ ModelImporter: bakeSimulation: 0 resampleCurves: 1 optimizeGameObjects: 0 + removeConstantScaleCurves: 0 motionNodeName: rigImportErrors: rigImportWarnings: @@ -43,6 +44,7 @@ ModelImporter: importBlendShapes: 1 importCameras: 0 importLights: 0 + nodeNameCollisionStrategy: 0 fileIdsGeneration: 2 swapUVChannels: 0 generateSecondaryUV: 0 @@ -54,6 +56,7 @@ ModelImporter: skinWeightsMode: 0 maxBonesPerVertex: 4 minBoneWeight: 0.001 + optimizeBones: 1 meshOptimizationFlags: -1 indexFormat: 0 secondaryUVAngleDistortion: 8 diff --git a/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/sensor/urg_bottom_origin.dae.meta b/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/sensor/urg_bottom_origin.dae.meta index bcfe4ba..567100f 100644 --- a/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/sensor/urg_bottom_origin.dae.meta +++ b/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/sensor/urg_bottom_origin.dae.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 guid: f1a8d43c362b6e949a7574d2a86da651 ModelImporter: - serializedVersion: 20200 + serializedVersion: 21202 internalIDToNameTable: [] externalObjects: {} materials: @@ -14,6 +14,7 @@ ModelImporter: bakeSimulation: 0 resampleCurves: 1 optimizeGameObjects: 0 + removeConstantScaleCurves: 0 motionNodeName: rigImportErrors: rigImportWarnings: @@ -43,6 +44,7 @@ ModelImporter: importBlendShapes: 1 importCameras: 0 importLights: 0 + nodeNameCollisionStrategy: 0 fileIdsGeneration: 2 swapUVChannels: 0 generateSecondaryUV: 0 @@ -54,6 +56,7 @@ ModelImporter: skinWeightsMode: 0 maxBonesPerVertex: 4 minBoneWeight: 0.001 + optimizeBones: 1 meshOptimizationFlags: -1 indexFormat: 0 secondaryUVAngleDistortion: 8 diff --git a/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/sensor/urg_optical_axis_center_origin.dae.meta b/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/sensor/urg_optical_axis_center_origin.dae.meta index bf11f65..3415d97 100644 --- a/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/sensor/urg_optical_axis_center_origin.dae.meta +++ b/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/sensor/urg_optical_axis_center_origin.dae.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 guid: 85089aaa6fac34c40871a2ecd5b66c26 ModelImporter: - serializedVersion: 20200 + serializedVersion: 21202 internalIDToNameTable: [] externalObjects: {} materials: @@ -14,6 +14,7 @@ ModelImporter: bakeSimulation: 0 resampleCurves: 1 optimizeGameObjects: 0 + removeConstantScaleCurves: 0 motionNodeName: rigImportErrors: rigImportWarnings: @@ -43,6 +44,7 @@ ModelImporter: importBlendShapes: 1 importCameras: 0 importLights: 0 + nodeNameCollisionStrategy: 0 fileIdsGeneration: 2 swapUVChannels: 0 generateSecondaryUV: 0 @@ -54,6 +56,7 @@ ModelImporter: skinWeightsMode: 0 maxBonesPerVertex: 4 minBoneWeight: 0.001 + optimizeBones: 1 meshOptimizationFlags: -1 indexFormat: 0 secondaryUVAngleDistortion: 8 diff --git a/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/wheel/RasPiMouse_wheel.dae.meta b/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/wheel/RasPiMouse_wheel.dae.meta index 915fa55..3084629 100644 --- a/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/wheel/RasPiMouse_wheel.dae.meta +++ b/MobileRobotUITutorialProject/Assets/URDF/raspimouse_description/meshes/dae/wheel/RasPiMouse_wheel.dae.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 guid: 9ed7525c73ff11a40b9ad0fd772638ff ModelImporter: - serializedVersion: 20200 + serializedVersion: 21202 internalIDToNameTable: [] externalObjects: {} materials: @@ -14,6 +14,7 @@ ModelImporter: bakeSimulation: 0 resampleCurves: 1 optimizeGameObjects: 0 + removeConstantScaleCurves: 0 motionNodeName: rigImportErrors: rigImportWarnings: @@ -43,6 +44,7 @@ ModelImporter: importBlendShapes: 1 importCameras: 0 importLights: 0 + nodeNameCollisionStrategy: 0 fileIdsGeneration: 2 swapUVChannels: 0 generateSecondaryUV: 0 @@ -54,6 +56,7 @@ ModelImporter: skinWeightsMode: 0 maxBonesPerVertex: 4 minBoneWeight: 0.001 + optimizeBones: 1 meshOptimizationFlags: -1 indexFormat: 0 secondaryUVAngleDistortion: 8 diff --git a/MobileRobotUITutorialProject/Packages/manifest.json b/MobileRobotUITutorialProject/Packages/manifest.json index f1be759..7d4b01e 100644 --- a/MobileRobotUITutorialProject/Packages/manifest.json +++ b/MobileRobotUITutorialProject/Packages/manifest.json @@ -1,14 +1,15 @@ { "dependencies": { - "com.unity.collab-proxy": "1.9.0", - "com.unity.ide.rider": "2.0.7", - "com.unity.ide.visualstudio": "2.0.11", - "com.unity.ide.vscode": "1.2.4", - "com.unity.robotics.ros-tcp-connector": "https://github.com/Unity-Technologies/ROS-TCP-Connector.git?path=/com.unity.robotics.ros-tcp-connector", - "com.unity.robotics.urdf-importer": "https://github.com/Unity-Technologies/URDF-Importer.git?path=/com.unity.robotics.urdf-importer", - "com.unity.test-framework": "1.1.29", + "com.unity.collab-proxy": "1.15.17", + "com.unity.ide.rider": "3.0.14", + "com.unity.ide.visualstudio": "2.0.15", + "com.unity.ide.vscode": "1.2.5", + "com.unity.inputsystem": "1.3.0", + "com.unity.robotics.ros-tcp-connector": "https://github.com/Unity-Technologies/ROS-TCP-Connector.git?path=/com.unity.robotics.ros-tcp-connector#v0.7.0", + "com.unity.robotics.urdf-importer": "https://github.com/Unity-Technologies/URDF-Importer.git?path=/com.unity.robotics.urdf-importer#v0.5.2", + "com.unity.test-framework": "1.1.31", "com.unity.textmeshpro": "3.0.6", - "com.unity.timeline": "1.4.8", + "com.unity.timeline": "1.6.4", "com.unity.toolchain.linux-x86_64": "0.1.19-preview", "com.unity.ugui": "1.0.0", "com.unity.modules.ai": "1.0.0", diff --git a/MobileRobotUITutorialProject/Packages/packages-lock.json b/MobileRobotUITutorialProject/Packages/packages-lock.json index d6d17a3..649aff0 100644 --- a/MobileRobotUITutorialProject/Packages/packages-lock.json +++ b/MobileRobotUITutorialProject/Packages/packages-lock.json @@ -1,10 +1,12 @@ { "dependencies": { "com.unity.collab-proxy": { - "version": "1.9.0", + "version": "1.15.17", "depth": 0, "source": "registry", - "dependencies": {}, + "dependencies": { + "com.unity.services.core": "1.0.1" + }, "url": "https://packages.unity.com" }, "com.unity.editorcoroutines": { @@ -22,16 +24,16 @@ "url": "https://packages.unity.com" }, "com.unity.ide.rider": { - "version": "2.0.7", + "version": "3.0.14", "depth": 0, "source": "registry", "dependencies": { - "com.unity.test-framework": "1.1.1" + "com.unity.ext.nunit": "1.0.6" }, "url": "https://packages.unity.com" }, "com.unity.ide.visualstudio": { - "version": "2.0.11", + "version": "2.0.15", "depth": 0, "source": "registry", "dependencies": { @@ -40,27 +42,54 @@ "url": "https://packages.unity.com" }, "com.unity.ide.vscode": { - "version": "1.2.4", + "version": "1.2.5", + "depth": 0, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, + "com.unity.inputsystem": { + "version": "1.3.0", "depth": 0, "source": "registry", + "dependencies": { + "com.unity.modules.uielements": "1.0.0" + }, + "url": "https://packages.unity.com" + }, + "com.unity.nuget.newtonsoft-json": { + "version": "3.0.2", + "depth": 2, + "source": "registry", "dependencies": {}, "url": "https://packages.unity.com" }, "com.unity.robotics.ros-tcp-connector": { - "version": "https://github.com/Unity-Technologies/ROS-TCP-Connector.git?path=/com.unity.robotics.ros-tcp-connector", + "version": "https://github.com/Unity-Technologies/ROS-TCP-Connector.git?path=/com.unity.robotics.ros-tcp-connector#v0.7.0", "depth": 0, "source": "git", "dependencies": {}, - "hash": "f7f669f212423ff03817a2094f489547158a3852" + "hash": "c27f00c6cf750d2d0564349b3039d19aa3925e7c" }, "com.unity.robotics.urdf-importer": { - "version": "https://github.com/Unity-Technologies/URDF-Importer.git?path=/com.unity.robotics.urdf-importer", + "version": "https://github.com/Unity-Technologies/URDF-Importer.git?path=/com.unity.robotics.urdf-importer#v0.5.2", "depth": 0, "source": "git", "dependencies": { "com.unity.editorcoroutines": "1.0.0" }, - "hash": "e9859c4becda48194e153356afc0a802516b1488" + "hash": "90f353e4352aae4df52fa2c05e49b804631d2a63" + }, + "com.unity.services.core": { + "version": "1.4.0", + "depth": 1, + "source": "registry", + "dependencies": { + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.nuget.newtonsoft-json": "3.0.2", + "com.unity.modules.androidjni": "1.0.0" + }, + "url": "https://packages.unity.com" }, "com.unity.sysroot": { "version": "0.1.19-preview", @@ -79,7 +108,7 @@ "url": "https://packages.unity.com" }, "com.unity.test-framework": { - "version": "1.1.29", + "version": "1.1.31", "depth": 0, "source": "registry", "dependencies": { @@ -99,7 +128,7 @@ "url": "https://packages.unity.com" }, "com.unity.timeline": { - "version": "1.4.8", + "version": "1.6.4", "depth": 0, "source": "registry", "dependencies": { diff --git a/MobileRobotUITutorialProject/ProjectSettings/MemorySettings.asset b/MobileRobotUITutorialProject/ProjectSettings/MemorySettings.asset new file mode 100644 index 0000000..5b5face --- /dev/null +++ b/MobileRobotUITutorialProject/ProjectSettings/MemorySettings.asset @@ -0,0 +1,35 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!387306366 &1 +MemorySettings: + m_ObjectHideFlags: 0 + m_EditorMemorySettings: + m_MainAllocatorBlockSize: -1 + m_ThreadAllocatorBlockSize: -1 + m_MainGfxBlockSize: -1 + m_ThreadGfxBlockSize: -1 + m_CacheBlockSize: -1 + m_TypetreeBlockSize: -1 + m_ProfilerBlockSize: -1 + m_ProfilerEditorBlockSize: -1 + m_BucketAllocatorGranularity: -1 + m_BucketAllocatorBucketsCount: -1 + m_BucketAllocatorBlockSize: -1 + m_BucketAllocatorBlockCount: -1 + m_ProfilerBucketAllocatorGranularity: -1 + m_ProfilerBucketAllocatorBucketsCount: -1 + m_ProfilerBucketAllocatorBlockSize: -1 + m_ProfilerBucketAllocatorBlockCount: -1 + m_TempAllocatorSizeMain: -1 + m_JobTempAllocatorBlockSize: -1 + m_BackgroundJobTempAllocatorBlockSize: -1 + m_JobTempAllocatorReducedBlockSize: -1 + m_TempAllocatorSizeGIBakingWorker: -1 + m_TempAllocatorSizeNavMeshWorker: -1 + m_TempAllocatorSizeAudioWorker: -1 + m_TempAllocatorSizeCloudWorker: -1 + m_TempAllocatorSizeGfx: -1 + m_TempAllocatorSizeJobWorker: -1 + m_TempAllocatorSizeBackgroundWorker: -1 + m_TempAllocatorSizePreloadManager: -1 + m_PlatformMemorySettings: {} diff --git a/MobileRobotUITutorialProject/ProjectSettings/ProjectSettings.asset b/MobileRobotUITutorialProject/ProjectSettings/ProjectSettings.asset index 43f2240..b51381d 100644 --- a/MobileRobotUITutorialProject/ProjectSettings/ProjectSettings.asset +++ b/MobileRobotUITutorialProject/ProjectSettings/ProjectSettings.asset @@ -3,7 +3,7 @@ --- !u!129 &1 PlayerSettings: m_ObjectHideFlags: 0 - serializedVersion: 22 + serializedVersion: 23 productGUID: 134da5f6c4487944e9ea72b2e20c7727 AndroidProfiler: 0 AndroidFilterTouchesWhenObscured: 0 @@ -68,6 +68,12 @@ PlayerSettings: androidRenderOutsideSafeArea: 1 androidUseSwappy: 1 androidBlitType: 0 + androidResizableWindow: 0 + androidDefaultWindowWidth: 1920 + androidDefaultWindowHeight: 1080 + androidMinimumWindowWidth: 400 + androidMinimumWindowHeight: 300 + androidFullscreenMode: 1 defaultIsNativeResolution: 1 macRetinaSupport: 1 runInBackground: 1 @@ -121,6 +127,7 @@ PlayerSettings: vulkanEnableSetSRGBWrite: 0 vulkanEnablePreTransform: 0 vulkanEnableLateAcquireNextImage: 0 + vulkanEnableCommandBufferRecycling: 1 m_SupportedAspectRatios: 4:3: 1 5:4: 1 @@ -138,11 +145,13 @@ PlayerSettings: enable360StereoCapture: 0 isWsaHolographicRemotingEnabled: 0 enableFrameTimingStats: 0 + enableOpenGLProfilerGPURecorders: 1 useHDRDisplay: 0 D3DHDRBitDepth: 0 m_ColorGamuts: 00000000 targetPixelDensity: 30 resolutionScalingMode: 0 + resetResolutionOnWindowResize: 0 androidSupportedAspectRatio: 1 androidMaxAspectRatio: 2.1 applicationIdentifier: {} @@ -152,7 +161,7 @@ PlayerSettings: tvOS: 0 overrideDefaultApplicationIdentifier: 0 AndroidBundleVersionCode: 1 - AndroidMinSdkVersion: 19 + AndroidMinSdkVersion: 22 AndroidTargetSdkVersion: 0 AndroidPreferredInstallLocation: 1 aotOptions: @@ -208,6 +217,7 @@ PlayerSettings: iOSLaunchScreeniPadCustomStoryboardPath: iOSDeviceRequirements: [] iOSURLSchemes: [] + macOSURLSchemes: [] iOSBackgroundModes: 0 iOSMetalForceHardShadows: 0 metalEditorSupport: 1 @@ -235,6 +245,7 @@ PlayerSettings: useCustomGradlePropertiesTemplate: 0 useCustomProguardFile: 0 AndroidTargetArchitectures: 1 + AndroidTargetDevices: 0 AndroidSplashScreenScale: 0 androidSplashScreen: {fileID: 0} AndroidKeystoreName: @@ -251,13 +262,106 @@ PlayerSettings: height: 180 banner: {fileID: 0} androidGamepadSupportLevel: 0 + chromeosInputEmulation: 1 AndroidMinifyWithR8: 0 AndroidMinifyRelease: 0 AndroidMinifyDebug: 0 AndroidValidateAppBundleSize: 1 AndroidAppBundleSizeToValidate: 150 m_BuildTargetIcons: [] - m_BuildTargetPlatformIcons: [] + m_BuildTargetPlatformIcons: + - m_BuildTarget: Android + m_Icons: + - m_Textures: [] + m_Width: 432 + m_Height: 432 + m_Kind: 2 + m_SubKind: + - m_Textures: [] + m_Width: 324 + m_Height: 324 + m_Kind: 2 + m_SubKind: + - m_Textures: [] + m_Width: 216 + m_Height: 216 + m_Kind: 2 + m_SubKind: + - m_Textures: [] + m_Width: 162 + m_Height: 162 + m_Kind: 2 + m_SubKind: + - m_Textures: [] + m_Width: 108 + m_Height: 108 + m_Kind: 2 + m_SubKind: + - m_Textures: [] + m_Width: 81 + m_Height: 81 + m_Kind: 2 + m_SubKind: + - m_Textures: [] + m_Width: 192 + m_Height: 192 + m_Kind: 0 + m_SubKind: + - m_Textures: [] + m_Width: 144 + m_Height: 144 + m_Kind: 0 + m_SubKind: + - m_Textures: [] + m_Width: 96 + m_Height: 96 + m_Kind: 0 + m_SubKind: + - m_Textures: [] + m_Width: 72 + m_Height: 72 + m_Kind: 0 + m_SubKind: + - m_Textures: [] + m_Width: 48 + m_Height: 48 + m_Kind: 0 + m_SubKind: + - m_Textures: [] + m_Width: 36 + m_Height: 36 + m_Kind: 0 + m_SubKind: + - m_Textures: [] + m_Width: 192 + m_Height: 192 + m_Kind: 1 + m_SubKind: + - m_Textures: [] + m_Width: 144 + m_Height: 144 + m_Kind: 1 + m_SubKind: + - m_Textures: [] + m_Width: 96 + m_Height: 96 + m_Kind: 1 + m_SubKind: + - m_Textures: [] + m_Width: 72 + m_Height: 72 + m_Kind: 1 + m_SubKind: + - m_Textures: [] + m_Width: 48 + m_Height: 48 + m_Kind: 1 + m_SubKind: + - m_Textures: [] + m_Width: 36 + m_Height: 36 + m_Kind: 1 + m_SubKind: m_BuildTargetBatching: - m_BuildTarget: Standalone m_StaticBatching: 1 @@ -309,7 +413,7 @@ PlayerSettings: m_BuildTargetGraphicsAPIs: - m_BuildTarget: AndroidPlayer m_APIs: 150000000b000000 - m_Automatic: 0 + m_Automatic: 1 - m_BuildTarget: iOSSupport m_APIs: 10000000 m_Automatic: 1 @@ -336,6 +440,7 @@ PlayerSettings: m_BuildTargetGroupLightmapEncodingQuality: [] m_BuildTargetGroupLightmapSettings: [] m_BuildTargetNormalMapEncoding: [] + m_BuildTargetDefaultTextureCompressionFormat: [] playModeTestRunnerEnabled: 0 runPlayModeTestAsEditModeTest: 0 actionOnDotNetUnhandledException: 1 @@ -345,6 +450,7 @@ PlayerSettings: cameraUsageDescription: locationUsageDescription: microphoneUsageDescription: + bluetoothUsageDescription: switchNMETAOverride: switchNetLibKey: switchSocketMemoryPoolSize: 6144 @@ -353,6 +459,7 @@ PlayerSettings: switchScreenResolutionBehavior: 2 switchUseCPUProfiler: 0 switchUseGOLDLinker: 0 + switchLTOSetting: 0 switchApplicationID: 0x01004b9000490000 switchNSODependencies: switchTitleNames_0: @@ -483,7 +590,9 @@ PlayerSettings: switchPlayerConnectionEnabled: 1 switchUseNewStyleFilepaths: 0 switchUseMicroSleepForYield: 1 + switchEnableRamDiskSupport: 0 switchMicroSleepForYieldTime: 25 + switchRamDiskSpaceSize: 12 ps4NPAgeRating: 12 ps4NPTitleSecret: ps4NPTrophyPackPath: @@ -554,7 +663,6 @@ PlayerSettings: ps4videoRecordingFeaturesUsed: 0 ps4contentSearchFeaturesUsed: 0 ps4CompatibilityPS5: 0 - ps4AllowPS5Detection: 0 ps4GPU800MHz: 1 ps4attribEyeToEyeDistanceSettingVR: 0 ps4IncludedModules: [] @@ -589,7 +697,6 @@ PlayerSettings: suppressCommonWarnings: 1 allowUnsafeCode: 0 useDeterministicCompilation: 1 - useReferenceAssemblies: 1 enableRoslynAnalyzers: 1 additionalIl2CppArgs: scriptingRuntimeVersion: 1 @@ -625,6 +732,7 @@ PlayerSettings: metroFTAName: metroFTAFileTypes: [] metroProtocolName: + vcxProjDefaultLanguage: XboxOneProductId: XboxOneUpdateKey: XboxOneSandboxId: @@ -667,7 +775,7 @@ PlayerSettings: m_VersionCode: 1 m_VersionName: apiCompatibilityLevel: 6 - activeInputHandler: 0 + activeInputHandler: 1 cloudProjectId: framebufferDepthMemorylessMode: 0 qualitySettingsNames: [] @@ -675,4 +783,6 @@ PlayerSettings: organizationId: cloudEnabled: 0 legacyClampBlendShapeWeights: 0 + playerDataPath: + forceSRGBBlit: 1 virtualTexturingSupportEnabled: 0 diff --git a/MobileRobotUITutorialProject/ProjectSettings/ProjectVersion.txt b/MobileRobotUITutorialProject/ProjectSettings/ProjectVersion.txt index 2c2c446..501a25e 100644 --- a/MobileRobotUITutorialProject/ProjectSettings/ProjectVersion.txt +++ b/MobileRobotUITutorialProject/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2020.3.17f1 -m_EditorVersionWithRevision: 2020.3.17f1 (a4537701e4ab) +m_EditorVersion: 2021.3.4f1 +m_EditorVersionWithRevision: 2021.3.4f1 (cb45f9cae8b7) diff --git a/MobileRobotUITutorialProject/ProjectSettings/QualitySettings.asset b/MobileRobotUITutorialProject/ProjectSettings/QualitySettings.asset index fee4de6..125311f 100644 --- a/MobileRobotUITutorialProject/ProjectSettings/QualitySettings.asset +++ b/MobileRobotUITutorialProject/ProjectSettings/QualitySettings.asset @@ -13,7 +13,7 @@ QualitySettings: shadowResolution: 0 shadowProjection: 1 shadowCascades: 1 - shadowDistance: 15 + shadowDistance: 2 shadowNearPlaneOffset: 3 shadowCascade2Split: 0.33333334 shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} @@ -49,7 +49,7 @@ QualitySettings: shadowResolution: 0 shadowProjection: 1 shadowCascades: 1 - shadowDistance: 20 + shadowDistance: 2 shadowNearPlaneOffset: 3 shadowCascade2Split: 0.33333334 shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} @@ -85,7 +85,7 @@ QualitySettings: shadowResolution: 0 shadowProjection: 1 shadowCascades: 1 - shadowDistance: 20 + shadowDistance: 2 shadowNearPlaneOffset: 3 shadowCascade2Split: 0.33333334 shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} @@ -121,7 +121,7 @@ QualitySettings: shadowResolution: 1 shadowProjection: 1 shadowCascades: 2 - shadowDistance: 40 + shadowDistance: 2 shadowNearPlaneOffset: 3 shadowCascade2Split: 0.33333334 shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} @@ -157,7 +157,7 @@ QualitySettings: shadowResolution: 2 shadowProjection: 1 shadowCascades: 2 - shadowDistance: 70 + shadowDistance: 2 shadowNearPlaneOffset: 3 shadowCascade2Split: 0.33333334 shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} @@ -193,7 +193,7 @@ QualitySettings: shadowResolution: 2 shadowProjection: 1 shadowCascades: 4 - shadowDistance: 12 + shadowDistance: 2 shadowNearPlaneOffset: 3 shadowCascade2Split: 0.33333334 shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} diff --git a/ROS/src/tf2_msgs/include/foo b/MobileRobotUITutorialProject/ProjectSettings/boot.config similarity index 100% rename from ROS/src/tf2_msgs/include/foo rename to MobileRobotUITutorialProject/ProjectSettings/boot.config diff --git a/ROS/Dockerfile b/ROS/Dockerfile index 96f99a5..fed1192 100644 --- a/ROS/Dockerfile +++ b/ROS/Dockerfile @@ -1,28 +1,27 @@ -FROM tiryoh/ros-desktop-vnc:melodic - -ENV ROS_WORKSPACE=/home/ubuntu/catkin_ws - -RUN apt-get update -q && \ - apt-get install -y dos2unix ros-melodic-joint-state-publisher-gui && \ - rm -rf /var/lib/apt/lists/* - -COPY ./src/ros_tcp_endpoint $ROS_WORKSPACE/src/ros_tcp_endpoint -COPY ./src/tf2_msgs $ROS_WORKSPACE/src/tf2_msgs -COPY ./src/raspimouse_sim $ROS_WORKSPACE/src/raspimouse_sim -COPY ./src/raspimouse_description $ROS_WORKSPACE/src/raspimouse_description -COPY ./configure.sh /home/ubuntu/configure.sh - -RUN cd ${ROS_WORKSPACE} && \ - /bin/bash -c "find $ROS_WORKSPACE -type f -print0 | xargs -0 dos2unix" && \ - dos2unix $HOME/configure.sh && \ - chown -R ubuntu:ubuntu /home/ubuntu - -USER ubuntu -RUN cd $ROS_WORKSPACE && \ - . /opt/ros/melodic/setup.sh && \ - catkin init && \ - catkin build && \ - echo ". \$HOME/catkin_ws/devel/setup.bash" >> /home/ubuntu/.bashrc && \ - echo ". \$HOME/configure.sh" >> /home/ubuntu/.bashrc - +FROM tiryoh/ros-desktop-vnc:melodic + +ENV ROS_WORKSPACE=/home/ubuntu/catkin_ws + +RUN apt-get update -q && \ + apt-get install -y dos2unix ros-melodic-joint-state-publisher-gui && \ + rm -rf /var/lib/apt/lists/* + +COPY ./src/ros_tcp_endpoint $ROS_WORKSPACE/src/ros_tcp_endpoint +COPY ./src/raspimouse_sim $ROS_WORKSPACE/src/raspimouse_sim +COPY ./src/raspimouse_description $ROS_WORKSPACE/src/raspimouse_description +COPY ./configure.sh /home/ubuntu/configure.sh + +RUN cd ${ROS_WORKSPACE} && \ + /bin/bash -c "find $ROS_WORKSPACE -type f -print0 | xargs -0 dos2unix" && \ + dos2unix $HOME/configure.sh && \ + chown -R ubuntu:ubuntu /home/ubuntu + +USER ubuntu +RUN cd $ROS_WORKSPACE && \ + . /opt/ros/melodic/setup.sh && \ + catkin init && \ + catkin build && \ + echo ". \$HOME/catkin_ws/devel/setup.bash" >> /home/ubuntu/.bashrc && \ + echo ". \$HOME/configure.sh" >> /home/ubuntu/.bashrc + USER root \ No newline at end of file diff --git a/ROS/configure.sh b/ROS/configure.sh index 6a01a4b..e63b2c8 100644 --- a/ROS/configure.sh +++ b/ROS/configure.sh @@ -1,12 +1,11 @@ -#!/bin/bash -eu - -ROS_IP=$(hostname -i) - -echo "ROS_IP: $ROS_IP" > $(rospack find ros_tcp_endpoint)/config/params.yaml -sed -i -e "s/127\.0\.0\.1/$ROS_IP/g" $HOME/.bashrc -if [ -e $HOME/.ignition/fuel/config.yaml ]; then - sed -i -e "s/ignitionfuel\.org/ignitionrobotics.org/g" $HOME/.ignition/fuel/config.yaml -fi - -export ROS_IP="$ROS_IP" -export ROS_MASTER_URI="http://$ROS_IP:11311" \ No newline at end of file +#!/bin/bash -eu + +ROS_IP=$(hostname -i) + +sed -i -e "s/127\.0\.0\.1/$ROS_IP/g" $HOME/.bashrc +if [ -e $HOME/.ignition/fuel/config.yaml ]; then + sed -i -e "s/ignitionfuel\.org/ignitionrobotics.org/g" $HOME/.ignition/fuel/config.yaml +fi + +export ROS_IP="$ROS_IP" +export ROS_MASTER_URI="http://$ROS_IP:11311" diff --git a/ROS/src/ros_tcp_endpoint b/ROS/src/ros_tcp_endpoint index f978d94..993d366 160000 --- a/ROS/src/ros_tcp_endpoint +++ b/ROS/src/ros_tcp_endpoint @@ -1 +1 @@ -Subproject commit f978d948c35e5c14542839b5f8c2e715c4b61a1d +Subproject commit 993d366b8900bf9f3d2da444fde64c0379b4dc7c diff --git a/ROS/src/tf2_msgs/CHANGELOG.rst b/ROS/src/tf2_msgs/CHANGELOG.rst deleted file mode 100644 index 078e365..0000000 --- a/ROS/src/tf2_msgs/CHANGELOG.rst +++ /dev/null @@ -1,165 +0,0 @@ -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Changelog for package tf2_msgs -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -0.6.7 (2020-03-09) ------------------- - -0.6.6 (2020-01-09) ------------------- - -0.6.5 (2018-11-16) ------------------- - -0.6.4 (2018-11-06) ------------------- - -0.6.3 (2018-07-09) ------------------- - -0.6.2 (2018-05-02) ------------------- - -0.6.1 (2018-03-21) ------------------- - -0.6.0 (2018-03-21) ------------------- - -0.5.17 (2018-01-01) -------------------- - -0.5.16 (2017-07-14) -------------------- - -0.5.15 (2017-01-24) -------------------- - -0.5.14 (2017-01-16) -------------------- - -0.5.13 (2016-03-04) -------------------- - -0.5.12 (2015-08-05) -------------------- - -0.5.11 (2015-04-22) -------------------- - -0.5.10 (2015-04-21) -------------------- - -0.5.9 (2015-03-25) ------------------- - -0.5.8 (2015-03-17) ------------------- -* remove useless Makefile files -* Contributors: Vincent Rabaud - -0.5.7 (2014-12-23) ------------------- - -0.5.6 (2014-09-18) ------------------- - -0.5.5 (2014-06-23) ------------------- - -0.5.4 (2014-05-07) ------------------- - -0.5.3 (2014-02-21) ------------------- - -0.5.2 (2014-02-20) ------------------- - -0.5.1 (2014-02-14) ------------------- - -0.5.0 (2014-02-14) ------------------- - -0.4.10 (2013-12-26) -------------------- - -0.4.9 (2013-11-06) ------------------- - -0.4.8 (2013-11-06) ------------------- - -0.4.7 (2013-08-28) ------------------- - -0.4.6 (2013-08-28) ------------------- - -0.4.5 (2013-07-11) ------------------- - -0.4.4 (2013-07-09) ------------------- - -0.4.3 (2013-07-05) ------------------- - -0.4.2 (2013-07-05) ------------------- - -0.4.1 (2013-07-05) ------------------- - -0.4.0 (2013-06-27) ------------------- -* Restoring test packages and bullet packages. - reverting 3570e8c42f9b394ecbfd9db076b920b41300ad55 to get back more of the packages previously implemented - reverting 04cf29d1b58c660fdc999ab83563a5d4b76ab331 to fix `#7 `_ - -0.3.6 (2013-03-03) ------------------- - -0.3.5 (2013-02-15 14:46) ------------------------- -* 0.3.4 -> 0.3.5 - -0.3.4 (2013-02-15 13:14) ------------------------- -* 0.3.3 -> 0.3.4 - -0.3.3 (2013-02-15 11:30) ------------------------- -* 0.3.2 -> 0.3.3 - -0.3.2 (2013-02-15 00:42) ------------------------- -* 0.3.1 -> 0.3.2 - -0.3.1 (2013-02-14) ------------------- -* 0.3.0 -> 0.3.1 - -0.3.0 (2013-02-13) ------------------- -* switching to version 0.3.0 -* removing packages with missing deps -* adding include folder -* adding tf2_msgs/srv/FrameGraph.srv -* catkin fixes -* catkinizing geometry-experimental -* catkinizing tf2_msgs -* Adding ROS service interface to cpp Buffer -* fix tf messages dependency and name -* add python transform listener -* Compiling version of the buffer server -* Compiling version of the buffer client -* Adding a message that encapsulates errors that can be returned by tf -* A fully specified version of the LookupTransform.action -* Commiting so I can merge -* Adding action for LookupTransform -* Updating CMake to call genaction -* Moving tfMessage to TFMessage to adhere to naming conventions -* Copying tfMessage from tf to new tf2_msgs package -* Creating a package for new tf messages diff --git a/ROS/src/tf2_msgs/CMakeLists.txt b/ROS/src/tf2_msgs/CMakeLists.txt deleted file mode 100644 index 7c06a2a..0000000 --- a/ROS/src/tf2_msgs/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -cmake_minimum_required(VERSION 2.8.3) -project(tf2_msgs) - -find_package(catkin REQUIRED COMPONENTS message_generation geometry_msgs actionlib_msgs) -find_package(Boost COMPONENTS thread REQUIRED) - -add_message_files(DIRECTORY msg FILES TF2Error.msg TFMessage.msg) -add_service_files(DIRECTORY srv FILES FrameGraph.srv) - -add_action_files(DIRECTORY action FILES LookupTransform.action) -generate_messages( - DEPENDENCIES actionlib_msgs std_msgs geometry_msgs -) - -catkin_package( - INCLUDE_DIRS include - CATKIN_DEPENDS message_generation geometry_msgs actionlib_msgs) - - - diff --git a/ROS/src/tf2_msgs/action/LookupTransform.action b/ROS/src/tf2_msgs/action/LookupTransform.action deleted file mode 100644 index 126e169..0000000 --- a/ROS/src/tf2_msgs/action/LookupTransform.action +++ /dev/null @@ -1,17 +0,0 @@ -#Simple API -string target_frame -string source_frame -time source_time -duration timeout - -#Advanced API -time target_time -string fixed_frame - -#Whether or not to use the advanced API -bool advanced - ---- -geometry_msgs/TransformStamped transform -tf2_msgs/TF2Error error ---- diff --git a/ROS/src/tf2_msgs/msg/TF2Error.msg b/ROS/src/tf2_msgs/msg/TF2Error.msg deleted file mode 100644 index e737b64..0000000 --- a/ROS/src/tf2_msgs/msg/TF2Error.msg +++ /dev/null @@ -1,10 +0,0 @@ -uint8 NO_ERROR = 0 -uint8 LOOKUP_ERROR = 1 -uint8 CONNECTIVITY_ERROR = 2 -uint8 EXTRAPOLATION_ERROR = 3 -uint8 INVALID_ARGUMENT_ERROR = 4 -uint8 TIMEOUT_ERROR = 5 -uint8 TRANSFORM_ERROR = 6 - -uint8 error -string error_string diff --git a/ROS/src/tf2_msgs/msg/TFMessage.msg b/ROS/src/tf2_msgs/msg/TFMessage.msg deleted file mode 100644 index fda1e4d..0000000 --- a/ROS/src/tf2_msgs/msg/TFMessage.msg +++ /dev/null @@ -1 +0,0 @@ -geometry_msgs/TransformStamped[] transforms diff --git a/ROS/src/tf2_msgs/package.xml b/ROS/src/tf2_msgs/package.xml deleted file mode 100644 index ad5b51a..0000000 --- a/ROS/src/tf2_msgs/package.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - tf2_msgs - 0.6.7 - - tf2_msgs - - Eitan Marder-Eppstein - Tully Foote - BSD - - http://www.ros.org/wiki/tf2_msgs - - catkin - - actionlib_msgs - geometry_msgs - message_generation - - actionlib_msgs - geometry_msgs - message_generation - - - - diff --git a/ROS/src/tf2_msgs/srv/FrameGraph.srv b/ROS/src/tf2_msgs/srv/FrameGraph.srv deleted file mode 100644 index 568d196..0000000 --- a/ROS/src/tf2_msgs/srv/FrameGraph.srv +++ /dev/null @@ -1,2 +0,0 @@ ---- -string frame_yaml diff --git a/UnityScripts/JoyStick/Scripts/OnScreenStickCmdVelPublisher.cs b/UnityScripts/JoyStick/Scripts/OnScreenStickCmdVelPublisher.cs new file mode 100644 index 0000000..c081b17 --- /dev/null +++ b/UnityScripts/JoyStick/Scripts/OnScreenStickCmdVelPublisher.cs @@ -0,0 +1,61 @@ +using UnityEngine; +using UnityEngine.InputSystem; +using Unity.Robotics.ROSTCPConnector; +using TwistMsg = RosMessageTypes.Geometry.TwistMsg; + +public class OnScreenStickCmdVelPublisher : MonoBehaviour +{ + [SerializeField] private InputAction _moveAction; + + [SerializeField] string topicName = "cmd_vel"; + private ROSConnection ros; + private TwistMsg cmdVelMessage = new TwistMsg(); + + private void Start() + { + ros = ROSConnection.GetOrCreateInstance(); + ros.RegisterPublisher(topicName); + StopPublish(); + + _moveAction.performed += _ => + { + var value = _moveAction.ReadValue(); + Debug.Log($"Move: ({value.x}, {value.y})"); + cmdVelMessage.linear.x = value.y * 0.2f; + cmdVelMessage.angular.z = value.x * -1.0f; + Publish(); + }; + + _moveAction.canceled += _ => + { + StopPublish(); + }; + } + + private void OnEnable() + { + _moveAction.Enable(); + } + + private void OnDisable() + { + _moveAction.Disable(); + } + + private void OnDestroy() + { + _moveAction.Dispose(); + } + + private void StopPublish() + { + cmdVelMessage.linear.x = 0.0f; + cmdVelMessage.angular.z = 0.0f; + Publish(); + } + + private void Publish() + { + ros.Publish(topicName, cmdVelMessage); + } +} diff --git a/UnityScripts/JoyStick/Textures/white_circle.png b/UnityScripts/JoyStick/Textures/white_circle.png new file mode 100644 index 0000000..74142f4 Binary files /dev/null and b/UnityScripts/JoyStick/Textures/white_circle.png differ diff --git a/UnityScripts/OdometryViewer/Scripts/OdometryViewer.cs b/UnityScripts/OdometryViewer/Scripts/OdometryViewer.cs index b1ec1ec..7a16865 100644 --- a/UnityScripts/OdometryViewer/Scripts/OdometryViewer.cs +++ b/UnityScripts/OdometryViewer/Scripts/OdometryViewer.cs @@ -1,80 +1,80 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using Unity.Robotics.ROSTCPConnector; -using OdometryMsg = RosMessageTypes.Nav.OdometryMsg; -using PointMsg = RosMessageTypes.Geometry.PointMsg; -using QuaternionMsg = RosMessageTypes.Geometry.QuaternionMsg; - -// This script is adapted from https://github.com/YusukeKato/raspimouse_odometry_tuning_unity/blob/master/Assets/Scripts/OdometryTuner.cs -// which is released under the MIT License. -// Copyright (c) 2018 YusukeKato - -/// -/// オドメトリ位置を可視化するためのクラス -/// (可視化のみを行い、座標変換を含むオドメトリの位置計算は予め行っている前提) -/// -public class OdometryViewer : MonoBehaviour -{ - - [SerializeField] bool isDebugMode = true; - [SerializeField] int lengthOfHistory = 10; - [SerializeField] float odometryDistanceThreshold = 0.03f; - [SerializeField] GameObject subscriberGameObject; - - [SerializeField] GameObject arrowPrefab; - - private List arrowList; - - private Vector3 previousRobotPosition = new Vector3(); - - /// - /// 初期化用のイベント関数 - /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html - /// ここで点群(オドメトリの矢印)用の配列を初期化 - /// - void Start() - { - arrowList = new List(lengthOfHistory); - - } - - /// - /// 1フレーム毎に呼び出されるイベント関数 - /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html - /// ここで点群の描画位置を決定 - /// - void Update() - { - Vector3 currentRobotPosition = subscriberGameObject.GetComponent().GetRobotPosition(); - Quaternion currentRobotPosture = subscriberGameObject.GetComponent().GetRobotPosture(); - - if (isDebugMode) - { - Debug.Log("diff: " + Vector3.Distance(currentRobotPosition, previousRobotPosition)); - } - if (Vector3.Distance(currentRobotPosition, previousRobotPosition) > odometryDistanceThreshold) - { - GameObject arrow = Instantiate(arrowPrefab); - arrow.transform.parent = gameObject.transform; - arrow.transform.position = currentRobotPosition; - arrow.transform.rotation = currentRobotPosture; - arrow.transform.Rotate(0, 180, 0); // ロボットの向きに合わせて矢印を回転 - if (arrowList.Count >= lengthOfHistory) { - Destroy(arrowList[0]); - arrowList.RemoveRange(0, 1); - } - arrowList.Add(arrow); - previousRobotPosition = currentRobotPosition; - - if (isDebugMode) - { - Debug.Log("arrow list length: " + arrowList.Count); - } - } - - - } - - +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Unity.Robotics.ROSTCPConnector; +using OdometryMsg = RosMessageTypes.Nav.OdometryMsg; +using PointMsg = RosMessageTypes.Geometry.PointMsg; +using QuaternionMsg = RosMessageTypes.Geometry.QuaternionMsg; + +// This script is adapted from https://github.com/YusukeKato/raspimouse_odometry_tuning_unity/blob/master/Assets/Scripts/OdometryTuner.cs +// which is released under the MIT License. +// Copyright (c) 2018 YusukeKato + +/// +/// オドメトリ位置を可視化するためのクラス +/// (可視化のみを行い、座標変換を含むオドメトリの位置計算は予め行っている前提) +/// +public class OdometryViewer : MonoBehaviour +{ + + [SerializeField] bool isDebugMode = true; + [SerializeField] int lengthOfHistory = 10; + [SerializeField] float odometryDistanceThreshold = 0.03f; + [SerializeField] GameObject subscriberGameObject; + + [SerializeField] GameObject arrowPrefab; + + private List arrowList; + + private Vector3 previousRobotPosition = new Vector3(); + + /// + /// 初期化用のイベント関数 + /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html + /// ここで点群(オドメトリの矢印)用の配列を初期化 + /// + void Start() + { + arrowList = new List(lengthOfHistory); + + } + + /// + /// 1フレーム毎に呼び出されるイベント関数 + /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html + /// ここで点群の描画位置を決定 + /// + void Update() + { + Vector3 currentRobotPosition = subscriberGameObject.GetComponent().GetRobotPosition(); + Quaternion currentRobotPosture = subscriberGameObject.GetComponent().GetRobotPosture(); + + if (isDebugMode) + { + Debug.Log("diff: " + Vector3.Distance(currentRobotPosition, previousRobotPosition)); + } + if (Vector3.Distance(currentRobotPosition, previousRobotPosition) > odometryDistanceThreshold) + { + GameObject arrow = Instantiate(arrowPrefab); + arrow.transform.parent = gameObject.transform; + arrow.transform.position = currentRobotPosition; + arrow.transform.rotation = currentRobotPosture; + arrow.transform.Rotate(0, 180, 0); // ロボットの向きに合わせて矢印を回転 + if (arrowList.Count >= lengthOfHistory) { + Destroy(arrowList[0]); + arrowList.RemoveRange(0, 1); + } + arrowList.Add(arrow); + previousRobotPosition = currentRobotPosition; + + if (isDebugMode) + { + Debug.Log("arrow list length: " + arrowList.Count); + } + } + + + } + + } \ No newline at end of file diff --git a/UnityScripts/PointCloud/Prefabs/Sphere.prefab b/UnityScripts/PointCloud/Prefabs/Sphere.prefab index 976346e..442ac2a 100644 --- a/UnityScripts/PointCloud/Prefabs/Sphere.prefab +++ b/UnityScripts/PointCloud/Prefabs/Sphere.prefab @@ -49,8 +49,8 @@ MeshRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2278637883144382342} m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 m_DynamicOccludee: 1 m_MotionVectors: 1 m_LightProbeUsage: 1 diff --git a/UnityScripts/Scripts/CmdVelPublisher.cs b/UnityScripts/Scripts/CmdVelPublisher.cs index 8a12f74..7fb560c 100644 --- a/UnityScripts/Scripts/CmdVelPublisher.cs +++ b/UnityScripts/Scripts/CmdVelPublisher.cs @@ -1,92 +1,93 @@ -using UnityEngine; -using Unity.Robotics.ROSTCPConnector; -// 各種ROSトピック形式 -using TwistMsg = RosMessageTypes.Geometry.TwistMsg; - -/// -/// CmdVel(TwistMsg)を送信するためのクラス -/// UIから各関数を呼び出して使うことを想定 -/// -public class CmdVelPublisher : MonoBehaviour -{ - // Variables required for ROS communication - // 送信するROSのトピック名 - [SerializeField] string topicName = "cmd_vel"; - - // 送信する速度指令の基準となる値(各関数でこの速度に所定の倍率をかける) - [SerializeField] float linearVel; - - // 送信する角速度指令の基準となる値(各関数でこの角速度に所定の倍率をかける) - [SerializeField] float angularVel; - - // ROS Connector - private ROSConnection ros; - - private TwistMsg cmdVelMessage = new TwistMsg(); - - /// - /// 初期化用のイベント関数 - /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html - /// - void Start() - { - // Get ROS connection static instance - ros = ROSConnection.instance; - SetStopVel(); - Publish(); - } - - /// - /// 前進方向の速度指令を設定 - /// - /// 指令する速度の倍率 - public void SetForwardVel(float ratio=1.0f) - { - cmdVelMessage.linear.x = linearVel * ratio; - } - - /// - /// 後進方向の速度指令を設定 - /// - /// 指令する速度の倍率 - public void SetBackwardVel(float ratio=1.0f) - { - cmdVelMessage.linear.x = -linearVel * ratio; - } - - /// - /// 右旋回の角速度指令を設定 - /// - /// 指令する角速度の倍率 - public void SetRightTurnVel(float ratio=1.0f) - { - cmdVelMessage.angular.z = -angularVel * ratio; - } - - /// - /// 左旋回の角速度指令を設定 - /// - /// 指令する角速度の倍率 - public void SetLeftTurnVel(float ratio=1.0f) - { - cmdVelMessage.angular.z = angularVel * ratio; - } - - /// - /// 停止の速度指令、角速度指令を設定 - /// - public void SetStopVel() - { - cmdVelMessage.linear.x = 0; - cmdVelMessage.angular.z = 0; - } - - /// - /// 速度指令、角速度指令を送信 - /// - public void Publish() - { - // ROSのros_tcp_endpointのdefault_server_endpoint.pyにメッセージを送信 - ros.Send(topicName, cmdVelMessage); - } -} +using UnityEngine; +using Unity.Robotics.ROSTCPConnector; +// 各種ROSトピック形式 +using TwistMsg = RosMessageTypes.Geometry.TwistMsg; + +/// +/// CmdVel(TwistMsg)を送信するためのクラス +/// UIから各関数を呼び出して使うことを想定 +/// +public class CmdVelPublisher : MonoBehaviour +{ + // Variables required for ROS communication + // 送信するROSのトピック名 + [SerializeField] string topicName = "cmd_vel"; + + // 送信する速度指令の基準となる値(各関数でこの速度に所定の倍率をかける) + [SerializeField] float linearVel; + + // 送信する角速度指令の基準となる値(各関数でこの角速度に所定の倍率をかける) + [SerializeField] float angularVel; + + // ROS Connector + private ROSConnection ros; + + private TwistMsg cmdVelMessage = new TwistMsg(); + + /// + /// 初期化用のイベント関数 + /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html + /// + void Start() + { + // Get ROS connection static instance + ros = ROSConnection.GetOrCreateInstance(); + ros.RegisterPublisher(topicName); + SetStopVel(); + Publish(); + } + + /// + /// 前進方向の速度指令を設定 + /// + /// 指令する速度の倍率 + public void SetForwardVel(float ratio=1.0f) + { + cmdVelMessage.linear.x = linearVel * ratio; + } + + /// + /// 後進方向の速度指令を設定 + /// + /// 指令する速度の倍率 + public void SetBackwardVel(float ratio=1.0f) + { + cmdVelMessage.linear.x = -linearVel * ratio; + } + + /// + /// 右旋回の角速度指令を設定 + /// + /// 指令する角速度の倍率 + public void SetRightTurnVel(float ratio=1.0f) + { + cmdVelMessage.angular.z = -angularVel * ratio; + } + + /// + /// 左旋回の角速度指令を設定 + /// + /// 指令する角速度の倍率 + public void SetLeftTurnVel(float ratio=1.0f) + { + cmdVelMessage.angular.z = angularVel * ratio; + } + + /// + /// 停止の速度指令、角速度指令を設定 + /// + public void SetStopVel() + { + cmdVelMessage.linear.x = 0; + cmdVelMessage.angular.z = 0; + } + + /// + /// 速度指令、角速度指令を送信 + /// + public void Publish() + { + // ROSのros_tcp_endpointのdefault_server_endpoint.pyにメッセージを送信 + ros.Publish(topicName, cmdVelMessage); + } +} diff --git a/UnityScripts/Scripts/CmdVelSubscriber.cs b/UnityScripts/Scripts/CmdVelSubscriber.cs index e3bba37..9ca0e3f 100644 --- a/UnityScripts/Scripts/CmdVelSubscriber.cs +++ b/UnityScripts/Scripts/CmdVelSubscriber.cs @@ -1,36 +1,36 @@ -using UnityEngine; -using Unity.Robotics.ROSTCPConnector; -// 各種ROSトピック形式 -using TwistMsg = RosMessageTypes.Geometry.TwistMsg; - -/// -/// CmdVel(TwistMsg)を受信するためのクラス -/// 主にデバッグ用に使うことを想定 -/// -public class CmdVelSubscriber : MonoBehaviour -{ - // 受信するROSのトピック名 - [SerializeField] string rosTopicName = "cmd_vel"; - // デバッグモードとするかどうか(デバッグモードではコンソールにログを出力) - [SerializeField] bool isDebugMode = true; - - /// - /// 初期化用のイベント関数 - /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html - /// - void Start() - { - ROSConnection.instance.Subscribe(rosTopicName, CmdVelUpdate); - } - - /// - /// ROSトピックを受け取った際に呼ばれるコールバック関数 - /// - void CmdVelUpdate(TwistMsg twistMessage) - { - if (isDebugMode) - { - Debug.Log(twistMessage); - } - } +using UnityEngine; +using Unity.Robotics.ROSTCPConnector; +// 各種ROSトピック形式 +using TwistMsg = RosMessageTypes.Geometry.TwistMsg; + +/// +/// CmdVel(TwistMsg)を受信するためのクラス +/// 主にデバッグ用に使うことを想定 +/// +public class CmdVelSubscriber : MonoBehaviour +{ + // 受信するROSのトピック名 + [SerializeField] string rosTopicName = "cmd_vel"; + // デバッグモードとするかどうか(デバッグモードではコンソールにログを出力) + [SerializeField] bool isDebugMode = true; + + /// + /// 初期化用のイベント関数 + /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html + /// + void Start() + { + ROSConnection.GetOrCreateInstance().Subscribe(rosTopicName, CmdVelUpdate); + } + + /// + /// ROSトピックを受け取った際に呼ばれるコールバック関数 + /// + void CmdVelUpdate(TwistMsg twistMessage) + { + if (isDebugMode) + { + Debug.Log(twistMessage); + } + } } \ No newline at end of file diff --git a/UnityScripts/Scripts/ImageSubscriber.cs b/UnityScripts/Scripts/ImageSubscriber.cs index 81daef3..1d72ab0 100644 --- a/UnityScripts/Scripts/ImageSubscriber.cs +++ b/UnityScripts/Scripts/ImageSubscriber.cs @@ -1,68 +1,81 @@ -using UnityEngine; -using UnityEngine.UI; -using Unity.Robotics.ROSTCPConnector; -using CompressedImageMsg = RosMessageTypes.Sensor.CompressedImageMsg; - -/// -/// LiDARスキャンデータ(LaserScanMsg)を受信するためのクラス -/// 主にスキャンデータの取得および座標変換に使い、描画は別のスクリプトを用意することを想定 -/// -public class ImageSubscriber : MonoBehaviour -{ - // 受信するROSのトピック名 - [SerializeField] string rosTopicName = "webcam/image_raw/compressed"; - // デバッグモードとするかどうか(デバッグモードではコンソールにログを出力) - [SerializeField] bool isDebugMode = true; - // カメラデータを貼り付けるRawImageオブジェクト - [SerializeField] RawImage rawImage; - - private Texture2D texture2D; - private byte[] imageData; - private bool isMessageReceived; - - /// - /// 初期化用のイベント関数 - /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html - /// - void Start() - { - ROSConnection.instance.Subscribe(rosTopicName, ImageMsgUpdate); - texture2D = new Texture2D(1, 1); - } - - /// - /// 1フレーム毎に呼び出されるイベント関数 - /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html - /// - void Update() - { - if (isMessageReceived) - { - ProcessMessage(); - } - } - - /// - /// ROSトピックを受け取った際に呼ばれるコールバック関数 - /// - void ImageMsgUpdate(CompressedImageMsg rawImage) - { - imageData = rawImage.data; - isMessageReceived = true; - if (isDebugMode) - { - Debug.Log("rawImage recieved. length :" + System.Buffer.ByteLength(imageData)); - } - } - - /// - /// ImageMsgのデータをTextureに反映する関数 - /// - void ProcessMessage() - { - texture2D.LoadImage(imageData); - texture2D.Apply(); - rawImage.texture = texture2D; - isMessageReceived = false; - } +using UnityEngine; +using UnityEngine.UI; +using Unity.Robotics.ROSTCPConnector; +using CompressedImageMsg = RosMessageTypes.Sensor.CompressedImageMsg; + +/// +/// カメラデータ(CompressedImageMsg)を受信し、描画するためのクラス +/// +public class ImageSubscriber : MonoBehaviour +{ + // 受信するROSのトピック名 + [SerializeField] string rosTopicName = "webcam/image_raw/compressed"; + // デバッグモードとするかどうか(デバッグモードではコンソールにログを出力) + [SerializeField] bool isDebugMode = true; + // カメラデータを貼り付けるRawImageオブジェクト + [SerializeField] RawImage rawImage; + + private Texture2D texture2D; + private CameraImage cameraImage = new CameraImage(); + private bool isMessageReceived; + + /// + /// 初期化用のイベント関数 + /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html + /// + void Start() + { + ROSConnection.GetOrCreateInstance().Subscribe(rosTopicName, ImageMsgUpdate); + texture2D = new Texture2D(1, 1); + } + + /// + /// 1フレーム毎に呼び出されるイベント関数 + /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html + /// + void Update() + { + if (isMessageReceived) + { + ProcessMessage(); + } + } + + /// + /// ROSトピックを受け取った際に呼ばれるコールバック関数 + /// + void ImageMsgUpdate(CompressedImageMsg rawImage) + { + lock (cameraImage) + { + cameraImage.imageData = rawImage.data; + if (isDebugMode) + { + Debug.Log("rawImage recieved. length :" + System.Buffer.ByteLength(cameraImage.imageData)); + } + } + isMessageReceived = true; + } + + /// + /// ImageMsgのデータをTextureに反映する関数 + /// + void ProcessMessage() + { + lock (cameraImage) + { + texture2D.LoadImage(cameraImage.imageData); + texture2D.Apply(); + } + rawImage.texture = texture2D; + isMessageReceived = false; + } +} + +/// +/// アクセス制限用のカメライメージデータ格納配列 +/// +class CameraImage +{ + public byte[] imageData { get; set; } } \ No newline at end of file diff --git a/UnityScripts/Scripts/LaserScanSubscriber.cs b/UnityScripts/Scripts/LaserScanSubscriber.cs index 7723743..50733d1 100644 --- a/UnityScripts/Scripts/LaserScanSubscriber.cs +++ b/UnityScripts/Scripts/LaserScanSubscriber.cs @@ -1,73 +1,73 @@ -using UnityEngine; -using Unity.Robotics.ROSTCPConnector; -// 座標変換用 -using Unity.Robotics.ROSTCPConnector.ROSGeometry; -// 各種ROSトピック形式 -using LaserScanMsg = RosMessageTypes.Sensor.LaserScanMsg; - -/// -/// LiDARスキャンデータ(LaserScanMsg)を受信するためのクラス -/// 主にスキャンデータの取得および座標変換に使い、描画は別のスクリプトを用意することを想定 -/// -public class LaserScanSubscriber : MonoBehaviour -{ - - // 受信するROSのトピック名 - [SerializeField] string rosTopicName = "scan"; - // デバッグモードとするかどうか(デバッグモードではコンソールにログを出力) - [SerializeField] bool isDebugMode = true; - - private float[] scanRangesArray; - private float scanAngleMin = 0; - private float scanAngleMax = 0; - - /// - /// 初期化用のイベント関数 - /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html - /// - void Start() - { - ROSConnection.instance.Subscribe(rosTopicName, ScanUpdate); - } - - - /// - /// ROSトピックを受け取った際に呼ばれるコールバック関数 - /// - void ScanUpdate(LaserScanMsg scanMessage) - { - if (isDebugMode) - { - Debug.Log(scanMessage); - } - - scanRangesArray = scanMessage.ranges; - scanAngleMax = scanMessage.angle_max; - scanAngleMin = scanMessage.angle_min; - } - - /// - /// 外部からスキャン結果の配列にアクセスするための関数 - /// - public float[] GetScanRanges() - { - return scanRangesArray; - - } - - /// - /// 外部からスキャン結果にアクセスするための関数 - /// - public float GetScanAngleMin() - { - return scanAngleMin; - } - - /// - /// 外部からスキャン結果にアクセスするための関数 - /// - public float GetScanAngleMax() - { - return scanAngleMax; - } +using UnityEngine; +using Unity.Robotics.ROSTCPConnector; +// 座標変換用 +using Unity.Robotics.ROSTCPConnector.ROSGeometry; +// 各種ROSトピック形式 +using LaserScanMsg = RosMessageTypes.Sensor.LaserScanMsg; + +/// +/// LiDARスキャンデータ(LaserScanMsg)を受信するためのクラス +/// 主にスキャンデータの取得および座標変換に使い、描画は別のスクリプトを用意することを想定 +/// +public class LaserScanSubscriber : MonoBehaviour +{ + + // 受信するROSのトピック名 + [SerializeField] string rosTopicName = "scan"; + // デバッグモードとするかどうか(デバッグモードではコンソールにログを出力) + [SerializeField] bool isDebugMode = true; + + private float[] scanRangesArray; + private float scanAngleMin = 0; + private float scanAngleMax = 0; + + /// + /// 初期化用のイベント関数 + /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html + /// + void Start() + { + ROSConnection.GetOrCreateInstance().Subscribe(rosTopicName, ScanUpdate); + } + + + /// + /// ROSトピックを受け取った際に呼ばれるコールバック関数 + /// + void ScanUpdate(LaserScanMsg scanMessage) + { + if (isDebugMode) + { + Debug.Log(scanMessage); + } + + scanRangesArray = scanMessage.ranges; + scanAngleMax = scanMessage.angle_max; + scanAngleMin = scanMessage.angle_min; + } + + /// + /// 外部からスキャン結果の配列にアクセスするための関数 + /// + public float[] GetScanRanges() + { + return scanRangesArray; + + } + + /// + /// 外部からスキャン結果にアクセスするための関数 + /// + public float GetScanAngleMin() + { + return scanAngleMin; + } + + /// + /// 外部からスキャン結果にアクセスするための関数 + /// + public float GetScanAngleMax() + { + return scanAngleMax; + } } \ No newline at end of file diff --git a/UnityScripts/Scripts/OdomSubscriber.cs b/UnityScripts/Scripts/OdomSubscriber.cs index ff81d84..3ed3110 100644 --- a/UnityScripts/Scripts/OdomSubscriber.cs +++ b/UnityScripts/Scripts/OdomSubscriber.cs @@ -1,70 +1,70 @@ -using UnityEngine; -using Unity.Robotics.ROSTCPConnector; -// 座標変換用 -using Unity.Robotics.ROSTCPConnector.ROSGeometry; -// 各種ROSトピック形式 -using OdometryMsg = RosMessageTypes.Nav.OdometryMsg; -using PointMsg = RosMessageTypes.Geometry.PointMsg; -using QuaternionMsg = RosMessageTypes.Geometry.QuaternionMsg; - -/// -/// オドメトリデータ(OdometryMsg)を受信するためのクラス -/// 主にオドメトリデータの取得および座標変換に使い、描画は別のスクリプトを用意することを想定 -/// -public class OdomSubscriber : MonoBehaviour -{ - - [SerializeField] string rosTopicName = "odom"; - [SerializeField] bool isDebugMode = true; - - private Vector3 robotPosition = new Vector3(); - private Quaternion robotPosture = new Quaternion(); - - /// - /// 初期化用のイベント関数 - /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html - /// - void Start() - { - ROSConnection.instance.Subscribe(rosTopicName, OdomUpdate); - } - - /// - /// ROSトピックを受け取った際に呼ばれるコールバック関数 - /// - void OdomUpdate(OdometryMsg odomMessage) - { - if (isDebugMode) - { - Debug.Log(odomMessage); - } - - PointMsg rosOdomPositionMsg = odomMessage.pose.pose.position; - QuaternionMsg rosOdomPostureMsg = odomMessage.pose.pose.orientation; - - // OdomのTwist情報も使う場合は以下を使用 - // Vector3Msg rosOdomTwistLinearMsg = odomMessage.twist.linear; - // Vector3Msg rosOdomTwistAngularMsg = odomMessage.twist.angular; - - // 座標変換 - robotPosition = rosOdomPositionMsg.From(); - robotPosture = rosOdomPostureMsg.From(); - } - - /// - /// 外部からオドメトリ(ROS上のオドメトリ情報をUnity座標に変換したもの)の位置情報にアクセスするための関数 - /// - public Vector3 GetRobotPosition() - { - return robotPosition; - - } - - /// - /// 外部からオドメトリ(ROS上のオドメトリ情報をUnity座標に変換したもの)の姿勢情報にアクセスするための関数 - /// - public Quaternion GetRobotPosture() - { - return robotPosture; - } +using UnityEngine; +using Unity.Robotics.ROSTCPConnector; +// 座標変換用 +using Unity.Robotics.ROSTCPConnector.ROSGeometry; +// 各種ROSトピック形式 +using OdometryMsg = RosMessageTypes.Nav.OdometryMsg; +using PointMsg = RosMessageTypes.Geometry.PointMsg; +using QuaternionMsg = RosMessageTypes.Geometry.QuaternionMsg; + +/// +/// オドメトリデータ(OdometryMsg)を受信するためのクラス +/// 主にオドメトリデータの取得および座標変換に使い、描画は別のスクリプトを用意することを想定 +/// +public class OdomSubscriber : MonoBehaviour +{ + + [SerializeField] string rosTopicName = "odom"; + [SerializeField] bool isDebugMode = true; + + private Vector3 robotPosition = new Vector3(); + private Quaternion robotPosture = new Quaternion(); + + /// + /// 初期化用のイベント関数 + /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html + /// + void Start() + { + ROSConnection.GetOrCreateInstance().Subscribe(rosTopicName, OdomUpdate); + } + + /// + /// ROSトピックを受け取った際に呼ばれるコールバック関数 + /// + void OdomUpdate(OdometryMsg odomMessage) + { + if (isDebugMode) + { + Debug.Log(odomMessage); + } + + PointMsg rosOdomPositionMsg = odomMessage.pose.pose.position; + QuaternionMsg rosOdomPostureMsg = odomMessage.pose.pose.orientation; + + // OdomのTwist情報も使う場合は以下を使用 + // Vector3Msg rosOdomTwistLinearMsg = odomMessage.twist.linear; + // Vector3Msg rosOdomTwistAngularMsg = odomMessage.twist.angular; + + // 座標変換 + robotPosition = rosOdomPositionMsg.From(); + robotPosture = rosOdomPostureMsg.From(); + } + + /// + /// 外部からオドメトリ(ROS上のオドメトリ情報をUnity座標に変換したもの)の位置情報にアクセスするための関数 + /// + public Vector3 GetRobotPosition() + { + return robotPosition; + + } + + /// + /// 外部からオドメトリ(ROS上のオドメトリ情報をUnity座標に変換したもの)の姿勢情報にアクセスするための関数 + /// + public Quaternion GetRobotPosture() + { + return robotPosture; + } } \ No newline at end of file diff --git a/UnityScripts/Scripts/TfSubscriber.cs b/UnityScripts/Scripts/TfSubscriber.cs index 6410eb3..941f7cf 100644 --- a/UnityScripts/Scripts/TfSubscriber.cs +++ b/UnityScripts/Scripts/TfSubscriber.cs @@ -1,125 +1,125 @@ -using UnityEngine; -using Unity.Robotics.ROSTCPConnector; -// 座標変換用 -using Unity.Robotics.ROSTCPConnector.ROSGeometry; - -// 各種ROSトピック形式 -using RosMessageTypes.Geometry; -using Tf = RosMessageTypes.Tf2.TFMessageMsg; -using RosPosVector3 = Unity.Robotics.ROSTCPConnector.ROSGeometry.Vector3; -using RosQuaternion = Unity.Robotics.ROSTCPConnector.ROSGeometry.Quaternion; - -/// -/// ロボットの位置姿勢データ(TFMessageMsg)を受信するためのクラス -/// 位置姿勢データの取得、座標変換を行い、指定したGameObjectの位置姿勢を指定する用途を想定 -/// -public class TfSubscriber : MonoBehaviour -{ - // Variables required for ROS communication - [SerializeField] string rosTopicName = "tf"; - - [SerializeField] GameObject mobileRobot; - - [SerializeField] bool isDebugMode = true; - - private int numRobotLinks = 4; - - private Transform[] robotLinkPositions; - - /// - /// 初期化用のイベント関数 - /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html - /// - void Start() - { - // // Get ROS connection static instance - ROSConnection.instance.Subscribe(rosTopicName, TfUpdate); - - robotLinkPositions = new Transform[numRobotLinks]; - - string footprint_link = "base_footprint"; - robotLinkPositions[0] = mobileRobot.transform.Find(footprint_link).transform; - - string body_link = footprint_link + "/base_link"; - robotLinkPositions[1] = mobileRobot.transform.Find(body_link).transform; - - string right_wheel_link = body_link + "/right_wheel_link"; - robotLinkPositions[2] = mobileRobot.transform.Find(right_wheel_link).transform; - - string left_wheel_link = body_link + "/left_wheel_link"; - robotLinkPositions[3] = mobileRobot.transform.Find(left_wheel_link).transform; - - - if (isDebugMode) - { - Debug.Log(robotLinkPositions[1].position + " " + robotLinkPositions[1].rotation); - } - } - - /// - /// デバッグ時の文字列生成用関数 - /// - string Vector3ToString(Vector3 vec, string titile = "") - { - return titile + " (" + vec[0] + ", " + vec[1] + ", " + vec[2] + ")"; - } - - /// - /// デバッグ時の文字列生成用関数 - /// - string RosPosVector3ToString(RosPosVector3 vec, string titile = "") - { - return titile + " (" + vec.x + ", " + vec.y + ", " + vec.z + ")"; - } - - /// - /// ROSトピックを受け取った際に呼ばれるコールバック関数 - /// - void TfUpdate(Tf tfMessage) - { - for (int i = 0; i < tfMessage.transforms.Length; i++) - { - if (tfMessage.transforms[i].child_frame_id == "base_footprint") - { - - Vector3Msg rosPosMsg = tfMessage.transforms[i].transform.translation; - QuaternionMsg rosQuaternionMsg = tfMessage.transforms[i].transform.rotation; - - // 座標変換 - // 座標変換に関するのドキュメント - // https://github.com/Unity-Technologies/ROS-TCP-Connector/blob/v0.5.0/ROSGeometry.md - // 上記ドキュメントの実装箇所 - // https://github.com/Unity-Technologies/ROS-TCP-Connector/blob/v0.5.0/com.unity.robotics.ros-tcp-connector/Runtime/ROSGeometry/CoordinateSpaces.cs - RosPosVector3 rosPos = rosPosMsg.As(); - Vector3 unityPos = rosPos.toUnity; - if (isDebugMode) - { - Debug.Log(RosPosVector3ToString(rosPos, "tf(ros)") + " --> " + Vector3ToString(unityPos, "tf(unity)")); - } - - RosQuaternion rosQuaternion = rosQuaternionMsg.As(); - Quaternion unityQuaternion = rosQuaternion.toUnity; - - // 座標変換はこちらでもOK (1) - // Vector3 unityPos = tfMessage.transforms[i].transform.translation.From(); - // Quaternion unityQuaternion = tfMessage.transforms[i].transform.rotation.From(); - - // 座標変換はこちらでもOK (2) - // Vector3 unityPos = new Vector3((float)-tfMessage.transforms[i].transform.translation.y, - // (float)tfMessage.transforms[i].transform.translation.z, - // (float)tfMessage.transforms[i].transform.translation.x); - // Quaternion unityQuaternion = new Quaternion((float)-tfMessage.transforms[i].transform.rotation.y, - // (float)tfMessage.transforms[i].transform.rotation.z, - // (float)tfMessage.transforms[i].transform.rotation.x, - // (float)-tfMessage.transforms[i].transform.rotation.w); - - robotLinkPositions[0].position = unityPos; - robotLinkPositions[0].rotation = unityQuaternion; - if (isDebugMode) - { - Debug.Log(Vector3ToString(unityPos, "pos")); - } - } - } - } -} +using UnityEngine; +using Unity.Robotics.ROSTCPConnector; +// 座標変換用 +using Unity.Robotics.ROSTCPConnector.ROSGeometry; + +// 各種ROSトピック形式 +using RosMessageTypes.Geometry; +using Tf = RosMessageTypes.Tf2.TFMessageMsg; +using RosPosVector3 = Unity.Robotics.ROSTCPConnector.ROSGeometry.Vector3; +using RosQuaternion = Unity.Robotics.ROSTCPConnector.ROSGeometry.Quaternion; + +/// +/// ロボットの位置姿勢データ(TFMessageMsg)を受信するためのクラス +/// 位置姿勢データの取得、座標変換を行い、指定したGameObjectの位置姿勢を指定する用途を想定 +/// +public class TfSubscriber : MonoBehaviour +{ + // Variables required for ROS communication + [SerializeField] string rosTopicName = "tf"; + + [SerializeField] GameObject mobileRobot; + + [SerializeField] bool isDebugMode = true; + + private int numRobotLinks = 4; + + private Transform[] robotLinkPositions; + + /// + /// 初期化用のイベント関数 + /// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html + /// + void Start() + { + // // Get ROS connection static instance + ROSConnection.GetOrCreateInstance().Subscribe(rosTopicName, TfUpdate); + + robotLinkPositions = new Transform[numRobotLinks]; + + string footprint_link = "base_footprint"; + robotLinkPositions[0] = mobileRobot.transform.Find(footprint_link).transform; + + string body_link = footprint_link + "/base_link"; + robotLinkPositions[1] = mobileRobot.transform.Find(body_link).transform; + + string right_wheel_link = body_link + "/right_wheel_link"; + robotLinkPositions[2] = mobileRobot.transform.Find(right_wheel_link).transform; + + string left_wheel_link = body_link + "/left_wheel_link"; + robotLinkPositions[3] = mobileRobot.transform.Find(left_wheel_link).transform; + + + if (isDebugMode) + { + Debug.Log(robotLinkPositions[1].position + " " + robotLinkPositions[1].rotation); + } + } + + /// + /// デバッグ時の文字列生成用関数 + /// + string Vector3ToString(Vector3 vec, string titile = "") + { + return titile + " (" + vec[0] + ", " + vec[1] + ", " + vec[2] + ")"; + } + + /// + /// デバッグ時の文字列生成用関数 + /// + string RosPosVector3ToString(RosPosVector3 vec, string titile = "") + { + return titile + " (" + vec.x + ", " + vec.y + ", " + vec.z + ")"; + } + + /// + /// ROSトピックを受け取った際に呼ばれるコールバック関数 + /// + void TfUpdate(Tf tfMessage) + { + for (int i = 0; i < tfMessage.transforms.Length; i++) + { + if (tfMessage.transforms[i].child_frame_id == "base_footprint") + { + + Vector3Msg rosPosMsg = tfMessage.transforms[i].transform.translation; + QuaternionMsg rosQuaternionMsg = tfMessage.transforms[i].transform.rotation; + + // 座標変換 + // 座標変換に関するのドキュメント + // https://github.com/Unity-Technologies/ROS-TCP-Connector/blob/v0.5.0/ROSGeometry.md + // 上記ドキュメントの実装箇所 + // https://github.com/Unity-Technologies/ROS-TCP-Connector/blob/v0.5.0/com.unity.robotics.ros-tcp-connector/Runtime/ROSGeometry/CoordinateSpaces.cs + RosPosVector3 rosPos = rosPosMsg.As(); + Vector3 unityPos = rosPos.toUnity; + if (isDebugMode) + { + Debug.Log(RosPosVector3ToString(rosPos, "tf(ros)") + " --> " + Vector3ToString(unityPos, "tf(unity)")); + } + + RosQuaternion rosQuaternion = rosQuaternionMsg.As(); + Quaternion unityQuaternion = rosQuaternion.toUnity; + + // 座標変換はこちらでもOK (1) + // Vector3 unityPos = tfMessage.transforms[i].transform.translation.From(); + // Quaternion unityQuaternion = tfMessage.transforms[i].transform.rotation.From(); + + // 座標変換はこちらでもOK (2) + // Vector3 unityPos = new Vector3((float)-tfMessage.transforms[i].transform.translation.y, + // (float)tfMessage.transforms[i].transform.translation.z, + // (float)tfMessage.transforms[i].transform.translation.x); + // Quaternion unityQuaternion = new Quaternion((float)-tfMessage.transforms[i].transform.rotation.y, + // (float)tfMessage.transforms[i].transform.rotation.z, + // (float)tfMessage.transforms[i].transform.rotation.x, + // (float)-tfMessage.transforms[i].transform.rotation.w); + + robotLinkPositions[0].position = unityPos; + robotLinkPositions[0].rotation = unityQuaternion; + if (isDebugMode) + { + Debug.Log(Vector3ToString(unityPos, "pos")); + } + } + } + } +} diff --git a/docs/appendix.md b/docs/appendix.md new file mode 100644 index 0000000..b064b7c --- /dev/null +++ b/docs/appendix.md @@ -0,0 +1,166 @@ +# 付録 + +## 概要 + +STEP1~7では扱わなかった内容についても紹介します。 + +## 動作確認済環境 + +* Windows 10 Home バージョン 21H2 +* Unity 2021.3.4f1 +* [Unity-Technologies/ROS-TCP-Connector](https://github.com/Unity-Technologies/ROS-TCP-Connector) v0.7.0 +* Docker Desktop 4.9.1 + +## 独自のROSメッセージへの対応 + +[Unity-Technologies/ROS-TCP-Connector](https://github.com/Unity-Technologies/ROS-TCP-Connector)では扱うすべてのROSのメッセージファイルをC#にて定義する必要があります。 +[`com.unity.robotics.ros-tcp-connector/Runtime/Messages`](https://github.com/Unity-Technologies/ROS-TCP-Connector/tree/v0.7.0/com.unity.robotics.ros-tcp-connector/Runtime/Messages)から予めUnity用に用意されているROSのメッセージ形式を確認できます。 +使うROSのメッセージがROS-TCP-Connectorに予め含まれていない場合にのみ、C#のスクリプトを用意する必要があります。 + +### 1. ROSのメッセージファイルを用意 + +変換したいROSのメッセージファイルを用意します。 +例えばRaspberry Pi Mouse実機に搭載されているLEDの点灯・消灯状態は`LedValues.msg`というメッセージファイルにて定義されている形式で管理されます。 + +https://github.com/rt-net/raspimouse/blob/1.0.0/raspimouse_msgs/msg/LedValues.msg + +### 2. ROSのメッセージファイルからC#スクリプト作成 + +変換にはROS-TCP-Connectorのメッセージ作成機能を用います。 + +メニューバーから`Robotics` -> `Generate ROS Messages...`を選択します。 + +![](./images/appendix-1.png) + +`ROS message path`を指定します。 +ROSのメッセージファイルをダウンロードしてきたフォルダを指定します。 + +![](./images/appendix-2.png) + +対象の`.msg`ファイルを選択して`Build msg`をクリックします。 + +![](./images/appendix-3.png) + +以上でROSのメッセージファイル作成は完了です。Unityプロジェクト内の`Assets/RosMessages`フォルダにC#のスクリプトが作成されています。 + +![](./images/appendix-4.png) + +## JoystickによるRaspberry Pi Mouseの操作 + +Input SystemのOn-Screen Stickを用いてスクリーン上にJoyStickを作成し、Raspberry Pi Mouseを操作します。 + +### 1. Input Systemの確認 + +Package Managerを開いてInput Systemがインストールされているか確認します。 + +メニューバーから `Window` -> `Package Manager` を選択します。 + +![](./images/appendix-13.png) + +`Package Manager`を開いたら、`Unity Registry`を選択して、`Input System`にチェックマークが付いているか確認します。 + +![](./images/appendix-28.png) + +もしもインストールされていない場合は、インストールを実行してください。 + +![](./images/appendix-14.png) + +### 2. On-Screen Stickの配置と設定 + +Input SystemのOn-Screen Stickを配置します。 + +前のステップで作成したロボット操作用ボタンの代わりにOn-Screen Stickを使用するため、 +Hierarchyの`Canvas` -> `Panel`を選択し、 +Inspectorでチェックを外して`Panel`を非表示にします。 + +![](./images/appendix-16.png) + +Hierarchyの`Canvas`の子オブジェクトとして`Image`を作成します。 + +![](./images/appendix-17.png) + +`Image`のInspectorでSource Imageに`Knob`を選択します。 + +![](./images/appendix-18.png) + +`Image`のInspectorで`Anchor Presets`を右下に設定し、 +さらにPositionとWidthとHeightを以下のように設定します。 + +- Pos X : -200 +- Pox Y : 200 +- Pos Z : 0 +- Width : 50 +- Height : 50 + +![](./images/appendix-19.png) + +`Image`のInspectorで`Add Component`を押し、 +`On-Screen Stick`を選択します。 +さらに`On-Screen Stick`の`Control Path`に`Gamepad` -> `Left Stick`を選択します。 + +![](./images/appendix-20.png) + +`EventSystem`のInspectorで`Standalone Input Module`の +`Replace with InputSystemUIInputModule`を押します。 + +![](./images/appendix-21.png) + +### 3. On-Screen Stick用のスクリプトを設定 + +まず準備として、`UnityScripts/JoyStick`フォルダをUnityプロジェクトの`Assets`フォルダにコピー(`Assets/JoyStick`として配置)します。 + +次に、Hierarchyの`Publisher`の`CmdVelPublisher`のチェックを外します。 + +さらに`Publisher`のAdd Componentを押して`OnScreenStickCmdVelPublisher`を追加します。 + +![](./images/appendix-22.png) + +### 4. Input Actionの設定 + +Hierarchyの`Publisher`にアタッチしてある`OnScreenStickCmdVelPublisher`の`Move Action`の+マークを押します。 +そして`add Up\Down\Left\Right Composite`を選択します。 + +`2D Vector`をダブルクリックして、 +`Composite Type`を`2D Vector`、 +`Mode`を`Analog`に設定します。 + +![](./images/appendix-23.png) + +さらに、`Up`には`Gamepad` -> `Left Stick` -> `Up`を選択します。 +`Down`と`Left`と`Right`も同じように設定します。 + +![](./images/appendix-24.png) + +### 5. インターフェースの調整 + +On-Screen Stickのインターフェースを調整します。 + +Hierarchyの`Canvas`の子オブジェクトとして、`UI` -> `Image`を作成します。 +名前は`WhiteCircle`とします。 +また、画像で示すように`Image`の上に`WhiteCircle`を配置するようにしてください。 + +![](./images/appendix-25.png) + +`WhiteCircle`のInspectorで、`Anchor Presets`を右下に設定します。 +さらにPositionとWidthとHeightを以下のように設定します。 + +- Pos X : -200 +- Pos Y : 200 +- Pos Z : 0 +- Width : 100 +- Height : 100 + +また、画像で示すように`Source Image`に`Assets/JoyStick/Textures/white_circle.png`を設定してください。 + +![](./images/appendix-26.png) + +`Source Image`に`white_circle`が設定できない場合、 +`white_circle`のInspectorで`Texture Type`が`Sprite (2D and UI)`になっているか確認してください。 + +![](./images/appendix-27.png) + +### 6. On-Screen StickでRaspberry Pi Mouseを操作 + +以上の作業を終えると、On-Screen StickでRaspberry Pi Mouseを操作できます。 + +![](./images/appendix-2.gif) diff --git a/docs/images/step4-1.png b/docs/images/appendix-1.png similarity index 100% rename from docs/images/step4-1.png rename to docs/images/appendix-1.png diff --git a/docs/images/appendix-13.png b/docs/images/appendix-13.png new file mode 100644 index 0000000..d2e2ccb Binary files /dev/null and b/docs/images/appendix-13.png differ diff --git a/docs/images/appendix-14.png b/docs/images/appendix-14.png new file mode 100644 index 0000000..434c69b Binary files /dev/null and b/docs/images/appendix-14.png differ diff --git a/docs/images/appendix-15.png b/docs/images/appendix-15.png new file mode 100644 index 0000000..191db9e Binary files /dev/null and b/docs/images/appendix-15.png differ diff --git a/docs/images/appendix-16.png b/docs/images/appendix-16.png new file mode 100644 index 0000000..01dbb33 Binary files /dev/null and b/docs/images/appendix-16.png differ diff --git a/docs/images/appendix-17.png b/docs/images/appendix-17.png new file mode 100644 index 0000000..d37ea0c Binary files /dev/null and b/docs/images/appendix-17.png differ diff --git a/docs/images/appendix-18.png b/docs/images/appendix-18.png new file mode 100644 index 0000000..69a7056 Binary files /dev/null and b/docs/images/appendix-18.png differ diff --git a/docs/images/appendix-19.png b/docs/images/appendix-19.png new file mode 100644 index 0000000..2fa7e3a Binary files /dev/null and b/docs/images/appendix-19.png differ diff --git a/docs/images/appendix-2.gif b/docs/images/appendix-2.gif new file mode 100644 index 0000000..e27484a Binary files /dev/null and b/docs/images/appendix-2.gif differ diff --git a/docs/images/step4-2.png b/docs/images/appendix-2.png similarity index 100% rename from docs/images/step4-2.png rename to docs/images/appendix-2.png diff --git a/docs/images/appendix-20.png b/docs/images/appendix-20.png new file mode 100644 index 0000000..60225ea Binary files /dev/null and b/docs/images/appendix-20.png differ diff --git a/docs/images/appendix-21.png b/docs/images/appendix-21.png new file mode 100644 index 0000000..169afe0 Binary files /dev/null and b/docs/images/appendix-21.png differ diff --git a/docs/images/appendix-22.png b/docs/images/appendix-22.png new file mode 100644 index 0000000..4f18a5b Binary files /dev/null and b/docs/images/appendix-22.png differ diff --git a/docs/images/appendix-23.png b/docs/images/appendix-23.png new file mode 100644 index 0000000..b1d89a5 Binary files /dev/null and b/docs/images/appendix-23.png differ diff --git a/docs/images/appendix-24.png b/docs/images/appendix-24.png new file mode 100644 index 0000000..89210fa Binary files /dev/null and b/docs/images/appendix-24.png differ diff --git a/docs/images/appendix-25.png b/docs/images/appendix-25.png new file mode 100644 index 0000000..53e6796 Binary files /dev/null and b/docs/images/appendix-25.png differ diff --git a/docs/images/appendix-26.png b/docs/images/appendix-26.png new file mode 100644 index 0000000..2e4adbe Binary files /dev/null and b/docs/images/appendix-26.png differ diff --git a/docs/images/appendix-27.png b/docs/images/appendix-27.png new file mode 100644 index 0000000..ed30f87 Binary files /dev/null and b/docs/images/appendix-27.png differ diff --git a/docs/images/appendix-28.png b/docs/images/appendix-28.png new file mode 100644 index 0000000..3504f9b Binary files /dev/null and b/docs/images/appendix-28.png differ diff --git a/docs/images/step4-3.png b/docs/images/appendix-3.png similarity index 100% rename from docs/images/step4-3.png rename to docs/images/appendix-3.png diff --git a/docs/images/step4-4.png b/docs/images/appendix-4.png similarity index 100% rename from docs/images/step4-4.png rename to docs/images/appendix-4.png diff --git a/docs/images/intro2-1-1.gif b/docs/images/intro2-1-1.gif new file mode 100644 index 0000000..4e05222 Binary files /dev/null and b/docs/images/intro2-1-1.gif differ diff --git a/docs/images/intro3-1.png b/docs/images/intro3-1.png new file mode 100644 index 0000000..e1a4b9b Binary files /dev/null and b/docs/images/intro3-1.png differ diff --git a/docs/images/intro3-2.png b/docs/images/intro3-2.png new file mode 100644 index 0000000..976dca0 Binary files /dev/null and b/docs/images/intro3-2.png differ diff --git a/docs/images/intro3-3.png b/docs/images/intro3-3.png new file mode 100644 index 0000000..be745b6 Binary files /dev/null and b/docs/images/intro3-3.png differ diff --git a/docs/images/intro3-4.png b/docs/images/intro3-4.png new file mode 100644 index 0000000..0257963 Binary files /dev/null and b/docs/images/intro3-4.png differ diff --git a/docs/images/intro3-5.png b/docs/images/intro3-5.png new file mode 100644 index 0000000..9b6079c Binary files /dev/null and b/docs/images/intro3-5.png differ diff --git a/docs/images/intro3-6.png b/docs/images/intro3-6.png new file mode 100644 index 0000000..9ab7afb Binary files /dev/null and b/docs/images/intro3-6.png differ diff --git a/docs/images/intro3-7.png b/docs/images/intro3-7.png new file mode 100644 index 0000000..66035bd Binary files /dev/null and b/docs/images/intro3-7.png differ diff --git a/docs/images/step0-1.png b/docs/images/step0-1.png index 81cd8d9..ebcbf8b 100644 Binary files a/docs/images/step0-1.png and b/docs/images/step0-1.png differ diff --git a/docs/images/step0-5.png b/docs/images/step0-5.png new file mode 100644 index 0000000..80bf027 Binary files /dev/null and b/docs/images/step0-5.png differ diff --git a/docs/images/step0-6.png b/docs/images/step0-6.png new file mode 100644 index 0000000..5283f12 Binary files /dev/null and b/docs/images/step0-6.png differ diff --git a/docs/images/step3-31.png b/docs/images/step3-31.png new file mode 100644 index 0000000..8f11b78 Binary files /dev/null and b/docs/images/step3-31.png differ diff --git a/docs/intro0.md b/docs/intro0.md index e7ef41e..13a28e1 100644 --- a/docs/intro0.md +++ b/docs/intro0.md @@ -1,69 +1,69 @@ -# 本教材で学べること - -![](./images/intro0-1.png) - -本教材はUnityとROSを組み合わせたロボット開発のための入門用教材です。 - -ROSで制御された移動ロボットをシミュレータ上で動かし、 -Unityを用いてロボット操作用のUIを作成します。 - -使用するロボットがシミュレータ上で動作するので -PC1台で全てのサンプルプログラムの動作を確認することができます。 - -使用するPCのOSはWindows PCを対象にしていますが -環境に合わせて適宜読み替えていただければmacOSやUbuntuでも実行可能です。 - -Unityでシミュレータ環境を構築する際はぜひ -[Unity Robotics Hub](https://github.com/Unity-Technologies/Unity-Robotics-Hub) -をご覧ください。 - -## 扱う内容 - -本教材で扱う内容は以下の通りです。 - -* DockerによるROS、Gazebo(シミュレータ)の環境構築 -* ロボットモデルの表示 -* フィールドモデルの表示 -* ロボット操作用ボタンの作成と速度指令値の送信 -* ロボット位置姿勢の可視化 -* オドメトリの可視化 -* LiDARデータの可視化 -* カメラ映像の可視化 - -使用するロボットのハードウェアやROSなどのツールについて詳細な解説は省いています。 - -特にソフトウェアのインストール手順などは頻繁に変更が生じるため、適宜外部のドキュメントへのリンクを案内しています。 - -## 扱わない内容 -本教材はUnityとROSとの通信とUI開発に特化しており、Unityによる物理演算や距離計測などのシミュレーションは行っていません。 - -## 想定している対象者 - -本教材の対象として以下の方を想定しています。 - -* Unityの開発経験がありロボット制御に興味のある方 -* ROSの開発経験がありUnityを使ったUI開発に興味のある方 -* Unity、ROSの開発経験がなくロボットのUI開発に興味のある方 - -UnityとROSが連携したシステムを開発するためには両方の知識が必要になりますが、 -連携部分をサンプルプログラムとして用意したので入門者でも扱いやすい内容となっています。 -サンプルに含まれていないデータのやり取りをしたい場合も、多くの場合はサンプルを少し書き換えることで対応可能です。 -本教材で学んだ後は、ぜひオリジナルのUI作成に挑戦してみて下さい。 - -## ROSのビジュアライズツールとの違い - -ROS対応しているロボットのUI開発において -RVizなどが広く用いられていますが、 -本教材ではこれらをUnityにおきかえることで高精細なグラフィックや -多様なインターフェースを実現することが出来ます。 - -こうしたUnityの特徴は現実で動作するロボットの状態を端末から確認するといった -いわゆるデジタルツイン分野においても非常に有効です。 - -[INTRO1](./intro1.md)ではROSとUnityが連携することの利点として -Unityの強みを少し掘り下げてご紹介します。 - ---- - -* [目次](./intro2.md) +# 本教材で学べること + +![](./images/intro0-1.png) + +本教材はUnityとROSを組み合わせたロボット開発のための入門用教材です。 + +ROSで制御された移動ロボットをシミュレータ上で動かし、 +Unityを用いてロボット操作用のUIを作成します。 + +使用するロボットがシミュレータ上で動作するので +PC1台で全てのサンプルプログラムの動作を確認することができます。 + +使用するPCのOSはWindows PCを対象にしていますが +環境に合わせて適宜読み替えていただければmacOSやUbuntuでも実行可能です。 + +Unityでシミュレータ環境を構築する際はぜひ +[Unity Robotics Hub](https://github.com/Unity-Technologies/Unity-Robotics-Hub) +をご覧ください。 + +## 扱う内容 + +本教材で扱う内容は以下の通りです。 + +* DockerによるROS、Gazebo(シミュレータ)の環境構築 +* ロボットモデルの表示 +* フィールドモデルの表示 +* ロボット操作用ボタンの作成と速度指令値の送信 +* ロボット位置姿勢の可視化 +* オドメトリの可視化 +* LiDARデータの可視化 +* カメラ映像の可視化 + +使用するロボットのハードウェアやROSなどのツールについて詳細な解説は省いています。 + +特にソフトウェアのインストール手順などは頻繁に変更が生じるため、適宜外部のドキュメントへのリンクを案内しています。 + +## 扱わない内容 +本教材はUnityとROSとの通信とUI開発に特化しており、Unityによる物理演算や距離計測などのシミュレーションは行っていません。 + +## 想定している対象者 + +本教材の対象として以下の方を想定しています。 + +* Unityの開発経験がありロボット制御に興味のある方 +* ROSの開発経験がありUnityを使ったUI開発に興味のある方 +* Unity、ROSの開発経験がなくロボットのUI開発に興味のある方 + +UnityとROSが連携したシステムを開発するためには両方の知識が必要になりますが、 +連携部分をサンプルプログラムとして用意したので入門者でも扱いやすい内容となっています。 +サンプルに含まれていないデータのやり取りをしたい場合も、多くの場合はサンプルを少し書き換えることで対応可能です。 +本教材で学んだ後は、ぜひオリジナルのUI作成に挑戦してみて下さい。 + +## ROSのビジュアライズツールとの違い + +ROS対応しているロボットのUI開発において +RVizなどが広く用いられていますが、 +本教材ではこれらをUnityにおきかえることで高精細なグラフィックや +多様なインターフェースを実現することが出来ます。 + +こうしたUnityの特徴は現実で動作するロボットの状態を端末から確認するといった +いわゆるデジタルツイン分野においても非常に有効です。 + +[INTRO1](./intro1.md)ではROSとUnityが連携することの利点として +Unityの強みを少し掘り下げてご紹介します。 + +--- + +* [目次](./intro2.md) * \> [INTRO1](./intro1.md) \ No newline at end of file diff --git a/docs/intro1.md b/docs/intro1.md index 49bbbf8..701c353 100644 --- a/docs/intro1.md +++ b/docs/intro1.md @@ -1,46 +1,46 @@ -# Unityとロボットが連携することの利点 -## UI作成が簡単 -キーボードやマウス、ゲームコントローラ、タッチパネルなどを用いたUIを簡単に作成することができます。 - -本教材ではUnityに最初から用意されているボタンの部品を使用してRaspberry Pi Mouseを操作できるようにします。 - -![](./images/intro1-1.png) - -## マルチプラットフォームサポート -様々なプラットフォーム上で動作するので使い方に応じて適切な端末を選ぶことができます。 - -例えばPCで動作するプロジェクトをスマートフォン向けにビルドすることが可能です。 - -現実のロボットを操作する際は、持ち運びしやすい端末から操作できるととても便利です。 - -またARやVR向けの対応も容易なため、より没入的で直感的なUIを作成することもできます。 - -対応プラットフォームについて詳しくは[こちら](https://unity.com/ja/features/multiplatform)をご覧ください。 - -![](./images/intro1-2.jpg) - -## リアルタイムレンダリング -Unityはリアルタイムレンダリングを実現するための様々な仕組みを統合した開発環境です。 - -実機の動きをなめらかに表現できるだけでなく、低遅延のインタラクションを実現することが出来ます。 - -また、HDRP(High Definition Render Pipeline)を使うと現実により忠実な高品質な表現が行えたり、URP(Universal Render Pipeline)という仕組みを使うと複雑なレンダリングの処理を簡易な処理に置き換えることで負荷を低減させたりすることが出来ます。 - -参考までに、下記画像は左がUnity標準のBuilt-in、右がより高精細なHDRPを用いた画面です。 - -![](./images/intro1-3.png) - -## 豊富な情報や素材 -[公式チュートリアル](https://learn.unity.com/course/unity-tutorials-for-beginners-jp)や[マニュアル](https://docs.unity3d.com/ja/2020.3/Manual/UnityManual.html)、Unity公式の素材集である[Unity Asset Store](https://assetstore.unity.com/?locale=ja-JP)、個人のブログ記事などゲーム開発で培われた様々な技術や素材が蓄積されています。 - -Unityの使い方等でわからないことが出てきたら、こちらの[コミュニティ](https://unity.com/ja/community)のページや、[Unityユーザー助け合い所](https://www.facebook.com/groups/unityuserj)(日本語での質問が可能)にアクセスしてみて下さい。 - -さらなる学びや情報収集には、Unity Japan が運営する [Unity Learning Materials](https://learning.unity3d.jp/)もおすすめです。 - -![](./images/intro1-4.png) - ---- - -* [目次](./intro2.md) -* < [INTRO0](./intro0.md) +# Unityとロボットが連携することの利点 +## UI作成が簡単 +キーボードやマウス、ゲームコントローラ、タッチパネルなどを用いたUIを簡単に作成することができます。 + +本教材ではUnityに最初から用意されているボタンの部品を使用してRaspberry Pi Mouseを操作できるようにします。 + +![](./images/intro1-1.png) + +## マルチプラットフォームサポート +様々なプラットフォーム上で動作するので使い方に応じて適切な端末を選ぶことができます。 + +例えばPCで動作するプロジェクトをスマートフォン向けにビルドすることが可能です。 + +現実のロボットを操作する際は、持ち運びしやすい端末から操作できるととても便利です。 + +またARやVR向けの対応も容易なため、より没入的で直感的なUIを作成することもできます。 + +対応プラットフォームについて詳しくは[こちら](https://unity.com/ja/features/multiplatform)をご覧ください。 + +![](./images/intro1-2.jpg) + +## リアルタイムレンダリング +Unityはリアルタイムレンダリングを実現するための様々な仕組みを統合した開発環境です。 + +実機の動きをなめらかに表現できるだけでなく、低遅延のインタラクションを実現することが出来ます。 + +また、HDRP(High Definition Render Pipeline)を使うと現実により忠実な高品質な表現が行えたり、URP(Universal Render Pipeline)という仕組みを使うと複雑なレンダリングの処理を簡易な処理に置き換えることで負荷を低減させたりすることが出来ます。 + +参考までに、下記画像は左がUnity標準のBuilt-in、右がより高精細なHDRPを用いた画面です。 + +![](./images/intro1-3.png) + +## 豊富な情報や素材 +[公式チュートリアル](https://learn.unity.com/course/unity-tutorials-for-beginners-jp)や[マニュアル](https://docs.unity3d.com/ja/2020.3/Manual/UnityManual.html)、Unity公式の素材集である[Unity Asset Store](https://assetstore.unity.com/?locale=ja-JP)、個人のブログ記事などゲーム開発で培われた様々な技術や素材が蓄積されています。 + +Unityの使い方等でわからないことが出てきたら、こちらの[コミュニティ](https://unity.com/ja/community)のページや、[Unityユーザー助け合い所](https://www.facebook.com/groups/unityuserj)(日本語での質問が可能)にアクセスしてみて下さい。 + +さらなる学びや情報収集には、Unity Japan が運営する [Unity Learning Materials](https://learning.unity3d.jp/)もおすすめです。 + +![](./images/intro1-4.png) + +--- + +* [目次](./intro2.md) +* < [INTRO0](./intro0.md) * \> [INTRO2](./intro2.md) \ No newline at end of file diff --git a/docs/intro2.md b/docs/intro2.md index 108b688..196d188 100644 --- a/docs/intro2.md +++ b/docs/intro2.md @@ -42,6 +42,10 @@ ROSのコマンドやその仕組み、Unityのインターフェース名称に ![](./images/intro2-1.png) +### 動作イメージ + +![](./images/intro2-1-1.gif) + ### PC UIの開発や動作確認、環境構築に使用します。 diff --git a/docs/intro3.md b/docs/intro3.md index dd05161..8b433f5 100644 --- a/docs/intro3.md +++ b/docs/intro3.md @@ -7,21 +7,27 @@ ## Dockerのインストール ドキュメントを参考にしながらDockerをインストールします。 -インストール手順は変わる可能性がありますので公式から案内される資料を参照してください。 +インストール手順は変わる可能性がありますので公式から案内される資料を参照してください。 +※ 2022年6月現在、WindowsでDockerを使用する際によく用いられる「Docker Desktop」は、 __一定の条件を満たしている場合を除いて有料__ です。詳しくは本資料の「参考情報」を参照してください。 * 公式ドキュメント(英語) * https://docs.docker.com/desktop/windows/install/ * 有志による非公式ドキュメント(日本語) * https://qiita.com/zaki-lknr/items/db99909ba1eb27803456 -※ 2021年9月現在、WindowsでDockerを使用する際に必要なDocker Desktopは一定の条件を満たしている場合を除き、2022年2月から有料化が予定されているとのお知らせが掲載されています。詳しくは本資料の「参考情報」を参照してください。 - ## 参考情報 ### Docker Desktopの料金プランについて -WindowsでDockerを使用する際に必要なDocker Desktopは一定の条件を満たしている場合を除き、2022年2月から有料化が予定されているとのことです(2021年9月現在)。 +WindowsでDockerを使用する際に必要なDocker Desktopは個人使用や教育使用などの一定の条件を満たしている場合を除き、2022年2月から有料化されています(2022年6月現在)。 +詳細については関連リンクをご参照ください。 + + +#### 関連リンク + +* Docker Subscription Service Agreement + * https://www.docker.com/legal/docker-subscription-service-agreement/ > Docker Desktopが有料化へ、ただし250人未満かつ年間売り上げ1000万ドル(約11億円)未満の組織や個人やオープンソースプロジェクトでは引き続き無料で利用可能 > https://www.publickey1.jp/blog/21/docker_desktop250100011.html @@ -35,6 +41,97 @@ WindowsでDockerを使用する際に必要なDocker Desktopは一定の条件 * 公式のお知らせ(英語) * https://www.docker.com/blog/accelerating-new-features-in-docker-desktop/ +> 「Docker Desktop for Linux」が登場、WindowsやMac版と同じ機能や操作を提供、Raspberry Pi OSにも対応 +> https://www.publickey1.jp/blog/22/docker_desktop_for_linuxwindowsmacraspberry_pi_os.html + +* 公式のお知らせ(英語) + * https://www.docker.com/blog/the-magic-of-docker-desktop-is-now-available-on-linux/ + +### WSL 2へのDockerのインストール + +[Docker Engine](https://docs.docker.com/engine/install/)は2022年6月現在、有料化対象外です。Docker Desktopよりも機能は少ないですが、WindowsでDocker CLIをWSL 2にインストールしてDockerを使い、本教材の内容を試すこともできます。 + +#### WSL 2の設定 + +WSL 2のインストール方法についてはMicrosoftが公開する資料にまとまっています。 + +参考:https://docs.microsoft.com/ja-jp/windows/wsl/install + +Windows 10のビルド 19041より前のバージョンでは「仮想マシンの機能の有効化」などの操作を手動で行う必要があります。 + +参考:https://docs.microsoft.com/ja-jp/windows/wsl/install-manual + +ここではWindows 10のビルド 19041以降のバージョンの方法を紹介します。 + +PowerShellを管理者権限で開き、WSLを有効化します。 + +``` +wsl --install +``` + +WSL 2をデフォルトバージョンに指定します。 + +``` +wsl --set-default-version 2 +``` + +Ubuntu 20.04を指定してインストールします。 + +``` +wsl --install -d Ubuntu-20.04 +``` + +![](./images/intro3-1.png) + +正常にインストールが完了していればここで「Enter new UNIX username:」と表示されます。 +WSL 2の中でのみ使用するユーザ名とパスワードなので忘れないように設定します。 + +![](./images/intro3-2.png) + +もしここで以下の図のように`0x800701bc`のエラーが出た場合は「Linux カーネル更新プログラム パッケージ」をインストールしてください。 + +https://docs.microsoft.com/ja-jp/windows/wsl/install-manual#step-4---download-the-linux-kernel-update-package + +![](./images/intro3-3.png) + +WSL 2に無事ログインできると以下の画像のようにbashが起動します。 +![](./images/intro3-4.png) + + +#### Dockerのインストール + +Dockerをインストールするために必要なパッケージをインストールします。 + +``` +sudo apt update +sudo apt install curl +curl -L get.docker.com | sh +sudo gpasswd -a $USER docker +``` + +![](./images/intro3-5.png) + + +![](./images/intro3-6.png) + +Dockerインストール時の設定を反映させるため、Linux シェルのウインドウを一度閉じ、WSL 2を起動し直します。 + +Dockerのサービスを起動します。 + +``` +sudo systemctl start docker +``` + +hello-worldを実行します。 + +``` +docker run hello-world +``` + +![](./images/intro3-7.png) + +以上でDockerのインストールと動作確認は完了です。 + --- * [目次](./intro2.md) diff --git a/docs/step0.md b/docs/step0.md index 140bd29..6a786f6 100644 --- a/docs/step0.md +++ b/docs/step0.md @@ -6,8 +6,8 @@ Unityプロジェクトの作成とROSがインストールされたDockerイメ ## 動作確認済環境 -* Windows 10 Home バージョン 20H2 -* Unity 2020.3.17f +* Windows 10 Home バージョン 21H2 +* Unity 2021.3.4f1 ## Unityプロジェクトの作成 @@ -23,7 +23,7 @@ Unityプロジェクトの作成とROSがインストールされたDockerイメ 次はDockerイメージの構築に進みます。 -## Dockerイメージの構築 +## Dockerイメージの構築(Docker Desktopの場合) `ROS`フォルダの中でPowerShellを起動します。 エクスプローラで`ROS`フォルダを開き、Shiftキーを押しながら右クリックして「PowerShell ウィンドウをここで開く」を選択します。 @@ -52,6 +52,57 @@ docker build -t raspimouse-unity:latest . 以上でROSがインストールされたDockerイメージの構築は完了です。 +※期間をあけて再度本チュートリアルを試している場合にはキャッシュが残っており、古いROSパッケージが参照されることがあります。 +その場合は以下のコマンドで最新版のDockerイメージを構築することができます。 + +```sh +docker pull tiryoh/ros-desktop-vnc:melodic +docker build --no-cache -t raspimouse-unity:latest . +``` + +## Dockerイメージの構築(WSL 2のDockerの場合) + +`ROS`フォルダの中でLinux シェルを起動します。 +エクスプローラで`ROS`フォルダを開き、Shiftキーを押しながら右クリックして「Linux シェルをここで開く」を選択します。 + +![](./images/step0-5.png) + +Linux シェルで以下のコマンドを実行します。 +Linux シェルでは右クリックでクリップボードの内容(コピーしたコマンド)を貼り付けることができます。 + +```sh +docker build -t raspimouse-unity:latest . +``` + +もし`Cannot connect to the Docker daemon`などのエラーが出た場合は、INTRO3で紹介したコマンドでDockerのサービスを起動してから`docker build`を実行します。 + +``` +sudo systemctl start docker +``` + +構築中はログが出力されます。 +初回は構築に時間がかかる場合があります。PCのスペックやネットワークに左右されますが5分程度かかる場合がありました。 + +この間、次の[STEP1](./step1.md)を進めておくこともできます。 + +以下のようなメッセージが出力されていればイメージ作成が正常に完了しています。 + +``` +Successfully tagged raspimouse-unity:latest +``` + +![](./images/step0-6.png) + +以上でROSがインストールされたDockerイメージの構築は完了です。 + +※期間をあけて再度本チュートリアルを試している場合にはキャッシュが残っており、古いROSパッケージが参照されることがあります。 +その場合は以下のコマンドで最新版のDockerイメージを構築することができます。 + +```sh +docker pull tiryoh/ros-desktop-vnc:melodic +docker build --no-cache -t raspimouse-unity:latest . +``` + ## 本STEPのまとめ Unityプロジェクトの作成方法とROSがインストールされたDockerイメージの構築について紹介しました。 @@ -62,4 +113,4 @@ Unityプロジェクトの作成方法とROSがインストールされたDocker * [目次](./intro2.md) * < [INTRO3](./intro3.md) -* \> [STEP1](./step1.md) \ No newline at end of file +* \> [STEP1](./step1.md) diff --git a/docs/step1.md b/docs/step1.md index 36c177e..6927a7e 100644 --- a/docs/step1.md +++ b/docs/step1.md @@ -11,9 +11,9 @@ Unityプロジェクトの新規作成までの手順は[STEP0](./step0.md)を ## 動作確認済環境 -* Windows 10 Home バージョン 20H2 -* Unity 2020.3.17f -* [Unity-Technologies/URDF-Importer](https://github.com/Unity-Technologies/URDF-Importer) v0.5.0 +* Windows 10 Home バージョン 21H2 +* Unity 2021.3.4f1 +* [Unity-Technologies/URDF-Importer](https://github.com/Unity-Technologies/URDF-Importer) v0.5.2 ## 手順 @@ -25,8 +25,9 @@ Unityプロジェクトの新規作成までの手順は[STEP0](./step0.md)を ![](./images/step1-1.png) -URDF-ImporterのGitリポジトリへのURLを最新のタグを指定して入力し、`Add`をクリックします。2021年8月24日現在最新のタグは`v0.5.0`です。 -この場合のGitリポジトリへのURLは `https://github.com/Unity-Technologies/URDF-Importer.git?path=/com.unity.robotics.urdf-importer#v0.5.0` となります。 +URDF-ImporterのGitリポジトリへのURLを最新のタグを指定して入力し、`Add`をクリックします。2022年6月現在最新のタグは`v0.5.2`です。 +この場合のGitリポジトリへのURLは `https://github.com/Unity-Technologies/URDF-Importer.git?path=/com.unity.robotics.urdf-importer#v0.5.2` となります。 +※今後のバージョンアップによって使い方が変わる可能性があります。本チュートリアルでは「動作確認環境」に記載のバージョンでのみ動作確認をしています。 ![](./images/step1-2.png) diff --git a/docs/step2.md b/docs/step2.md index 926566f..da19032 100644 --- a/docs/step2.md +++ b/docs/step2.md @@ -10,8 +10,8 @@ ## 動作確認済環境 -* Windows 10 Home バージョン 20H2 -* Unity 2020.3.17f +* Windows 10 Home バージョン 21H2 +* Unity 2021.3.4f1 ## 手順 diff --git a/docs/step3.md b/docs/step3.md index 5baf9f2..968e036 100644 --- a/docs/step3.md +++ b/docs/step3.md @@ -8,10 +8,10 @@ ## 動作確認済環境 -* Windows 10 Home バージョン 20H2 -* Unity 2020.3.17f -* [Unity-Technologies/ROS-TCP-Connector](https://github.com/Unity-Technologies/ROS-TCP-Connector) v0.5.0 -* Docker Desktop 3.6.0 +* Windows 10 Home バージョン 21H2 +* Unity 2021.3.4f1 +* [Unity-Technologies/ROS-TCP-Connector](https://github.com/Unity-Technologies/ROS-TCP-Connector) v0.7.0 +* Docker Desktop 4.9.1 ## 手順 @@ -23,8 +23,9 @@ ![](./images/step1-1.png) -ROS-TCP-ConnectorのGitリポジトリへのURLを最新のタグを指定して入力し、`Add`をクリックします。2021年9月現在最新のタグは`v0.5.0`です。 -この場合のGitリポジトリへのURLは `https://github.com/Unity-Technologies/ROS-TCP-Connector.git?path=/com.unity.robotics.ros-tcp-connector#v0.5.0` となります。 +ROS-TCP-ConnectorのGitリポジトリへのURLを最新のタグを指定して入力し、`Add`をクリックします。2022年6月現在最新のタグは`v0.7.0`です。 +この場合のGitリポジトリへのURLは `https://github.com/Unity-Technologies/ROS-TCP-Connector.git?path=/com.unity.robotics.ros-tcp-connector#v0.7.0` となります。 +※今後のバージョンアップによって使い方が変わる可能性があります。本チュートリアルでは「動作確認環境」に記載のバージョンでのみ動作確認をしています。 メニューバーに`Robotics`というメニューが追加されます。メニューバーから`Robotics` -> `ROS Settings`を開き、以下の設定となっていることを確認します。 @@ -34,37 +35,7 @@ ROS-TCP-ConnectorのGitリポジトリへのURLを最新のタグを指定して * ROS Port: 10000 * Show HUD: True -![](./images/step3-14.png) - -### 2. ROSのメッセージファイル作成 - -UnityでROSから配信されるロボットの位置姿勢を受信するために、配信されているメッセージの形式をUnityプロジェクトで扱えるようにします。 -ROSで使われている定義ファイルをC#のスクリプトに変換します。 - -変換にはROS-TCP-Connectorのメッセージ作成機能を用います。 - -なお、この手順は今回のように使うROSのメッセージがROS-TCP-Connectorに予め含まれていない場合にのみ必要です。 -([STEP3](./step3.md)ではROS-TCP-Connectorに予め定義されているROSのメッセージ作成のみ使用しています。[STEP4](./step4.md)にて使用するメッセージを先に用意しておきます。) -[`com.unity.robotics.ros-tcp-connector/Runtime/Messages`](https://github.com/Unity-Technologies/ROS-TCP-Connector/tree/main/com.unity.robotics.ros-tcp-connector/Runtime/Messages)から予めUnity用に用意されているROSのメッセージ形式を確認できます。 - -メニューバーから`Robotics` -> `Generate ROS Messages...`を選択します。 - -![](./images/step4-1.png) - -`ROS message path`を指定します。 -[`ROS/src`](../ROS/src)フォルダを指定します。 - -![](./images/step4-2.png) - -`tf2_msgs/msg/TFMessage.msg`を選択して`Build msg`をクリックします。 - -![](./images/step4-3.png) - -以上でROSのメッセージファイル作成は完了です。Unityプロジェクト内の`Assets/RosMessages`フォルダに`Tf2/msg/TFMessageMsg.cs`というスクリプトが作成されています。 - -![](./images/step4-4.png) - -### 3. ロボット操作用ボタンを作成 +### 2. ロボット操作用ボタンを作成 Hierarchyウィンドウを右クリックして`UI`->`Panel`を選択します。 @@ -113,7 +84,7 @@ Pos X, Pos Y, Pos Z, Width, Heightはそれぞれ0, 100, 0, 100, 100にします ![](./images/step3-10.png) ![](./images/step3-11.png) -### 4. 操作用ボタンにイベントを登録 +### 3. 操作用ボタンにイベントを登録 次に作成したボタンにイベントを登録します。 @@ -175,9 +146,9 @@ Pos X, Pos Y, Pos Z, Width, Heightはそれぞれ0, 100, 0, 100, 100にします それぞれ`CmdVelPublisher.SetLeftTurnVel`と`CmdVelPublisher.SetRightTurnVel`を指定します。 以上で4つのボタンへのイベントの登録が完了です。 -### 5. ROS環境を起動 +### 4. ROS環境を起動 -PowerShellを起動してDockerコンテナを起動します。 +PowerShell/Linux シェルを起動してDockerコンテナを起動します。 ``` docker run --rm -it -p 10000:10000 -p 5005:5005 -p 6080:80 --shm-size=512m raspimouse-unity:latest @@ -195,17 +166,21 @@ Webブラウザを開き[http://127.0.0.1:6080](http://127.0.0.1:6080)にアク ![](./images/step3-24.png) -### 6. 再生モードでUnityプロジェクトを実行 +### 5. 再生モードでUnityプロジェクトを実行 Unityで再生ボタンを押し、再生モードでプロジェクトを実行します。 ![](./images/step3-25.png) -この状態で操作ボタンの動作確認をしてみます。ボタンを押すと左上の`Last Message Sent`の欄が更新されているのが確認できます。 +この状態で操作ボタンの動作確認をしてみます。ボタンを押すと左上の`Last Message Sent`の欄が更新されているのが確認できます。 ![](./images/step3-26.gif) -この間以下のようなメッセージが出ますが、無視して問題ありません。 +※ROS-TCP-Connectorのバージョンによっては以下の画像のようにデバッグ用の詳細情報が表示されない場合もあります。 + +![](./images/step3-31.png) + +この間以下のようなメッセージがUnityのコンソールに出る場合もありますが、無視して問題ありません。 ``` Connection to 127.0.0.1:10000 failed - System.Net.Sockets.SocketException (0x80004005): 対象のコンピューターによって拒否されたため、接続できませんでした。 @@ -216,7 +191,7 @@ Connection to 127.0.0.1:10000 failed - System.Net.Sockets.SocketException (0x800 ![](./images/step3-26-1.png) -### 7. Gazeboシミュレータを起動 +### 6. Gazeboシミュレータを起動 先程まで開いていたWebブラウザでLXTerminalを2つ起動します。 diff --git a/docs/step4.md b/docs/step4.md index a1dfedf..66755cd 100644 --- a/docs/step4.md +++ b/docs/step4.md @@ -1,89 +1,89 @@ -# Raspberry Pi Mouse位置姿勢の可視化 -## 概要 - -Gazebo上のロボットの位置姿勢を取得し、Unity上に反映させる方法を紹介します。 - -本ステップ実行後の状態のSceneファイルは[`MobileRobotUITutorialProject/Assets/Scenes/Step4.unity`](../MobileRobotUITutorialProject/Assets/Scenes/Step4.unity)から入手できます。 - -## 動作確認済環境 - -* Windows 10 Home バージョン 20H2 -* Unity 2020.3.17f -* [Unity-Technologies/ROS-TCP-Connector](https://github.com/Unity-Technologies/ROS-TCP-Connector) v0.5.0 -* Docker Desktop 3.6.0 - -## 手順 - -### 1. ROSトピックのサブスクライバスクリプトの登録 - -ROSから配信されるトピックを受信するために、サブスクライバをUnityに登録します。 - -Hierarchyウィンドウを右クリックして`Create Empty`を選択し、`Subscriber`としてGameObjectを作成します。 - -![](./images/step4-5.png) - - -作成した`Subscriber`オブジェクトに`Assets/Scripts/TfSubscriber.cs`スクリプトをアタッチします。 -(`Hierarchy`ウィンドウからGameObjectを選択してInspectorウィンドウ上で任意のスクリプト コンポーネントを追加することも可能です。) - -![](./images/step4-6.gif) - -Inspectorウィンドウで`Tf Subscriber`コンポーネントの`Mobile Robot`に`raspimouse`オブジェクトを指定します。 - -![](./images/step4-7.gif) - -以上でROSから配信されるロボットの位置姿勢を受信してUnity上のロボットに反映させる準備ができました。 - -### 2. Unityプロジェクトの実行 - -[STEP3](./step3.md)と同様に、 - -1. 再生モードでUnityプロジェクトを実行 -2. Gazeboシミュレータを起動 -3. 操作ボタンから移動指令送信 - -の手順でロボットを動かしてみます。 - -![](./images/step4-8.gif) - -[STEP3](./step3.md)までは操作ボタンを押した際にGazebo上のロボットが移動するだけでしたが、Gazebo上の移動ロボットに合わせてUnityのロボットも動かすことができました。 -操作ボタンを使わなくてもGazebo上でロボットを動かすことでも反映されます。 - -![](./images/step4-9.gif) - -Consoleを見ると位置姿勢の受信結果と座標変換のデバッグログを確認できます。 -ROSとUnityでは座標系が異なるため、この差分を吸収するために`TfSubscriber.cs`スクリプト内で座標変換をしています。 -座標変換については次の「位置姿勢の表現方法とROSとUnityにおける座標系の違い」を参照してください。 - -## 位置姿勢の表現方法とROSとUnityにおける座標系の違い -### 位置の表現方法 -ロボットの位置を表現するには原点を基準にした前後、左右、上下方向の距離を用います。例えば下図のように原点から見たロボット位置を前後、左右、上下の順に書くと(4,2,0)と表現できます。このように数値で表現された位置を座標、表現方法の決まりごとを座標系といいます。ちなみに今回用いる座標系は3つの方向がそれぞれ直角に交わっているため直交座標系とよばれています。 - -![](./images/step4-99.png) - -### 姿勢の表現方法 -ロボットの姿勢はクォータニオンとよばれる形式が用いられます。位置と同じように回転する軸の方向を3つの要素で表現し、回転量をもう1つの要素で表現する方法です。これは人の直感的な認識に沿わないので数値を見ても姿勢を想像することが難しいのですが、コンピュータ上で処理する際にとても便利な形式になっています。クォータニオンの値を人が直接扱うことはあまりないためわからなくても問題ありません。クォータニオンはこのような祭りが開催されるほどステップアップのための重要なテーマになっています。 - -* [納涼クォータニオン夏祭り | Unity Learning Materials](https://learning.unity3d.jp/5830/) - -### UnityとROSの座標系の違い -UnityもROSもロボット位置にx,y,zの3つ、姿勢の場合はx,y,z,wの4つの変数が割り当てていますが、それぞれの座標系で変数と方向の対応が異なる点に注意する必要があります。Unity座標系におけるx,y,zはそれぞれ右、上、前方向に対応していますが、ROS座標系では前、左、上の順で対応しています。 - -![](./images/step4-100.png) - -UnityとROSの座標系の変換を変数で表現してみます。Unity座標系における位置(x,y,z)がROS座標系では(z,−x,y)、ROS座標系における位置(x,y,z)がUnity座標系では(−y,z,x)となります。姿勢も位置と同様にUnity座標系における姿勢(x,y,z,w)がROS座標系では(z,-x,y,-w)、ROS座標系における姿勢(x,y,z,w)がUnity座標系では(-y,z,x,-w)になります。非常にややこしいのですが変換のコードさえ書いてしまえば毎回考える必要はありません。今回の説明を読んでピンとこない方もUnityとROSの間では何かしら変換が必要であることだけを意識していただければ問題ないです。 - -![](./images/step4-101.png) - -### 本STEPのまとめ - -Gazebo上のロボットの位置姿勢をUnity上で表示じて可視化する方法とその確認方法を紹介しました。 -またUnityとROSの座標系の違いについても紹介しました。 - -次は[STEP5](./step5.md)でロボットのオドメトリを可視化する方法を紹介します。 - ---- - -* [目次](./intro2.md) -* < [STEP3](./step3.md) +# Raspberry Pi Mouse位置姿勢の可視化 +## 概要 + +Gazebo上のロボットの位置姿勢を取得し、Unity上に反映させる方法を紹介します。 + +本ステップ実行後の状態のSceneファイルは[`MobileRobotUITutorialProject/Assets/Scenes/Step4.unity`](../MobileRobotUITutorialProject/Assets/Scenes/Step4.unity)から入手できます。 + +## 動作確認済環境 + +* Windows 10 Home バージョン 21H2 +* Unity 2021.3.4f1 +* [Unity-Technologies/ROS-TCP-Connector](https://github.com/Unity-Technologies/ROS-TCP-Connector) v0.7.0 +* Docker Desktop 4.9.1 + +## 手順 + +### 1. ROSトピックのサブスクライバスクリプトの登録 + +ROSから配信されるトピックを受信するために、サブスクライバをUnityに登録します。 + +Hierarchyウィンドウを右クリックして`Create Empty`を選択し、`Subscriber`としてGameObjectを作成します。 + +![](./images/step4-5.png) + + +作成した`Subscriber`オブジェクトに`Assets/Scripts/TfSubscriber.cs`スクリプトをアタッチします。 +(`Hierarchy`ウィンドウからGameObjectを選択してInspectorウィンドウ上で任意のスクリプト コンポーネントを追加することも可能です。) + +![](./images/step4-6.gif) + +Inspectorウィンドウで`Tf Subscriber`コンポーネントの`Mobile Robot`に`raspimouse`オブジェクトを指定します。 + +![](./images/step4-7.gif) + +以上でROSから配信されるロボットの位置姿勢を受信してUnity上のロボットに反映させる準備ができました。 + +### 2. Unityプロジェクトの実行 + +[STEP3](./step3.md)と同様に、 + +1. 再生モードでUnityプロジェクトを実行 +2. Gazeboシミュレータを起動 +3. 操作ボタンから移動指令送信 + +の手順でロボットを動かしてみます。 + +![](./images/step4-8.gif) + +[STEP3](./step3.md)までは操作ボタンを押した際にGazebo上のロボットが移動するだけでしたが、Gazebo上の移動ロボットに合わせてUnityのロボットも動かすことができました。 +操作ボタンを使わなくてもGazebo上でロボットを動かすことでも反映されます。 + +![](./images/step4-9.gif) + +Consoleを見ると位置姿勢の受信結果と座標変換のデバッグログを確認できます。 +ROSとUnityでは座標系が異なるため、この差分を吸収するために`TfSubscriber.cs`スクリプト内で座標変換をしています。 +座標変換については次の「位置姿勢の表現方法とROSとUnityにおける座標系の違い」を参照してください。 + +## 位置姿勢の表現方法とROSとUnityにおける座標系の違い +### 位置の表現方法 +ロボットの位置を表現するには原点を基準にした前後、左右、上下方向の距離を用います。例えば下図のように原点から見たロボット位置を前後、左右、上下の順に書くと(4,2,0)と表現できます。このように数値で表現された位置を座標、表現方法の決まりごとを座標系といいます。ちなみに今回用いる座標系は3つの方向がそれぞれ直角に交わっているため直交座標系とよばれています。 + +![](./images/step4-99.png) + +### 姿勢の表現方法 +ロボットの姿勢はクォータニオンとよばれる形式が用いられます。位置と同じように回転する軸の方向を3つの要素で表現し、回転量をもう1つの要素で表現する方法です。これは人の直感的な認識に沿わないので数値を見ても姿勢を想像することが難しいのですが、コンピュータ上で処理する際にとても便利な形式になっています。クォータニオンの値を人が直接扱うことはあまりないためわからなくても問題ありません。クォータニオンはこのような祭りが開催されるほどステップアップのための重要なテーマになっています。 + +* [納涼クォータニオン夏祭り | Unity Learning Materials](https://learning.unity3d.jp/5830/) + +### UnityとROSの座標系の違い +UnityもROSもロボット位置にx,y,zの3つ、姿勢の場合はx,y,z,wの4つの変数が割り当てていますが、それぞれの座標系で変数と方向の対応が異なる点に注意する必要があります。Unity座標系におけるx,y,zはそれぞれ右、上、前方向に対応していますが、ROS座標系では前、左、上の順で対応しています。 + +![](./images/step4-100.png) + +UnityとROSの座標系の変換を変数で表現してみます。Unity座標系における位置(x,y,z)がROS座標系では(z,−x,y)、ROS座標系における位置(x,y,z)がUnity座標系では(−y,z,x)となります。姿勢も位置と同様にUnity座標系における姿勢(x,y,z,w)がROS座標系では(z,-x,y,-w)、ROS座標系における姿勢(x,y,z,w)がUnity座標系では(-y,z,x,-w)になります。非常にややこしいのですが変換のコードさえ書いてしまえば毎回考える必要はありません。今回の説明を読んでピンとこない方もUnityとROSの間では何かしら変換が必要であることだけを意識していただければ問題ないです。 + +![](./images/step4-101.png) + +### 本STEPのまとめ + +Gazebo上のロボットの位置姿勢をUnity上で表示じて可視化する方法とその確認方法を紹介しました。 +またUnityとROSの座標系の違いについても紹介しました。 + +次は[STEP5](./step5.md)でロボットのオドメトリを可視化する方法を紹介します。 + +--- + +* [目次](./intro2.md) +* < [STEP3](./step3.md) * \> [STEP5](./step5.md) \ No newline at end of file diff --git a/docs/step5.md b/docs/step5.md index d591b4b..827739f 100644 --- a/docs/step5.md +++ b/docs/step5.md @@ -9,10 +9,10 @@ ## 動作確認済環境 -* Windows 10 Home バージョン 20H2 -* Unity 2020.3.17f -* [Unity-Technologies/ROS-TCP-Connector](https://github.com/Unity-Technologies/ROS-TCP-Connector) v0.5.0 -* Docker Desktop 3.6.0 +* Windows 10 Home バージョン 21H2 +* Unity 2021.3.4f1 +* [Unity-Technologies/ROS-TCP-Connector](https://github.com/Unity-Technologies/ROS-TCP-Connector) v0.7.0 +* Docker Desktop 4.9.1 ## 手順 diff --git a/docs/step6.md b/docs/step6.md index 76c1d2a..2ea4785 100644 --- a/docs/step6.md +++ b/docs/step6.md @@ -9,10 +9,10 @@ ## 動作確認済環境 -* Windows 10 Home バージョン 20H2 -* Unity 2020.3.17f -* [Unity-Technologies/ROS-TCP-Connector](https://github.com/Unity-Technologies/ROS-TCP-Connector) v0.5.0 -* Docker Desktop 3.6.0 +* Windows 10 Home バージョン 21H2 +* Unity 2021.3.4f1 +* [Unity-Technologies/ROS-TCP-Connector](https://github.com/Unity-Technologies/ROS-TCP-Connector) v0.7.0 +* Docker Desktop 4.9.1 ## 手順 diff --git a/docs/step7.md b/docs/step7.md index dcd1fb7..7421f56 100644 --- a/docs/step7.md +++ b/docs/step7.md @@ -7,10 +7,10 @@ ## 動作確認済環境 -* Windows 10 Home バージョン 20H2 -* Unity 2020.3.17f -* [Unity-Technologies/ROS-TCP-Connector](https://github.com/Unity-Technologies/ROS-TCP-Connector) v0.5.0 -* Docker Desktop 3.6.0 +* Windows 10 Home バージョン 21H2 +* Unity 2021.3.4f1 +* [Unity-Technologies/ROS-TCP-Connector](https://github.com/Unity-Technologies/ROS-TCP-Connector) v0.7.0 +* Docker Desktop 4.9.1 ## 手順