Skip to content
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

connecting to two different IP (2 UR Robots) #4

Open
CheAbdullah opened this issue Oct 27, 2022 · 4 comments
Open

connecting to two different IP (2 UR Robots) #4

CheAbdullah opened this issue Oct 27, 2022 · 4 comments

Comments

@CheAbdullah
Copy link

Hi Roman Parak,

I am tring to connect to two different UR16 - on two different IPs
if I use the same ur_data_processing(https://github.com/rparak/Unity3D_Robotics_UR/blob/main/Universal_Robots_Unity_App/Assets/Scripts/UR3/ur_data_processing.cs) then, the unity arm A will follow the actual Robot Arm A, but Unity Arm B will do the same as well, before it goes to the actual Robot Arm B's pose. And, this repeats over time, sometimes A copy B, and sometime B copy A.

How do I make sure that unity amr A copy actual Robot Arm A only, and the same for Arm B?

Thanks,
Kind regards,
Zul

@CheAbdullah
Copy link
Author

IEnumerator set_FlipflopSwitch2(int which)
{
yield return new WaitForSeconds(delay);// (0.05f);
if (which == 1)
{
LeftRobot.GetComponent<ur_data_processing>().enabled = true;
RightRobot.GetComponent<ur_data_processing>().enabled = false;

        LeftRobot.GetComponent<ur_data_processing>().main_ur_state = 1;
        LeftRobot.GetComponent<ur_data_processing>().connectionStatus = true;

        RightRobot.GetComponent<ur_data_processing>().main_ur_state = 0; // go to disconnect state
        RightRobot.GetComponent<ur_data_processing>().connectionStatus = false;
    }

@CheAbdullah
Copy link
Author

at the moment, I am just switching on and off the state for Arm A and Arm B. and, this results with A copying B, and A goes to the right pose for A, and then copy B again, afterwards.

@rparak
Copy link
Owner

rparak commented Oct 30, 2022

Hi Zul,

sorry for the late response, but I'm really busy.

The problem is that the program "ur_data_processing.cs" contains global variables for control, data collection and also for user interface control.

My advice is that you need to create another global variable to control and collect data from robot 2. It is also necessary to change the programs for collecting data from the robot joints "ur3_link{1 .. 6}.cs". Because inside the programs there is a global variable from "ur_data_processing.cs".

I'm working on a new update so I'll probably add a feature to connect multiple robots at the same time.

Thank you for your feedback. I hope everything is clear, if not, please email me again.

Best regards,
Roman Parak

Repository owner deleted a comment from rajmeetsng Oct 12, 2023
@curbybair
Copy link

Hello Roman Parak,

I am having a similar issue when connecting two robots using the ur_data_processing and main_ui_control. I am connecting to the dashboard server to play a program on the robots control board. When I connect to one of the robots using different global variables for the two robots, I receive no data from the joint positions (only receiving the first collected data then a WSACancelBlockingCall)
System.Net.Sockets.Socket.Receive (System.Byte buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags) (at :0) System.Net.Sockets.NetworkStream.Read (System.Byte buffer, System.Int32 offset, System.Int32 size) (at :0) Rethrow as IOException: Unable to read data from the transport connection: A blocking operation was interrupted by a call to WSACancelBlockingCall.
Would this be because of connecting to the dashboard server? Or would it involve my connection to the IP Addresses? I will attach my connection methods, if you need any more information please let me know. Thank you.

`void ConnectToIP(string ipAddress)
{
ur_data_processing.UR_Stream_Data.ip_address = ipAddress;
ur_data_processing.UR_Control_Data.ip_address = ipAddress;

    // Trigger connection (simulate connecting action)
    ur_data_processing.GlobalVariables_Main_Control.connect = true;
    ur_data_processing.GlobalVariables_Main_Control.disconnect = false;

    Debug.Log("Connecting to IP: " + ipAddress);
}`

`public class UR_Control_Dashboard : MonoBehaviour
{
// TCP/IP Communication for Dashboard Server
private TcpClient dashboard_client = new TcpClient();
private NetworkStream dashboard_stream = null;

private bool exit_thread = false;
public string programName;



// Method to send a command to the Dashboard Server
public void SendDashboardCommand(string command)
{
    try
    {
        if (dashboard_client.Connected == false)
        {
            // Connect to the robot's Dashboard Server on port 29999
            dashboard_client.Connect(ur_data_processing.UR_Control_Data.ip_address, 29999);
        }

        // Send the command
        dashboard_stream = dashboard_client.GetStream();
        byte[] command_bytes = System.Text.Encoding.ASCII.GetBytes(command + "\n");
        dashboard_stream.Write(command_bytes, 0, command_bytes.Length);

        // Read the response (optional, can be omitted if you don't need the response)
        byte[] response = new byte[256];
        dashboard_stream.Read(response, 0, response.Length);
        string response_str = System.Text.Encoding.ASCII.GetString(response);
        Debug.Log("Dashboard Response: " + response_str);
    }
    catch (SocketException e)
    {
        Debug.LogException(e);
    }
}

// Method to load and run a program
public void RunProgram(string programName)
{
    // Load the program
    SendDashboardCommand("load " + programName + ".urp");
    //Debug.LogWarning("Loaded Program");
    // Start the program
    SendDashboardCommand("robotmode");
    StartCoroutine(PlayProgramAfterDelay());
}
public void CheckRobotStatus()
{
    SendDashboardCommand("robotmode");
    // You should get a response from the robot that indicates if it's ready
    // Adjust the logic sbased on the response to ensure it's ready to run the next program
}

private IEnumerator PlayProgramAfterDelay()
{
    yield return new WaitForSeconds(1);
    SendDashboardCommand("robotmode"); // Adjust delay if necessary
    SendDashboardCommand("play");
    SendDashboardCommand("robotmode");
    
}

public void OnRunRobot1()
{
    SendDashboardCommand("stop");
    SendDashboardCommand("robotmode");
    RunProgram("test");
}

public void OnRunRobot2()
{
    //SendDashboardCommand("set operational mode manual");
    SendDashboardCommand("stop");
    SendDashboardCommand("robotmode");
    RunProgram("robottestnew");
}

public void Start()
{
    // Start thread or any other control logic
    exit_thread = false;

    // Example to run a program from Unity
    //RunProgram("robotblocktestnew");
}

public void Destroy()
{
    if (dashboard_client.Connected == true)
    {
        // Disconnect communication
        dashboard_stream.Dispose();
        dashboard_client.Close();
    }
    Thread.Sleep(100);
}

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants