Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
U
ur_simple_control
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marko Guberina
ur_simple_control
Commits
93d0c01d
Commit
93d0c01d
authored
5 months ago
by
Marko Guberina
Browse files
Options
Downloads
Patches
Plain Diff
stuff
parent
43a0dd06
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
python/examples/graz/protobuf_to_ros1.py
+39
-32
39 additions, 32 deletions
python/examples/graz/protobuf_to_ros1.py
with
39 additions
and
32 deletions
python/examples/graz/protobuf_to_ros1.py
+
39
−
32
View file @
93d0c01d
...
@@ -5,7 +5,7 @@ import time
...
@@ -5,7 +5,7 @@ import time
import
argparse
import
argparse
import
message_specs_pb2
import
message_specs_pb2
import
rospy
import
rospy
from
geometry_msgs
import
WrenchStamped
from
geometry_msgs
.msg
import
WrenchStamped
def
getArgs
():
def
getArgs
():
...
@@ -33,6 +33,7 @@ def parse_message(buffer):
...
@@ -33,6 +33,7 @@ def parse_message(buffer):
"""
"""
pos
,
next_pos
=
0
,
0
pos
,
next_pos
=
0
,
0
buffer_len
=
len
(
buffer
)
buffer_len
=
len
(
buffer
)
print
(
"
buffer_len
"
,
buffer_len
)
msg_in_bytes
=
b
""
msg_in_bytes
=
b
""
len_size_offset
=
0
len_size_offset
=
0
while
True
:
while
True
:
...
@@ -46,6 +47,11 @@ def parse_message(buffer):
...
@@ -46,6 +47,11 @@ def parse_message(buffer):
return
msg_in_bytes
,
pos
return
msg_in_bytes
,
pos
# ros parts
#rospy.init_node("ur5e_to_ros1_mapper", anonymous=True)
#pub = rospy.Publisher("wrench_msg_mapper", WrenchStamped, queue_size=10)
args
=
getArgs
()
args
=
getArgs
()
host_addr
=
(
args
.
host
,
args
.
port
)
host_addr
=
(
args
.
host
,
args
.
port
)
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
...
@@ -57,15 +63,16 @@ while True:
...
@@ -57,15 +63,16 @@ while True:
except
ConnectionRefusedError
:
except
ConnectionRefusedError
:
time
.
sleep
(
0.005
)
time
.
sleep
(
0.005
)
print
(
"
NETWORKING CLIENT: connected to server
"
)
print
(
"
NETWORKING CLIENT: connected to server
"
)
s
.
settimeout
(
None
)
# ros parts
#try:
pub
=
rospy
.
Publisher
(
"
wrench_msg_mapper
"
,
WrenchStamped
,
queue_size
=
10
)
rospy
.
init_node
(
"
ur5e_to_ros1_mapper
"
,
anonymous
=
True
)
try
:
while
True
:
while
True
:
msg_raw
=
s
.
recv
(
1024
)
msg_raw
=
s
.
recv
(
1024
)
buffer
+=
msg_raw
buffer
+=
msg_raw
print
(
msg_raw
)
print
(
len
(
msg_raw
))
if
len
(
msg_raw
)
<
1
:
continue
msg_in_bytes
,
pos
=
parse_message
(
buffer
)
msg_in_bytes
,
pos
=
parse_message
(
buffer
)
buffer
=
buffer
[
pos
:]
buffer
=
buffer
[
pos
:]
...
@@ -77,18 +84,18 @@ try:
...
@@ -77,18 +84,18 @@ try:
print
(
pb2_msg
.
wrench
)
print
(
pb2_msg
.
wrench
)
# here you send construct and send the ros message
# here you send construct and send the ros message
wrench_message
=
WrenchStamped
()
#
wrench_message = WrenchStamped()
wrench_message
.
wrench
.
force
.
x
=
pb2_msg
.
wrench
[
0
]
#
wrench_message.wrench.force.x = pb2_msg.wrench[0]
wrench_message
.
wrench
.
force
.
y
=
pb2_msg
.
wrench
[
1
]
#
wrench_message.wrench.force.y = pb2_msg.wrench[1]
wrench_message
.
wrench
.
force
.
z
=
pb2_msg
.
wrench
[
2
]
#
wrench_message.wrench.force.z = pb2_msg.wrench[2]
wrench_message
.
wrench
.
torque
.
x
=
pb2_msg
.
wrench
[
3
]
#
wrench_message.wrench.torque.x = pb2_msg.wrench[3]
wrench_message
.
wrench
.
torque
.
y
=
pb2_msg
.
wrench
[
4
]
#
wrench_message.wrench.torque.y = pb2_msg.wrench[4]
wrench_message
.
wrench
.
torque
.
z
=
pb2_msg
.
wrench
[
5
]
#
wrench_message.wrench.torque.z = pb2_msg.wrench[5]
wrench_message
.
header
.
stamp
=
rospy
.
Time
.
now
()
#
wrench_message.header.stamp = rospy.Time.now()
wrench_message
.
header
.
frame_id
=
0
#
wrench_message.header.frame_id = 0
pub
.
publish
(
wrench_message
)
#
pub.publish(wrench_message)
# time.sleep(0.002)
# time.sleep(0.002)
except
KeyboardInterrupt
:
#
except KeyboardInterrupt:
s
.
close
()
#
s.close()
print
(
"
NETWORKING_CLIENT: caught KeyboardInterrupt, i
'
m out
"
)
#
print("NETWORKING_CLIENT: caught KeyboardInterrupt, i'm out")
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment