netft_utils_cpp_test.cpp
Go to the documentation of this file.
1 
2 /*
3 Copyright (c) 2016, Los Alamos National Security, LLC
4 All rights reserved.
5 Copyright 2016. Los Alamos National Security, LLC. This software was produced under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National Laboratory (LANL), which is operated by Los Alamos National Security, LLC for the U.S. Department of Energy. The U.S. Government has rights to use, reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to produce derivative works, such modified software should be clearly marked, so as not to confuse it with the version available from LANL.
6 
7 Additionally, redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10 3. Neither the name of Los Alamos National Security, LLC, Los Alamos National Laboratory, LANL, the U.S. Government, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11 
12 THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13 
14 Author: Andy Zelenak
15 */
16 
17 #ifndef KEY_COMPLIANCE_H_
18 #define KEY_COMPLIANCE_H_
19 #endif
20 
21 #include "ros/ros.h"
22 #include "std_msgs/Bool.h"
23 #include "std_msgs/String.h"
24 #include "geometry_msgs/WrenchStamped.h"
25 #include "geometry_msgs/TwistStamped.h"
26 #include "ros/console.h"
27 #include "netft_utils_lean.h"
28 
29 // Test the C++ interface for the ATI force/torque sensor with a Netbox.
30 
31 // Most of the action happens in this class.
32 // The underscores denote members of the class.
34 {
35  public:
36 
38  double ftSleep_; // Controls the data acquisition rate
40  geometry_msgs::WrenchStamped wrench_; // For data from the sensor
41 
42  // Constructor
43  netftExample();
44 
45  // Most of the action happens here
46  void getFTData();
47 };
48 
49 int main(int argc, char **argv)
50 {
51  ros::init(argc, argv, "netft_utils_cpp_test");
53  spinner = new ros::AsyncSpinner(3);
54  spinner->start();
55 
56  // Create a new netftExample object.
57  // Most of the action happens here
58  netftExample *myNetftExample = new netftExample();
59 
61 
62  return 0;
63 }
64 
65 // Constructor for the netftExample class
67 {
68  // Connect and bias the ft sensor
69  fti_ = new NetftUtilsLean(&n_);
70  fti_->setFTAddress("192.168.1.84");
71  // Adjust the data acquisition rate and set the World and Sensor frames, respectively
72  ftSleep_ = 0.05; // Will yield a 20 Hz data acquisition rate
73  fti_->initialize(1/ftSleep_, "right_ur5_base_link", "right_ur5_ee_link");
74 
75  // Set max and threshold force/torque readings
76  // Vaules below the thresholds will register as zero
77  fti_->setMax(80.0, 8.0, 60.0, 6.0);
78  std::future<bool> ftThread;
79  ftThread = std::async(std::launch::async, &NetftUtilsLean::run, fti_);
80  fti_->biasSensor(1);
81 
82  getFTData();
83 }
84 
86 {
87  while (ros::ok())
88  {
90  ROS_INFO_STREAM("X force in the tool frame: " << wrench_.wrench.force.x);
91 
93  ROS_INFO_STREAM("X force in the world frame: " << wrench_.wrench.force.x);
94 
95  sleep(ftSleep_);
96  }
97 }
bool biasSensor(bool toBias)
geometry_msgs::WrenchStamped wrench_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool setMax(double fMaxU, double tMaxU, double fMaxB, double tMaxB)
int main(int argc, char **argv)
void spinner()
void setFTAddress(std::string ftAddress)
void getWorldData(geometry_msgs::WrenchStamped &data)
ros::NodeHandle n_
ROSCPP_DECL bool ok()
#define ROS_INFO_STREAM(args)
NetftUtilsLean * fti_
void getToolData(geometry_msgs::WrenchStamped &data)
bool initialize(double rate, std::string world, std::string ft, double force=60.0, double torque=6.0)
ROSCPP_DECL void waitForShutdown()


netft_utils
Author(s): Alex von Sternberg , Derek King, Andy Zelenak
autogenerated on Tue Mar 2 2021 03:15:08