ouster-lidar / ouster-sdk

Ouster, Inc. sample code
Other
469 stars 438 forks source link

Client State returns IMU_DATA(4) data available when I disconnect the sensor from the network. #578

Open zimazz157 opened 9 months ago

zimazz157 commented 9 months ago

I am currently utilizing the client_example.cpp, and when I disconnect the cable or unplug the sensor, it consistently returns a state value of 4, corresponding to IMU_DATA. Consequently, so I am unable to check for states indicative of a timeout, client error, or an exit condition. ouster::sensor::client_state st = ouster::sensor::poll_client(*_handle);

if (st == ouster::sensor::TIMEOUT || st & ouster::sensor::CLIENT_ERROR || st & ouster::sensor::EXIT) { std::cout << "client error\n"; break; } the condition is never true even if I unplug the sensor from my network

However, in the mtp_client_example.cpp, the behavior is consistently normal. In the event of a connection interruption, the state is appropriately altered to ouster::sensor::TIMEOUT, denoted by the value 0.

sensor::client_state state = sensor::poll_client(*cli); if (state == sensor::EXIT) { std::cerr << "caught signal, exiting" << std::endl; done = true; } if (state == sensor::TIMEOUT) { std::cerr << "Timed out" << std::endl; continue; }

here is the function that returns the state client_state poll_client(const client& c, const int timeout_sec) { fd_set rfds; FD_ZERO(&rfds); FD_SET(c.lidar_fd, &rfds); FD_SET(c.imu_fd, &rfds);

timeval tv;
tv.tv_sec = timeout_sec;
tv.tv_usec = 0;

SOCKET max_fd = std::max(c.lidar_fd, c.imu_fd);

SOCKET retval = select((int)max_fd + 1, &rfds, NULL, NULL, &tv);

client_state res = client_state(0);

if (!impl::socket_valid(retval) && impl::socket_exit()) {
    res = EXIT;
} else if (!impl::socket_valid(retval)) {
    logger().error("select: {}", impl::socket_get_error());
    res = client_state(res | CLIENT_ERROR);
} else if (retval) {
    if (FD_ISSET(c.lidar_fd, &rfds)) res = client_state(res | LIDAR_DATA);
    if (FD_ISSET(c.imu_fd, &rfds)) res = client_state(res | IMU_DATA);
}

return res;

So, in unicast mode, the result state (res) always ends up as 6 when there's data and 4 (IMU_DATA) when there's no connection. This happens because the conditions are always true in unicast mode. Specifically, the state becomes 6 if the lidar data is present and 4 if there's IMU data, which isn't what I expect. I'm looking for a solution to make sure the function shows the right state in unicast mode, indicating whether there's data or connection error.

in unicast mode these to conditions always true that's why state is equal to 6 if (FD_ISSET(c.lidar_fd, &rfds)) res = client_state(res | LIDAR_DATA); if (FD_ISSET(c.imu_fd, &rfds)) res = client_state(res | IMU_DATA);

twslankard commented 4 months ago

Thanks for the report @zimazz157 .

Is this happening on Linux? Which revision of ouster-sdk are you using?

Cheers,

Tom Slankard Staff Engineer Ouster Inc.