29 #include <schunk_sdh/TactileSensor.h> 30 #include <schunk_sdh/TactileMatrix.h> 33 #include <diagnostic_msgs/DiagnosticArray.h> 34 #include <diagnostic_msgs/KeyValue.h> 36 #include <schunk_sdh/dsa.h> 38 #include <boost/lexical_cast.hpp> 39 #include <boost/bind.hpp> 52 res.resize(namesXmlRpc.
size());
53 for (
int i = 0; i < namesXmlRpc.
size(); i++)
55 res[i] = (T)namesXmlRpc[i];
110 nh_(
"~"), dsa_(0), last_data_publish_(0), isDSAInitialized_(false), error_counter_(0)
112 topicPub_Diagnostics_ = nh_.
advertise < diagnostic_msgs::DiagnosticArray > (
"/diagnostics", 1);
113 topicPub_TactileSensor_ = nh_.
advertise < schunk_sdh::TactileSensor > (
"tactile_data", 1);
121 if (isDSAInitialized_)
130 timer_publish.
stop();
142 nh_.
param(
"dsadevicestring", dsadevicestring_, std::string(
""));
143 if (dsadevicestring_.empty())
146 nh_.
param(
"dsadevicenum", dsadevicenum_, 0);
147 nh_.
param(
"maxerror", maxerror_, 8);
149 double publish_frequency, diag_frequency;
151 nh_.
param(
"debug", debug_,
false);
152 nh_.
param(
"polling", polling_,
false);
153 nh_.
param(
"use_rle", use_rle_,
true);
154 nh_.
param(
"diag_frequency", diag_frequency, 5.0);
157 nh_.
param(
"poll_frequency", frequency_, 5.0);
158 nh_.
param(
"publish_frequency", publish_frequency, 0.0);
160 auto_publish_ =
true;
170 if (publish_frequency > 0.0)
172 auto_publish_ =
false;
181 if (!
read_vector(nh_,
"dsa_reorder", dsa_reorder_))
183 dsa_reorder_.resize(6);
198 if (isDSAInitialized_)
203 isDSAInitialized_ =
false;
209 if (isDSAInitialized_ ==
false)
212 if (!dsadevicestring_.empty())
216 dsa_ =
new SDH::cDSA(0, dsadevicenum_, dsadevicestring_.c_str());
218 dsa_->SetFramerate(frequency_, use_rle_);
220 dsa_->SetFramerate(0, use_rle_);
222 ROS_INFO(
"Initialized RS232 for DSA Tactile Sensors on device %s", dsadevicestring_.c_str());
227 isDSAInitialized_ =
true;
229 catch (SDH::cSDHLibraryException* e)
231 isDSAInitialized_ =
false;
232 ROS_ERROR(
"An exception was caught: %s", e->what());
249 if (isDSAInitialized_)
253 SDH::UInt32 last_time;
254 last_time = dsa_->GetFrame().timestamp;
256 if (last_time != dsa_->GetFrame().timestamp)
259 if (error_counter_ > 0)
265 catch (SDH::cSDHLibraryException* e)
267 ROS_ERROR(
"An exception was caught: %s", e->what());
271 if (error_counter_ > maxerror_)
285 if (isDSAInitialized_)
289 dsa_->SetFramerate(0, use_rle_);
292 catch (SDH::cSDHLibraryException* e)
294 ROS_ERROR(
"An exception was caught: %s", e->what());
298 if (error_counter_ > maxerror_)
313 last_data_publish_ = dsa_->GetFrame().timestamp;
315 schunk_sdh::TactileSensor msg;
318 msg.tactile_matrix.resize(dsa_->GetSensorInfo().nb_matrices);
319 ROS_ASSERT(dsa_->GetSensorInfo().nb_matrices == dsa_reorder_.size());
320 for (
unsigned int i = 0; i < dsa_reorder_.size(); i++)
323 schunk_sdh::TactileMatrix &tm = msg.tactile_matrix[i];
325 tm.cells_x = dsa_->GetMatrixInfo(m).cells_x;
326 tm.cells_y = dsa_->GetMatrixInfo(m).cells_y;
327 tm.tactile_array.resize(tm.cells_x * tm.cells_y);
328 for (y = 0; y < tm.cells_y; y++)
330 for (x = 0; x < tm.cells_x; x++)
331 tm.tactile_array[tm.cells_x * y + x] = dsa_->GetTexel(m, x, y);
335 topicPub_TactileSensor_.
publish(msg);
340 diagnostic_msgs::DiagnosticArray diagnostics;
341 diagnostics.status.resize(1);
343 diagnostics.status[0].values.resize(1);
344 diagnostics.status[0].values[0].key =
"error_count";
345 diagnostics.status[0].values[0].value = boost::lexical_cast < std::string > (
error_counter_);
348 if (isDSAInitialized_)
350 diagnostics.status[0].level = 0;
351 diagnostics.status[0].message =
"DSA tactile sensing initialized and running";
353 else if (error_counter_ == 0)
355 diagnostics.status[0].level = 1;
356 diagnostics.status[0].message =
"DSA not initialized";
360 diagnostics.status[0].level = 2;
361 diagnostics.status[0].message =
"DSA exceeded eror count";
364 topicPub_Diagnostics_.
publish(diagnostics);
376 int main(
int argc,
char** argv)
383 if (!dsa_node.
init())
392 ROS_INFO(
"...dsa node shut down...");
void publish(const boost::shared_ptr< M > &message) const
~DsaNode()
Destructor for SdhNode class.
std::string dsadevicestring_
ros::Publisher topicPub_Diagnostics_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int main(int argc, char **argv)
Main loop of ROS node.
bool init()
Initializes node to get parameters, subscribe and publish to topics.
void publishDiagnostics()
ros::NodeHandle nh_
create a handle for this node, initialize node
DsaNode()
Constructor for SdhNode class.
bool read_vector(ros::NodeHandle &n_, const std::string &key, std::vector< T > &res)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
const std::string & getNamespace() const
SDH::UInt32 last_data_publish_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_DEBUG_STREAM(args)
std::vector< int > dsa_reorder_
ros::Publisher topicPub_TactileSensor_
bool getParam(const std::string &key, std::string &s) const
Implementation of ROS node for DSA.
bool hasParam(const std::string &key) const
void publishTactileData()