source code
Catkin package
catkin_create_pkg demo_gazebo rospy
cd demo_gazebo
mkdir launch
mkdir urdf
Minimal urdf file
URDF model link
mast have inertia
The inertia matrix explained
<?xml version="1.0"?>
<robot name="robot">
<link name="base_link">
<collision>
<origin xyz="0 0 1" rpy="0 0 0"/>
<geometry>
<box size="2 2 2"/>
</geometry>
</collision>
<visual>
<origin xyz="0 0 1" rpy="0 0 0"/>
<geometry>
<box size="2 2 2"/>
</geometry>
<material name="orange"/>
</visual>
<inertial>
<origin xyz="0 0 1" 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>
</robot>
Spawn models
<launch>
<param name="robot_description" textfile="$(find demo_gazebo)/urdf/robot_description.urdf" />
<include file="$(find gazebo_ros)/launch/empty_world.launch"/>
<node name="spawn_urdf" pkg="gazebo_ros" type="spawn_model" args="-param robot_description -urdf -model my_robot" />
</launch>
rosrun gazebo_ros spawn_model -file `rospack find demo_gazebo`/urdf/robot_description.urdf -urdf -z 1 -model my_robot
Gazebo services
rosservice call /gazebo/get_world_properties
sim_time: 1155.376
model_names: [ground_plane, my_robot]
rendering_enabled: True
success: True
rosservice call /gazebo/delete_model "model_name: 'my_robot'"
success: True
status_message: "DeleteModel: successfully deleted model"
ROS python node
- Call service to insert model into
import rospy
from gazebo_msgs.srv import SpawnModel
from geometry_msgs.msg import Pose
rospy.init_node('insert_object',log_level=rospy.INFO)
initial_pose = Pose()
initial_pose.position.x = 1
initial_pose.position.y = 1
initial_pose.position.z = 1
f = open('/home/user/simulation_ws/src/demo_gazebo/urdf/robot_description.urdf','r')
urdff = f.read()
rospy.wait_for_service('gazebo/spawn_urdf_model')
spawn_model_proxy = rospy.ServiceProxy('gazebo/spawn_urdf_model', SpawnModel)
spawn_model_proxy("some_robot_name", urdff, "robotos_name_space", initial_pose, "world")
No comments:
Post a Comment