2025-10-23 18:43:38 +09:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System;
|
2025-10-30 09:31:05 +09:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
using System.Collections.Generic;
|
2025-10-23 18:43:38 +09:00
|
|
|
|
|
|
|
|
|
|
public class RobotController : MonoBehaviour
|
|
|
|
|
|
{
|
2025-10-30 09:31:05 +09:00
|
|
|
|
[Header("IK")]
|
|
|
|
|
|
[SerializeField] private HybridInverseKinematicsNode kinematicsNode;
|
|
|
|
|
|
|
2025-10-23 18:43:38 +09:00
|
|
|
|
[Header("Motor State")]
|
|
|
|
|
|
[SerializeField] private GameObject motorStatusIndicator1;
|
|
|
|
|
|
[SerializeField] private GameObject motorStatusIndicator2;
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] private Material indicatorMaterial1; // <20>⺻<EFBFBD><E2BABB>(ȸ<><C8B8>)
|
|
|
|
|
|
[SerializeField] private Material indicatorMaterial2; // <20>ʷ<EFBFBD>
|
|
|
|
|
|
|
2025-10-30 09:31:05 +09:00
|
|
|
|
public event Action OnPoseUpdateRequest;
|
|
|
|
|
|
|
2025-10-24 11:55:43 +09:00
|
|
|
|
private bool isMotorOn;
|
2025-10-23 18:43:38 +09:00
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (motorStatusIndicator1 != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
motorStatusIndicator1.GetComponent<MeshRenderer>().material = indicatorMaterial1;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (motorStatusIndicator2 != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
motorStatusIndicator2.GetComponent<MeshRenderer>().material = indicatorMaterial1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-30 09:31:05 +09:00
|
|
|
|
private void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
OnPoseUpdateRequest?.Invoke();// TODO. <20>κ<EFBFBD><CEBA><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ƴ<EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD>
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-23 18:43:38 +09:00
|
|
|
|
public void SetMotorState(bool isOn)
|
|
|
|
|
|
{
|
|
|
|
|
|
isMotorOn = isOn;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isMotorOn)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (indicatorMaterial2 != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
motorStatusIndicator1.GetComponent<MeshRenderer>().material = indicatorMaterial2;
|
|
|
|
|
|
motorStatusIndicator2.GetComponent<MeshRenderer>().material = indicatorMaterial2;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (indicatorMaterial1 != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
motorStatusIndicator1.GetComponent<MeshRenderer>().material = indicatorMaterial1;
|
|
|
|
|
|
motorStatusIndicator2.GetComponent<MeshRenderer>().material = indicatorMaterial1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-30 09:31:05 +09:00
|
|
|
|
|
|
|
|
|
|
public void SetRobotPosition(RobotData robotData) // <20><><EFBFBD><EFBFBD> <20>κ<EFBFBD> <20><>ġ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ
|
|
|
|
|
|
{
|
|
|
|
|
|
// x, y, z, rx, ry, rz => endpoint<6E><74>
|
|
|
|
|
|
// j1, ..., j6 => 6<><36> <20><><EFBFBD><EFBFBD> ȸ<><C8B8><EFBFBD><EFBFBD>
|
|
|
|
|
|
kinematicsNode.targetTransform.localPosition = new Vector3(robotData.x, robotData.y, robotData.z);
|
|
|
|
|
|
kinematicsNode.targetTransform.localRotation = new Quaternion(robotData.rx, robotData.ry, robotData.rz, 0);
|
|
|
|
|
|
|
|
|
|
|
|
List<float> list_jAngle = new List<float>();
|
|
|
|
|
|
list_jAngle.Add(robotData.j6);
|
|
|
|
|
|
list_jAngle.Add(robotData.j5);
|
|
|
|
|
|
list_jAngle.Add(robotData.j4);
|
|
|
|
|
|
list_jAngle.Add(robotData.j3);
|
|
|
|
|
|
list_jAngle.Add(robotData.j2);
|
|
|
|
|
|
list_jAngle.Add(robotData.j1);
|
|
|
|
|
|
|
|
|
|
|
|
kinematicsNode.SetCurrentJointAxisRotations(list_jAngle, 'x');
|
|
|
|
|
|
}
|
2025-10-23 18:43:38 +09:00
|
|
|
|
}
|