ros-mobile-robots / diffbot

DiffBot is an autonomous 2wd differential drive robot using ROS Noetic on a Raspberry Pi 4 B. With its SLAMTEC Lidar and the ROS Control hardware interface it's capable of navigating in an environment using the ROS Navigation stack and making use of SLAM algorithms to create maps of unknown environments.
https://ros-mobile-robots.com
BSD 3-Clause "New" or "Revised" License
275 stars 82 forks source link

Robot spawns in the world origin, not at specified x,y,z location specified in gazebo_ros spawn_model #57

Closed fjp closed 2 years ago

fjp commented 2 years ago

Running the following launch file results in spawning the robot in the origin (x, y, z= 0, 0, 0) of the world, even though the x, y, z location is set to non zero values in diffbot_gazebo/launch/diffbot_view.launch.

roslaunch diffbot_gazebo diffbot.launch

image

fjp commented 2 years ago

It appears that the PID gains aren't tuned correctly. The change in commit 4b308a5a0b60e0c8210a7dc20804a5867016ab62 lead to this issue.

After tuning the gains correctly or, alternatively, not loading the pid.yaml file in diffbo_control.launch can solve this issue.

https://github.com/ros-mobile-robots/diffbot/blob/a018318c368fc3d637aec62c9e5d1ad1efde7ccd/diffbot_control/launch/diffbot_control.launch#L13-L14

When not using the pid.yaml file, and therefore not setting the pid gains, the following error will appear in Gazebo:

[ERROR] [1644167650.124120487, 0.370000000]: No p gain specified for pid.  Namespace: /diffbot/gazebo_ros_control/pid_gains/front_right_wheel_joint
[ERROR] [1644167650.124597413, 0.370000000]: No p gain specified for pid.  Namespace: /diffbot/gazebo_ros_control/pid_gains/front_left_wheel_joint

To avoid this error I prefer to make use of pid.yaml and tune the gains correctly.

Issue https://github.com/ros-simulation/gazebo_ros_pkgs/issues/886 explains what happens when the pid gains are set/not set:

I had the same question some weeks ago, and I think I understood what is happening. The point is that Gazebo allows you to use position and velocity control interfaces in a flexible way:

  • if you do not specify the gains: when setting the position (velocity) command, the function SetPosition (SetParam) is used (see here and here). This should mean that the command is applied exactly, and therefore I think the dynamics will not be taken into account.
  • you do specify gains: when you set a position (velocity) command, for each motor an effort is computed via the PID and the command is passed to SetForce (see here and here). Here you have a more realistic simulation that takes into account robot's dynamics.

The reason why you get a weird behavior is probably that the gains are not well tuned. I would also consider adding gravity compensation for the manipulator (there should be a plugin in Gazebo doing it). Otherwise, if you do not care about the dynamics, simply unset the PID gains and forget about the error!

Related answer: https://answers.ros.org/question/293830/what-is-the-fix-for-no-p-gain-specified-for-pid-namespace-gazebo_ros_controlpid_gainsback_right_wheel_joint-ros-melodic/