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
12 stars 32 forks source link

I cannot connect to the nanoScan3 #23

Closed MFHuniovi closed 3 months ago

MFHuniovi commented 12 months ago

Hello. I am trying to create a diagnostic application for the sick nanoScan3 and I am following the communications example (missing "" and ; where ip are defined). The problem is that I never manage to make a connection/receive data, it always exits when calling the isDataAvaliable() method. My ip is 192.168.1.3 but I don't understand the udp_port = 0, I keep it as it was by default (although I imagine that the problem is here). This is my code:

int main()
{
  cout << "start" << endl;
  // 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 CommSettings for Sensor streaming data
  sick::datastructure::CommSettings comm_settings;
  std::string host_ip_str = "192.168.1.3";
  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);

  if(!safety_scanner->isDataAvailable())
  {
    cout<<"no estas disponible para recibir datos"<<endl;
    return 0;
  }
    cout<<"estas disponible para recibir datos"<<endl;
  // Receive one sensor data packet
  auto timeout = boost::posix_time::seconds(5);
  sick::datastructure::Data data = safety_scanner->receive(timeout);
  std::shared_ptr<sick::datastructure::GeneralSystemState> dataGeneralSystemPtr = data.getGeneralSystemStatePtr();

  if(dataGeneralSystemPtr)
  {
    bool deviceError = dataGeneralSystemPtr->getDeviceError();
    if(deviceError)
    {
      std::cout << "El dispositivo tiene un error." << std::endl;
    }
    else {
      std::cout << "El dispositivo no tiene errores." << std::endl;
    }
    bool applicationError = dataGeneralSystemPtr->getApplicationError();
    if(deviceError)
    {
      std::cout << "La aplicacion tiene un error." << std::endl;
    }
    else {
      std::cout << "La aplicacion no tiene errores." << std::endl;
    }
  }
  else {
    //puntero nulo
    std::cout << "El puntero dataHeaderPtr es nulo." << std::endl;
  }
  return 0;
}
puck-fzi commented 11 months ago

Hi,

are you able to ping the sensor? The UDP Port 0 should not cause a problem since it will simply select an port from the ephemeral range then and use that.

MFHuniovi commented 11 months ago

I already managed to get the data through the ROS system which publishes the same as I can get from the "data" in "sick::datastructure::Data data = safety_scanner->receive(timeout);".

How could I get more error information from the application or the device? I only get a flag from the GeneralSystemState indicating whether or not it is in error but I would like to be able to do more detailed diagnostics.

puck-fzi commented 10 months ago

Hi, did you have a look at the ROS2 driver? This uses this class as a base. Maybe that helps in how to properly set it up. otherwise, all the information and the API are reflected in the Readme, you will find all services there. They can directly trigger the corresponding cola2 call to the sensor.

puck-fzi commented 3 months ago

Closing due to inactivity