From 39621a239bf4a9d68a43bb2b7e90d28c8987d84c Mon Sep 17 00:00:00 2001 From: Jugal Pahuja Date: Mon, 26 May 2025 18:41:01 +0530 Subject: [PATCH] Assignment 1 by Jugal Pahuja --- README.md | 9 --- ...tics_Autonomous_Navigation_Assignment_1.py | 66 +++++++++++++++++++ 2 files changed, 66 insertions(+), 9 deletions(-) delete mode 100644 README.md create mode 100644 submissions/Jugal-Pahuja/Assignment-1/Robotics_Autonomous_Navigation_Assignment_1.py diff --git a/README.md b/README.md deleted file mode 100644 index 814030a..0000000 --- a/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# AutoNav2025 - -1. Fork this GitHub repo. -2. Clone your forked repo to your laptop locally. -3. Make a folder with of format 'yourname'. -4. Copy your Python files into the folder -5. Stage and commit your Python file to your local repository. -6. Push whatever you have done into your forked branch. -7. Click "New pull request", add a title name_assignment1_submission, then submit. diff --git a/submissions/Jugal-Pahuja/Assignment-1/Robotics_Autonomous_Navigation_Assignment_1.py b/submissions/Jugal-Pahuja/Assignment-1/Robotics_Autonomous_Navigation_Assignment_1.py new file mode 100644 index 0000000..10bf823 --- /dev/null +++ b/submissions/Jugal-Pahuja/Assignment-1/Robotics_Autonomous_Navigation_Assignment_1.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 +import rclpy +from rclpy.node import Node +from geometry_msgs.msg import Twist + +class DrawSquareNode(Node): + def _init_(self): + super()._init_("draw_square") + self.cmd_vel_pub_=self.create_publisher(Twist,'/turtle1/cmd_vel',10) + self.timer_=self.create_timer(2,self.send_velocity_command) + self.state="move" + self.get_logger().info("Draw square node has been started.") + + def send_velocity_command(self): + msg=Twist() + if (self.state=="move"): + msg.linear.x=1.5 + msg.angular.z=0.0 + self.cmd_vel_pub_.publish(msg) + self.state="turn_right" + elif (self.state=="turn_right"): + msg.linear.x=0.0 + msg.angular.z=1.5707963267948966 + self.cmd_vel_pub_.publish(msg) + self.state="move" + +def main(args=None): + rclpy.init(args=args) + node=DrawSquareNode() + rclpy.spin(node) + rclpy.shutdown() + +if (_name=='main_'): + main() + +#above code is for drawing square and below code is to count the squares + +#!/usr/bin/env python3 +import rclpy +from rclpy.node import Node +from turtlesim.msg import Pose + +class DrawSquareSubcriberNode(Node): + def _init_(self): + super()._init_("count_squares") + self.draw_square_subscribe_=self.create_subscription(Pose,"/turtle1/pose",self.pose_callback,10) + self.prev_theta=None + self.no_of_squares=0 + + def pose_callback(self,msg:Pose): + current_theta=msg.theta + if (self.prev_theta is not None): + if (current_theta>0 and self.prev_theta<0): + self.no_of_squares=self.no_of_squares+1 + self.get_logger().info(f"Number of Squares {self.no_of_squares}") + self.prev_theta=current_theta + + +def main(args=None): + rclpy.init(args=args) + node=DrawSquareSubcriberNode() + rclpy.spin(node) + rclpy.shutdown() + +if (_name=="main_"): + main() \ No newline at end of file