From 5b7dbdd5d63d609c2aebd19290f55f2a70aa810c Mon Sep 17 00:00:00 2001 From: Rudraksh919 Date: Wed, 10 Sep 2025 03:36:40 +0530 Subject: [PATCH 1/4] test code added --- a.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 a.cpp diff --git a/a.cpp b/a.cpp new file mode 100644 index 0000000..1e47c30 --- /dev/null +++ b/a.cpp @@ -0,0 +1,9 @@ +#include + +using namespace std; + +int main() +{ + cout << "Hello, World!"; + return 0; +} \ No newline at end of file From c9dd1afd4c0d840e86f48701c209cf5895b136f6 Mon Sep 17 00:00:00 2001 From: Rudraksh Date: Wed, 10 Sep 2025 03:38:17 +0530 Subject: [PATCH 2/4] username changed --- a.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/a.cpp b/a.cpp index 1e47c30..c02c2ec 100644 --- a/a.cpp +++ b/a.cpp @@ -4,6 +4,6 @@ using namespace std; int main() { - cout << "Hello, World!"; + return 0; } \ No newline at end of file From d246acfa2d591c27ffe8495fe08c6992f57b8648 Mon Sep 17 00:00:00 2001 From: Rudraksh Date: Wed, 10 Sep 2025 03:39:09 +0530 Subject: [PATCH 3/4] test code removed --- a.cpp | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 a.cpp diff --git a/a.cpp b/a.cpp deleted file mode 100644 index c02c2ec..0000000 --- a/a.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include - -using namespace std; - -int main() -{ - - return 0; -} \ No newline at end of file From 5f456cf68c899b9910eee6fa5668294abc2bca8e Mon Sep 17 00:00:00 2001 From: Rudraksh Date: Wed, 10 Sep 2025 20:12:26 +0530 Subject: [PATCH 4/4] Rudraksh Kumawat 240891 --- 240891/readme.md | 17 ++++++ 240891/src/turtle_pub/package.xml | 18 ++++++ 240891/src/turtle_pub/resource/turtle_pub | 0 240891/src/turtle_pub/setup.cfg | 4 ++ 240891/src/turtle_pub/setup.py | 26 ++++++++ 240891/src/turtle_pub/test/test_copyright.py | 25 ++++++++ 240891/src/turtle_pub/test/test_flake8.py | 25 ++++++++ 240891/src/turtle_pub/test/test_pep257.py | 23 +++++++ 240891/src/turtle_pub/turtle_pub/__init__.py | 0 240891/src/turtle_pub/turtle_pub/client.py | 64 ++++++++++++++++++++ 10 files changed, 202 insertions(+) create mode 100644 240891/readme.md create mode 100644 240891/src/turtle_pub/package.xml create mode 100644 240891/src/turtle_pub/resource/turtle_pub create mode 100644 240891/src/turtle_pub/setup.cfg create mode 100644 240891/src/turtle_pub/setup.py create mode 100644 240891/src/turtle_pub/test/test_copyright.py create mode 100644 240891/src/turtle_pub/test/test_flake8.py create mode 100644 240891/src/turtle_pub/test/test_pep257.py create mode 100644 240891/src/turtle_pub/turtle_pub/__init__.py create mode 100644 240891/src/turtle_pub/turtle_pub/client.py diff --git a/240891/readme.md b/240891/readme.md new file mode 100644 index 0000000..76c2eac --- /dev/null +++ b/240891/readme.md @@ -0,0 +1,17 @@ +# Assignment 1 + +## Instructions to Run the Code + +### Terminal 1 +Start the **turtlesim node**: + +```bash +ros2 run turtlesim turtlesim_node +``` +### Terminal 2 + +```bash +colcon build +source install/setup.bash +ros2 run turtle_pub client +``` \ No newline at end of file diff --git a/240891/src/turtle_pub/package.xml b/240891/src/turtle_pub/package.xml new file mode 100644 index 0000000..ffecf54 --- /dev/null +++ b/240891/src/turtle_pub/package.xml @@ -0,0 +1,18 @@ + + + + turtle_pub + 0.0.0 + TODO: Package description + astroboy + TODO: License declaration + + ament_copyright + ament_flake8 + ament_pep257 + python3-pytest + + + ament_python + + diff --git a/240891/src/turtle_pub/resource/turtle_pub b/240891/src/turtle_pub/resource/turtle_pub new file mode 100644 index 0000000..e69de29 diff --git a/240891/src/turtle_pub/setup.cfg b/240891/src/turtle_pub/setup.cfg new file mode 100644 index 0000000..a84b69e --- /dev/null +++ b/240891/src/turtle_pub/setup.cfg @@ -0,0 +1,4 @@ +[develop] +script_dir=$base/lib/turtle_pub +[install] +install_scripts=$base/lib/turtle_pub diff --git a/240891/src/turtle_pub/setup.py b/240891/src/turtle_pub/setup.py new file mode 100644 index 0000000..87a2c62 --- /dev/null +++ b/240891/src/turtle_pub/setup.py @@ -0,0 +1,26 @@ +from setuptools import find_packages, setup + +package_name = 'turtle_pub' + +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='astroboy', + maintainer_email='rudrakshkumawat919@gmail.com', + description='TODO: Package description', + license='TODO: License declaration', + tests_require=['pytest'], + entry_points={ + 'console_scripts': [ + 'client = turtle_pub.client:main' + ], + }, +) diff --git a/240891/src/turtle_pub/test/test_copyright.py b/240891/src/turtle_pub/test/test_copyright.py new file mode 100644 index 0000000..97a3919 --- /dev/null +++ b/240891/src/turtle_pub/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/240891/src/turtle_pub/test/test_flake8.py b/240891/src/turtle_pub/test/test_flake8.py new file mode 100644 index 0000000..27ee107 --- /dev/null +++ b/240891/src/turtle_pub/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/240891/src/turtle_pub/test/test_pep257.py b/240891/src/turtle_pub/test/test_pep257.py new file mode 100644 index 0000000..b234a38 --- /dev/null +++ b/240891/src/turtle_pub/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' diff --git a/240891/src/turtle_pub/turtle_pub/__init__.py b/240891/src/turtle_pub/turtle_pub/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/240891/src/turtle_pub/turtle_pub/client.py b/240891/src/turtle_pub/turtle_pub/client.py new file mode 100644 index 0000000..54fa0b1 --- /dev/null +++ b/240891/src/turtle_pub/turtle_pub/client.py @@ -0,0 +1,64 @@ +import rclpy +from rclpy.node import Node +from turtlesim.srv import TeleportAbsolute +from geometry_msgs.msg import Twist + + +class TurtleController(Node): + def __init__(self): + super().__init__('turtle_controller') + + # Service client for teleportation + self.teleport_cli = self.create_client(TeleportAbsolute, '/turtle1/teleport_absolute') + while not self.teleport_cli.wait_for_service(timeout_sec=1.0): + self.get_logger().info('Waiting for teleport service...') + + # Publisher for circular motion + self.pub = self.create_publisher(Twist, '/turtle1/cmd_vel', 10) + + def teleport(self, x, y, theta): + request = TeleportAbsolute.Request() + request.x = float(x) + request.y = float(y) + request.theta = float(theta) + + future = self.teleport_cli.call_async(request) + rclpy.spin_until_future_complete(self, future) + + if future.result() is not None: + self.get_logger().info(f"Turtle teleported to x={x}, y={y}, theta={theta}") + else: + self.get_logger().error("Teleportation failed") + + def move_in_circle(self, r, v): + twist = Twist() + twist.linear.x = float(v) + twist.angular.z = float(v) / float(r) + + self.get_logger().info(f"Starting circular motion: radius={r}, velocity={v}, angular={twist.angular.z}") + + while rclpy.ok(): # Keep publishing until shutdown + self.pub.publish(twist) + + +def main(args=None): + rclpy.init(args=args) + node = TurtleController() + + # Step 1: Teleport the turtle + x = input("Enter x : ") + y = input("Enter y : ") + theta = input("Enter theta : ") + node.teleport(x, y, theta) + + # Step 2: Move in a circle + r = float(input("Enter radius: ")) + v = float(input("Enter velocity: ")) + node.move_in_circle(r, v) + + node.destroy_node() + rclpy.shutdown() + + +if __name__ == '__main__': + main()