flexiv_rdk icon indicating copy to clipboard operation
flexiv_rdk copied to clipboard

[BUG] getPrimitiveStates error no response from server

Open acf986 opened this issue 1 year ago • 6 comments

Version information

  • RDK: v0.10
  • Robot software: v2.10.9
  • OS: Ubuntu 20.04

Describe the bug Unlike in the previously reported issue here, I am only calling getPrimitiveStates at 10Hz. After starting a primitive from the RDK, the function getPrimitiveStates is used to monitor the primitive's executing status. However, it sometimes gives the error No response from server and crashes the program.

Steps to reproduce

  1. Issue the MoveComp primitive
  2. Call getPrimitiveStates at 10Hz
  3. The error only happens sometime, not every time, you might need to repeat this multiple times at different network conditions.

Expected behavior It at least should not close the connection and terminate the program. Screenshots WhatsApp Image 2024-07-31 at 15 38 17 (1)

Additional context Will catch the thrown out error help in this case?

acf986 avatar Aug 12 '24 13:08 acf986

@acf986 Have you caught the exception thrown by getPrimitiveStates() when the error "No response from server" happens? Exception will be propagated to the top of stack and trigger the program to exit if not handled.

Server response timeout can happen under busy networks. To address this, you can write a try catch statement to handle such exception: put the first getPrimitiveStates() in the try{} statement, then put another getPrimitiveStates() call in the catch {} statement. This way, a retry of getting primitive states is executed if the first attempt failed.

pzhu-flexiv avatar Aug 12 '24 17:08 pzhu-flexiv

@pzhu-flexiv , hi we have tried to catch the error with the following code:

bool CompPrimState::is_finished()
{
  std::vector<std::string> states;
  try
  {
    states = m_se->get_robot()->getPrimitiveStates();
  }
  catch(const flexiv::CommException& e )
  {
    std::cout<<"Catched the error: "<<e.what()<<std::endl;
    std::cout<<"Retrying"<<e.what()<<std::endl;
    states = m_se->get_robot()->getPrimitiveStates();
    std::cout<<"Retry finished"<<e.what()<<std::endl;
  }

  return execution_started_ && flexiv::utility::parsePtStates(states, "reachedTarget") == "1";
}

This checking function is triggered by a timer at 10Hz. We've caught the error as shown in the attached image, but the process still failed.

Screenshot from 2024-08-13 19-37-58

It appears the RDK terminated the process and the program never reach the retry part. Can you suggest a more reliable method to check if a primitive has finished? As this issue will halt the usage of all primitives from RDK.

acf986 avatar Aug 13 '24 09:08 acf986

@acf986 (1/2) What are the primitives you are using?

pzhu-flexiv avatar Aug 13 '24 16:08 pzhu-flexiv

@acf986 (1/2) What are the primitives you are using?

I am using the moveCompliance primitive.

acf986 avatar Aug 13 '24 16:08 acf986

@acf986 (2/2) Could you update the get primitive states part of your code to the following and try again?

std::vector<std::string> states;
do {
    try {
        states = m_se->get_robot()->getPrimitiveStates();
    } catch (const flexiv::CommException& e) {
        std::cout << "Get primitive states failed, trying again ..." << std::endl
    }
    std::this_thread::sleep_for(std::chrono::milliseconds(100));
} while (flexiv::utility::parsePtStates(states, "reachedTarget") != "1");

pzhu-flexiv avatar Aug 13 '24 16:08 pzhu-flexiv

@acf986 (1/2) What are the primitives you are using?

I am using the moveCompliance primitive.

Then you have two options, one is to try the revised code I provided above, the other is to use Robot::isStopped() with some initial wait until the robot starts to move.

pzhu-flexiv avatar Aug 13 '24 16:08 pzhu-flexiv

@acf986 Closed issue due to inactivity. You can reopen it if the issue is not solved.

pzhu-flexiv avatar Sep 03 '24 17:09 pzhu-flexiv