How to convert x and y velocities to linear.x and angular.z?

asked 2020-10-06 03:20:51 -0500

kjn gravatar image

Hi, I'm trying to control the turtlesim using computed accelerations in the x and y direction.

However, since we are publishing to geometry_msgs/Twist, I can't figure out how to make this work. My initial thought was that I could ignore the angular velocity, and just change and publish the linear.x and linear.y components of the twist message. However, although the x component works how I expect it to, the turtlesim does not move up and down.

This makes me think I need to somehow convert the x and y accelerations into linear.x and angular.z components.

Having set rate = rospy.Rate(30) and using rate.sleep() within my while loop, I know that each time step will be approximately delta_t = (1/30) seconds.

There I calculated the change in x and y components of velocity at each time step by multiplying the components of acceleration, and adding it to the x and y components of the original velocity (obtained by subscribing to the pose of the /turtle1/, taking the angle theta and multiplying linear.x with either sin(theta) or cos(theta))

However, from here, I am completely stuck. I'm thinking I'd need to find a change in angle after the timestep derived from the direction of the new velocity vector, and dividing that change in angle by delta_t to get the rate of change, and set angular.z to that value, but my first attempt at that failed.

This was a convoluted way to say that I'm not really sure how to control the turtlesim using geometry_msgs/Twist. Thank you for the help.

edit retag flag offensive close merge delete