Robotics StackExchange | Archived questions

I cannot get the correct robot speed through the /gazebo/get_model_state ros service

I am using ubuntu 16.04 ros-kinetic and gazebo 9.18.0.I test my robot in an empty environment. The following code only sends a 0.5m/s straight walk command to the robot. I get the status of the robot through the /gazebo/getmodelstate service 0.5s after each command is issued.

    self.get_model_srv = rospy.ServiceProxy('/gazebo/get_model_state', GetModelState)
    self.robot_model = GetModelStateRequest()
    self.robot_model.model_name = 'base'
    self.robot_model.relative_entity_name = 'world'
     ....
    def get_model_state(self):
        rospy.wait_for_service('/gazebo/get_model_state')
        try:
             data = self.get_model_srv('base','world')
        except rospy.ServiceException as e:
             print("'/gazebo/get_model_state' service call failed")
             return
        print(data)
     ....
    def step(self, cmd=(0.0, 0.0)):  # cmd v,w
        self.cmd_vel .linear.x = cmd[0]
        self.cmd_vel .angular.z = cmd[1]
        self.pub_akm_twist.publish(self.cmd_vel)
        rospy.sleep(0.5)
        self.get_model_state()
     ....
    for i in range(25000):
          env.step((0.5, 0))

The result I got through the above code is as follows: image description

The result I got through the terminal command is as follows: image description

As you can see, the position of the two results is not much different but the speed is completely different .I also tested the /gazebo/model_states topic callback function to get the robot's state, and the test result was consistent with the command line result without any problems.This makes me very confused, can you help me?

Asked by tou_star on 2022-01-05 08:03:20 UTC

Comments

Answers