diff --git a/ros2_ws/.vscode/c_cpp_properties.json b/ros2_ws/.vscode/c_cpp_properties.json deleted file mode 100644 index d3a36710a1e87bb47ec34f667fa85c20bb7a8a70..0000000000000000000000000000000000000000 --- a/ros2_ws/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "configurations": [ - { - "browse": { - "databaseFilename": "${default}", - "limitSymbolsToIncludedHeaders": false - }, - "includePath": [ - "/home/ventsi/trajektorien-des-menschlichen-aufstehens-fuer-die-entwicklung-eines-kooperativen-assistenzsystems/ros2_ws/install/impedance_controller/include/**", - "/home/ventsi/trajektorien-des-menschlichen-aufstehens-fuer-die-entwicklung-eines-kooperativen-assistenzsystems/ros2_ws/install/iiwa_hardware/include/**", - "/home/ventsi/trajektorien-des-menschlichen-aufstehens-fuer-die-entwicklung-eines-kooperativen-assistenzsystems/ros2_ws/install/external_torque_sensor_broadcaster/include/**", - "/opt/ros/humble/include/**", - "/home/ventsi/trajektorien-des-menschlichen-aufstehens-fuer-die-entwicklung-eines-kooperativen-assistenzsystems/ros2_ws/src/iiwa/iiwa_controllers/external_torque_sensor_broadcaster/include/**", - "/home/ventsi/trajektorien-des-menschlichen-aufstehens-fuer-die-entwicklung-eines-kooperativen-assistenzsystems/ros2_ws/src/iiwa/iiwa_controllers/impedance_controller/include/**", - "/home/ventsi/trajektorien-des-menschlichen-aufstehens-fuer-die-entwicklung-eines-kooperativen-assistenzsystems/ros2_ws/src/iiwa/iiwa_hardware/include/**", - "/usr/include/**" - ], - "name": "ROS", - "intelliSenseMode": "gcc-x64", - "compilerPath": "/usr/bin/gcc", - "cStandard": "gnu11", - "cppStandard": "c++14" - } - ], - "version": 4 -} \ No newline at end of file diff --git a/ros2_ws/.vscode/settings.json b/ros2_ws/.vscode/settings.json deleted file mode 100644 index a5d34f69e2c3fc582fa248ffed8483f5c492df4c..0000000000000000000000000000000000000000 --- a/ros2_ws/.vscode/settings.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "python.autoComplete.extraPaths": [ - "/home/ventsi/trajektorien-des-menschlichen-aufstehens-fuer-die-entwicklung-eines-kooperativen-assistenzsystems/ros2_ws/install/simple_robot_3dof/lib/python3.10/site-packages", - "/home/ventsi/trajektorien-des-menschlichen-aufstehens-fuer-die-entwicklung-eines-kooperativen-assistenzsystems/ros2_ws/install/simple_robot_2dof/lib/python3.10/site-packages", - "/home/ventsi/trajektorien-des-menschlichen-aufstehens-fuer-die-entwicklung-eines-kooperativen-assistenzsystems/ros2_ws/install/simple_robot_1dof/lib/python3.10/site-packages", - "/home/ventsi/trajektorien-des-menschlichen-aufstehens-fuer-die-entwicklung-eines-kooperativen-assistenzsystems/ros2_ws/install/iiwa_inverse_kinematics/lib/python3.10/site-packages", - "/opt/ros/humble/lib/python3.10/site-packages", - "/opt/ros/humble/local/lib/python3.10/dist-packages" - ], - "python.analysis.extraPaths": [ - "/home/ventsi/trajektorien-des-menschlichen-aufstehens-fuer-die-entwicklung-eines-kooperativen-assistenzsystems/ros2_ws/install/simple_robot_3dof/lib/python3.10/site-packages", - "/home/ventsi/trajektorien-des-menschlichen-aufstehens-fuer-die-entwicklung-eines-kooperativen-assistenzsystems/ros2_ws/install/simple_robot_2dof/lib/python3.10/site-packages", - "/home/ventsi/trajektorien-des-menschlichen-aufstehens-fuer-die-entwicklung-eines-kooperativen-assistenzsystems/ros2_ws/install/simple_robot_1dof/lib/python3.10/site-packages", - "/home/ventsi/trajektorien-des-menschlichen-aufstehens-fuer-die-entwicklung-eines-kooperativen-assistenzsystems/ros2_ws/install/iiwa_inverse_kinematics/lib/python3.10/site-packages", - "/opt/ros/humble/lib/python3.10/site-packages", - "/opt/ros/humble/local/lib/python3.10/dist-packages" - ] -} \ No newline at end of file diff --git a/ros2_ws/src/simple_robot_1dof/launch/kuka_rviz_simulation_1dof_launch.py b/ros2_ws/src/simple_robot_1dof/launch/kuka_rviz_simulation_1dof_launch.py index 405da311ebb1eebcb116246589a1bf88fbd2d652..c27d1ea7e46e9dcba98e86baa503e634d05b2f18 100644 --- a/ros2_ws/src/simple_robot_1dof/launch/kuka_rviz_simulation_1dof_launch.py +++ b/ros2_ws/src/simple_robot_1dof/launch/kuka_rviz_simulation_1dof_launch.py @@ -122,7 +122,9 @@ def generate_launch_description(): package='joint_state_publisher', executable='joint_state_publisher', output = 'both', - # parameters=[params] + parameters=[ + {'robot_description': robot_desc} + ] ) joint_state_publisher_gui = Node( package='joint_state_publisher_gui', @@ -138,7 +140,7 @@ def generate_launch_description(): inverse_kinematics_node, robot_state_publisher, joint_state_publisher, - joint_state_publisher_gui + # joint_state_publisher_gui ] return LaunchDescription(declared_arguments + nodes) \ No newline at end of file diff --git a/ros2_ws/src/simple_robot_1dof/setup.py b/ros2_ws/src/simple_robot_1dof/setup.py index dee6002c5e4a68aa17ccc99b18725e77ce6e450d..860d6d7d9faa340a524d6026f1f75709b17dd3e4 100644 --- a/ros2_ws/src/simple_robot_1dof/setup.py +++ b/ros2_ws/src/simple_robot_1dof/setup.py @@ -29,7 +29,6 @@ setup( 'console_scripts': [ 'forward_kinematics_node_1dof = simple_robot_1dof.forward_kinematics_node_1dof:main', 'reference_node_1dof = simple_robot_1dof.reference_node_1dof:main', - 'reference_node_1dof_velocity = simple_robot_1dof.reference_node_1dof_velocity:main', ], }, ) diff --git a/ros2_ws/src/simple_robot_1dof/simple_robot_1dof/forward_kinematics_node_1dof.py b/ros2_ws/src/simple_robot_1dof/simple_robot_1dof/forward_kinematics_node_1dof.py index 44c4fff8699bf3cc9aaa001b5cc425ed278c68c5..3331c8bfeb16f8a76e42b202201e5f28c98a9b77 100644 --- a/ros2_ws/src/simple_robot_1dof/simple_robot_1dof/forward_kinematics_node_1dof.py +++ b/ros2_ws/src/simple_robot_1dof/simple_robot_1dof/forward_kinematics_node_1dof.py @@ -51,7 +51,7 @@ class Forward_Kinematics_Node_1Dof(Node): # create a publisher for the plotjuggler angles self.angle_publisher_ = self.create_publisher(Float64, '/simple_robot/angles_1dof/plotjuggler', 10) # create a publisher for the pose - self.pose_publisher_simple_robot_ = self.create_publisher(PoseStamped, '/simple_robot/target_pose', 10) + self.pose_publisher_simple_robot_ = self.create_publisher(Pose, '/simple_robot/target_pose', 10) self.pose_publisher_kuka_robot_ = self.create_publisher(Pose, '/kuka_iiwa/target_pose', 10) #RViz self.path = Path() @@ -189,17 +189,17 @@ class Forward_Kinematics_Node_1Dof(Node): def publish_pose_simple_robot(self, vector, quaternion): - pose_msg = PoseStamped() - pose_msg.header.frame_id = "map" - pose_msg.header.stamp = self.get_clock().now().to_msg() - pose_msg.pose.position.x = vector[0] - pose_msg.pose.position.y = vector[1] - pose_msg.pose.position.z = vector[2] - pose_msg.pose.orientation.x = quaternion[0] - pose_msg.pose.orientation.y = quaternion[1] - pose_msg.pose.orientation.z = quaternion[2] - pose_msg.pose.orientation.w = quaternion[3] - self.pose_publisher_simple_robot_.publish(pose_msg) + pose_msg_sr = Pose() + # pose_msg.header.frame_id = "map" + # pose_msg.header.stamp = self.get_clock().now().to_msg() + pose_msg_sr.position.x = vector[0] + pose_msg_sr.position.y = vector[1] + pose_msg_sr.position.z = vector[2] + pose_msg_sr.orientation.x = quaternion[0] + pose_msg_sr.orientation.y = quaternion[1] + pose_msg_sr.orientation.z = quaternion[2] + pose_msg_sr.orientation.w = quaternion[3] + self.pose_publisher_simple_robot_.publish(pose_msg_sr) def publish_pose_target_pose(self, vector, quaternion): # Create a Pose message for the target pose diff --git a/ros2_ws/src/simple_robot_inverse_kinematik/LICENSE b/ros2_ws/src/simple_robot_inverse_kinematik/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..d645695673349e3947e8e5ae42332d0ac3164cd7 --- /dev/null +++ b/ros2_ws/src/simple_robot_inverse_kinematik/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/ros2_ws/src/simple_robot_inverse_kinematik/package.xml b/ros2_ws/src/simple_robot_inverse_kinematik/package.xml new file mode 100644 index 0000000000000000000000000000000000000000..da002a7528997ba7ffd8843caa4ac10a402bb098 --- /dev/null +++ b/ros2_ws/src/simple_robot_inverse_kinematik/package.xml @@ -0,0 +1,41 @@ +<?xml version="1.0"?> +<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> +<package format="3"> + <name>simple_robot_inverse_kinematik</name> + <version>0.0.0</version> + <description>TODO: Package description</description> + <maintainer email="uquzq@student.kit.edu">ventsi</maintainer> + <license>Apache-2.0</license> + + <test_depend>ament_copyright</test_depend> + <test_depend>ament_flake8</test_depend> + <test_depend>ament_pep257</test_depend> + <test_depend>python3-pytest</test_depend> + + + <depend>rclpy</depend> + <depend>robot_state_publisher</depend> + <depend>rviz2</depend> + <depend>joint_state_publisher_gui</depend> + + <depend>builtin_interfaces</depend> + <depend>geometry_msgs</depend> + <depend>kdl_parser</depend> + <depend>orocos_kdl_vendor</depend> + <depend>rcl_interfaces</depend> + <depend>rclcpp</depend> + <depend>rclcpp_components</depend> + <depend>sensor_msgs</depend> + <depend>std_msgs</depend> + <depend>tf2_ros</depend> + <depend>urdf</depend> + + <test_depend>ament_copyright</test_depend> + <test_depend>ament_flake8</test_depend> + <test_depend>ament_pep257</test_depend> + <test_depend>python3-pytest</test_depend> + + <export> + <build_type>ament_python</build_type> + </export> +</package> diff --git a/ros2_ws/src/simple_robot_inverse_kinematik/resource/simple_robot_inverse_kinematik b/ros2_ws/src/simple_robot_inverse_kinematik/resource/simple_robot_inverse_kinematik new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/ros2_ws/src/simple_robot_inverse_kinematik/setup.cfg b/ros2_ws/src/simple_robot_inverse_kinematik/setup.cfg new file mode 100644 index 0000000000000000000000000000000000000000..1682a5ac4c91be175ab79c05b39dacc4fcdf6556 --- /dev/null +++ b/ros2_ws/src/simple_robot_inverse_kinematik/setup.cfg @@ -0,0 +1,4 @@ +[develop] +script_dir=$base/lib/simple_robot_inverse_kinematik +[install] +install_scripts=$base/lib/simple_robot_inverse_kinematik diff --git a/ros2_ws/src/simple_robot_inverse_kinematik/setup.py b/ros2_ws/src/simple_robot_inverse_kinematik/setup.py new file mode 100644 index 0000000000000000000000000000000000000000..6112391abb8bdea92a88de327645862d493ed989 --- /dev/null +++ b/ros2_ws/src/simple_robot_inverse_kinematik/setup.py @@ -0,0 +1,26 @@ +from setuptools import find_packages, setup + +package_name = 'simple_robot_inverse_kinematik' + +setup( + name=package_name, + version='0.0.0', + packages=find_packages(exclude=['test']), + data_files=[ + ('share/ament_index/resource_index/packages', + ['resource/' + package_name]), + ('share/' + package_name, ['package.xml']), + ], + install_requires=['setuptools'], + zip_safe=True, + maintainer='ventsi', + maintainer_email='uquzq@student.kit.edu', + description='TODO: Package description', + license='Apache-2.0', + tests_require=['pytest'], + entry_points={ + 'console_scripts': [ + 'simple_robot_inverse = simple_robot_inverse_kinematik.inverse_kinematik:main', + ], + }, +) diff --git a/ros2_ws/src/simple_robot_inverse_kinematik/simple_robot_inverse_kinematik/__init__.py b/ros2_ws/src/simple_robot_inverse_kinematik/simple_robot_inverse_kinematik/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/ros2_ws/src/simple_robot_inverse_kinematik/simple_robot_inverse_kinematik/inverse_kinematik.py b/ros2_ws/src/simple_robot_inverse_kinematik/simple_robot_inverse_kinematik/inverse_kinematik.py new file mode 100644 index 0000000000000000000000000000000000000000..4abe7a90aa7795ffae9f6fd5e2f4531e13aeeba2 --- /dev/null +++ b/ros2_ws/src/simple_robot_inverse_kinematik/simple_robot_inverse_kinematik/inverse_kinematik.py @@ -0,0 +1,92 @@ +import os +import re + +import rclpy +from rclpy.node import Node +from geometry_msgs.msg import Pose +from sensor_msgs.msg import JointState +from trajectory_msgs.msg import JointTrajectory, JointTrajectoryPoint +from modern_robotics import IKinBody, RpToTrans, FKinBody +import numpy as np +from ament_index_python.packages import get_package_share_directory +from mr_urdf_loader import loadURDF +from scipy.spatial.transform import Rotation +from rclpy.clock import Clock + +class InverseKinematicsSimpleRobot(Node): + def __init__(self): + super().__init__('inverse_kinematics_simple_robot') + self.subscription = self.create_subscription( + Pose, + '/simple_robot/target_pose', + self.pose_callback, + 10) + self.publisher = self.create_publisher(JointState, '/joint_states', 10) + + urdf_file_path = os.path.join( + get_package_share_directory('simple_robot_1dof'), 'urdf', 'simple_robot.urdf') + self.get_logger().info(f'Loading URDF from: {urdf_file_path}') + self.simple_robot = loadURDF(urdf_file_path) + + self.M = self.simple_robot["M"] + self.Slist = self.simple_robot["Slist"] + self.Mlist = self.simple_robot["Mlist"] + self.Glist = self.simple_robot["Glist"] + self.Blist = self.simple_robot["Blist"] + + self.joint_names = [f'joint{i+1}' for i in range(len(self.Slist[0]))] + + self.joint_angles = np.zeros(len(self.Slist[0])) + + T = FKinBody(self.M, self.Blist, self.joint_angles) + rotation_matrix = T[:3, :3] + quat = Rotation.from_matrix(rotation_matrix).as_quat() + position = T[:3, 3] + self.get_logger().info('T: "%s":' %T) + + self.get_logger().info(f'Calculated Forward Kinematics Quaternion: {quat}') + self.get_logger().info(f'Calculated Forward Kinematics Position: {position}') + + def pose_callback(self, pose: Pose): + quat = [pose.orientation.x, pose.orientation.y, pose.orientation.z, pose.orientation.w] + r = Rotation.from_quat(quat) + rotation_matrix = r.as_matrix() + T_sd = RpToTrans(rotation_matrix, np.array([pose.position.x, pose.position.y, pose.position.z])) + eomg = 1e-4 # Fehlergrenze für Winkel + ev = 1e-4 # Fehlergrenze für Translation + + joint_angles, success = IKinBody(self.Blist, self.M, T_sd, self.joint_angles, eomg, ev) + + + if success: + # self.joint_angles = joint_angles + + + joint_state_msg = JointState() + joint_state_msg.header.stamp = Clock().now().to_msg() + joint_state_msg.name = self.joint_names + joint_state_msg.position = joint_angles.tolist() + + # joint_trajectory_msg = JointTrajectory() + # joint_trajectory_msg.joint_names = self.joint_names + # point = JointTrajectoryPoint() + # point.positions = joint_angles.tolist() + # point.time_from_start.sec = 1 # Example time, adjust as needed + # point.time_from_start.nanosec = 450000000 # Balint fragen, ob das verbessert werden kann + # joint_trajectory_msg.points.append(point) + + # self.publisher.publish(joint_trajectory_msg) + self.publisher.publish(joint_state_msg) + else: + self.get_logger().error("Inverse Kinematics failed to find a solution.") + + +def main(args=None): + rclpy.init(args=args) + node = InverseKinematicsSimpleRobot() + rclpy.spin(node) + node.destroy_node() + rclpy.shutdown() + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/ros2_ws/src/simple_robot_inverse_kinematik/test/test_copyright.py b/ros2_ws/src/simple_robot_inverse_kinematik/test/test_copyright.py new file mode 100644 index 0000000000000000000000000000000000000000..97a39196e84db97954341162a6d2e7f771d938c0 --- /dev/null +++ b/ros2_ws/src/simple_robot_inverse_kinematik/test/test_copyright.py @@ -0,0 +1,25 @@ +# Copyright 2015 Open Source Robotics Foundation, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from ament_copyright.main import main +import pytest + + +# Remove the `skip` decorator once the source file(s) have a copyright header +@pytest.mark.skip(reason='No copyright header has been placed in the generated source file.') +@pytest.mark.copyright +@pytest.mark.linter +def test_copyright(): + rc = main(argv=['.', 'test']) + assert rc == 0, 'Found errors' diff --git a/ros2_ws/src/simple_robot_inverse_kinematik/test/test_flake8.py b/ros2_ws/src/simple_robot_inverse_kinematik/test/test_flake8.py new file mode 100644 index 0000000000000000000000000000000000000000..27ee1078ff077cc3a0fec75b7d023101a68164d1 --- /dev/null +++ b/ros2_ws/src/simple_robot_inverse_kinematik/test/test_flake8.py @@ -0,0 +1,25 @@ +# Copyright 2017 Open Source Robotics Foundation, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from ament_flake8.main import main_with_errors +import pytest + + +@pytest.mark.flake8 +@pytest.mark.linter +def test_flake8(): + rc, errors = main_with_errors(argv=[]) + assert rc == 0, \ + 'Found %d code style errors / warnings:\n' % len(errors) + \ + '\n'.join(errors) diff --git a/ros2_ws/src/simple_robot_inverse_kinematik/test/test_pep257.py b/ros2_ws/src/simple_robot_inverse_kinematik/test/test_pep257.py new file mode 100644 index 0000000000000000000000000000000000000000..b234a3840f4c5bd38f043638c8622b8f240e1185 --- /dev/null +++ b/ros2_ws/src/simple_robot_inverse_kinematik/test/test_pep257.py @@ -0,0 +1,23 @@ +# Copyright 2015 Open Source Robotics Foundation, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from ament_pep257.main import main +import pytest + + +@pytest.mark.linter +@pytest.mark.pep257 +def test_pep257(): + rc = main(argv=['.', 'test']) + assert rc == 0, 'Found code style errors / warnings'