Skip to content

Commit 441d35d

Browse files
authored
Fix Servo pose tracking tutorial (#973)
1 parent 9e3bd6e commit 441d35d

File tree

4 files changed

+69
-38
lines changed

4 files changed

+69
-38
lines changed

doc/examples/realtime_servo/config/panda_simulated_config.yaml

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
# override_velocity_scaling_factor = 0.0 # valid range [0.0:1.0]
77

88
## Properties of outgoing commands
9-
publish_period: 0.034 # 1/Nominal publish rate [seconds]
9+
publish_period: 0.01 # 1/Nominal publish rate [seconds]
10+
max_expected_latency: 0.1 # delay between sending a command and the robot executing it [seconds]
1011

11-
command_in_type: "speed_units" # "unitless"> in the range [-1:1], as if from joystick. "speed_units"> cmds are in m/s and rad/s
12+
command_in_type: "speed_units" # "unitless"> in the range [-1:1], as if from joystick. "speed_units"> cmds are in m/s and rad/s
1213
scale:
1314
# Scale parameters are only used if command_in_type=="unitless"
14-
linear: 0.4 # Max linear velocity. Unit is [m/s]. Only used for Cartesian commands.
15-
rotational: 0.8 # Max angular velocity. Unit is [rad/s]. Only used for Cartesian commands.
15+
linear: 0.2 # Max linear velocity. Unit is [m/s]. Only used for Cartesian commands.
16+
rotational: 0.8 # Max angular velocity. Unit is [rad/s]. Only used for Cartesian commands.
1617
# Max joint angular/linear velocity. Only used for joint commands on joint_command_in_topic.
1718
joint: 0.5
1819

@@ -27,36 +28,36 @@ publish_joint_accelerations: false
2728

2829
## Plugins for smoothing outgoing commands
2930
use_smoothing: true
30-
smoothing_filter_plugin_name: "online_signal_smoothing::ButterworthFilterPlugin"
31+
smoothing_filter_plugin_name: "online_signal_smoothing::AccelerationLimitedPlugin"
3132

3233
# If is_primary_planning_scene_monitor is set to true, the Servo server's PlanningScene advertises the /get_planning_scene service,
3334
# which other nodes can use as a source for information about the planning environment.
3435
# NOTE: If a different node in your system is responsible for the "primary" planning scene instance (e.g. the MoveGroup node),
3536
# then is_primary_planning_scene_monitor needs to be set to false.
3637
is_primary_planning_scene_monitor: true
38+
check_octomap_collisions: false # Check collision against the octomap (if a 3D sensor plugin is available)
3739

3840
## MoveIt properties
39-
move_group_name: panda_arm # Often 'manipulator' or 'arm'
40-
planning_frame: panda_link0 # The MoveIt planning frame. Often 'base_link' or 'world'
41-
42-
## Other frames
43-
ee_frame: panda_hand # The name of the end effector link, used to return the EE pose
41+
move_group_name: panda_arm # Often 'manipulator' or 'arm'
4442

4543
## Configure handling of singularities and joint limits
46-
lower_singularity_threshold: 17.0 # Start decelerating when the condition number hits this (close to singularity)
47-
hard_stop_singularity_threshold: 30.0 # Stop when the condition number hits this
48-
joint_limit_margin: 0.1 # added as a buffer to joint limits [radians]. If moving quickly, make this larger.
49-
leaving_singularity_threshold_multiplier: 2.0 # Multiply the hard stop limit by this when leaving singularity.
44+
lower_singularity_threshold: 30.0 # Start decelerating when the condition number hits this (close to singularity)
45+
hard_stop_singularity_threshold: 50.0 # Stop when the condition number hits this
46+
leaving_singularity_threshold_multiplier: 2.0 # Multiply the hard stop limit by this when leaving singularity (see https://github.com/moveit/moveit2/pull/620)
47+
# Added as a buffer to joint variable position bounds [in that joint variable's respective units].
48+
# Can be of size 1, which applies the margin to all joints, or the same size as the number of degrees of freedom of the active joint group.
49+
# If moving quickly, make these values larger.
50+
joint_limit_margins: [0.12]
5051

5152
## Topic names
5253
cartesian_command_in_topic: ~/delta_twist_cmds # Topic for incoming Cartesian twist commands
53-
joint_command_in_topic: ~/delta_joint_cmds # Topic for incoming joint angle commands
54-
joint_topic: /joint_states
55-
status_topic: ~/status # Publish status to this topic
56-
command_out_topic: /panda_arm_controller/joint_trajectory # Publish outgoing commands here
54+
joint_command_in_topic: ~/delta_joint_cmds # Topic for incoming joint angle commands
55+
joint_topic: /joint_states # Get joint states from this tpoic
56+
status_topic: ~/status # Publish status to this topic
57+
command_out_topic: /panda_arm_controller/joint_trajectory # Publish outgoing commands here
5758

5859
## Collision checking for the entire robot body
59-
check_collisions: true # Check collisions?
60-
collision_check_rate: 10.0 # [Hz] Collision-checking can easily bog down a CPU if done too often.
61-
self_collision_proximity_threshold: 0.01 # Start decelerating when a self-collision is this far [m]
62-
scene_collision_proximity_threshold: 0.02 # Start decelerating when a scene collision is this far [m]
60+
check_collisions: true # Check collisions?
61+
collision_check_rate: 10.0 # [Hz] Collision-checking can easily bog down a CPU if done too often.
62+
self_collision_proximity_threshold: 0.01 # Start decelerating when a self-collision is this far [m]
63+
scene_collision_proximity_threshold: 0.02 # Start decelerating when a scene collision is this far [m]

doc/examples/realtime_servo/launch/pose_tracking_tutorial.launch.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def generate_launch_description():
1212
moveit_config = (
1313
MoveItConfigsBuilder("moveit_resources_panda")
1414
.robot_description(file_path="config/panda.urdf.xacro")
15+
.joint_limits(file_path="config/hard_joint_limits.yaml")
16+
.robot_description_kinematics()
1517
.to_moveit_configs()
1618
)
1719

@@ -27,8 +29,9 @@ def generate_launch_description():
2729
.to_dict()
2830
}
2931

30-
# This filter parameter should be >1. Increase it for greater smoothing but slower motion.
31-
low_pass_filter_coeff = {"butterworth_filter_coeff": 1.5}
32+
# This sets the update rate and planning group name for the acceleration limiting filter.
33+
acceleration_filter_update_period = {"update_period": 0.01}
34+
planning_group_name = {"planning_group_name": "panda_arm"}
3235

3336
# RViz
3437
rviz_config_file = (
@@ -96,10 +99,12 @@ def generate_launch_description():
9699
name="servo_node",
97100
parameters=[
98101
servo_params,
99-
low_pass_filter_coeff,
102+
acceleration_filter_update_period,
103+
planning_group_name,
100104
moveit_config.robot_description,
101105
moveit_config.robot_description_semantic,
102106
moveit_config.robot_description_kinematics,
107+
moveit_config.joint_limits,
103108
],
104109
condition=UnlessCondition(launch_as_standalone_node),
105110
),
@@ -126,10 +131,12 @@ def generate_launch_description():
126131
name="servo_node",
127132
parameters=[
128133
servo_params,
129-
low_pass_filter_coeff,
134+
acceleration_filter_update_period,
135+
planning_group_name,
130136
moveit_config.robot_description,
131137
moveit_config.robot_description_semantic,
132138
moveit_config.robot_description_kinematics,
139+
moveit_config.joint_limits,
133140
],
134141
output="screen",
135142
condition=IfCondition(launch_as_standalone_node),
@@ -150,6 +157,6 @@ def generate_launch_description():
150157
panda_arm_controller_spawner,
151158
servo_node,
152159
container,
153-
launch.actions.TimerAction(period=10.0, actions=[demo_node]),
160+
launch.actions.TimerAction(period=8.0, actions=[demo_node]),
154161
]
155162
)

doc/examples/realtime_servo/realtime_servo_tutorial.rst

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,11 @@ The user can use status for higher-level decision making.
200200
See :moveit_codedir:`moveit_servo/demos <moveit_ros/moveit_servo/demos/cpp_interface>` for complete examples of using the C++ interface.
201201
The demos can be launched using the launch files found in :moveit_codedir:`moveit_servo/launch <moveit_ros/moveit_servo/launch>`.
202202

203-
- ``ros2 launch moveit_servo demo_joint_jog.launch.py``
204-
- ``ros2 launch moveit_servo demo_twist.launch.py``
205-
- ``ros2 launch moveit_servo demo_pose.launch.py``
203+
.. code-block:: bash
204+
205+
ros2 launch moveit_servo demo_joint_jog.launch.py
206+
ros2 launch moveit_servo demo_twist.launch.py
207+
ros2 launch moveit_servo demo_pose.launch.py
206208
207209
208210
Using the ROS API
@@ -222,7 +224,11 @@ selected using the *command_out_type* parameter, and published on the topic spec
222224

223225
The command type can be selected using the ``ServoCommandType`` service, see definition :moveit_msgs_codedir:`ServoCommandType <srv/ServoCommandType.srv>`.
224226

225-
From cli : ``ros2 service call /<node_name>/switch_command_type moveit_msgs/srv/ServoCommandType "{command_type: 1}"``
227+
From the CLI:
228+
229+
.. code-block:: bash
230+
231+
ros2 service call /<node_name>/switch_command_type moveit_msgs/srv/ServoCommandType "{command_type: 1}"
226232
227233
Programmatically:
228234

@@ -248,10 +254,22 @@ Similarly, servoing can be paused using the pause service ``<node_name>/pause_se
248254

249255
When using the ROS interface, the status of Servo is available on the topic ``/<node_name>/status``, see definition :moveit_msgs_codedir:`ServoStatus <msg/ServoStatus.msg>`.
250256

251-
Launch ROS interface demo: ``ros2 launch moveit_servo demo_ros_api.launch.py``.
257+
Launch ROS interface demo:
258+
259+
.. code-block:: bash
260+
261+
ros2 launch moveit_servo demo_ros_api.launch.py
252262
253263
Once the demo is running, the robot can be teleoperated through the keyboard.
254264

255-
Launch the keyboard demo: ``ros2 run moveit_servo servo_keyboard_input``.
265+
Launch the keyboard demo:
266+
267+
.. code-block:: bash
268+
269+
ros2 run moveit_servo servo_keyboard_input
256270
257271
An example of using the pose commands in the context of servoing to open a door can be seen in this :codedir:`example <examples/realtime_servo/src/pose_tracking_tutorial.cpp>`.
272+
273+
.. code-block:: bash
274+
275+
ros2 launch moveit2_tutorials pose_tracking_tutorial.launch.py

doc/examples/realtime_servo/src/pose_tracking_tutorial.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ int main(int argc, char* argv[])
208208
executor->add_node(node);
209209

210210
// Spin the node.
211-
std::thread executor_thread([&]() { executor->spin(); });
211+
std::thread executor_thread([&executor]() { executor->spin(); });
212212

213213
visualization_msgs::msg::MarkerArray marray;
214214
std::vector<Eigen::Vector3d> path = getPath();
@@ -231,20 +231,25 @@ int main(int argc, char* argv[])
231231
// Create the ROS message.
232232
auto request = std::make_shared<moveit_msgs::srv::ServoCommandType::Request>();
233233
request->command_type = moveit_msgs::srv::ServoCommandType::Request::POSE;
234-
auto response = switch_input_client->async_send_request(request);
234+
auto response_future = switch_input_client->async_send_request(request);
235+
if (response_future.wait_for(std::chrono::duration<double>(3.0)) == std::future_status::timeout)
236+
{
237+
RCLCPP_ERROR_STREAM(node->get_logger(), "Timed out waiting for MoveIt servo command switching request.");
238+
}
239+
const auto response = response_future.get();
235240
if (response.get()->success)
236241
{
237-
RCLCPP_INFO_STREAM(node->get_logger(), "Switched to input type: Pose");
242+
RCLCPP_INFO_STREAM(node->get_logger(), "Switched to command input type: Pose");
238243
}
239244
else
240245
{
241-
RCLCPP_WARN_STREAM(node->get_logger(), "Could not switch input to: Pose");
246+
RCLCPP_ERROR_STREAM(node->get_logger(), "Could not switch MoveIt servo command input type.");
242247
}
243248

244249
// Follow the trajectory
245250

246251
const double publish_period = 0.15;
247-
rclcpp::WallRate rate(1 / publish_period);
252+
rclcpp::WallRate rate(1.0 / publish_period);
248253

249254
// The path needs to be reversed since the last point in the path is where we want to start.
250255
std::reverse(path.begin(), path.end());

0 commit comments

Comments
 (0)