force_torque_sensor_sim.cpp
Go to the documentation of this file.
00001 /****************************************************************
00002  *
00003  * Copyright 2016 Intelligent Industrial Robotics (IIROB) Group,
00004  * Institute for Anthropomatics and Robotics (IAR) -
00005  * Intelligent Process Control and Robotics (IPR),
00006  * Karlsruhe Institute of Technology
00007  *
00008  * Maintainers: Denis Štogl, email: denis.stogl@kit.edu
00009  *                     Andreea Tulbure
00010  *
00011  * Date of update: 2014-2017
00012  *
00013  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00014  *
00015  * Redistribution and use in source and binary forms, with or without
00016  * modification, are permitted provided that the following conditions are met:
00017  *
00018  *     * Redistributions of source code must retain the above copyright
00019  *       notice, this list of conditions and the following disclaimer.
00020  *     * Redistributions in binary form must reproduce the above copyright
00021  *       notice, this list of conditions and the following disclaimer in the
00022  *       documentation and/or other materials provided with the distribution.
00023  *     * Neither the name of the copyright holder nor the names of its
00024  *       contributors may be used to endorse or promote products derived from
00025  *       this software without specific prior written permission.
00026  *
00027  * This program is free software: you can redistribute it and/or modify
00028  * it under the terms of the GNU Lesser General Public License LGPL as
00029  * published by the Free Software Foundation, either version 3 of the
00030  * License, or (at your option) any later version.
00031  *
00032  * This program is distributed in the hope that it will be useful,
00033  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00034  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00035  * GNU Lesser General Public License LGPL for more details.
00036  *
00037  * You should have received a copy of the GNU Lesser General Public
00038  * License LGPL along with this program.
00039  * If not, see <http://www.gnu.org/licenses/>.
00040  *
00041  ****************************************************************/
00042 
00043 #include <ati_force_torque/force_torque_sensor_sim.h>
00044 
00045 ForceTorqueSensorSim::ForceTorqueSensorSim(ros::NodeHandle& nh) : nh_(nh), pub_params_{nh.getNamespace()+"/Publish"}, node_params_{nh.getNamespace()+"/Node"}
00046 {
00047     std::cout<<"ForceTorqueSensorSim"<<std::endl;
00048     pub_params_.fromParamServer();
00049     node_params_.fromParamServer();
00050     transform_frame_ = node_params_.transform_frame;
00051      //Wrench Publisher  
00052     is_pub_sensor_data_=pub_params_.sensor_data;
00053     if(is_pub_sensor_data_){
00054         sensor_data_pub_ = nh_.advertise<geometry_msgs::WrenchStamped>("sensor_data", 1);
00055     }
00056     is_pub_transformed_data_  = pub_params_.transformed_data;
00057     if(is_pub_transformed_data_){
00058         transformed_data_pub_ = nh_.advertise<geometry_msgs::WrenchStamped>("transformed_data", 1);
00059     }
00060     ftUpdateTimer_ = nh.createTimer(ros::Rate(node_params_.ft_pub_freq), &ForceTorqueSensorSim::updateFTData, this, false, false);
00061     ftPullTimer_ = nh.createTimer(ros::Rate(node_params_.ft_pull_freq), &ForceTorqueSensorSim::pullFTData, this, false, false);
00062     p_tfBuffer = new tf2_ros::Buffer();
00063     p_tfListener = new tf2_ros::TransformListener(*p_tfBuffer, true);
00064     init_sensor();
00065     ftUpdateTimer_.start();
00066 }
00067 void ForceTorqueSensorSim::init_sensor() {
00068     force_input_subscriber = nh_.subscribe("/cmd_force", 1, &ForceTorqueSensorSim::subscribeData, this);
00069     ftPullTimer_.start();
00070 }
00071 
00072 void ForceTorqueSensorSim::subscribeData(const geometry_msgs::Twist::ConstPtr& msg){
00073     joystick_data.wrench.force.x = msg->linear.x;
00074     joystick_data.wrench.force.y = msg->linear.y;
00075     joystick_data.wrench.force.z = msg->linear.z;
00076     joystick_data.wrench.torque.z = msg->angular.z;
00077     joystick_data.wrench.torque.x = msg->angular.x;;
00078     joystick_data.wrench.torque.y = msg->angular.y;
00079 }
00080 
00081 void ForceTorqueSensorSim::pullFTData(const ros::TimerEvent &event)
00082 {
00083     if(is_pub_sensor_data_)
00084         sensor_data_pub_.publish(joystick_data);
00085 }
00086 bool ForceTorqueSensorSim::transform_wrench(std::string goal_frame, std::string source_frame, geometry_msgs::Wrench wrench, geometry_msgs::Wrench *transformed)
00087 {
00088   geometry_msgs::TransformStamped transform;
00089   geometry_msgs::Vector3Stamped temp_vector_in, temp_vector_out;
00090   
00091   try
00092     {
00093         transform = p_tfBuffer->lookupTransform(goal_frame, source_frame, ros::Time(0));
00094         _num_transform_errors = 0;
00095     }
00096     catch (tf2::TransformException ex)
00097     {
00098       if (_num_transform_errors%100 == 0){
00099         ROS_ERROR("%s", ex.what());
00100       }
00101       _num_transform_errors++;
00102       return false;
00103     }
00104 
00105     temp_vector_in.vector = wrench.force;
00106     tf2::doTransform(temp_vector_in, temp_vector_out, transform);
00107     transformed->force = temp_vector_out.vector;
00108 
00109     temp_vector_in.vector = wrench.torque;
00110     tf2::doTransform(temp_vector_in, temp_vector_out, transform);
00111     transformed->torque = temp_vector_out.vector;
00112     
00113     return true;  
00114 }
00115 void ForceTorqueSensorSim::filterFTData(){
00116     transformed_data.header.stamp = ros::Time::now();
00117     transformed_data.header.frame_id =  node_params_.transform_frame;
00118     transform_wrench(node_params_.transform_frame, sensor_frame_, joystick_data.wrench, &transformed_data.wrench);
00119     threshold_filtered_force = transformed_data;
00120      if(is_pub_transformed_data_)
00121         transformed_data_pub_.publish(threshold_filtered_force);
00122 }


ati_force_torque
Author(s): Denis Štogl, Alexander Bubeck
autogenerated on Thu Jun 6 2019 21:13:29