![]() |
ROS ROBOTIC MOVEMENT PYTHON - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: ROS ROBOTIC MOVEMENT PYTHON (/thread-36834.html) |
ROS ROBOTIC MOVEMENT PYTHON - frkndmrsln - Apr-04-2022 https://prnt.sc/kQJCg6V_GdRE Hello everyone. As seen in the image, the Robot will start from the top and follow a certain path. At the end of the movement, it will stop in the lower and middle part. I can move the robot but I cannot direct it down. I'm running on Ubuntu My code #!/usr/bin/env python #chmod u+x ~/catkin_ws/src/beginner_tutorials/src/movedistance.py import rospy import sys from geometry_msgs.msg import Twist #nodeid = str(sys.argv[1]) #nodename = "turtle" + nodeid def moveRobot(vel_x, vel_y, vel_z,distance): rospy.init_node('move') pub = rospy.Publisher("/turtle1/cmd_vel", Twist, queue_size=10) vel_msg = Twist() vel_msg.linear.x = vel_x vel_msg.linear.y = vel_y vel_msg.linear.z = 0 vel_msg.angular.x = 0 vel_msg.angular.y = 0 vel_msg.angular.z = vel_z rate=rospy.Rate(10) rospy.loginfo("Moving into distance ...") t0 = rospy.Time.now().to_sec() current_distance = 0 while current_distance < distance: pub.publish(vel_msg) t1 = rospy.Time.now().to_sec() current_distance = vel_msg.linear.x * (t1-t0) rate.sleep() def git(): moveRobot(0.3, 0, 0,1) moveRobot(0, -0.3, 0,2) #vel_msg.linear.x = 0.0 #stop robot #vel_msg.angular.z = 0.0 #stop robot #spub.publish(vel_msg) if __name__ == "__main__": try: git() except rospy.ROSInterruptException: pass |