diff --git a/ros2_ws/src/python_parameters/LICENSE b/ros2_ws/src/python_parameters/LICENSE deleted file mode 100644 index d645695673349e3947e8e5ae42332d0ac3164cd7..0000000000000000000000000000000000000000 --- a/ros2_ws/src/python_parameters/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - 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/python_parameters/package.xml b/ros2_ws/src/python_parameters/package.xml deleted file mode 100644 index f3365b2d859e0e8f6fdf11aba64605bf332033a9..0000000000000000000000000000000000000000 --- a/ros2_ws/src/python_parameters/package.xml +++ /dev/null @@ -1,20 +0,0 @@ -<?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>python_parameters</name> - <version>0.0.0</version> - <description>TODO: Package description</description> - <maintainer email="udnpp@student.kit.edu">ventsi</maintainer> - <license>Apache-2.0</license> - - <depend>rclpy</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/python_parameters/python_parameters/__init__.py b/ros2_ws/src/python_parameters/python_parameters/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/ros2_ws/src/python_parameters/python_parameters/velocity_parameter.py b/ros2_ws/src/python_parameters/python_parameters/velocity_parameter.py deleted file mode 100644 index c462f2ad2f15ce4683a354122269218c861f3f6e..0000000000000000000000000000000000000000 --- a/ros2_ws/src/python_parameters/python_parameters/velocity_parameter.py +++ /dev/null @@ -1,34 +0,0 @@ -import rclpy -from rclpy.node import Node -from rclpy.parameter import Parameter -from std_msgs.msg import Float64 - -class VelocityParam(Node): - def __init__(self): - super().__init__('velocity_param_node') - # Declare a parameter named 'velocity' with a default value of 10 - self.declare_parameter('velocity', 10.0) - - self.velocity_publisher_ = self.create_publisher(Float64, '/simple_robot/velocity', 10) - - # Create a timer that triggers the timer_callback every second - # self.timer = self.create_timer(1, self.timer_callback) - self.timer_callback() - - def timer_callback(self): - # Get the current value of the 'velocity' parameter - velocity = self.get_parameter('velocity').value - msg = Float64() - msg.data = velocity - self.velocity_publisher_.publish(msg) - self.get_logger().info(f'Current velocity: {msg.data}') - -def main(): - rclpy.init() - node = VelocityParam() - rclpy.spin(node) - node.destroy_node() - rclpy.shutdown() - -if __name__ == '__main__': - main() diff --git a/ros2_ws/src/python_parameters/resource/python_parameters b/ros2_ws/src/python_parameters/resource/python_parameters deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/ros2_ws/src/python_parameters/setup.cfg b/ros2_ws/src/python_parameters/setup.cfg deleted file mode 100644 index 82e18be1be03b85ab636b0c8d0ed3fdc1b13a00b..0000000000000000000000000000000000000000 --- a/ros2_ws/src/python_parameters/setup.cfg +++ /dev/null @@ -1,4 +0,0 @@ -[develop] -script_dir=$base/lib/python_parameters -[install] -install_scripts=$base/lib/python_parameters diff --git a/ros2_ws/src/python_parameters/setup.py b/ros2_ws/src/python_parameters/setup.py deleted file mode 100644 index 3d6eff6ca73a84c6786f1c23aa2be0573f0d8aab..0000000000000000000000000000000000000000 --- a/ros2_ws/src/python_parameters/setup.py +++ /dev/null @@ -1,26 +0,0 @@ -from setuptools import find_packages, setup - -package_name = 'python_parameters' - -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='udnpp@student.kit.edu', - description='TODO: Package description', - license='Apache-2.0', - tests_require=['pytest'], - entry_points={ - 'console_scripts': [ - 'velocity_param_node = python_parameters.velocity_parameter:main', - ], - }, -) diff --git a/ros2_ws/src/python_parameters/test/test_copyright.py b/ros2_ws/src/python_parameters/test/test_copyright.py deleted file mode 100644 index 97a39196e84db97954341162a6d2e7f771d938c0..0000000000000000000000000000000000000000 --- a/ros2_ws/src/python_parameters/test/test_copyright.py +++ /dev/null @@ -1,25 +0,0 @@ -# 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/python_parameters/test/test_flake8.py b/ros2_ws/src/python_parameters/test/test_flake8.py deleted file mode 100644 index 27ee1078ff077cc3a0fec75b7d023101a68164d1..0000000000000000000000000000000000000000 --- a/ros2_ws/src/python_parameters/test/test_flake8.py +++ /dev/null @@ -1,25 +0,0 @@ -# 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/python_parameters/test/test_pep257.py b/ros2_ws/src/python_parameters/test/test_pep257.py deleted file mode 100644 index b234a3840f4c5bd38f043638c8622b8f240e1185..0000000000000000000000000000000000000000 --- a/ros2_ws/src/python_parameters/test/test_pep257.py +++ /dev/null @@ -1,23 +0,0 @@ -# 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' 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 a7343c2abb72c3c83dcee760c427ece180cd383c..05e75e71b508ab6e18fba33595758d2bd511ffe8 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 @@ -1,8 +1,10 @@ import os from launch import LaunchDescription from launch_ros.actions import Node -from launch.actions import ExecuteProcess +from launch.actions import ExecuteProcess, DeclareLaunchArgument from ament_index_python.packages import get_package_share_directory +from launch.substitutions import LaunchConfiguration + def generate_launch_description(): @@ -14,7 +16,28 @@ def generate_launch_description(): 'forward_kinematics_simulations.rviz' ) + velocity1_launch_arg = DeclareLaunchArgument('velocity1', default_value = '0.01') # constant: 0.015 acceleration: 0.005 + velocity1 = LaunchConfiguration('velocity1') + + velocity2_launch_arg = DeclareLaunchArgument('velocity2', default_value = '0.03') + velocity2 = LaunchConfiguration('velocity2') + + velocity3_launch_arg = DeclareLaunchArgument('velocity3', default_value = '0.005') + velocity3 = LaunchConfiguration('velocity3') + + slope_launch_arg = DeclareLaunchArgument('slope', default_value = '0.25') # [0 ; 0.5] + slope = LaunchConfiguration('slope') + + velocity_constant_launch_arg = DeclareLaunchArgument('velocity_constant', default_value = '0.015') + velocity_constant = LaunchConfiguration('velocity_constant') + + return LaunchDescription([ + velocity1_launch_arg, + velocity2_launch_arg, + slope_launch_arg, + velocity3_launch_arg, + velocity_constant_launch_arg, Node( package = package_name, executable = 'forward_kinematics_node_1dof', @@ -27,7 +50,13 @@ def generate_launch_description(): executable = 'reference_node_1dof', name = 'reference_node', output = 'screen', - parameters = [] + parameters = [ + {'velocity1': velocity1}, + {'velocity2': velocity2}, + {'velocity3': velocity3}, + {'velocity_constant': velocity_constant}, + {'slope': slope} + ] ), Node( package='rviz2', @@ -36,12 +65,6 @@ def generate_launch_description(): output='screen', arguments=['-d', rviz_config_file] ), - # Node( - # package = 'python_parameters', - # executable='velocity_param_node', - # name='velocity_param_node', - # output='screen' - # ) Node( package= 'iiwa_inverse_kinematics', executable='inverse_kinematics_node', diff --git a/ros2_ws/src/simple_robot_1dof/setup.py b/ros2_ws/src/simple_robot_1dof/setup.py index 6aae5652cbc53e2ce9519ea01d9ec08d9dd83523..193051f60cac3dafba068325cb54e0423ccc79a5 100644 --- a/ros2_ws/src/simple_robot_1dof/setup.py +++ b/ros2_ws/src/simple_robot_1dof/setup.py @@ -1,4 +1,6 @@ from setuptools import find_packages, setup +import os +from glob import glob package_name = 'simple_robot_1dof' @@ -12,6 +14,7 @@ setup( ('share/' + package_name, ['package.xml']), ('share/' + package_name + '/launch', ['launch/kuka_rviz_simulation_1dof_launch.py']), ('share/' + package_name + '/rviz', ['rviz/forward_kinematics_simulations.rviz']), + (os.path.join('share', package_name, 'launch'), glob(os.path.join('launch', '*launch.[pxy][yma]*'))) ], install_requires=['setuptools'], zip_safe=True, @@ -24,6 +27,7 @@ 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 0bd56f23a891ab4d9d9b4c5024ee1320a3f4133f..2e8b6d2b75741680b94bebc25775fecc972f913e 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 @@ -13,6 +13,7 @@ from geometry_msgs.msg import Pose from visualization_msgs.msg import Marker import transformations from scipy.spatial.transform import Rotation +import time class Forward_Kinematics_Node_1Dof(Node): @@ -47,10 +48,15 @@ class Forward_Kinematics_Node_1Dof(Node): self.path.header.frame_id = "map" self.path.header.stamp = self.get_clock().now().to_msg() + self.index = 0 + def listener_callback(self, msg): # Get the message self.phi = msg.data # call the transformation function + if self.phi == 0: + self.index += 1 + self.transformation() def transformation(self): @@ -83,14 +89,14 @@ class Forward_Kinematics_Node_1Dof(Node): end_position = end_forward_kinematics[:4, 3] end_orientation = Rotation.from_matrix(end_forward_kinematics[:3, :3]).as_quat() - - # Calculate the intermediate vectors - intermediate_vector = np.matmul(intermediate_rotation, start_position) - + + self.publish_pose_simple_robot(end_position, end_orientation) - self.publish_pose_target_pose(end_position, end_orientation) + + if self.index == 1: + self.publish_pose_target_pose(end_position, end_orientation) - self.construct_path(intermediate_vector) + self.construct_path(end_position) def construct_path(self, vector): # RViz @@ -164,6 +170,8 @@ class Forward_Kinematics_Node_1Dof(Node): pose_msg.orientation.z = quaternion[2] pose_msg.orientation.w = quaternion[3] self.pose_publisher_kuka_robot_.publish(pose_msg) + # if self.phi == 0.0: + # time.sleep(2) def main(args = None): diff --git a/ros2_ws/src/simple_robot_1dof/simple_robot_1dof/reference_node_1dof.py b/ros2_ws/src/simple_robot_1dof/simple_robot_1dof/reference_node_1dof.py index bcb4def714e3d481e1fe89842663b6b7420b7d73..2456a00c2ef55e89cf060c5d0d96823d0e558801 100644 --- a/ros2_ws/src/simple_robot_1dof/simple_robot_1dof/reference_node_1dof.py +++ b/ros2_ws/src/simple_robot_1dof/simple_robot_1dof/reference_node_1dof.py @@ -12,12 +12,28 @@ class Reference_Node_1DoF(Node): super().__init__('reference_node_1dof') #Create a publisher sending the vector as a message self.publisher_ = self.create_publisher(Float64, '/dof1/reference_angles', 10) - timer_period = 0.1 # seconds - self.timer = self.create_timer(timer_period, self.ref_point_publisher) + + self.declare_parameter('velocity1', 0.0) + self.declare_parameter('velocity2', 0.0) + self.declare_parameter('velocity3', 0.0) + self.declare_parameter('velocity_constant', 0.0) + self.declare_parameter('slope', 0.0) + + self.velocity1 = self.get_parameter('velocity1').get_parameter_value().double_value + self.velocity2 = self.get_parameter('velocity2').get_parameter_value().double_value + self.velocity3 = self.get_parameter('velocity3').get_parameter_value().double_value + self.velocity_constant = self.get_parameter('velocity_constant').get_parameter_value().double_value + self.slope = self.get_parameter('slope').get_parameter_value().double_value + self.phi_start = 0.0 self.phi_end = 1.0 self.phi = self.phi_start - self.delta = 0.005 + self.delta = self.velocity_constant + + self.constant_speed = False + + self.timer_period = 0.1 # seconds + self.timer = self.create_timer(self.timer_period, self.ref_point_publisher) # List the points def ref_point_publisher(self): @@ -25,12 +41,21 @@ class Reference_Node_1DoF(Node): # Interpolate between x_0 - x_1 msg = Float64() - self.phi = self.phi + self.delta - + + if self.constant_speed == True: + self.phi = self.phi + self.delta + elif self.constant_speed == False: + if self.phi < self.slope: + self.phi = self.phi + self.velocity1 + elif self.phi > 1 - self.slope: + self.phi = self.phi + self.velocity3 + else: + self.phi = self.phi + self.velocity2 + #setting back to 0 if self.phi>self.phi_end: self.phi = self.phi_start - #self.get_logger().info('Resetting "%f"' % self.phi) + # self.get_logger().info('Resetting "%f"' % self.phi) msg.data = self.phi self.publisher_.publish(msg) diff --git a/ros2_ws/src/simple_robot_1dof/simple_robot_1dof/reference_node_1dof_velocity.py b/ros2_ws/src/simple_robot_1dof/simple_robot_1dof/reference_node_1dof_velocity.py deleted file mode 100644 index b85f85f5eaa2d576bfccb02416120e1661b05c19..0000000000000000000000000000000000000000 --- a/ros2_ws/src/simple_robot_1dof/simple_robot_1dof/reference_node_1dof_velocity.py +++ /dev/null @@ -1,63 +0,0 @@ -import rclpy -from rclpy.node import Node -import numpy as np -from std_msgs.msg import Float64 -from geometry_msgs.msg import Point, PoseStamped -import time - - -class Reference_Node_1DoF_Velocity(Node): - - def __init__(self): - super().__init__('reference_node_1dof_velocity') - self.subscription = self.create_subscription( - Float64, - '/simple_robot/velocity', - self.listener_callback, - 10) - #Create a publisher sending the vector as a message - self.publisher_ = self.create_publisher(Float64, '/dof1/reference_angles', 10) - # timer_period = 0.05 # seconds - # self.timer = self.create_timer(timer_period, self.ref_point_publisher) - # self.phi_start = 0.0 - # self.phi_end = 1.0 - # self.phi = self.phi_start - # self.delta = 0.005 - # # List the points - - def listener_callback(self, msg): - velocity = msg.data - timer_period = 1 / velocity # seconds - self.timer = self.create_timer(timer_period, self.ref_point_publisher) - self.phi_start = 0.0 - self.phi_end = 1.0 - self.phi = self.phi_start - self.delta = 0.005 - # List the points - - - def ref_point_publisher(self): - # Ref position over the time - # Interpolate between x_0 - x_1 - - msg = Float64() - self.phi = self.phi + self.delta - - #setting back to 0 - if self.phi>self.phi_end: - self.phi = self.phi_start - #self.get_logger().info('Resetting "%f"' % self.phi) - - msg.data = self.phi - self.publisher_.publish(msg) - - -def main(args = None): - rclpy.init(args = args) - node = Reference_Node_1DoF_Velocity() - rclpy.spin(node) - node.destroy_node() - rclpy.shutdown() - -if __name__ == '__main__': - main() \ No newline at end of file