Python Forum
ROS ROBOTIC MOVEMENT PYTHON
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ROS ROBOTIC MOVEMENT PYTHON
#1
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
Larz60+ write Apr-04-2022, 03:56 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Attached Files

.zip   movedistance.py.zip (Size: 760 bytes / Downloads: 148)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trouble with a turtle movement assignment. JosephSondgeroth 1 1,411 Jan-27-2022, 11:56 PM
Last Post: JosephSondgeroth
  Animating 2D object movement with matplotlib esamalihalil1993 0 1,791 Nov-23-2020, 05:49 PM
Last Post: esamalihalil1993

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020