31 #include <sensor_msgs/LaserScan.h> 49 std::cerr <<
"IP of laser range finder not set!" << std::endl;
71 std::cout <<
"Connecting to scanner at " <<
scanner_ip_ <<
" ... ";
73 std::cout <<
"OK" << std::endl;
76 std::cout <<
"FAILED!" << std::endl;
77 std::cerr <<
"Connection to scanner at " << scanner_ip_ <<
" failed!" << std::endl;
86 std::cout <<
"Current scanner settings:" << std::endl;
87 std::cout <<
"============================================================" << std::endl;
88 for(
const auto& p : params )
89 std::cout << p.first <<
" : " << p.second << std::endl;
90 std::cout <<
"============================================================" << std::endl;
94 std::cout <<
"Starting capturing: ";
96 std::cout <<
"OK" << std::endl;
99 std::cout <<
"FAILED!" << std::endl;
110 std::cout <<
"ERROR: Laser range finder disconnected. Trying to reconnect..." << std::endl;
113 std::cout <<
"ERROR: Reconnect failed. Trying again in 2 seconds..." << std::endl;
118 if( scandata.amplitude_data.empty() || scandata.distance_data.empty() )
121 sensor_msgs::LaserScan scanmsg;
125 scanmsg.angle_min = -M_PI;
126 scanmsg.angle_max = +M_PI;
127 scanmsg.angle_increment = 2*M_PI/float(scandata.distance_data.size());
128 scanmsg.time_increment = 1/35.0f/float(scandata.distance_data.size());
134 scanmsg.ranges.resize(scandata.distance_data.size());
135 scanmsg.intensities.resize(scandata.amplitude_data.size());
136 for( std::size_t i=0; i<scandata.distance_data.size(); i++ )
138 scanmsg.ranges[i] = float(scandata.distance_data[i])/1000.0f;
139 scanmsg.intensities[i] = scandata.amplitude_data[i];
147 const std::string& cmd = msg->data;
148 static const std::string set_scan_frequency_cmd(
"set scan_frequency=");
149 static const std::string set_samples_per_scan_cmd(
"set samples_per_scan=");
153 if( cmd.substr(0,set_scan_frequency_cmd.size()) == set_scan_frequency_cmd )
155 std::string value = cmd.substr(set_scan_frequency_cmd.size());
156 int frequency = std::atoi(value.c_str());
157 if(frequency>=10 && frequency<=50)
166 if( cmd.substr(0,set_samples_per_scan_cmd.size()) == set_samples_per_scan_cmd )
168 std::string value = cmd.substr(set_samples_per_scan_cmd.size());
169 int samples = std::atoi(value.c_str());
170 if(samples>=72 && samples<=25200)
181 int main(
int argc,
char **argv)
int scan_frequency_
scan_frequency parameter
Driver for the laserscanner R2000 of Pepperl+Fuchs.
const std::map< std::string, std::string > & getParametersCached() const
R2000Node()
Initialize and connect to laser range finder.
int samples_per_scan_
samples_per_scan parameter
void publish(const boost::shared_ptr< M > &message) const
ros::NodeHandle nh_
Internal ROS node handle.
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void cmdMsgCallback(const std_msgs::StringConstPtr &msg)
Callback function for control commands.
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool setSamplesPerScan(unsigned int samples)
bool setScanFrequency(unsigned int frequency)
ROS driver node for the Pepperl+Fuchs R2000 laser range finder.
void getScanData(const ros::TimerEvent &e)
Time callback function for getting data from the driver and sending them out.
std::string scanner_ip_
IP or hostname of laser range finder.
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
ros::Subscriber cmd_subscriber_
ROS subscriber for receiving control commands.
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::Timer get_scan_data_timer_
Callback timer for getScanData(...)
ros::Publisher scan_publisher_
ROS publisher for publishing scan data.
bool connect(const std::string hostname, int port=80)
int main(int argc, char **argv)
R2000Driver * driver_
Pointer to driver.
std::string frame_id_
frame_id of sensor_msgs/Laserscan messages
const std::map< std::string, std::string > & getParameters()