AS: updated readme

This commit is contained in:
Alexander Schaefer
2025-05-13 13:48:46 +02:00
parent 15b3fbb66e
commit d6ddbfc852
5 changed files with 157 additions and 80 deletions

View File

@@ -14,7 +14,6 @@ import time
import os
import re
import socket
import csv
class JointNameListener(Node):
def __init__(self):
@@ -92,9 +91,6 @@ class OSC_ROS2_interface(Node):
self.new = False
self.latency = []
while True:
try:
print('+-' * 50)
@@ -141,6 +137,7 @@ class OSC_ROS2_interface(Node):
continue
if robot:
while True:
print('+-' * 50)
set_limits = input("Do you want to set limit for x, y and z? (y/n): ").strip().lower()
if set_limits == 'y':
while True:
@@ -200,11 +197,12 @@ class OSC_ROS2_interface(Node):
if lower_limit and upper_limit and float(lower_limit) >= float(upper_limit):
print("Invalid input. Lower limit must be less than upper limit.")
continue
if lower_limit:
lower_limit = float(lower_limit) if lower_limit!="" else None
upper_limit = float(upper_limit) if upper_limit!="" else None
if lower_limit!=None:
if lower_limit<lim[0][i]:
while True:
sure = input(f"Are you sure you want to set the lower limit to {lower_limit} rad which is less than the default limit {lim[0][i]}(y/n): ").strip().lower()
sure = input(f"Are you sure you want to set the lower limit to {lower_limit} rad which is less than the default limit {lim[0][i]} (y/n)?: ").strip().lower()
if sure == 'y':
lim[0][i] = float(lower_limit)
break
@@ -213,10 +211,10 @@ class OSC_ROS2_interface(Node):
break
print("Invalid input. Please enter 'y' or 'n'.")
else: lim[0][i] = float(lower_limit)
if upper_limit:
if upper_limit<lim[0][i]:
if upper_limit!=None:
if upper_limit>lim[1][i]:
while True:
sure = input(f"Are you sure you want to set the upper limit to {upper_limit} rad which is more than the default limit {lim[1][i]}(y/n): ").strip().lower()
sure = input(f"Are you sure you want to set the upper limit to {upper_limit} rad which is more than the default limit {lim[1][i]} (y/n)?: ").strip().lower()
if sure == 'y':
lim[1][i] = float(upper_limit)
break
@@ -224,7 +222,7 @@ class OSC_ROS2_interface(Node):
print("Upper limit not changed.")
break
print("Invalid input. Please enter 'y' or 'n'.")
else: lim[0][i] = float(lower_limit)
else: lim[1][i] = float(upper_limit)
self.robot.qlim = lim
print(f"New limits for joint '{self.joint_names[i]}': [{self.robot.qlim[0][i]} {self.robot.qlim[1][i]}] rad")
print("-" * 50)
@@ -653,28 +651,26 @@ class OSC_ROS2_interface(Node):
try:
if self.desired is None or not(self.new):
return
start_time = time.time()
if self.desired[0] == "joint_positions":
self.new = False
self.send_joint_positions()
#return
return
elif self.desired[0] == "tcp_coordinates":
self.new = False
self.send_tcp_coordinates()
#return
return
elif self.desired[0] == "joint_trajectory":
self.new = False
self.send_joint_trajectory()
#return
return
elif self.desired[0] == "cartesian_trajectory":
self.new = False
self.send_cartesian_trajectory()
#return
return
else:
self.get_logger().warn(f"update_position: Unknown desired type '{self.desired[0]}'.")
return
self.latency.append(time.time()-start_time)
except Exception as e:
@@ -748,7 +744,7 @@ def main():
while True:
try:
print('-+'*50)
print("The cost mask determines which coordinates are used for the IK. Each element of the cost mask corresponds to a catesian coordinate [x, y, z, Rx, Ry, Rz].")
print("The cost mask determines which coordinates are used for the IK.\nEach element of the cost mask corresponds to a Cartesian coordinate [x, y, z, roll, pitch, yaw].")
print("The cost mask [1, 1, 1, 0, 0, 0] means that the IK will only consider translation and no rotaion.")
cost_mask = [int(i) for i in input(f"Enter the cost mask (6 integers (1 or 0), of which <= {robot.n} are 1): ")]
if sum(cost_mask) <= robot.n and len(cost_mask) == 6:
@@ -757,7 +753,7 @@ def main():
print(f"Invalid input. Expected 6 integers of which {robot.n if robot.n < 6 else 6} or less are 1.")
except ValueError:
print("Invalid input. Please enter integers only.")
print(f"Cost mask: {cost_mask}")
print(f"The following coordinates will be used for the IK: {[j for i,j in enumerate(['x','y','z','roll','pitch','yaw']) if cost_mask[i]==1]}")
break
elif use_urdf == 'n':
node = JointNameListener()
@@ -797,17 +793,6 @@ def main():
except KeyboardInterrupt:
print("")
finally:
file_path = "./latency_log.csv"
# If file doesn't exist, create with header
if not os.path.exists(file_path):
with open(file_path, mode='w', newline='') as f:
writer = csv.writer(f)
writer.writerow('latency')
with open(file_path, mode='a', newline='') as f:
writer = csv.writer(f)
for i in node.latency:
writer.writerow([i])
node.destroy_node()
rclpy.shutdown()
osc_terminate()

View File

@@ -14,11 +14,11 @@ setup(
install_requires=[
'setuptools',
'osc4py3',
'roboticstoolbox-python==1.0.1',
'numpy==1.23.5',
'scipy==1.10.1',
'spatialmath-python==1.0.0',
'matplotlib==3.6.3',],
'roboticstoolbox-python==1.1.1',
'numpy==1.22.4',
'scipy==1.7.3',
'spatialmath-python==1.1.14',
'matplotlib==3.4.3',],
zip_safe=True,
maintainer='Alexander Schaefer',
maintainer_email='a.schaefer@tuhh.de',
@@ -28,7 +28,6 @@ setup(
entry_points={
'console_scripts': [
'interface = osc_ros2.osc_ros2:main',
'interface1 = osc_ros2.osc_ros2_rpy:main',
],
},
)