Professional Documents
Culture Documents
robotics
robotics
#!/usr/bin/env python3
import rospy
from geometry_msgs.msg import Twist
from turtlesim.msg import Pose
robot_x = 0
robot_y = 0
def pose_callback(pose):
global robot_x
global robot_y
rospy.loginfo('Robot X = %f\n',pose.x)
rospy.loginfo('Robot Y = %f\n',pose.y)
robot_x = pose.x
robot_y = pose.y
if(ang_vel == 0):
if __name__=='__main__':
try:
move(0,0.5,0,5.5,6.0)
move(-0.5,0,0,5.0,6.0)
move(0,-0.5,0,5.0,5.6)
move(-0.5,0,-0.5,5.5,6.2)
except rospy.ROSInterruptException:
pass
#!/usr/bin/env python3
import rospy
from geometry_msgs.msg import Twist
from turtlesim.msg import Pose
from math import pow, atan2, sqrt
class TurtleBot:
def __init__(self):
rospy.init_node('turtlebot_controller', anonymous=True)
self.velocity_publisher =
rospy.Publisher('/turtle1/cmd_vel',Twist, queue_size=10)
self.pose_subscriber = rospy.Subscriber('/turtle1/pose',Pose,
self.update_pose)
self.pose = Pose()
self.rate = rospy.Rate(10)
self.pose = data
self.pose.x = round(self.pose.x, 4)
self.pose.y = round(self.pose.y, 4)
def euclidean_distance(self, goal_pose):
return sqrt(pow((goal_pose.x - self.pose.x), 2) +
pow((goal_pose.y - self.pose.y), 2))
def move2goal(self):
goal_pose = Pose()
vel_msg = Twist()
while vel
vel_msg.linear.x = self.linear_vel(goal_pose)
vel_msg.linear.y = 0
vel_msg.linear.z = 0
vel_msg.angular.x = 0
vel_msg.angular.y = 0
vel_msg.angular.z = self.angular_vel(goal_pose)
self.velocity_publisher.publish(vel_msg)
self.rate.sleep()
vel_msg.linear.x = 0
vel_msg.angular.z = 0
self.velocity_publisher.publish(vel_msg)
rospy.spin()
if __name__ == '__main__':
try:
x = TurtleBot()
x.move2goal()
except rospy.ROSInterruptException:
pass
turtlesim modified
#!/usr/bin/env python3
import rospy
from geometry_msgs.msg import Twist
from turtlesim.msg import Pose
from math import sqrt , atan2,pow
robot_x = 0
robot_y = 0
def pose_callback(pose):
global robot_x
global robot_y
rospy.loginfo('Robot X = %d\n',pose.x)
rospy.loginfo('Robot Y = %d\n',pose.y)
robot_x = pose.x
robot_y = pose.y
if __name__=='__main__':
try:
move(7,7)
#move(-0.5,0,0,5.0,6.0)
#move(0,-0.5,0,5.0,5.6)
#move(-0.5,0,-0.5,5.5,6.2)
except rospy.ROSInterruptException:
pass
class TurtleBot:
def _init_(self):
rospy.init_node('turtlebot_controller', anonymous=True)
self.velocity_publisher = rospy.Publisher('/turtle1/cmd_vel',
Twist, queue_size=10)
self.pose_subscriber = rospy.Subscriber('/turtle1/pose', Pose,
self.update_pose)
self.pose = Pose()
self.rate = rospy.Rate(10)
def move2goal(self):
init_pose = Pose()
init_pose.x = 0.0
init_pose.y = 0.0
init_pose.theta=-0.5*pi
vel_msg = Twist()
vel_msg.angular.x = 0
vel_msg.angular.y = 0
vel_msg.angular.z = self.angular_vel(goal_pose)
self.velocity_publisher.publish(vel_msg)
self.rate.sleep()
vel_msg.linear.x = 0
vel_msg.angular.z = 0
self.velocity_publisher.publish(vel_msg)
rospy.spin()
if _name_ == '_main_':
try:
x = TurtleBot()
x.move2goal()
except rospy.ROSInterruptException:
pass
import rclpy
from geometry_msgs.msg import Twist
from turtlesim.msg import Pose
robot_x = 0
robot_y = 0
def pose_callback(pose):
rclpy.loginfo('Robot X = %f\n',pose.x)
rclpy.loginfo('Robot Y = %f\n',pose.y)
robot_x = pose.x
robot_y = pose.y
if(ang_vel == 0):
class TurtleBot:
def init(self):
rclpy.init_node('turtlebot_controller', anonymous=True)
self.velocity_publisher = rclpy.Publisher('/turtle1/cmd_vel',
Twist, queue_size=10)
self.pose_subscriber = rclpy.Subscriber('/turtle1/pose', Pose,
self.update_pose)
self.pose = Pose()
self.rate = rclpy.Rate(10)
def move2goal(self):
init_pose = Pose()
init_pose.x = 0.0
init_pose.y = 0.0
init_pose.theta=-0.5*pi
vel_msg = Twist()
distance_tolerance = 0.1
vel_msg.linear.x = self.linear_vel(goal_pose)
vel_msg.linear.y = 0
vel_msg.linear.z = 0
vel_msg.angular.x = 0
vel_msg.angular.y = 0
vel_msg.angular.z = self.angular_vel(goal_pose)
self.velocity_publisher.publish(vel_msg)
self.rate.sleep()
vel_msg.linear.x = 0
vel_msg.angular.z = 0
self.velocity_publisher.publish(vel_msg)
rclpy.spin()
if _name_ == 'main':
try:
x = TurtleBot()
x.move2goal()
except rclpy.ROSInterruptException:
pass