2025-10-23 18:43:38 +09:00
using Newtonsoft.Json ;
using Newtonsoft.Json.Linq ;
using System ;
2025-10-14 16:38:35 +09:00
using System.Collections.Generic ;
using System.Linq ;
2025-10-23 18:43:38 +09:00
using System.Net.Http ;
using System.Text ;
using System.Threading ;
using System.Threading.Tasks ;
using UdpClientLib ;
using UnityEngine ;
2025-12-03 21:19:07 +09:00
/// <summary>
/// <20> <> <EFBFBD> ø<EFBFBD> <C3B8> <EFBFBD> <EFBFBD> ̼<EFBFBD> <CCBC> <EFBFBD> <20> ٽ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> Ͻ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ϴ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> Ŭ<> <C5AC> <EFBFBD> <EFBFBD>
/// <20> κ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> TCP/UDP <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ϸ<EFBFBD> , <20> κ<EFBFBD> <CEBA> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> ȸ, <20> ̵<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> ,
/// <20> <> <EFBFBD> α <CEB1> (Job) <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> /<2F> <> <EFBFBD> <EFBFBD> /<2F> <> <EFBFBD> <EFBFBD> /<2F> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
/// </summary>
///
2025-11-19 18:38:48 +09:00
public class ProgramModel
2025-10-14 16:38:35 +09:00
{
2025-10-24 14:36:33 +09:00
private string tcpBaseUrl ;
private string udpBaseUrl ;
2025-10-23 18:43:38 +09:00
HttpClient httpClient = new HttpClient ( ) ;
2025-11-06 15:28:16 +09:00
private SingleTcpClient tcpClient ;
private SingleUdpClient udpClient ;
2025-10-24 14:36:33 +09:00
public UdpClientManager manager = new UdpClientManager ( ) ;
2025-10-14 16:38:35 +09:00
2025-12-03 21:19:07 +09:00
// --- <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ij<> <C4B3> ---
private List < JobInfoDTO > allProgramsCache = new List < JobInfoDTO > ( ) ; // <20> κ<EFBFBD> <CEBA> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> α <CEB1> <20> <> <EFBFBD> <EFBFBD> ij<> <C4B3>
public RobotProgram CurrentProgram { get ; private set ; } // <20> <> <EFBFBD> <EFBFBD> <20> ε<EFBFBD> <CEB5> <EFBFBD> <20> <> <EFBFBD> α <CEB1> <20> <> <EFBFBD> <EFBFBD>
2025-10-24 14:36:33 +09:00
private RobotData robotData ;
2025-12-03 21:19:07 +09:00
// --- <20> <> <EFBFBD> <EFBFBD> ȭ <20> <> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> ---
private readonly object lockObject = new object ( ) ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> ȭ<EFBFBD> <C8AD> <20> <> <EFBFBD> <EFBFBD> <20> <> <20> <> ü
private bool hasNewData ; // <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> ÷<EFBFBD> <C3B7> <EFBFBD>
2025-10-24 14:36:33 +09:00
2025-12-03 21:19:07 +09:00
public bool IsMoving ; // <20> <> <EFBFBD> <EFBFBD> <20> κ<EFBFBD> <CEBA> <EFBFBD> <20> ̵<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
public bool isError ; // <20> <> <EFBFBD> <EFBFBD> <20> κ<EFBFBD> <CEBA> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
2025-11-10 19:14:16 +09:00
2025-12-03 21:19:07 +09:00
private Vector3 startMovementPosition ; // <20> ̵<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <20> <> ǥ <20> <> ġ (UDP <20> <> Ŷ <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> )
private int currentToolNum = 0 ; // <20> <> <EFBFBD> <EFBFBD> <20> κ<EFBFBD> <CEBA> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> ȣ
public bool isMoveAllowed = true ; // <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> ÷<EFBFBD> <C3B7> <EFBFBD>
public event Action < bool > OnRobotErrorStateChanged ; // <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <20> ˸ <EFBFBD> <CBB8> <EFBFBD> <20> ֱ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> ̺<EFBFBD> Ʈ
/// <summary>
/// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> : <20> <> <EFBFBD> <EFBFBD> URL<52> <4C> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ϰ<EFBFBD> <20> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> ۾<EFBFBD> <DBBE> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
/// </summary>
2025-11-04 11:36:19 +09:00
public ProgramModel ( string hostip , int tcpPort , int udpPort , RobotController robotController )
2025-10-23 18:43:38 +09:00
{
2025-10-24 14:36:33 +09:00
tcpBaseUrl = $"http://{hostip}:{tcpPort}" ;
udpBaseUrl = $"http://{hostip}:{udpPort}" ;
2025-11-06 15:28:16 +09:00
_ = HandleAsyncWork ( hostip , tcpPort , udpPort ) ;
}
2025-12-03 21:19:07 +09:00
/// <summary>
/// TCP <20> <> UDP Ŭ<> <C5AC> <EFBFBD> ̾<EFBFBD> Ʈ<EFBFBD> <C6AE> <20> ʱ<EFBFBD> ȭ<EFBFBD> ϰ<EFBFBD> <20> <> <EFBFBD> <EFBFBD>
/// </summary>
2025-11-06 15:28:16 +09:00
public async Task HandleAsyncWork ( string hostip , int tcpPort , int udpPort )
{
tcpClient = new SingleTcpClient ( ) ;
await tcpClient . ConnectAsync ( "Tcp-Client" , hostip , tcpPort ) ;
udpClient = manager . AddClient ( "Udp-client" , hostip , udpPort ) ;
manager . PrintStatus ( ) ;
2025-10-23 18:43:38 +09:00
}
2025-12-03 21:19:07 +09:00
/// <summary>
/// <20> <> <EFBFBD> ø<EFBFBD> <C3B8> <EFBFBD> <EFBFBD> ̼<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <20> ʿ<EFBFBD> <CABF> <EFBFBD> <20> ʱ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> ε<EFBFBD>
/// (<28> <> <EFBFBD> α <CEB1> <20> <> <EFBFBD> <EFBFBD> , <20> <> <20> <> ȣ <20> <> )
/// </summary>
2025-10-23 18:43:38 +09:00
public async Task InitializeAsync ( )
{
await LoadAllPrograms ( ) ;
2025-12-02 20:57:36 +09:00
hasNewData = true ;
2025-10-30 09:31:05 +09:00
IsMoving = false ;
2025-11-06 15:28:16 +09:00
isError = false ;
2025-11-06 20:14:27 +09:00
try
{
currentToolNum = await GetRobotToolNum ( ) ;
}
catch ( Exception e )
{
Debug . LogWarning ( $"<22> <> <EFBFBD> <EFBFBD> <20> <> <20> <> ȣ <EFBFBD> <C8A3> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ߽<EFBFBD> <DFBD> ϴ<EFBFBD> : {e.Message}. <20> ⺻<EFBFBD> <E2BABB> (0)<29> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> մϴ<D5B4> ." ) ;
currentToolNum = 1 ;
}
2025-10-23 18:43:38 +09:00
return ;
}
2025-12-03 21:19:07 +09:00
/// <summary>
/// UI(ProgramPresenter)<29> <> <EFBFBD> <EFBFBD> <20> ֽ<EFBFBD> <20> κ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> Ͱ<EFBFBD> <20> ִ<EFBFBD> <D6B4> <EFBFBD> Ȯ<> <C8AE> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD>
/// </summary>
2025-10-24 14:36:33 +09:00
public bool IsNewDataAvailable ( )
{
2025-12-02 20:57:36 +09:00
return robotData ! = null ;
2025-10-24 14:36:33 +09:00
}
2025-12-03 21:19:07 +09:00
/// <summary>
/// <20> <> <EFBFBD> <EFBFBD> <D7B6> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> 忡<EFBFBD> <E5BFA1> <20> <> <EFBFBD> ŵ<EFBFBD> <20> ֽ<EFBFBD> <20> κ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ϰ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
/// </summary>
2025-10-24 14:36:33 +09:00
public RobotData GetLatestRobotData ( )
{
lock ( lockObject )
{
2025-12-03 21:19:07 +09:00
//hasNewData = false; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> о <EFBFBD> <D0BE> <EFBFBD> <EFBFBD> Ƿ<EFBFBD> <20> ÷<EFBFBD> <C3B7> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> (<28> <> <EFBFBD> <EFBFBD> ȭ<EFBFBD> <C8AD> <20> <> <EFBFBD> <EFBFBD> <20> ּ<EFBFBD> ó<> <C3B3> <EFBFBD> <EFBFBD> : <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <20> ְ<EFBFBD> <20> <> )
2025-10-30 09:31:05 +09:00
return robotData ;
2025-10-24 14:36:33 +09:00
}
}
2025-10-30 09:31:05 +09:00
/// <summary>
/// <20> <> <EFBFBD> α <CEB1> <20> <> <EFBFBD> <EFBFBD> /<2F> ҷ<EFBFBD> <D2B7> <EFBFBD> <EFBFBD> <EFBFBD> <20> ý<EFBFBD> <C3BD> <EFBFBD>
/// </summary>
2025-10-23 18:43:38 +09:00
public async Task < bool > CheckProgramExists ( string jobProgramName )
2025-10-14 16:38:35 +09:00
{
2025-10-24 14:36:33 +09:00
string requestUri = $"{tcpBaseUrl}/file_manager/file_exist?pathname=project/jobs/{jobProgramName}" ;
2025-10-23 18:43:38 +09:00
HttpResponseMessage result = await httpClient . GetAsync ( requestUri ) ;
string jsonResponse = await result . Content . ReadAsStringAsync ( ) ;
return jsonResponse . Equals ( "true" ) ;
2025-10-14 16:38:35 +09:00
}
2025-10-23 18:43:38 +09:00
public async Task < bool > CreateNewProgram ( string userInputId )
2025-10-14 16:38:35 +09:00
{
2025-11-04 11:36:19 +09:00
string robotModelName ;
2025-10-14 16:38:35 +09:00
if ( string . IsNullOrEmpty ( userInputId ) ) return false ;
string newProgramId = $"{userInputId}.job" ;
2025-10-23 18:43:38 +09:00
if ( await CheckProgramExists ( newProgramId ) )
2025-10-14 16:38:35 +09:00
{
2025-10-23 18:43:38 +09:00
Debug . LogError ( "<22> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> ̹<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> մϴ<D5B4> ." ) ;
2025-10-14 16:38:35 +09:00
return false ;
}
2025-10-23 18:43:38 +09:00
else
Debug . Log ( $"{newProgramId} <20> <> <EFBFBD> <EFBFBD> " ) ;
2025-10-14 16:38:35 +09:00
2025-10-23 18:43:38 +09:00
try
{
robotModelName = await GetRobotModelNameAsync ( ) ;
}
catch ( Exception e )
{
Debug . LogError ( $"<22> κ<EFBFBD> <20> <EFBFBD> <F0B5A8B8> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ߽<EFBFBD> <DFBD> ϴ<EFBFBD> : {e.Message}" ) ;
return false ;
}
2025-10-14 16:38:35 +09:00
2025-10-23 18:43:38 +09:00
NewJobRequestDTO newJob = new NewJobRequestDTO
{
fname = newProgramId ,
model_name = robotModelName ,
n_add_ax = 0
} ;
string jsonString = JsonConvert . SerializeObject ( newJob ) ;
HttpContent jsonPayload = new StringContent ( jsonString , Encoding . UTF8 , "application/json" ) ;
2025-11-06 15:28:16 +09:00
2025-10-24 14:36:33 +09:00
string requestUri = $"{tcpBaseUrl}/project/jobs/create_job" ;
2025-10-23 18:43:38 +09:00
try
{
HttpResponseMessage result = await httpClient . PostAsync ( requestUri , jsonPayload ) ;
if ( result . IsSuccessStatusCode )
{
2025-11-10 19:14:16 +09:00
await LoadProgram ( newProgramId ) ;
object payload = CmdLinePayload ( "end" , 0 ) ;
jsonString = JsonConvert . SerializeObject ( payload ) ;
jsonPayload = new StringContent ( jsonString , Encoding . UTF8 , "application/json" ) ;
HttpResponseMessage jsonResponse = await httpClient . PostAsync (
$"{tcpBaseUrl}/project/jobs/{CurrentProgram.ProgramId}/ins_cmd_line" , jsonPayload ) ;
if ( jsonResponse . IsSuccessStatusCode )
return true ;
else
return false ;
2025-10-23 18:43:38 +09:00
}
else
return false ;
}
catch ( Exception e )
{
Debug . LogError ( $"<22> <> <EFBFBD> α <CEB1> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> : {userInputId}, {e.Message}" ) ;
return false ;
}
2025-10-14 16:38:35 +09:00
}
2025-10-23 18:43:38 +09:00
private async Task < string > GetRobotModelNameAsync ( )
2025-10-14 16:38:35 +09:00
{
2025-10-24 14:36:33 +09:00
string requestUri = $"{tcpBaseUrl}/project/rgen" ;
2025-10-23 18:43:38 +09:00
HttpResponseMessage result = await httpClient . GetAsync ( requestUri ) ;
string jsonResponse = await result . Content . ReadAsStringAsync ( ) ;
JObject data = JObject . Parse ( jsonResponse ) ;
string modelName = ( string ) data . SelectToken ( "robot_model" ) ;
if ( string . IsNullOrEmpty ( modelName ) )
2025-10-14 16:38:35 +09:00
{
2025-10-23 18:43:38 +09:00
throw new Exception ( "<22> κ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> API <20> <> <EFBFBD> 信<EFBFBD> <E4BFA1> <20> <EFBFBD> <F0B5A8B8> <EFBFBD> ã<> <C3A3> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ϴ<EFBFBD> ." ) ;
2025-10-14 16:38:35 +09:00
}
2025-10-23 18:43:38 +09:00
return modelName ;
2025-10-14 16:38:35 +09:00
}
2025-10-24 11:55:43 +09:00
public async Task < bool > GetRobotMotorStateAsync ( )
{
2025-10-24 14:36:33 +09:00
string requestUri = $"{tcpBaseUrl}/project/rgen" ;
2025-10-24 11:55:43 +09:00
HttpResponseMessage result = await httpClient . GetAsync ( requestUri ) ;
string jsonResponse = await result . Content . ReadAsStringAsync ( ) ;
JObject data = JObject . Parse ( jsonResponse ) ;
int motorState = ( int ) data . SelectToken ( "enable_state" ) ;
2025-11-04 11:36:19 +09:00
if ( motorState = = 0 | | motorState = = 256 )
2025-10-24 11:55:43 +09:00
return true ;
else if ( motorState = = 1 )
return false ;
else
{
throw new Exception ( "<22> κ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> API <20> <> <EFBFBD> 信<EFBFBD> <E4BFA1> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> ¸ <EFBFBD> ã<> <C3A3> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ϴ<EFBFBD> ." ) ;
}
}
2025-11-06 15:28:16 +09:00
public async Task < int > GetRobotToolNum ( )
{
string requestUri = $"{tcpBaseUrl}/project/rgen" ;
HttpResponseMessage result = await httpClient . GetAsync ( requestUri ) ;
string jsonResponse = await result . Content . ReadAsStringAsync ( ) ;
JObject data = JObject . Parse ( jsonResponse ) ;
int toolNum = ( int ) data . SelectToken ( "tool_no" ) ;
return toolNum ;
}
2025-12-03 21:19:07 +09:00
/// <summary>
/// [<5B> <> <EFBFBD> <EFBFBD> <D7B6> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> 1] TCP<43> <50> <20> <> <EFBFBD> <EFBFBD> <20> κ<EFBFBD> <CEBA> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> ǥ<EFBFBD> <C7A5> <20> ֱ<EFBFBD> <D6B1> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> ȸ
/// </summary>
2025-10-30 09:31:05 +09:00
public async Task GetTCPAsync ( CancellationToken token )
2025-10-24 14:36:33 +09:00
{
2025-11-04 11:36:19 +09:00
while ( ! token . IsCancellationRequested )
2025-10-24 14:36:33 +09:00
{
try
{
string requestUri = $"{tcpBaseUrl}/project/robot/po_cur" ;
HttpResponseMessage result = await httpClient . GetAsync ( requestUri ) ;
string jsonResponse = await result . Content . ReadAsStringAsync ( ) ;
var tempRobotData = JsonConvert . DeserializeObject < RobotData > ( jsonResponse , new JsonSerializerSettings { CheckAdditionalContent = false } ) ;
lock ( lockObject )
{
robotData = tempRobotData ;
hasNewData = true ;
}
2025-12-02 20:57:36 +09:00
await Task . Delay ( 10 , token ) ;
2025-10-24 14:36:33 +09:00
}
2025-11-04 11:36:19 +09:00
catch ( Exception e )
2025-10-24 14:36:33 +09:00
{
Debug . Log ( e ) ;
await Task . Delay ( 1000 ) ; // <20> <> <EFBFBD> <EFBFBD> <20> <> <20> <> <20> <> <20> <> <EFBFBD> <EFBFBD>
}
}
}
2025-12-03 21:19:07 +09:00
/// <summary>
/// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ư<> <C6AF> <20> <> <EFBFBD> α <CEB1> <D7B7> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> ε<EFBFBD> <CEB5> Ͽ<EFBFBD> CurrentProgram<61> <6D> <20> <> <EFBFBD> <EFBFBD>
/// </summary>
2025-10-23 18:43:38 +09:00
public async Task < bool > LoadProgram ( string programId )
2025-10-14 16:38:35 +09:00
{
2025-10-24 14:36:33 +09:00
string requestUri = $"{tcpBaseUrl}/file_manager/files?pathname=project/jobs/{programId}&common" ;
2025-10-14 16:38:35 +09:00
2025-10-23 18:43:38 +09:00
HttpResponseMessage result = await httpClient . GetAsync ( requestUri ) ;
string rawTextContent = await result . Content . ReadAsStringAsync ( ) ;
2025-10-14 16:38:35 +09:00
2025-10-23 18:43:38 +09:00
if ( string . IsNullOrEmpty ( rawTextContent ) )
{
return false ;
}
2025-10-14 16:38:35 +09:00
2025-10-23 18:43:38 +09:00
CurrentProgram = new RobotProgram ( programId , rawTextContent ) ;
2025-10-24 14:36:33 +09:00
2025-10-23 18:43:38 +09:00
return true ;
2025-10-14 16:38:35 +09:00
}
2025-12-03 21:19:07 +09:00
/// <summary>
/// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> Job <20> <> <EFBFBD> α <CEB1> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ij<> <C4B3>
/// </summary>
2025-10-23 18:43:38 +09:00
private async Task LoadAllPrograms ( )
2025-10-14 16:38:35 +09:00
{
2025-10-23 18:43:38 +09:00
allProgramsCache . Clear ( ) ;
string jsonResponse = null ;
string wrappedJson = null ;
try
2025-10-14 16:38:35 +09:00
{
2025-10-24 14:36:33 +09:00
HttpResponseMessage result = await httpClient . GetAsync ( $"{tcpBaseUrl}/project/jobs_info" ) ;
2025-10-23 18:43:38 +09:00
jsonResponse = await result . Content . ReadAsStringAsync ( ) ;
wrappedJson = $"{{\" jobs \ ":{jsonResponse}}}" ;
JobListWrapper wrapper = JsonUtility . FromJson < JobListWrapper > ( wrappedJson ) ;
if ( wrapper ! = null & & wrapper . jobs ! = null )
{
allProgramsCache = wrapper . jobs ;
}
else
{
Debug . LogError ( "<22> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> job <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> Ľ<EFBFBD> <C4BD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ϴ<EFBFBD> : " + jsonResponse ) ;
}
}
catch ( ArgumentException e )
{
Debug . LogError ( $"JSON <20> Ľ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> : {e.Message}" ) ;
}
catch ( Exception e )
{
Debug . LogError ( $"LoadAllPrograms <20> <> <20> <> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> : {e.Message}" ) ;
2025-10-14 16:38:35 +09:00
}
}
2025-12-01 19:18:22 +09:00
public async Task < List < string > > GetAllProgramIds ( )
2025-10-14 16:38:35 +09:00
{
2025-12-01 19:18:22 +09:00
await LoadAllPrograms ( ) ;
2025-10-23 18:43:38 +09:00
List < string > ids = new List < string > ( ) ;
foreach ( var jobInfo in allProgramsCache )
2025-10-14 16:38:35 +09:00
{
2025-10-23 18:43:38 +09:00
ids . Add ( jobInfo . fname ) ;
2025-10-14 16:38:35 +09:00
}
2025-10-23 18:43:38 +09:00
return ids ;
2025-10-14 16:38:35 +09:00
}
2025-10-24 14:36:33 +09:00
2025-10-30 09:31:05 +09:00
/// <summary>
/// <20> κ<EFBFBD> <20> <> ġ <20> <> <EFBFBD> <EFBFBD> <20> ý<EFBFBD> <C3BD> <EFBFBD>
/// </summary>
2025-11-10 19:14:16 +09:00
// <20> <> <EFBFBD> α <CEB1> <D7B7> <EFBFBD> <20> <> <EFBFBD> ɹ<EFBFBD> <20> ߰<EFBFBD>
public object CmdLinePayload ( string cmd_line , int sno_ref )
{
object payload ;
if ( cmd_line = = "end" )
{
payload = new
{
cmd_line = cmd_line ,
sno_ref = sno_ref
} ;
}
else
{
payload = new
{
adjust_branch = true ,
cmd_line = cmd_line ,
fno_ref = - 1 ,
mechinfo = - 1 ,
move_cursor = 1 ,
ofs = 0 ,
save_file = true ,
set_cur_pose = 1 ,
sno_ref = sno_ref
} ;
}
return payload ;
}
2025-12-03 21:19:07 +09:00
/// <summary>
/// <20> <> <EFBFBD> <EFBFBD> <20> κ<EFBFBD> <CEBA> <EFBFBD> <20> <> ġ<EFBFBD> <C4A1> <20> <> <EFBFBD> α <CEB1> <D7B7> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ϰų<CFB0> , <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
/// index<65> <78> -1<> ̸<EFBFBD> <20> ߰<EFBFBD> , 0 <20> ̻<EFBFBD> <CCBB> ̸<EFBFBD> <20> ش<EFBFBD> <20> ε<EFBFBD> <CEB5> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
/// </summary>
2025-10-30 09:31:05 +09:00
public async Task < bool > SavePointToProgramAsync ( RobotData pointData , int index = - 1 )
{
if ( CurrentProgram = = null )
{
Debug . LogError ( "<22> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> α <CEB1> <D7B7> <EFBFBD> <20> ε<EFBFBD> <CEB5> <EFBFBD> <EFBFBD> <EFBFBD> <20> ʾ ҽ <CABE> <D2BD> ϴ<EFBFBD> ." ) ;
return false ;
}
2025-11-06 20:14:27 +09:00
string jsonPayload ;
string requestUri ;
HttpContent content ;
object payload ;
2025-10-30 09:31:05 +09:00
try
{
2025-11-06 20:14:27 +09:00
if ( index = = - 1 )
{
// sno_ref = <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> ȣ , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 0
int sno_ref = ( CurrentProgram . Steps . Count > 0 ) ? CurrentProgram . Steps . Last ( ) . StepNumber : 0 ;
2025-11-10 19:14:16 +09:00
payload = CmdLinePayload ( $"move P,spd=50%,accu=3,tool={currentToolNum}" , sno_ref ) ;
2025-11-06 20:14:27 +09:00
requestUri = $"{tcpBaseUrl}/project/jobs/{CurrentProgram.ProgramId}/ins_cmd_line" ;
}
else
{
// sno = <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> ȣ
int sno = CurrentProgram . Steps [ index ] . StepNumber ;
payload = new
{
mechinfo = - 1 ,
save_file = true ,
sno = sno
} ;
requestUri = $"{tcpBaseUrl}/project/jobs/{CurrentProgram.ProgramId}/pose_modify" ;
}
jsonPayload = JsonConvert . SerializeObject ( payload ) ;
content = new StringContent ( jsonPayload , Encoding . UTF8 , "application/json" ) ;
2025-10-30 09:31:05 +09:00
HttpResponseMessage result = await httpClient . PostAsync ( requestUri , content ) ;
2025-11-06 20:14:27 +09:00
2025-10-30 09:31:05 +09:00
if ( result . IsSuccessStatusCode )
{
2025-11-06 20:14:27 +09:00
// <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ϸ<EFBFBD> , <20> <> <EFBFBD> <EFBFBD> ij<> ÿ<EFBFBD> <C3BF> <EFBFBD> <20> ݿ<EFBFBD>
2025-10-30 09:31:05 +09:00
if ( index = = - 1 )
2025-11-06 20:14:27 +09:00
CurrentProgram . AddStep ( pointData , currentToolNum ) ; // <20> <> <EFBFBD> <EFBFBD> ij<> ÿ<EFBFBD> <20> ߰<EFBFBD>
2025-10-30 09:31:05 +09:00
else
2025-11-06 20:14:27 +09:00
CurrentProgram . UpdateStep ( index , pointData ) ; // <20> <> <EFBFBD> <EFBFBD> ij<> <C4B3> <20> <> <EFBFBD> <EFBFBD>
2025-10-30 09:31:05 +09:00
return true ;
}
2025-11-06 20:14:27 +09:00
Debug . LogError ( $"SavePointToProgramAsync <20> <> <EFBFBD> <EFBFBD> : {await result.Content.ReadAsStringAsync()}" ) ;
2025-10-30 09:31:05 +09:00
return false ;
}
catch ( Exception e )
{
Debug . LogError ( $"<22> <> <EFBFBD> <EFBFBD> Ʈ <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> : {e.Message}" ) ;
return false ;
}
}
2025-12-03 21:19:07 +09:00
/// <summary>
/// <20> <> <EFBFBD> α <CEB1> <D7B7> <EFBFBD> <EFBFBD> <EFBFBD> Ư<> <C6AF> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
/// </summary>
2025-10-30 09:31:05 +09:00
public async Task < bool > DeletePointFromProgramAsync ( int index )
{
2025-11-06 20:14:27 +09:00
if ( CurrentProgram = = null | | index < 0 | | index > = CurrentProgram . Steps . Count )
{
Debug . LogError ( $"DeletePointFromProgramAsync: <20> ߸<EFBFBD> <DFB8> <EFBFBD> <20> ε<EFBFBD> <CEB5> <EFBFBD> {index}" ) ;
return false ;
}
// sno_ref = <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> ȣ (0-based index<65> <78> <20> ƴ<EFBFBD> )
int sno_ref = CurrentProgram . Steps [ index ] . StepNumber ;
2025-10-30 09:31:05 +09:00
2025-11-06 20:14:27 +09:00
var payload = new
{
adjust_branch = true ,
fno_ref = 0 ,
ofs = 0 ,
save_file = true ,
sno_ref = sno_ref
} ;
2025-10-30 09:31:05 +09:00
string jsonPayload = JsonConvert . SerializeObject ( payload ) ;
HttpContent content = new StringContent ( jsonPayload , Encoding . UTF8 , "application/json" ) ;
string requestUri = $"{tcpBaseUrl}/project/jobs/{CurrentProgram.ProgramId}/del_cmd_line" ;
try
{
HttpResponseMessage result = await httpClient . PostAsync ( requestUri , content ) ;
if ( result . IsSuccessStatusCode )
{
2025-11-06 20:14:27 +09:00
// <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> , <20> <> <EFBFBD> <EFBFBD> ij<> ÿ<EFBFBD> <C3BF> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2025-10-30 09:31:05 +09:00
CurrentProgram . DeleteStep ( index ) ;
return true ;
}
2025-11-06 20:14:27 +09:00
Debug . LogError ( $"DeletePointFromProgramAsync <20> <> <EFBFBD> <EFBFBD> : {await result.Content.ReadAsStringAsync()}" ) ;
2025-10-30 09:31:05 +09:00
return false ;
}
catch ( Exception e )
{
Debug . LogError ( $"<22> <> <EFBFBD> <EFBFBD> Ʈ <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> : {e.Message}" ) ;
return false ;
}
}
2025-11-04 11:36:19 +09:00
// Ÿ<> <C5B8> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> ̵<EFBFBD>
2025-11-06 15:28:16 +09:00
public async Task < bool > MoveToPoseTcpAsync ( Vector3 position )
2025-10-30 09:31:05 +09:00
{
2025-11-11 13:21:20 +09:00
//await clientLock.WaitAsync();
2025-11-27 19:05:25 +09:00
if ( ! isMoveAllowed )
{
Debug . Log ( "TCP <20> <> <EFBFBD> <EFBFBD> <20> ߴ <EFBFBD> " ) ;
return false ;
}
2025-11-04 11:36:19 +09:00
try
2025-10-30 09:31:05 +09:00
{
2025-11-06 15:28:16 +09:00
startMovementPosition . x = Convert . ToSingle ( Math . Round ( - 1 * position . x * 1000 , 2 ) ) ;
startMovementPosition . y = Convert . ToSingle ( Math . Round ( - 1 * position . z * 1000 , 2 ) ) ;
startMovementPosition . z = Convert . ToSingle ( Math . Round ( position . y * 1000 , 2 ) ) ;
2025-11-04 11:36:19 +09:00
2025-12-03 18:51:06 +09:00
float currentRx = - 180f ;
float currentRy = 0f ;
float currentRz = 180f ;
2025-12-03 11:20:10 +09:00
2025-11-19 18:38:48 +09:00
string jsonResponse = await tcpClient . SendPostRequestAsync ( "/project/robot/move_to_pose_manual" ,
2025-12-03 11:20:10 +09:00
$"{{\" pose_tg \ ":{{\"crd\":\"robot\",\"_type\":\"Pose\",\"mechinfo\":1,\"x\":{startMovementPosition.x},\"y\":{startMovementPosition.y},\"z\":{startMovementPosition.z}, \"rx\":{currentRx}, \"ry\":{currentRy}, \"rz\":{currentRz}}}}}" ) ;
2025-11-04 11:36:19 +09:00
2025-11-06 15:28:16 +09:00
if ( jsonResponse . Contains ( "200" ) )
2025-10-30 09:31:05 +09:00
{
2025-11-04 11:36:19 +09:00
Debug . Log ( "TCP POST (Move) <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> " ) ;
2025-11-06 15:28:16 +09:00
IsMoving = true ;
2025-11-04 11:36:19 +09:00
return true ;
}
else
{
2025-11-06 15:28:16 +09:00
Debug . LogError ( $"TCP POST (Move) <20> <> <EFBFBD> <EFBFBD> " ) ;
2025-11-04 11:36:19 +09:00
return false ;
2025-10-30 09:31:05 +09:00
}
2025-11-04 11:36:19 +09:00
}
2025-11-19 18:38:48 +09:00
catch ( TaskCanceledException )
{
Debug . Log ( "TCP <20> <> û<EFBFBD> <C3BB> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> ." ) ;
return false ;
}
2025-11-04 11:36:19 +09:00
catch ( Exception e )
{
2025-11-19 18:38:48 +09:00
Debug . Log ( $"MoveToPoseTcpAsync <20> <> <EFBFBD> <EFBFBD> : {e.Message}" ) ;
2025-11-04 11:36:19 +09:00
return false ;
2025-10-30 09:31:05 +09:00
}
2025-11-10 19:14:16 +09:00
finally
{
2025-11-11 13:21:20 +09:00
//clientLock.Release();
2025-11-10 19:14:16 +09:00
}
2025-10-30 09:31:05 +09:00
}
2025-11-04 11:36:19 +09:00
// TCP POST <20> ̵<EFBFBD> <20> <> <EFBFBD> <EFBFBD> üũ
public async Task StartMovementCheckLoopAsync ( CancellationToken token )
2025-10-30 09:31:05 +09:00
{
2025-11-27 19:05:25 +09:00
if ( ! isMoveAllowed )
{
Debug . Log ( "udp<64> <70> Ŷ <20> <> <EFBFBD> <EFBFBD> <20> ߴ <EFBFBD> " ) ;
return ;
}
2025-11-25 15:15:54 +09:00
while ( ! token . IsCancellationRequested )
2025-10-30 09:31:05 +09:00
{
2025-11-25 15:15:54 +09:00
try
2025-10-30 09:31:05 +09:00
{
2025-11-06 15:28:16 +09:00
if ( IsMoving )
2025-10-30 09:31:05 +09:00
{
2025-11-06 15:28:16 +09:00
await udpClient . SendFilledBytesAsync ( new Dictionary < int , byte > { { 2 , 0x20 } } ) ;
2025-11-27 19:05:25 +09:00
await Task . Delay ( 10 ) ;
2025-11-04 11:36:19 +09:00
RobotData currentPose = null ;
2025-11-06 15:28:16 +09:00
lock ( lockObject ) { currentPose = this . robotData ; }
2025-11-04 11:36:19 +09:00
2025-11-28 12:36:04 +09:00
Vector3 targetPos = startMovementPosition ;
Vector3 currentPos = new Vector3 ( Convert . ToSingle ( currentPose . x ) , Convert . ToSingle ( currentPose . y ) , Convert . ToSingle ( currentPose . z ) ) ;
if ( Vector3 . Distance ( targetPos , currentPos ) < 0.1f )
2025-11-04 11:36:19 +09:00
{
2025-11-28 12:36:04 +09:00
IsMoving = false ;
2025-11-04 11:36:19 +09:00
}
}
2025-11-06 15:28:16 +09:00
else
2025-11-04 11:36:19 +09:00
{
2025-12-03 18:51:06 +09:00
await Task . Delay ( 10 , token ) ;
2025-10-30 09:31:05 +09:00
}
}
2025-11-25 15:15:54 +09:00
catch ( TaskCanceledException )
{
Debug . Log ( "MovementCheckLoopAsync Canceled." ) ;
}
catch ( Exception e )
{
Debug . LogError ( $"MovementCheckLoopAsync Error: {e.Message}\n{e.StackTrace}" ) ;
}
2025-10-30 09:31:05 +09:00
}
}
2025-11-19 18:38:48 +09:00
//Ÿ<> <C5B8> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> κ<EFBFBD> <20> ̵<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> ʰ<EFBFBD> <CAB0> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> ó<> <C3B3>
public async Task GetMovementState ( CancellationToken token )
{
while ( ! token . IsCancellationRequested )
{
try
{
var jsonResponse = await tcpClient . SendGetRequestAsync ( "/project/rgen" ) ;
var pasrsingJsonResponse = HttpResponseParser . ExtractJsonFromHttpResponse ( jsonResponse ) ;
var tempRobotData = JsonConvert . DeserializeObject < RobotStateData > ( pasrsingJsonResponse , new JsonSerializerSettings { CheckAdditionalContent = false } ) ;
jsonResponse = await tcpClient . SendGetRequestAsync ( $"/logManager/search?cat_p=E&id_min={Convert.ToInt32(tempRobotData.eid_last_err) - 3}&id_max={tempRobotData.eid_last_err}" ) ;
pasrsingJsonResponse = HttpResponseParser . ExtractJsonFromHttpResponse ( jsonResponse ) ;
tempRobotData = JsonConvert . DeserializeObject < RobotStateData > ( pasrsingJsonResponse , new JsonSerializerSettings { CheckAdditionalContent = false } ) ;
bool newErrorState = tempRobotData ! = null & & tempRobotData . code ! = null & & ( tempRobotData . code . Contains ( "228" ) | | tempRobotData . code . Contains ( "6037" ) ) ;
if ( this . isError ! = newErrorState )
{
this . isError = newErrorState ;
OnRobotErrorStateChanged ? . Invoke ( this . isError ) ;
2025-11-25 15:15:54 +09:00
//Debug.Log($"[<5B> ̵<EFBFBD> <CCB5> <EFBFBD> <EFBFBD> <EFBFBD> ] <20> ̵<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> : {newErrorState}");
2025-11-19 18:38:48 +09:00
}
2025-11-27 19:05:25 +09:00
await Task . Delay ( 10 ) ;
2025-11-19 18:38:48 +09:00
}
catch ( System . Exception )
{
}
}
}
2025-11-25 18:33:31 +09:00
public void SetLocalErrorState ( bool state )
2025-11-19 18:38:48 +09:00
{
2025-11-25 18:33:31 +09:00
this . isError = state ;
OnRobotErrorStateChanged ? . Invoke ( this . isError ) ;
2025-11-19 18:38:48 +09:00
}
// <20> ̵<EFBFBD> <20> <> <20> Ǵ<EFBFBD>
2025-11-06 15:28:16 +09:00
public async Task < string > GetMovingState ( )
2025-10-24 14:36:33 +09:00
{
2025-11-07 16:26:43 +09:00
string jsonResponse = await tcpClient . SendGetRequestAsync ( "/project/robot/moving_to_pose_manual" ) ;
string parsingJsonResponse = HttpResponseParser . ExtractJsonFromHttpResponse ( jsonResponse ) ;
return parsingJsonResponse ;
2025-10-24 14:36:33 +09:00
}
2025-11-13 21:23:28 +09:00
/// <summary>
/// <20> <> <EFBFBD> α <CEB1> <20> <> <EFBFBD> <EFBFBD> <20> г <EFBFBD>
/// </summary>
public async Task < bool > ResetProgram ( )
{
int jobProgramLines = CurrentProgram . Steps . Count + 1 ;
var payload = new
{
idx_st = 1 ,
n_line = jobProgramLines ,
save_file = true
} ;
string jsonPayload = JsonConvert . SerializeObject ( payload ) ;
HttpContent content = new StringContent ( jsonPayload , Encoding . UTF8 , "application/json" ) ;
string requestUri = $"{tcpBaseUrl}/project/jobs/{CurrentProgram.ProgramId}/del_cmd_lines" ;
try
{
HttpResponseMessage result = await httpClient . PostAsync ( requestUri , content ) ;
if ( result . IsSuccessStatusCode )
{
// <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> , <20> <> <EFBFBD> <EFBFBD> ij<> ÿ<EFBFBD> <C3BF> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
CurrentProgram . ResetSteps ( ) ;
// <20> ٽ<EFBFBD> end<6E> <64> <20> ߰<EFBFBD>
object endPayload = CmdLinePayload ( "end" , 0 ) ;
string endJsonString = JsonConvert . SerializeObject ( endPayload ) ;
HttpContent endContent = new StringContent ( endJsonString , Encoding . UTF8 , "application/json" ) ;
string endRequestUri = $"{tcpBaseUrl}/project/jobs/{CurrentProgram.ProgramId}/ins_cmd_line" ;
HttpResponseMessage endResponse = await httpClient . PostAsync ( endRequestUri , endContent ) ;
if ( endResponse . IsSuccessStatusCode )
{
return true ;
}
else
{
Debug . LogError ( $"ResetProgramAsync: 'end' <20> <> <EFBFBD> ɾ<EFBFBD> <20> ߰<EFBFBD> <20> <> <EFBFBD> <EFBFBD> : {await endResponse.Content.ReadAsStringAsync()}" ) ;
return false ;
}
}
Debug . LogError ( $"ResetProgramAsync <20> <> <EFBFBD> <EFBFBD> : {await result.Content.ReadAsStringAsync()}" ) ;
return false ;
}
catch ( Exception e )
{
Debug . LogError ( $"<22> <> <EFBFBD> α <CEB1> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> : {e.Message}" ) ;
return false ;
}
}
public async Task startProgram ( )
{
string requestUri = $"{tcpBaseUrl}/project/robot/start" ;
HttpContent content = new StringContent ( "{}" , Encoding . UTF8 , "application/json" ) ;
try
{
HttpResponseMessage result = await httpClient . PostAsync ( requestUri , content ) ;
if ( result . IsSuccessStatusCode )
{
Debug . Log ( "<22> <> <EFBFBD> α <CEB1> <20> <> <EFBFBD> <EFBFBD> " ) ;
}
}
catch ( Exception e )
{
Debug . LogError ( $"<22> <> <EFBFBD> α <CEB1> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> : {e.Message}" ) ;
}
}
public async Task stopProgram ( )
{
string requestUri = $"{tcpBaseUrl}/project/robot/stop" ;
HttpContent content = new StringContent ( "{}" , Encoding . UTF8 , "application/json" ) ;
try
{
HttpResponseMessage result = await httpClient . PostAsync ( requestUri , content ) ;
if ( result . IsSuccessStatusCode )
{
Debug . Log ( "<22> <> <EFBFBD> α <CEB1> <20> <> <EFBFBD> <EFBFBD> " ) ;
}
}
catch ( Exception e )
{
Debug . LogError ( $"<22> <> <EFBFBD> α <CEB1> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> : {e.Message}" ) ;
}
}
public async Task setProgramSpeed ( int spdRate )
{
var payload = new
{
type = 1 ,
val = spdRate
} ;
string jsonPayload = JsonConvert . SerializeObject ( payload ) ;
HttpContent content = new StringContent ( jsonPayload , Encoding . UTF8 , "application/json" ) ;
string requestUri = $"{tcpBaseUrl}/project/control/op_cnd/set_playback_spd_rate" ;
try
{
HttpResponseMessage result = await httpClient . PostAsync ( requestUri , content ) ;
if ( result . IsSuccessStatusCode )
{
Debug . Log ( "<22> <> <EFBFBD> <EFBFBD> <20> ӵ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> " ) ;
}
}
catch ( Exception e )
{
Debug . LogError ( $"<22> <> <EFBFBD> <EFBFBD> <20> ӵ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> : {e.Message}" ) ;
}
}
2025-10-14 16:38:35 +09:00
}