force_torque_sensor_sim.cpp
Go to the documentation of this file.
1 /****************************************************************
2  *
3  * Copyright 2016 Intelligent Industrial Robotics (IIROB) Group,
4  * Institute for Anthropomatics and Robotics (IAR) -
5  * Intelligent Process Control and Robotics (IPR),
6  * Karlsruhe Institute of Technology
7  *
8  * Maintainers: Denis Štogl, email: denis.stogl@kit.edu
9  * Andreea Tulbure
10  *
11  * Date of update: 2014-2017
12  *
13  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions are met:
17  *
18  * * Redistributions of source code must retain the above copyright
19  * notice, this list of conditions and the following disclaimer.
20  * * Redistributions in binary form must reproduce the above copyright
21  * notice, this list of conditions and the following disclaimer in the
22  * documentation and/or other materials provided with the distribution.
23  * * Neither the name of the copyright holder nor the names of its
24  * contributors may be used to endorse or promote products derived from
25  * this software without specific prior written permission.
26  *
27  * This program is free software: you can redistribute it and/or modify
28  * it under the terms of the GNU Lesser General Public License LGPL as
29  * published by the Free Software Foundation, either version 3 of the
30  * License, or (at your option) any later version.
31  *
32  * This program is distributed in the hope that it will be useful,
33  * but WITHOUT ANY WARRANTY; without even the implied warranty of
34  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35  * GNU Lesser General Public License LGPL for more details.
36  *
37  * You should have received a copy of the GNU Lesser General Public
38  * License LGPL along with this program.
39  * If not, see <http://www.gnu.org/licenses/>.
40  *
41  ****************************************************************/
42 
44 
45 ForceTorqueSensorSim::ForceTorqueSensorSim(ros::NodeHandle& nh) : nh_(nh), pub_params_{nh.getNamespace()+"/Publish"}, node_params_{nh.getNamespace()+"/Node"}
46 {
47  std::cout<<"ForceTorqueSensorSim"<<std::endl;
48  pub_params_.fromParamServer();
49  node_params_.fromParamServer();
50  transform_frame_ = node_params_.transform_frame;
51  //Wrench Publisher
52  is_pub_sensor_data_=pub_params_.sensor_data;
54  sensor_data_pub_ = nh_.advertise<geometry_msgs::WrenchStamped>("sensor_data", 1);
55  }
56  is_pub_transformed_data_ = pub_params_.transformed_data;
57  if(is_pub_transformed_data_){
58  transformed_data_pub_ = nh_.advertise<geometry_msgs::WrenchStamped>("transformed_data", 1);
59  }
60  ftUpdateTimer_ = nh.createTimer(ros::Rate(node_params_.ft_pub_freq), &ForceTorqueSensorSim::updateFTData, this, false, false);
61  ftPullTimer_ = nh.createTimer(ros::Rate(node_params_.ft_pull_freq), &ForceTorqueSensorSim::pullFTData, this, false, false);
64  init_sensor();
65  ftUpdateTimer_.start();
66 }
70 }
71 
72 void ForceTorqueSensorSim::subscribeData(const geometry_msgs::Twist::ConstPtr& msg){
73  joystick_data.wrench.force.x = msg->linear.x;
74  joystick_data.wrench.force.y = msg->linear.y;
75  joystick_data.wrench.force.z = msg->linear.z;
76  joystick_data.wrench.torque.z = msg->angular.z;
77  joystick_data.wrench.torque.x = msg->angular.x;;
78  joystick_data.wrench.torque.y = msg->angular.y;
79 }
80 
82 {
85 }
86 bool ForceTorqueSensorSim::transform_wrench(std::string goal_frame, std::string source_frame, geometry_msgs::Wrench wrench, geometry_msgs::Wrench *transformed)
87 {
88  geometry_msgs::TransformStamped transform;
89  geometry_msgs::Vector3Stamped temp_vector_in, temp_vector_out;
90 
91  try
92  {
93  transform = p_tfBuffer->lookupTransform(goal_frame, source_frame, ros::Time(0));
95  }
96  catch (tf2::TransformException ex)
97  {
98  if (_num_transform_errors%100 == 0){
99  ROS_ERROR("%s", ex.what());
100  }
102  return false;
103  }
104 
105  temp_vector_in.vector = wrench.force;
106  tf2::doTransform(temp_vector_in, temp_vector_out, transform);
107  transformed->force = temp_vector_out.vector;
108 
109  temp_vector_in.vector = wrench.torque;
110  tf2::doTransform(temp_vector_in, temp_vector_out, transform);
111  transformed->torque = temp_vector_out.vector;
112 
113  return true;
114 }
116  transformed_data.header.stamp = ros::Time::now();
117  transformed_data.header.frame_id = node_params_.transform_frame;
118  transform_wrench(node_params_.transform_frame, sensor_frame_, joystick_data.wrench, &transformed_data.wrench);
122 }
bool transform_wrench(std::string goal_frame, std::string source_frame, geometry_msgs::Wrench wrench, geometry_msgs::Wrench *transformed)
void publish(const boost::shared_ptr< M > &message) const
tf2_ros::Buffer * p_tfBuffer
ForceTorqueSensorSim(ros::NodeHandle &nh)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
virtual geometry_msgs::TransformStamped lookupTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, const ros::Duration timeout) const
void start()
void pullFTData(const ros::TimerEvent &event)
void doTransform(const T &data_in, T &data_out, const geometry_msgs::TransformStamped &transform)
ati_force_torque::PublishConfigurationParameters pub_params_
geometry_msgs::WrenchStamped joystick_data
ros::Publisher transformed_data_pub_
const std::string & getNamespace() const
tf2_ros::TransformListener * p_tfListener
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
geometry_msgs::WrenchStamped transformed_data
void subscribeData(const geometry_msgs::Twist::ConstPtr &msg)
virtual void updateFTData(const ros::TimerEvent &event)=0
static Time now()
ros::Subscriber force_input_subscriber
#define ROS_ERROR(...)
ati_force_torque::NodeConfigurationParameters node_params_
geometry_msgs::WrenchStamped threshold_filtered_force


ati_force_torque
Author(s): Denis Štogl, Alexander Bubeck
autogenerated on Thu Sep 17 2020 03:18:35