Ask Your Question
0

How to move a ball using ros controllers in Gazebo?

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

mkb_10062949 gravatar image

updated 2020-01-03 14:14:14 -0600

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"/> 
</joint>


<link name="base_link">

  <visual>

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

<gazebo reference="base_link">
  <transparency>0.9</transparency>
  <mu1>2</mu1>
  <mu2>2</mu2>
  <material>Gazebo/Red</material>
  <!-- <plugin name="plannar_mover_plugin" filename="libplannar_mover_plugin.so"/> -->
</gazebo>


  <!-- ROS Control plugin for Gazebo -->
  <gazebo>
    <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
      <robotNamespace>target_red</robotNamespace>
    </plugin>
  </gazebo>

  <!-- transmission -->
  <transmission name="target_red">
    <type>transmission_interface/SimpleTransmission</type>
    <actuator name="motor1">
      <mechanicalReduction>1</mechanicalReduction>
    </actuator>
    <joint name="joint_fix">
      <hardwareInterface>PositionJointInterface</hardwareInterface>
    </joint>
  </transmission>
</robot>

</robot>

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 = sm.run()
  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/ElementTree.py", line 1311, in XML
    parser.feed(text)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", 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"?>

<launch>
 <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 ...
(more)
edit retag flag offensive close merge delete

Comments

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 imageRayROS ( 2020-01-10 07:37:03 -0600 )edit

1 Answer

Sort by » oldest newest most voted
1

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

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 = g.read()

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

Comments

Perfect thank you very much :)

RayROS gravatar imageRayROS ( 2020-01-13 12:56:54 -0600 )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

Stats

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

Seen: 34 times

Last updated: Jan 10