Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Tried to make a function of co-ordinates and theta constant to operate in 1 flow but it wasn’t

executable.

THE CODE:

#!/usr/bin/env python3

import rclpy

import math

from rclpy.node import Node

from geometry_msgs.msg import Twist

from turtlesim.msg import Pose

class turtle_move(Node):

def _init_(self):

super()._init_('draw_letter')

self.get_logger().info("drawing_letter started")

self.my_pose_sub = self.create_subscription(Pose, "/turtle1/pose", self.pose_callback, 10)

self.my_vel_command = self.create_publisher(Twist, "/turtle1/cmd_vel", 10)

self.final_x = 7.54

self.final_y = 5.54

def pose_callback(self, msg: Pose):

self.get_logger().info(f"Current x={msg.x} current y={msg.y} ")

error_x = self.final_x - msg.x

error_y = self.final_y - msg.y

error_dist = (error_x*2+error_y2)*0.5
self.get_logger().info(f"Error in x {error_x} and error in y {error_y}")

theta = math.atan2(error_y, error_x)

error_theta = theta - msg.theta

while error_theta > math.pi:

error_theta -= 2.0 * math.pi

while error_theta < -math.pi:

error_theta += 2.0 * math.pi

self.get_logger().info(f"final Angle = {theta} current angle {msg.theta} ")

dist_const = 0.5

theta_const = 1

linear_vel = dist_const * abs(error_dist)

angular_vel = theta_const * error_theta s

self.velocity_cont(linear_vel, angular_vel)

def velocity_cont(self, linear_vel, angular_vel):

msg = Twist()

msg.linear.x = linear_vel

msg.angular.z = angular_vel

self.my_vel_command.publish(msg)

def main(args=None):

rclpy.init(args=args)

node = turtle_move()

rclpy.spin(node)

node.destroy_node()

rclpy.shutdown()

if _name_ == '_main_':

main()
Combinations of coordinates and theta constant used :

1. Final_x = 7.54 , final_y = 5.54 , theta_const = 1


2. Final_x =7.54 , final_y =7.54 , , theta_const = 1
3. Final_x = 5.54 , final_y = 7.54 , theta_const = 5
4. Final_x = 5.54 , final_y = 3.54, theta_const = 5
5. Final_x = 7.54 , final_y =3.54, theta_const = 5
6. Final_x = 7.54 , final_y = 5.54, theta_const =1

2.0 WHY ROS2 OVER ROS ??

*ROS2 is a new version of ROS that was developed from scratch to address some of the limitations
and challenges of ROS1.

*Some of the key differences are:

--ROS2 does not require a ROS master node to manage communication which was a single point
failure.

--ROS2 supports multiple programming languages such as C++, Python, Java, Rust, etc.

--ROS2 has improved performance, security, and real-time capabilities.

*The developers are shifting from ROS to ROS2 due to unavailiblity of distributions support such as :

--ROS Noetic was release in 2020 and it's the last ROS1 version having life till may,2025 whereas we
will have new version every year in ROS2 and LTS version in every 2 years.

*ROS was only supported by ubuntu but ROS2 is supported by Ubuntu , Windows and MacOs which
makes ROS2 more accessible and embedded.

*Nodelets in ROS becoming components in ROS2 having almost same functionality.

*The developers used DDS(data distribution system) as the network protocol for all communication
that happens internally in ROS2 to use in critical infrastructures such as battleships.

You might also like