diff --git a/docs/en/snippets.md b/docs/en/snippets.md index 052270b59..3334cd1d9 100644 --- a/docs/en/snippets.md +++ b/docs/en/snippets.md @@ -488,3 +488,23 @@ Check, if the code is running inside a [Gazebo simulation](simulation.md): ```python is_simulation = rospy.get_param('/use_sim_time', False) ``` + +### # #{simulator-interaction} + +You can move a physical object (link) in Gazebo (as well as change its velocity) using the `gazebo/set_link_state` service (of the type [`SetLinkState`](http://docs.ros.org/en/api/gazebo_msgs/html/srv/SetLinkState.html)). For example, if you add a cube to the world (link `unit_box::link`), you can move it to the point (1, 2, 3): + +```python +import rospy +from geometry_msgs.msg import Point, Pose, Quaternion +from gazebo_msgs.srv import SetLinkState +from gazebo_msgs.msg import LinkState + +rospy.init_node('flight') + +set_link_state = rospy.ServiceProxy('gazebo/set_link_state', SetLinkState) + +# Change link's position +set_link_state(LinkState(link_name='unit_box::link', pose=Pose(position=Point(1, 2, 3), orientation=Quaternion(0, 0, 0, 1)))) +``` + +> **Info** Simple object animation in Gazebo can be implemented [using actors](http://classic.gazebosim.org/tutorials?tut=actor&cat=build_robot). diff --git a/docs/ru/snippets.md b/docs/ru/snippets.md index 89d15d60f..0f85ad4f7 100644 --- a/docs/ru/snippets.md +++ b/docs/ru/snippets.md @@ -499,3 +499,23 @@ param_set(param_id='MPC_Z_P', value=ParamValue(real=1.5)) ```python is_simulation = rospy.get_param('/use_sim_time', False) ``` + +### # #{simulator-interaction} + +Переместить физический объект (линк) в Gazebo (а также поменять его скорости) можно при помощи сервиса `gazebo/set_link_state` (тип [`SetLinkState`](http://docs.ros.org/en/api/gazebo_msgs/html/srv/SetLinkState.html)). Например, если добавить в мир объект куб (линк `unit_box::link`), то так можно переместить его в точку (1, 2, 3): + +```python +import rospy +from geometry_msgs.msg import Point, Pose, Quaternion +from gazebo_msgs.srv import SetLinkState +from gazebo_msgs.msg import LinkState + +rospy.init_node('flight') + +set_link_state = rospy.ServiceProxy('gazebo/set_link_state', SetLinkState) + +# Переместить линк в Gazebo +set_link_state(LinkState(link_name='unit_box::link', pose=Pose(position=Point(1, 2, 3), orientation=Quaternion(0, 0, 0, 1)))) +``` + +> **Info** Простую анимацию объектов в Gazebo можно реализовать [с помощью акторов](http://classic.gazebosim.org/tutorials?tut=actor&cat=build_robot).