16 #ifndef PSEN_SCAN_V2_ROS_SCANNER_NODE_H 17 #define PSEN_SCAN_V2_ROS_SCANNER_NODE_H 26 #include <fmt/format.h> 28 #include <gtest/gtest_prod.h> 31 #include <std_msgs/UInt8.h> 32 #include <sensor_msgs/LaserScan.h> 53 template <
typename S = ScannerV2>
67 const std::string& topic,
68 const std::string& tf_prefix,
69 const double& x_axis_rotation,
82 void publishChangedIOStates(
const std::vector<psen_scan_v2_standalone::IOState>& io_states);
92 std::atomic_bool terminate_{
false };
96 friend class RosScannerNodeTests;
97 FRIEND_TEST(RosScannerNodeTests, shouldStartAndStopSuccessfullyIfScannerRespondsToRequests);
98 FRIEND_TEST(RosScannerNodeTests, shouldPublishScansWhenLaserScanCallbackIsInvoked);
99 FRIEND_TEST(RosScannerNodeTests, shouldPublishActiveZonesetWhenLaserScanCallbackIsInvoked);
100 FRIEND_TEST(RosScannerNodeTests, shouldWaitWhenStopRequestResponseIsMissing);
101 FRIEND_TEST(RosScannerNodeTests, shouldProvideScanTopic);
102 FRIEND_TEST(RosScannerNodeTests, shouldProvideActiveZonesetTopic);
103 FRIEND_TEST(RosScannerNodeTests, shouldPublishScanEqualToConversionOfSuppliedLaserScan);
104 FRIEND_TEST(RosScannerNodeTests, shouldThrowExceptionSetInScannerStartFuture);
105 FRIEND_TEST(RosScannerNodeTests, shouldThrowExceptionSetInScannerStopFuture);
106 FRIEND_TEST(RosScannerNodeTests, shouldPublishChangedIOStatesEqualToConversionOfSuppliedStandaloneIOStates);
107 FRIEND_TEST(RosScannerNodeTests, shouldPublishLatchedOnIOStatesTopic);
108 FRIEND_TEST(RosScannerNodeTests, shouldLogChangedIOStates);
113 template <
typename S>
115 const std::string& topic,
116 const std::string& tf_prefix,
117 const double& x_axis_rotation,
120 , tf_prefix_(tf_prefix)
121 , x_axis_rotation_(x_axis_rotation)
129 template <
typename S>
137 "Publishing laser scan with angle_min={:.1f} angle_max={:.1f} angle_increment={:.1f} degrees. {} angle values.",
141 laser_scan_msg.ranges.size());
144 std_msgs::UInt8 active_zoneset;
151 catch (
const std::invalid_argument&
e)
158 template <
typename S>
161 for (
const auto& io : io_states)
168 "IOs changed, new input: {}, new output: {}",
176 template <
typename S>
182 template <
typename S>
186 auto start_future =
scanner_.start();
187 const auto start_status = start_future.wait_for(3
s);
188 if (start_status == std::future_status::ready)
199 const auto stop_status = stop_future.wait_for(3
s);
200 if (stop_status == std::future_status::ready)
208 #endif // PSEN_SCAN_V2_ROS_SCANNER_NODE_H
void run(class_loader::ClassLoader *loader)
void laserScanCallback(const LaserScan &scan)
ROS Node that continuously publishes scan data of a single PSENscan laser scanner.
#define PSENSCAN_INFO_ONCE(name,...)
Represents the set of all I/Os of the scanner and their states.
Contains the events needed to define and implement the scanner protocol.
void laserScanCallback(const LaserScan &scan)
std::string formatPinStates(const std::vector< PinState > &pins)
Formats a vector of PinStates.
psen_scan_v2::IOState toIOStateMsg(const psen_scan_v2_standalone::IOState &io_state, const std::string &frame_id)
ROSScannerNodeT ROSScannerNode
Higher level data type storing the configuration details of the scanner like scanner IP...
void publish(const boost::shared_ptr< M > &message) const
void terminate()
Terminates the fetching and publishing of scanner data.
#define PSENSCAN_INFO(name,...)
sensor_msgs::LaserScan toLaserScanMsg(const LaserScan &laserscan, const std::string &frame_id, const double x_axis_rotation)
void run()
Continuously fetches data from the scanner and publishes the data into the ROS network.
ROSScannerNodeT(ros::NodeHandle &nh, const std::string &topic, const std::string &tf_prefix, const double &x_axis_rotation, const ScannerConfiguration &scanner_config)
Constructor.
Root namespace in which the software components to communicate with the scanner (firmware-version: 2)...
Root namespace for the ROS part.
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
const IOData & ioStates() const
uint8_t activeZoneset() const
#define ROS_ERROR_STREAM(args)
static constexpr double radianToDegree(const double &angle_in_rad)
std::atomic_bool terminate_
void publishChangedIOStates(const std::vector< psen_scan_v2_standalone::IOState > &io_states)
This class represents a single laser scan in the <tf_prefix> target frame.
psen_scan_v2_standalone::IOState last_io_state_