SICKAG / sick_safetyscanners_base

CPP (C++) Driver for SICK safety laser scanners
https://www.sick.com/de/en/opto-electronic-protective-devices/safety-laser-scanners/c/g187225
Apache License 2.0
13 stars 32 forks source link

How to connect to nS3 via CPP driver? #27

Open kinni318 opened 7 months ago

kinni318 commented 7 months ago

Hello, Failed to connecting the nanoScan3 by the following steps... We have no idea what caused this problem. Could you some one to help on it?

1, Installing the library on a linux PC(ubuntu18.04 & C++ environment.) Followed the Installation step of https://github.com/SICKAG/sick_safetyscanners_base *libsick_safetyscanners_base.so was created.

2, Building via the command below; g++ main.cpp -I../sick_safetyscanners_base/include/ -L. -lsick_safetyscanners_base -lboost_system -o main

3.Result of running $./main ; [INFO]: Command Method Acknowledged. terminate called after throwing an instance of 'sick::timeout_error' what(): Timeout exceeded while waiting for sensor data [timeout: 5seconds] ...... PS: We can run sick_safetyscanners.launch and get data by python at the same PC and the same nonaScan3.

===>The file - main.cpp;<===

int main() {

// Sensor IP and Port
    std::string sensor_ip_str = "192.168.1.2";
    sick::types::ip_address_t sensor_ip = boost::asio::ip::address_v4::from_string(sensor_ip_str);
    sick::types::port_t tcp_port {2122};

    // Prepare the CommPP Settings for Sensor streaming data
    sick::datastructure::CommSettings comm_settings;
    std::string host_ip_str = "192.168.1.21";
    comm_settings.host_ip = boost::asio::ip::address_v4::from_string(host_ip_str);
    comm_settings.host_udp_port = 0;

// Create a sensor instance
    auto safety_scanner = std::make_unique<sick::SyncSickSafetyScanner>(sensor_ip, tcp_port, comm_settings);

    // Receive one sensor data packet
    auto timeout = boost::posix_time::seconds(5);
    sick::datastructure::Data data = safety_scanner->receive(timeout);

std::cout << "hello" << std::endl;
//printf("hello\n");
return(1);

} Thanks in advance.

lenpuc commented 4 months ago

Hello, what is the IP of the sensor? is it the one configured in the CPP code? And is your host IP correctly configured?

And since you are using the .launch as well, maybe I think you want to use the ASync Interface https://github.com/SICKAG/sick_safetyscanners_base?tab=readme-ov-file#asynchronous-client