sicks300.cpp
Go to the documentation of this file.
00001 /*
00002  *
00003  * sicks300.cpp
00004  *
00005  *
00006  * Copyright (C) 2014
00007  * Software Engineering Group
00008  * RWTH Aachen University
00009  *
00010  *
00011  * Author: Dimitri Bohlender
00012  *
00013  *
00014  * This program is free software; you can redistribute it and/or modify
00015  * it under the terms of the GNU General Public License as published by
00016  * the Free Software Foundation; either version 3 of the License, or
00017  * (at your option) any later version.
00018  *
00019  * This program is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00022  * GNU General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU General Public License
00025  * along with this program; if not, write to the Free Software
00026  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00027  *
00028  *
00029  * Origin:
00030  *  Copyright (C) 2010
00031  *     Andreas Hochrath, Torsten Fiolka
00032  *     Autonomous Intelligent Systems Group
00033  *     University of Bonn, Germany
00034  *
00035  *  Player - One Hell of a Robot Server
00036  *  serialstream.cc & sicks3000.cc
00037  *  Copyright (C) 2003
00038  *     Brian Gerkey
00039  *  Copyright (C) 2000
00040  *     Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard
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   // reading transformation parameters from parameter server
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   // Setting full field of view (270 degree) or reduced (180 degree)
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   // Reading device parameters
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 


sicks300
Author(s): Dimitri Bohlender
autogenerated on Mon Oct 6 2014 07:37:46