Skip to content

Commit 3ededf4

Browse files
committed
FT300 socket connection publisher
1 parent 4be6b0c commit 3ededf4

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

robotiq_ft_sensor/config/config.ini

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[Information]
2+
ip_address = 10.0.0.2
3+
port = 63351
4+
output_file_location =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env python
2+
import ConfigParser
3+
import rospy
4+
import time
5+
import socket
6+
import rospkg
7+
8+
from geometry_msgs.msg import WrenchStamped
9+
from ur_control import conversions
10+
11+
12+
class socket_connection ():
13+
14+
def __init__(self):
15+
16+
try:
17+
rospack = rospkg.RosPack()
18+
packpath = rospack.get_path("robotiq_ft_sensor")
19+
config_path = packpath + '/config/' + "config.ini"
20+
21+
config = ConfigParser.ConfigParser()
22+
config.read(config_path)
23+
24+
self.host_ip = config.get('Information', 'ip_address')
25+
self.port = int(config.get('Information', 'port'))
26+
self.output_file_location = config.get('Information', 'output_file_location')
27+
28+
self.write_object = True
29+
30+
if self.output_file_location is "":
31+
self.output_file_location = ""
32+
elif self.output_file_location is "None":
33+
self.write_object = False
34+
else:
35+
self.output_file_location = self.output_file_location + "/"
36+
37+
except:
38+
39+
print("Warning: Config.ini file problem, please check Config.ini")
40+
41+
self.socket_object = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
42+
self.publisher = rospy.Publisher('/ft300/wrench', WrenchStamped, queue_size=10)
43+
self.publisher_rate = rospy.Rate(100)
44+
self.is_published = False
45+
46+
47+
48+
def connect(self):
49+
50+
try:
51+
52+
print("Warning: Connecting to UR ip address: " + self.host_ip)
53+
self.socket_object.connect((self.host_ip, self.port))
54+
55+
if self.write_object is True:
56+
print("Warning: File Write Location: " + self.output_file_location)
57+
f = open(self.output_file_location + "DataStream.csv", "w")
58+
59+
try:
60+
print("Publishing FT300 data, Press ctrl + c to stop")
61+
while not rospy.is_shutdown():
62+
now = rospy.get_rostime()
63+
data = self.socket_object.recv(1024)
64+
65+
msg = WrenchStamped()
66+
msg.header.stamp = now
67+
msg.wrench = conversions.to_wrench(list(eval(data)))
68+
69+
rospy.logdebug(data)
70+
71+
self.publisher.publish(msg)
72+
self.publisher_rate.sleep()
73+
74+
except KeyboardInterrupt:
75+
76+
f.close
77+
self.socket_object.close
78+
79+
return False
80+
81+
except Exception as e:
82+
83+
print("Error: No Connection!! Please check your ethernet cable :)" + str(e))
84+
85+
return False
86+
87+
88+
def main():
89+
rospy.init_node('FT300_publisher', anonymous=True)
90+
91+
socket_connection_obj = socket_connection()
92+
socket_connection_obj.connect()
93+
94+
95+
if __name__ == "__main__":
96+
97+
try:
98+
main()
99+
except rospy.ROSInterruptException:
100+
pass

0 commit comments

Comments
 (0)