SickSafetyscanners.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 
24 // -- END LICENSE BLOCK ------------------------------------------------
25 
26 //----------------------------------------------------------------------
33 //----------------------------------------------------------------------
34 
35 
37 
38 namespace sick {
39 
41  packetReceivedCallbackFunction newPacketReceivedCallbackFunction,
43  : m_newPacketReceivedCallbackFunction(newPacketReceivedCallbackFunction)
44 {
45  ROS_INFO("Starting SickSafetyscanners");
46  m_io_service_ptr = std::make_shared<boost::asio::io_service>();
47  m_async_udp_client_ptr = std::make_shared<sick::communication::AsyncUDPClient>(
48  boost::bind(&SickSafetyscanners::processUDPPacket, this, _1),
49  boost::ref(*m_io_service_ptr),
50  settings->getHostUdpPort());
51  settings->setHostUdpPort(
52  m_async_udp_client_ptr
53  ->get_local_port()); // Store which port was used, needed for data request from the laser
54  m_packet_merger_ptr = std::make_shared<sick::data_processing::UDPPacketMerger>();
55  ROS_INFO("Started SickSafetyscanners");
56 }
57 
59 {
60  m_io_service_ptr->stop();
63 }
64 
66 {
68  new boost::thread(boost::bind(&SickSafetyscanners::UDPClientThread, this)));
69 
70  m_async_udp_client_ptr->runService();
71  return true;
72 }
73 
75 {
76  ROS_INFO("Enter io thread");
77  m_io_work_ptr = std::make_shared<boost::asio::io_service::work>(boost::ref(*m_io_service_ptr));
78  m_io_service_ptr->run();
79  ROS_INFO("Exit io thread");
80  return true;
81 }
82 
83 
85 {
86  // Not needed for current functionality, inplace for possible future developments
87 }
88 
90 {
91  startTCPConnection(settings);
92 
94 
96 }
97 
100 {
101  startTCPConnection(settings);
102 
103  requestTypeCodeInColaSession(type_code);
104 
106 }
107 
109  std::vector<sick::datastructure::FieldData>& field_data)
110 {
111  startTCPConnection(settings);
112 
113  requestFieldDataInColaSession(field_data);
114 
116 }
117 
119  const datastructure::CommSettings& settings,
120  std::vector<sick::datastructure::MonitoringCaseData>& monitoring_cases)
121 {
122  startTCPConnection(settings);
123 
124  requestMonitoringCaseDataInColaSession(monitoring_cases);
125 
127 }
128 
130  std::string& device_name)
131 {
132  startTCPConnection(settings);
133 
134  requestDeviceNameInColaSession(device_name);
135 
137 }
138 
140  sick::datastructure::ConfigData& config_data)
141 {
142  startTCPConnection(settings);
143 
145 
147 }
148 
150 {
151  std::shared_ptr<sick::communication::AsyncTCPClient> async_tcp_client =
152  std::make_shared<sick::communication::AsyncTCPClient>(
153  boost::bind(&SickSafetyscanners::processTCPPacket, this, _1),
154  boost::ref(*m_io_service_ptr),
155  settings.getSensorIp(),
156  settings.getSensorTcpPort());
157  async_tcp_client->doConnect();
158 
159  m_session_ptr.reset();
160  m_session_ptr = std::make_shared<sick::cola2::Cola2Session>(async_tcp_client);
161 
162  m_session_ptr->open();
163 }
164 
166  const datastructure::CommSettings& settings)
167 {
169  std::make_shared<sick::cola2::ChangeCommSettingsCommand>(boost::ref(*m_session_ptr), settings);
170  m_session_ptr->executeCommand(command_ptr);
171 }
172 
174  std::vector<sick::datastructure::FieldData>& fields)
175 {
177 
178  /*sick::cola2::Cola2Session::CommandPtr command_ptr =
179  std::make_shared<sick::cola2::MeasurementPersistentConfigVariableCommand>(
180  boost::ref(*m_session_ptr), pers_config_data);
181  m_session_ptr->executeCommand(command_ptr);
182 */
184  std::make_shared<sick::cola2::MeasurementCurrentConfigVariableCommand>(
185  boost::ref(*m_session_ptr), config_data);
186  m_session_ptr->executeCommand(command_ptr);
187  /*
188  command_ptr = std::make_shared<sick::cola2::MonitoringCaseTableHeaderVariableCommand>(
189  boost::ref(*m_session_ptr), common_field_data);
190  m_session_ptr->executeCommand(command_ptr);
191  */
192  for (int i = 0; i < 128; i++)
193  {
195 
196  command_ptr = std::make_shared<sick::cola2::FieldHeaderVariableCommand>(
197  boost::ref(*m_session_ptr), field_data, i);
198  m_session_ptr->executeCommand(command_ptr);
199 
200  if (field_data.getIsValid())
201  {
202  command_ptr = std::make_shared<sick::cola2::FieldGeometryVariableCommand>(
203  boost::ref(*m_session_ptr), field_data, i);
204  m_session_ptr->executeCommand(command_ptr);
205 
206  field_data.setStartAngleDegrees(config_data.getStartAngle());
207  field_data.setAngularBeamResolutionDegrees(config_data.getAngularBeamResolution());
208 
209  fields.push_back(field_data);
210  }
211  else if (i > 0) // index 0 is reserved for contour data
212  {
213  break; // skip other requests after first invalid
214  }
215  }
216 }
217 
219  std::vector<sick::datastructure::MonitoringCaseData>& monitoring_cases)
220 {
222  for (int i = 0; i < 254; i++)
223  {
224  sick::datastructure::MonitoringCaseData monitoring_case_data;
225 
226  command_ptr = std::make_shared<sick::cola2::MonitoringCaseVariableCommand>(
227  boost::ref(*m_session_ptr), monitoring_case_data, i);
228  m_session_ptr->executeCommand(command_ptr);
229  if (monitoring_case_data.getIsValid())
230  {
231  monitoring_cases.push_back(monitoring_case_data);
232  }
233  else
234  {
235  break; // skip other requests after first invalid
236  }
237  }
238 }
239 
241 {
243  std::make_shared<sick::cola2::DeviceNameVariableCommand>(boost::ref(*m_session_ptr),
244  device_name);
245  m_session_ptr->executeCommand(command_ptr);
246  ROS_INFO("Device name: %s", device_name.c_str());
247 }
248 
250 {
252  std::make_shared<sick::cola2::TypeCodeVariableCommand>(boost::ref(*m_session_ptr), type_code);
253  m_session_ptr->executeCommand(command_ptr);
254 }
255 
257  sick::datastructure::ConfigData& config_data)
258 {
260  std::make_shared<sick::cola2::MeasurementPersistentConfigVariableCommand>(
261  boost::ref(*m_session_ptr), config_data);
262  m_session_ptr->executeCommand(command_ptr);
263 }
264 
266 {
267  m_session_ptr->close();
268  m_session_ptr->doDisconnect();
269 }
270 
271 
273 {
274  if (m_packet_merger_ptr->addUDPPacket(buffer))
275  {
276  sick::datastructure::PacketBuffer deployedBuffer =
277  m_packet_merger_ptr->getDeployedPacketBuffer();
280  data_parser.parseUDPSequence(deployedBuffer, data);
281 
283  }
284 }
285 
286 } // namespace sick
float getStartAngle() const
Get the start angle of the configuration.
Definition: ConfigData.cpp:42
void requestFieldData(const sick::datastructure::CommSettings &settings, std::vector< sick::datastructure::FieldData > &field_data)
Requests data of the protective and warning fields from the sensor.
void requestMonitoringCases(const sick::datastructure::CommSettings &settings, std::vector< sick::datastructure::MonitoringCaseData > &monitoring_cases)
Requests the monitoring cases from the sensor.
void processUDPPacket(const datastructure::PacketBuffer &buffer)
A packetbuffer for the raw data from the sensor.
Definition: PacketBuffer.h:61
void requestDeviceNameInColaSession(std::string &device_name)
std::shared_ptr< sick::cola2::Command > CommandPtr
Typedef for a pointer containing a command to be executed.
Definition: Cola2Session.h:78
void requestDeviceName(const sick::datastructure::CommSettings &settings, std::string &device_name)
Requests the name of the device from the sensor.
void changeCommSettingsInColaSession(const datastructure::CommSettings &settings)
void requestPersistentConfigInColaSession(sick::datastructure::ConfigData &config_data)
Field data for warning and protective fields.
Definition: FieldData.h:48
Containing the communication settings for the sensor which can be changed on runtime.
Definition: CommSettings.h:48
std::shared_ptr< sick::communication::AsyncUDPClient > m_async_udp_client_ptr
The data class containing all data blocks of a measurement.
Definition: Data.h:55
void changeSensorSettings(const sick::datastructure::CommSettings &settings)
Changes the internal settings of the sensor.
Parses the udp data packets depending on which data will be received.
Definition: ParseData.h:56
#define ROS_INFO(...)
void startTCPConnection(const sick::datastructure::CommSettings &settings)
bool parseUDPSequence(const sick::datastructure::PacketBuffer buffer, sick::datastructure::Data &data) const
Parses the udp data transferred in the packet buffer. It will be parsed into the data reference...
Definition: ParseData.cpp:52
std::shared_ptr< boost::asio::io_service::work > m_io_work_ptr
uint16_t getSensorTcpPort() const
Gets the sensor tcp port.
SickSafetyscanners(packetReceivedCallbackFunction newPacketReceivedCallbackFunction, sick::datastructure::CommSettings *settings)
Constructor of the SickSafetyscanners class.
boost::asio::ip::address_v4 getSensorIp() const
Gets the sensor IP-address.
bool run()
Start the connection to the sensor and enables output.
std::shared_ptr< sick::cola2::Cola2Session > m_session_ptr
Config data for current and persistent sensor config.
Definition: ConfigData.h:48
void setHostUdpPort(const uint16_t &host_udp_port)
Sets the host udp port.
void requestPersistentConfig(const datastructure::CommSettings &settings, sick::datastructure::ConfigData &config_data)
Requests the persistent configuration from the sensor.
Stores the data for the different monitoring cases.
void requestTypeCode(const sick::datastructure::CommSettings &settings, sick::datastructure::TypeCode &type_code)
Requests the typecode of the sensor.
void requestFieldDataInColaSession(std::vector< sick::datastructure::FieldData > &fields)
packetReceivedCallbackFunction m_newPacketReceivedCallbackFunction
virtual ~SickSafetyscanners()
Destructor.
std::shared_ptr< boost::asio::io_service > m_io_service_ptr
void requestMonitoringCaseDataInColaSession(std::vector< sick::datastructure::MonitoringCaseData > &monitoring_cases)
void processTCPPacket(const sick::datastructure::PacketBuffer &buffer)
Class containing the type code of a laser scanner.
Definition: TypeCode.h:62
boost::scoped_ptr< boost::thread > m_udp_client_thread_ptr
uint16_t getHostUdpPort() const
Gets the host udp port.
std::shared_ptr< sick::data_processing::UDPPacketMerger > m_packet_merger_ptr
float getAngularBeamResolution() const
Returns the angular resolution between the beams.
Definition: ConfigData.cpp:72
void requestTypeCodeInColaSession(sick::datastructure::TypeCode &type_code)
boost::function< void(const sick::datastructure::Data &)> packetReceivedCallbackFunction


sick_safetyscanners
Author(s): Lennart Puck
autogenerated on Thu May 9 2019 02:41:08