robotiq_2f_gripper_ethercat_node.cpp
Go to the documentation of this file.
1 #include "ros/ros.h"
2 
3 #include <boost/bind.hpp>
4 #include <boost/ref.hpp>
5 
7 #include <robotiq_2f_gripper_control/Robotiq2FGripper_robot_input.h>
9 
10 
11 /*
12  Note that this code currently works only to control ONE 2F gripper
13  attached to ONE network interface. If you want to add more grippers
14  to the same network, you'll need to edit the source file.
15 */
16 
17 // Note that you will likely need to run the following on your binary:
18 // sudo setcap cap_net_raw+ep <filename>
19 
20 
22  const robotiq_2f_gripper_control::Robotiq2FGripperEtherCatClient::GripperOutput::ConstPtr& msg)
23 {
24  client.writeOutputs(*msg);
25 }
26 
27 
28 int main(int argc, char** argv)
29 {
32 
33  typedef Robotiq2FGripperEtherCatClient::GripperOutput GripperOutput;
34  typedef Robotiq2FGripperEtherCatClient::GripperInput GripperInput;
35 
36  ros::init(argc, argv, "robotiq_2f_gripper_node");
37 
38  ros::NodeHandle nh ("~");
39 
40  // Parameter names
41  std::string ifname;
42  int slave_no;
43  bool activate;
44 
45  nh.param<std::string>("ifname", ifname, "eth1");
46  nh.param<int>("slave_number", slave_no, 1);
47  nh.param<bool>("activate", activate, true);
48 
49  // Start ethercat manager
50  EtherCatManager manager(ifname);
51  // register client
52  Robotiq2FGripperEtherCatClient client(manager, slave_no);
53 
54  // conditionally activate the gripper
55  if (activate)
56  {
57  // Check to see if resetting is required? Or always reset?
58  GripperOutput out;
59  out.rACT = 0x1;
60  client.writeOutputs(out);
61  }
62 
63  // Sorry for the indentation, trying to keep it under 100 chars
64  ros::Subscriber sub =
65  nh.subscribe<GripperOutput>("output", 1,
66  boost::bind(changeCallback, boost::ref(client), _1));
67 
68  ros::Publisher pub = nh.advertise<GripperInput>("input", 100);
69 
70  ros::Rate rate(10); // 10 Hz
71 
72  while (ros::ok())
73  {
74  Robotiq2FGripperEtherCatClient::GripperInput input = client.readInputs();
75  pub.publish(input);
76  ros::spinOnce();
77  rate.sleep();
78  }
79 
80  return 0;
81 }
This class provides a client for the EtherCAT manager object that can translate robot input/output me...
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
ROSCPP_DECL bool ok()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void changeCallback(robotiq_2f_gripper_control::Robotiq2FGripperEtherCatClient &client, const robotiq_2f_gripper_control::Robotiq2FGripperEtherCatClient::GripperOutput::ConstPtr &msg)
void writeOutputs(const GripperOutput &output)
Write the given set of control flags to the memory of the gripper.
ROSCPP_DECL void spinOnce()
int main(int argc, char **argv)


robotiq_2f_gripper_control
Author(s): Nicolas Lauzier (Robotiq inc.)
autogenerated on Tue Jun 1 2021 02:29:54