ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to change the orientation of a robot

asked 2020-11-13 02:52:03 -0600

Qilos gravatar image

Hello guys, i have a problem with my simulation. I wanna learn a robot to navigate via reinforcement learning and that the robot generalizes better i wanted the robot to have multiple start locations which get picked randomly

But i got the issue that even though my code sets the orientation yaw angle the robot always faces the same direction at each point

Here is the function i wrote to set the pose of the robot:

def reset_pose():

state_msg = ModelState()
state_msg.model_name = 'pepper_MP'

n_pose=range(4)

choice= random.choice(n_pose)

if choice == 0:
    x=0
    y=0
    z=3.14
if choice == 1:
    x=-7
    y=4
    z=-1
if choice == 2:
    x=1
    y=4
    z=3.7
if choice == 3:
    x=-7
    y=-4
    z=0.7

state_msg.pose.position.x = x
state_msg.pose.position.y = y
state_msg.pose.position.z = 0
state_msg.pose.orientation.x = 0
state_msg.pose.orientation.y = 0
state_msg.pose.orientation.z = z
state_msg.pose.orientation.w = 0


rospy.wait_for_service('/gazebo/set_model_state')
try:
    set_state = rospy.ServiceProxy('/gazebo/set_model_state', SetModelState)
    resp = set_state( state_msg )
    return x,y
except rospy.ServiceException:
    print ("Service call failed: %s")

The x and y coordinate get set correct but the state_msg.pose.orientation doesnt get set correctly

edit retag flag offensive close merge delete

Comments

Doesn't state_msg.pose.orientation.w also need to be changed?

miura gravatar image miura  ( 2020-11-13 04:59:01 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-11-13 07:02:54 -0600

shiraz_baig gravatar image

when you are dealing with angles you need to use quaternions. A quaternion expresses the RPY values into 4 parameters (x,y,z,w). You should use these in the set state commands. You need to call following function to convert RPY values into quaternion. tf2::Quaternion myQuaternion; myQuaternion.setRPY( r, p, y ) Here is a good tutorial for converting RPY values into quaternion values. http://wiki.ros.org/tf2/Tutorials/Qua...

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-11-13 02:52:03 -0600

Seen: 788 times

Last updated: Nov 13 '20