-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an example with a passive joint #172
Merged
ahcorde
merged 18 commits into
ros-controls:master
from
christophfroehlich:add_passive_joint_demo
Apr 30, 2024
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
cda9796
Add an example with a passive joint
christophfroehlich 232ac7d
Fix copyright
christophfroehlich 2589512
Update README.md
christophfroehlich 3c91f0f
Merge branch 'master' into add_passive_joint_demo
christophfroehlich 4179dd6
Fix inertias by introducing a macro
christophfroehlich 4e39ac5
Fix origin in macro and set some damping
christophfroehlich c043d80
Enable passive joints again (fix #219)
christophfroehlich 5d1cbec
Merge branch 'master' into add_passive_joint_demo
christophfroehlich d3d1f60
Format code
christophfroehlich 6361a7a
Merge branch 'master' into add_passive_joint_demo
christophfroehlich 7d22e1b
Fix launch file
christophfroehlich a0adfe3
Update urdf
christophfroehlich 2da9fa9
Update doc/index.rst
christophfroehlich fd472b6
Merge branch 'master' into add_passive_joint_demo
christophfroehlich d89020c
Add link to PR.
christophfroehlich e3bb11c
Update copyright
christophfroehlich b493c12
Apply suggestions from code review
christophfroehlich 782a4a1
Adapt URDF to match the effort one
christophfroehlich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
gazebo_ros2_control_demos/launch/pendulum_example_effort.launch.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Copyright 2020 Open Source Robotics Foundation, Inc. | ||
christophfroehlich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
|
||
from ament_index_python.packages import get_package_share_directory | ||
|
||
|
||
from launch import LaunchDescription | ||
from launch.actions import ExecuteProcess, IncludeLaunchDescription, RegisterEventHandler | ||
from launch.event_handlers import OnProcessExit | ||
from launch.launch_description_sources import PythonLaunchDescriptionSource | ||
|
||
from launch_ros.actions import Node | ||
|
||
import xacro | ||
|
||
|
||
def generate_launch_description(): | ||
gazebo = IncludeLaunchDescription( | ||
PythonLaunchDescriptionSource([os.path.join( | ||
get_package_share_directory('gazebo_ros'), 'launch'), '/gazebo.launch.py']), | ||
) | ||
|
||
gazebo_ros2_control_demos_path = os.path.join( | ||
get_package_share_directory('gazebo_ros2_control_demos')) | ||
|
||
xacro_file = os.path.join(gazebo_ros2_control_demos_path, | ||
'urdf', | ||
'test_pendulum_effort.xacro.urdf') | ||
|
||
doc = xacro.parse(open(xacro_file)) | ||
xacro.process_doc(doc) | ||
params = {'robot_description': doc.toxml()} | ||
|
||
node_robot_state_publisher = Node( | ||
package='robot_state_publisher', | ||
executable='robot_state_publisher', | ||
output='screen', | ||
parameters=[params] | ||
) | ||
|
||
spawn_entity = Node(package='gazebo_ros', executable='spawn_entity.py', | ||
arguments=['-topic', 'robot_description', | ||
'-entity', 'cartpole'], | ||
output='screen') | ||
|
||
load_joint_state_controller = ExecuteProcess( | ||
cmd=['ros2', 'control', 'load_controller', '--set-state', 'active', | ||
'joint_state_broadcaster'], | ||
output='screen' | ||
) | ||
|
||
load_joint_trajectory_controller = ExecuteProcess( | ||
cmd=['ros2', 'control', 'load_controller', '--set-state', 'active', 'effort_controllers'], | ||
output='screen' | ||
) | ||
|
||
return LaunchDescription([ | ||
RegisterEventHandler( | ||
event_handler=OnProcessExit( | ||
target_action=spawn_entity, | ||
on_exit=[load_joint_state_controller], | ||
) | ||
), | ||
RegisterEventHandler( | ||
event_handler=OnProcessExit( | ||
target_action=load_joint_state_controller, | ||
on_exit=[load_joint_trajectory_controller], | ||
) | ||
), | ||
gazebo, | ||
node_robot_state_publisher, | ||
spawn_entity, | ||
]) |
87 changes: 87 additions & 0 deletions
87
gazebo_ros2_control_demos/launch/pendulum_example_position.launch.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Copyright 2020 Open Source Robotics Foundation, Inc. | ||
christophfroehlich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
|
||
from ament_index_python.packages import get_package_share_directory | ||
|
||
|
||
from launch import LaunchDescription | ||
from launch.actions import ExecuteProcess, IncludeLaunchDescription, RegisterEventHandler | ||
from launch.event_handlers import OnProcessExit | ||
from launch.launch_description_sources import PythonLaunchDescriptionSource | ||
|
||
from launch_ros.actions import Node | ||
|
||
import xacro | ||
|
||
|
||
def generate_launch_description(): | ||
gazebo = IncludeLaunchDescription( | ||
PythonLaunchDescriptionSource([os.path.join( | ||
get_package_share_directory('gazebo_ros'), 'launch'), '/gazebo.launch.py']), | ||
) | ||
|
||
gazebo_ros2_control_demos_path = os.path.join( | ||
get_package_share_directory('gazebo_ros2_control_demos')) | ||
|
||
xacro_file = os.path.join(gazebo_ros2_control_demos_path, | ||
'urdf', | ||
'test_pendulum_position.xacro.urdf') | ||
|
||
doc = xacro.parse(open(xacro_file)) | ||
xacro.process_doc(doc) | ||
params = {'robot_description': doc.toxml()} | ||
|
||
node_robot_state_publisher = Node( | ||
package='robot_state_publisher', | ||
executable='robot_state_publisher', | ||
output='screen', | ||
parameters=[params] | ||
) | ||
|
||
spawn_entity = Node(package='gazebo_ros', executable='spawn_entity.py', | ||
arguments=['-topic', 'robot_description', | ||
'-entity', 'cartpole'], | ||
output='screen') | ||
|
||
load_joint_state_controller = ExecuteProcess( | ||
cmd=['ros2', 'control', 'load_controller', '--set-state', 'active', | ||
'joint_state_broadcaster'], | ||
output='screen' | ||
) | ||
|
||
load_joint_trajectory_controller = ExecuteProcess( | ||
cmd=['ros2', 'control', 'load_controller', '--set-state', 'active', | ||
'joint_trajectory_controller'], | ||
output='screen' | ||
) | ||
|
||
return LaunchDescription([ | ||
RegisterEventHandler( | ||
event_handler=OnProcessExit( | ||
target_action=spawn_entity, | ||
on_exit=[load_joint_state_controller], | ||
) | ||
), | ||
RegisterEventHandler( | ||
event_handler=OnProcessExit( | ||
target_action=load_joint_state_controller, | ||
on_exit=[load_joint_trajectory_controller], | ||
) | ||
), | ||
gazebo, | ||
node_robot_state_publisher, | ||
spawn_entity, | ||
]) |
108 changes: 108 additions & 0 deletions
108
gazebo_ros2_control_demos/urdf/test_pendulum_effort.xacro.urdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?xml version="1.0" ?> | ||
<!-- =================================================================================== --> | ||
<!-- | This document was autogenerated by xacro from cartpole.xacro.urdf | --> | ||
<!-- | EDITING THIS FILE BY HAND IS NOT RECOMMENDED | --> | ||
<!-- =================================================================================== --> | ||
<robot name="cartopole"> | ||
<link name="world"/> | ||
<link name="slideBar"> | ||
<visual> | ||
<geometry> | ||
<box size="30 0.05 0.05"/> | ||
</geometry> | ||
<origin xyz="0 0 0"/> | ||
<material name="green"> | ||
<color rgba="0 0.8 .8 1"/> | ||
</material> | ||
</visual> | ||
<inertial> | ||
<mass value="100"/> | ||
<inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/> | ||
</inertial> | ||
</link> | ||
<link name="cart"> | ||
<visual> | ||
<geometry> | ||
<box size="0.5 0.5 0.2"/> | ||
</geometry> | ||
<origin xyz="0 0 0"/> | ||
<material name="blue"> | ||
<color rgba="0 0 .8 1"/> | ||
</material> | ||
</visual> | ||
<inertial> | ||
<mass value="10"/> | ||
<inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/> | ||
</inertial> | ||
</link> | ||
|
||
<link name="pendulum"> | ||
<visual> | ||
<geometry> | ||
<box size="0.2 0.2 1.0"/> | ||
</geometry> | ||
<origin xyz="0 0 -0.4"/> | ||
<material name="blue"> | ||
<color rgba="0 0 .8 1"/> | ||
</material> | ||
</visual> | ||
<inertial> | ||
<mass value="1"/> | ||
<inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/> | ||
<origin xyz="0 0 -0.4"/> | ||
</inertial> | ||
</link> | ||
|
||
<joint name="world_to_base" type="fixed"> | ||
<origin rpy="0 0 0" xyz="0 0 1"/> | ||
<parent link="world"/> | ||
<child link="slideBar"/> | ||
</joint> | ||
<joint name="slider_to_cart" type="prismatic"> | ||
<axis xyz="1 0 0"/> | ||
<origin xyz="0.0 0.0 0.0"/> | ||
<parent link="slideBar"/> | ||
<child link="cart"/> | ||
<limit effort="1000.0" lower="-15" upper="15" velocity="30"/> | ||
<dynamics damping="0.0" friction="0.0"/> | ||
</joint> | ||
<joint name="cart_to_pendulum" type="revolute"> | ||
<axis xyz="0 1 0"/> | ||
<origin xyz="0.0 0.35 0.0"/> | ||
<parent link="cart"/> | ||
<child link="pendulum"/> | ||
<limit effort="1000.0" lower="-10000" upper="10000" velocity="30"/> | ||
<dynamics damping="0.1" friction="0.1"/> | ||
</joint> | ||
|
||
<ros2_control name="GazeboSystem" type="system"> | ||
<hardware> | ||
<plugin>gazebo_ros2_control/GazeboSystem</plugin> | ||
</hardware> | ||
<joint name="slider_to_cart"> | ||
<command_interface name="effort"> | ||
<param name="min">-1000</param> | ||
<param name="max">1000</param> | ||
</command_interface> | ||
<state_interface name="position"> | ||
<param name="initial_value">1.0</param> | ||
</state_interface> | ||
<state_interface name="velocity"/> | ||
<state_interface name="effort"/> | ||
</joint> | ||
<joint name="cart_to_pendulum"> | ||
<state_interface name="position"> | ||
<!-- this does not work if no command interface is set --> | ||
<param name="initial_value">1.57</param> | ||
</state_interface> | ||
<state_interface name="velocity"/> | ||
<state_interface name="effort"/> | ||
</joint> | ||
</ros2_control> | ||
|
||
<gazebo> | ||
<plugin filename="libgazebo_ros2_control.so" name="gazebo_ros2_control"> | ||
<parameters>$(find gazebo_ros2_control_demos)/config/cartpole_controller_effort.yaml</parameters> | ||
christophfroehlich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</plugin> | ||
</gazebo> | ||
</robot> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attention: If the position or velocity command interface is used instead, the motion of the pendulum is not
calculated correctly and does not move at all, see the following example. This also holds true if a mimicked joint
with position or velocity interface is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I understand correctly that you want to delete the hint with the position interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ahcorde could you please give me an update about what you want me to change here? According to the reactions below, I'd suggest to add the hint with the position interface again.