diff --git a/Implementation_Details.pdf b/Implementation_Details.pdf new file mode 100644 index 0000000..7b7913a Binary files /dev/null and b/Implementation_Details.pdf differ diff --git a/yadnyesh-24/drawsquare.py b/yadnyesh-24/drawsquare.py new file mode 100755 index 0000000..94ed41b --- /dev/null +++ b/yadnyesh-24/drawsquare.py @@ -0,0 +1,57 @@ +import rclpy +from rclpy.node import Node +from std_msgs.msg import String +from geometry_msgs.msg import Twist +import math +import time +from std_msgs.msg import Int32 + + +class drawsquare(Node): + + def __init__(self): + super().__init__('drawsquare') + self.publisher_ = self.create_publisher(Twist, '/turtle1/cmd_vel', 10) + self.count = self.create_publisher(Int32, 'pose', 10) + go=Twist() + go.linear.x=3.0 + go.angular.z=0.0 + turn=Twist() + turn.linear.x=0.0 + turn.angular.z=math.pi/2 + self.i=0 + + while True : + self.publisher_.publish(go) + time.sleep(2) + self.publisher_.publish(turn) + time.sleep(1) + self.publisher_.publish(go) + time.sleep(2) + self.publisher_.publish(turn) + time.sleep(1) + self.publisher_.publish(go) + time.sleep(2) + self.publisher_.publish(turn) + time.sleep(1) + self.publisher_.publish(go) + time.sleep(2) + self.publisher_.publish(turn) + time.sleep(1) + self.i=self.i+1 + msg=Int32() + msg.data=self.i + self.count.publish(msg) + + +def main(args=None): + + rclpy.init(args=args) + node = drawsquare() + drawsquare + drawsquare.destroy_node() + rclpy.shutdown() + + +if __name__ == '__main__': + main() diff --git a/yadnyesh-24/subscriber.py b/yadnyesh-24/subscriber.py new file mode 100755 index 0000000..16a1a4d --- /dev/null +++ b/yadnyesh-24/subscriber.py @@ -0,0 +1,32 @@ +import rclpy +from rclpy.node import Node +from std_msgs.msg import Int32 + + +class count(Node): + + def __init__(self): + super().__init__('count') + self.subscription = self.create_subscription( + Int32, + 'pose', + self.listener_callback, + 10) + self.subscription # prevent unused variable warning + + def listener_callback(self, msg): + self.get_logger().info('Number of turns moved: "%s"' % msg.data) + + +def main(args=None): + rclpy.init(args=args) + + node = count() + + rclpy.spin(node) + node.destroy_node() + rclpy.shutdown() + + +if __name__ == '__main__': + main()