How to move a ball using ros controllers in Gazebo?
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 to TF transforms -->
<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" respawn="false" output="screen">
<remap from="/joint_states" to="/target_red/joint_states" />
</node>
</launch>
And my target:controller.yaml file is
target_red:
type: position_controllers/JointTrajectoryController
joints:
- joint_fix
constraints:
goal_time: 0.1
stopped_velocity_tolerance: 0.01
shoulder_pan_joint: {trajectory: 0.1, goal: 0.1}
shoulder_lift_joint: {trajectory: 0.1, goal: 0.1}
elbow_joint: {trajectory: 0.1, goal: 0.1}
wrist_1_joint: {trajectory: 0.1, goal: 0.1}
wrist_2_joint: {trajectory: 0.1, goal: 0.1}
wrist_3_joint: {trajectory: 0.1, goal: 0.1}
stop_trajectory_duration: 0.1
state_publish_rate: 500
action_monitor_rate: 100
joint_state_controller:
type: joint_state_controller/JointStateController
publish_rate: 20
Asked by mkb_10062949 on 2020-01-03 09:22:27 UTC
Answers
@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)
Asked by mkb_10062949 on 2020-01-10 09:18:31 UTC
Comments
Perfect thank you very much :)
Asked by RayROS on 2020-01-13 13:56:54 UTC
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?
Asked by RayROS on 2020-01-10 08:37:03 UTC