Ask Your Question

How to move a ball using ros controllers in Gazebo?

asked 2020-01-03 08:22:27 -0500

mkb_10062949 gravatar image

updated 2022-01-22 16:10:14 -0500

Evgeny gravatar image

How to move a ball using ros-controllers in Gazebo?

Hello I have created a sphere urdf file i.e.,

<?xml version="1.0"?>
<robot name="target_point2_r2">

<!-- conveyor belt is just a long flat box for objects to slide on it -->

<!-- world link -->
<link name="world"/>

<!-- base_link and its fixed joint -->
<joint name="joint_fix" type="fixed">
  <parent link="world"/>
  <child link="base_link"/>
  <axis xyz="1 0 0"/>
  <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/> 

<link name="base_link">


    <origin xyz="0 0 0" rpy="0 0 0"/>
        <sphere radius="0.045"/>
<!-- -0.229794383458 -->
    <origin xyz="0 0 0‬" rpy="0 0 0"/>
    <mass value="1"/>
      ixx="1.0" ixy="0.0" ixz="0.0"
      iyy="1.0" iyz="0.0"

<gazebo reference="base_link">
  <!-- <plugin name="plannar_mover_plugin" filename=""/> -->

  <!-- ROS Control plugin for Gazebo -->
    <plugin name="gazebo_ros_control" filename="">

  <!-- transmission -->
  <transmission name="target_red">
    <actuator name="motor1">
    <joint name="joint_fix">


I want to move it at different positions using ros controllers specifically joint trajectory controller. But I am not sure whether the urdf I have made is correct.

I have also made launch file and a target_controller.yaml file. But when I try to launch the launch file I get this error.,

Traceback (most recent call last):
  File "/opt/ros/melodic/lib/gazebo_ros/spawn_model", line 232, in <module>
    exit_code =
  File "/opt/ros/melodic/lib/gazebo_ros/spawn_model", line 146, in run
    xml_parsed = xml.etree.ElementTree.fromstring(model_xml)
  File "/usr/lib/python2.7/xml/etree/", line 1311, in XML
  File "/usr/lib/python2.7/xml/etree/", line 1657, in feed
    self._parser.Parse(data, 0)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u202c' in position 603: ordinal not in range(128)
[spawn_gazebo_model-2] process has died [pid 2107, exit code 1, cmd /opt/ros/melodic/lib/gazebo_ros/spawn_model -urdf -model target_red -param robot_description -z 0.805 __name:=spawn_gazebo_model __log:=/home/at-lab/.ros/log/6db6e4a6-2e31-11ea-b56e-64006a45f649/spawn_gazebo_model-2.log].
log file: /home/at-lab/.ros/log/6db6e4a6-2e31-11ea-b56e-64006a45f649/spawn_gazebo_model-2*.log

My launch file is,

<?xml version="1.0"?>

 <param name="robot_description" textfile="$(find target_desc)/urdf/target_point2_r2.urdf" />
 <node name="spawn_gazebo_model" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen" args=" -urdf -model 
 target_red -param robot_description -z 0.805" />

<!-- loads the controllers -->
 <rosparam file="$(find target_desc)/config/target_controller.yaml" command="load" />
 <node name="controller_spawner" pkg="controller_manager" type="spawner" ns="/target_red" args="target_red joint_state_controller"/> 

<!-- converts joint states ...
edit retag flag offensive close merge delete


Hello @mkb_10062949, I have the same problem but I am trying to move a rectangle. Have you found the solution? If so, could you please post it?

RayROS gravatar image RayROS  ( 2020-01-10 07:37:03 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2020-01-10 08:18:31 -0500

mkb_10062949 gravatar image

@RayROS Okay my goal was actually to spawn the ball at different positions for that I don't need ros controllers at all. This can be done simply by using gazebo spawn and delete model services for example, I want to spawn the ball at this position and orientation,

import rospy
import rospkg
from gazebo_msgs.srv import *

#name of the model
self.target_green = "target_green"
self.targetPositionONE = np.asarray([-0.0749362396642, -0.233472578779, 0.624066967802]) # Green Ball
self.target_orientationONE = np.asarray([0.976932377427, 0.0165487931393, 0.00360177921781, -0.212876242372]) # arrow looking down [w, x, y, z]

self.target2_pose1 = Pose(Point(x=self.targetPositionONE[0]+0.35,y= self.targetPositionONE[1],z=self.targetPositionONE[2]+0.805), Quaternion(x=self.target_orientationONE[1],y=self.target_orientationONE[2],z=self.target_orientationONE[3],w=self.target_orientationONE[0]))

self.spawner = rospy.ServiceProxy('/gazebo/spawn_urdf_model', SpawnModel)
self.destroyer = rospy.ServiceProxy('/gazebo/delete_model', DeleteModel)
ros_pack_target = rospkg.RosPack()
target2_green_path = ros_pack_target.get_path('ur5_notebook')
target2_green_path += '/target_description/urdf/target_point_Green.urdf'
# Read the urdf file.
with open(target2_green_path, "r") as g:
  self.target2_green_urdf =

#Then when you want to spawn it just call the spawner, self.target2_green_urdf, "", self.target2_pose1, "world")
#When you want to delete the model just do
edit flag offensive delete link more


Perfect thank you very much :)

RayROS gravatar image RayROS  ( 2020-01-13 12:56:54 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-01-03 08:22:27 -0500

Seen: 602 times

Last updated: Jan 10 '20