Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Implementation_Details.pdf
Binary file not shown.
57 changes: 57 additions & 0 deletions yadnyesh-24/drawsquare.py
Original file line number Diff line number Diff line change
@@ -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()
32 changes: 32 additions & 0 deletions yadnyesh-24/subscriber.py
Original file line number Diff line number Diff line change
@@ -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()