sr_pst_tactile_sensor_publisher.cpp
Go to the documentation of this file.
00001 
00011 
00012 
00013 #include "sr_tactile_sensor_controller/sr_pst_tactile_sensor_publisher.hpp"
00014 
00015 namespace controller
00016 {
00017 void SrPSTTactileSensorPublisher::init(const ros::Time& time)
00018 {
00019   // initialize time
00020   last_publish_time_ = time;
00021 
00022   // realtime publisher
00023   pst_realtime_pub_ = PSTPublisherPtr(
00024     new realtime_tools::RealtimePublisher<sr_robot_msgs::ShadowPST>(nh_prefix_, "tactile", 4));
00025   pst_realtime_pub_->msg_.pressure.resize(sensors_->size());
00026   pst_realtime_pub_->msg_.temperature.resize(sensors_->size());
00027 }
00028 
00029 void SrPSTTactileSensorPublisher::update(const ros::Time& time, const ros::Duration& period)
00030 {
00031   bool pst_published = false;
00032   // limit rate of publishing
00033   if (publish_rate_ > 0.0 && last_publish_time_ + ros::Duration(1.0 / publish_rate_) < time)
00034   {
00035     // try to publish
00036     if (pst_realtime_pub_->trylock())
00037     {
00038       // we're actually publishing, so increment time
00039       last_publish_time_ = last_publish_time_ + ros::Duration(1.0 / publish_rate_);
00040       pst_published = true;
00041       // populate message
00042       pst_realtime_pub_->msg_.header.stamp = time;
00043       pst_realtime_pub_->msg_.header.frame_id = prefix_+"distal";
00044       // data
00045       for (unsigned i = 0; i < sensors_->size(); i++)
00046       {
00047         pst_realtime_pub_->msg_.pressure[i] = sensors_->at(i).pst.pressure;
00048         pst_realtime_pub_->msg_.temperature[i] = sensors_->at(i).pst.temperature;
00049       }
00050       pst_realtime_pub_->unlockAndPublish();
00051     }
00052   }
00053 }
00054 }  // end namespace controller
00055 
00056 
00057 /* For the emacs weenies in the crowd.
00058 Local Variables:
00059    c-basic-offset: 2
00060 End:
00061  */


sr_tactile_sensor_controller
Author(s): Guillaume Walck
autogenerated on Mon Jul 1 2019 20:06:36