Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include "sicks300.h"
00045
00046 #include "termios.h"
00047
00048 SickS300::SickS300()
00049 {
00050
00051 ros::NodeHandle param_node("~");
00052 ros::NodeHandle nodeHandle("/");
00053
00054 int param;
00055 double x, y, z;
00056
00057
00058 param_node.param(std::string("frame"), scan_data_.header.frame_id, std::string("base_laser_link"));
00059 param_node.param(std::string("send_transform"), param, 1);
00060 if (param)
00061 {
00062 send_transform_ = true;
00063 }
00064 else
00065 {
00066 send_transform_ = false;
00067 }
00068 param_node.param(std::string("tf_x"), x, 0.115);
00069 param_node.param(std::string("tf_y"), y, 0.0);
00070 param_node.param(std::string("tf_z"), z, 0.21);
00071
00072 transform_vector_ = tf::Vector3(x, y, z);
00073
00074
00075 param_node.param(std::string("reduced_fov"), param, 0);
00076 if (param != 0)
00077 {
00078 reduced_FOV_ = true;
00079 ROS_INFO("INFO: Starting Sick300-Laser with reduced field ov view of 180 degree");
00080 }
00081 else
00082 {
00083 reduced_FOV_ = false;
00084 }
00085
00086 if (!reduced_FOV_)
00087 {
00088 scan_data_.angle_min = -135.f / 180.f * M_PI;
00089 scan_data_.angle_max = 135.f / 180.f * M_PI;
00090 scan_data_.angle_increment = 0.5f / 180.f * M_PI;
00091 scan_data_.time_increment = 0;
00092 scan_data_.scan_time = 0.08;
00093 scan_data_.range_min = 0.1;
00094 scan_data_.range_max = 29.0;
00095 scan_data_.ranges.resize(541);
00096 scan_data_.intensities.resize(541);
00097 }
00098 else
00099 {
00100 scan_data_.angle_min = -90.f / 180.f * M_PI;
00101 scan_data_.angle_max = 90.f / 180.f * M_PI;
00102 scan_data_.angle_increment = 0.5f / 180.f * M_PI;
00103 scan_data_.time_increment = 0;
00104 scan_data_.scan_time = 0.08;
00105 scan_data_.range_min = 0.1;
00106 scan_data_.range_max = 29.0;
00107 scan_data_.ranges.resize(361);
00108 scan_data_.intensities.resize(361);
00109 }
00110
00111
00112 param_node.param(std::string("devicename"), device_name_, std::string("/dev/sick300"));
00113 param_node.param(std::string("baudrate"), baud_rate_, 500000);
00114
00115 connected_ = serial_comm_.connect(device_name_, baud_rate_);
00116
00117 scan_data_publisher_ = nodeHandle.advertise<sensor_msgs::LaserScan> ("laserscan", 10);
00118
00119 }
00120
00121 SickS300::~SickS300()
00122 {
00123 }
00124
00125 void SickS300::update()
00126 {
00127
00128 if (connected_ != 0)
00129 {
00130 connected_ = serial_comm_.connect(device_name_, baud_rate_);
00131 }
00132
00133 if (connected_ == 0 && serial_comm_.readData() == 0)
00134 {
00135
00136 float* ranges = serial_comm_.getRanges();
00137 unsigned int numRanges = serial_comm_.getNumRanges();
00138 if (!reduced_FOV_)
00139 {
00140 scan_data_.ranges.resize(numRanges);
00141 for (unsigned int i = 0; i < numRanges; i++)
00142 scan_data_.ranges[i] = ranges[i];
00143 }
00144 else
00145 {
00146 for (unsigned int i = 0; i < 361; i++)
00147 scan_data_.ranges[i] = ranges[i + 89];
00148 }
00149 scan_data_.header.stamp = ros::Time::now();
00150
00151 scan_data_publisher_.publish(scan_data_);
00152
00153 }
00154
00155 }
00156
00157 void SickS300::broadcast_transform()
00158 {
00159 if (send_transform_)
00160 {
00161 tf_broadcaster_.sendTransform(tf::StampedTransform(tf::Transform(tf::Quaternion(0, 0, 0, 1), transform_vector_),
00162 ros::Time::now(), "base_link", "base_laser_link"));
00163 }
00164
00165 }
00166
00167 int main(int argc, char** argv)
00168 {
00169
00170 ros::init(argc, argv, "sicks300");
00171 ros::Time::init();
00172 ros::Rate loop_rate(20);
00173
00174 ROS_INFO("Opening connection to Sick300-Laser...");
00175
00176 SickS300 sickS300;
00177
00178 ROS_INFO("Sick300 connected.");
00179
00180 while (ros::ok())
00181 {
00182
00183 sickS300.update();
00184 sickS300.broadcast_transform();
00185
00186 ros::spinOnce();
00187 loop_rate.sleep();
00188 }
00189
00190 ROS_INFO("Laser shut down.");
00191
00192 return 0;
00193 }
00194