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

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

Open
zimazz157 opened this issue Feb 18, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@zimazz157
Copy link

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);

@zimazz157 zimazz157 added the bug Something isn't working label Feb 18, 2024
@twslankard
Copy link
Collaborator

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.

@twslankard twslankard self-assigned this Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants