Skip to content

Upgrade packages #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion MobileRobotUITutorialProject/Assets/Models/maze.dae.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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

/// <summary>
/// オドメトリ位置を可視化するためのクラス
/// (可視化のみを行い、座標変換を含むオドメトリの位置計算は予め行っている前提)
/// </summary>
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<GameObject> arrowList;

private Vector3 previousRobotPosition = new Vector3();

/// <summary>
/// 初期化用のイベント関数
/// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html
/// ここで点群(オドメトリの矢印)用の配列を初期化
/// </summary>
void Start()
{
arrowList = new List<GameObject>(lengthOfHistory);

}

/// <summary>
/// 1フレーム毎に呼び出されるイベント関数
/// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html
/// ここで点群の描画位置を決定
/// </summary>
void Update()
{
Vector3 currentRobotPosition = subscriberGameObject.GetComponent<OdomSubscriber>().GetRobotPosition();
Quaternion currentRobotPosture = subscriberGameObject.GetComponent<OdomSubscriber>().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
/// <summary>
/// オドメトリ位置を可視化するためのクラス
/// (可視化のみを行い、座標変換を含むオドメトリの位置計算は予め行っている前提)
/// </summary>
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<GameObject> arrowList;
private Vector3 previousRobotPosition = new Vector3();
/// <summary>
/// 初期化用のイベント関数
/// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html
/// ここで点群(オドメトリの矢印)用の配列を初期化
/// </summary>
void Start()
{
arrowList = new List<GameObject>(lengthOfHistory);
}
/// <summary>
/// 1フレーム毎に呼び出されるイベント関数
/// https://docs.unity3d.com/ja/2020.3/Manual/ExecutionOrder.html
/// ここで点群の描画位置を決定
/// </summary>
void Update()
{
Vector3 currentRobotPosition = subscriberGameObject.GetComponent<OdomSubscriber>().GetRobotPosition();
Quaternion currentRobotPosture = subscriberGameObject.GetComponent<OdomSubscriber>().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);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 0 additions & 8 deletions MobileRobotUITutorialProject/Assets/RosMessages/Tf2.meta

This file was deleted.

8 changes: 0 additions & 8 deletions MobileRobotUITutorialProject/Assets/RosMessages/Tf2/msg.meta

This file was deleted.

This file was deleted.

This file was deleted.

Loading