-
Notifications
You must be signed in to change notification settings - Fork 526
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 standalone executable for Servo server node #621
Merged
AndyZe
merged 9 commits into
moveit:main
from
schornakj:feature/servo-server-standalone-node
Sep 14, 2021
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1c1aaaa
add a standalone executable node for the servo_server
schornakj 8e5c29b
use single-threaded executor
schornakj f241d03
clang-format fix
schornakj 9745c19
set PickNik Inc. as copyright holder
schornakj 1791baf
add launch file to run servo node
schornakj 6a18040
delete extra file parsing
schornakj 0e258d0
Merge branch 'main' into feature/servo-server-standalone-node
henningkayser b101b0c
Update the launch file to include RViz
eab5e3a
Include example of launching Servo as a node component
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
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,171 @@ | ||
import os | ||
import yaml | ||
from launch import LaunchDescription | ||
from launch_ros.actions import Node | ||
from ament_index_python.packages import get_package_share_directory | ||
from launch_ros.actions import ComposableNodeContainer | ||
from launch_ros.descriptions import ComposableNode | ||
from launch.actions import ExecuteProcess | ||
import xacro | ||
|
||
|
||
def load_file(package_name, file_path): | ||
package_path = get_package_share_directory(package_name) | ||
absolute_file_path = os.path.join(package_path, file_path) | ||
|
||
try: | ||
with open(absolute_file_path, "r") as file: | ||
return file.read() | ||
except EnvironmentError: # parent of IOError, OSError *and* WindowsError where available | ||
return None | ||
|
||
|
||
def load_yaml(package_name, file_path): | ||
package_path = get_package_share_directory(package_name) | ||
absolute_file_path = os.path.join(package_path, file_path) | ||
|
||
try: | ||
with open(absolute_file_path, "r") as file: | ||
return yaml.safe_load(file) | ||
except EnvironmentError: # parent of IOError, OSError *and* WindowsError where available | ||
return None | ||
|
||
|
||
def generate_launch_description(): | ||
# Get parameters for the Servo node | ||
servo_yaml = load_yaml("moveit_servo", "config/panda_simulated_config.yaml") | ||
servo_params = {"moveit_servo": servo_yaml} | ||
|
||
# Get URDF and SRDF | ||
robot_description_config = xacro.process_file( | ||
os.path.join( | ||
get_package_share_directory("moveit_resources_panda_moveit_config"), | ||
"config", | ||
"panda.urdf.xacro", | ||
) | ||
) | ||
robot_description = {"robot_description": robot_description_config.toxml()} | ||
|
||
robot_description_semantic_config = load_file( | ||
"moveit_resources_panda_moveit_config", "config/panda.srdf" | ||
) | ||
robot_description_semantic = { | ||
"robot_description_semantic": robot_description_semantic_config | ||
} | ||
|
||
# RViz | ||
rviz_config_file = ( | ||
get_package_share_directory("moveit2_tutorials") | ||
+ "/config/demo_rviz_config.rviz" | ||
) | ||
rviz_node = Node( | ||
package="rviz2", | ||
executable="rviz2", | ||
name="rviz2", | ||
output="log", | ||
arguments=["-d", rviz_config_file], | ||
parameters=[robot_description, robot_description_semantic], | ||
) | ||
|
||
# ros2_control using FakeSystem as hardware | ||
ros2_controllers_path = os.path.join( | ||
get_package_share_directory("moveit_resources_panda_moveit_config"), | ||
"config", | ||
"panda_ros_controllers.yaml", | ||
) | ||
ros2_control_node = Node( | ||
package="controller_manager", | ||
executable="ros2_control_node", | ||
parameters=[robot_description, ros2_controllers_path], | ||
output={ | ||
"stdout": "screen", | ||
"stderr": "screen", | ||
}, | ||
) | ||
|
||
# Load controllers | ||
load_controllers = [] | ||
for controller in ["panda_arm_controller", "joint_state_broadcaster"]: | ||
load_controllers += [ | ||
ExecuteProcess( | ||
cmd=["ros2 run controller_manager spawner.py {}".format(controller)], | ||
shell=True, | ||
output="screen", | ||
) | ||
] | ||
|
||
# Launch as much as possible in components | ||
container = ComposableNodeContainer( | ||
name="moveit_servo_demo_container", | ||
namespace="/", | ||
package="rclcpp_components", | ||
executable="component_container", | ||
composable_node_descriptions=[ | ||
# Example of launching Servo as a node component | ||
# ComposableNode( | ||
# package="moveit_servo", | ||
# plugin="moveit_servo::ServoServer", | ||
# name="servo_server", | ||
# parameters=[ | ||
# servo_params, | ||
# robot_description, | ||
# robot_description_semantic, | ||
# ], | ||
# extra_arguments=[{"use_intra_process_comms": True}], | ||
# ), | ||
ComposableNode( | ||
package="robot_state_publisher", | ||
plugin="robot_state_publisher::RobotStatePublisher", | ||
name="robot_state_publisher", | ||
parameters=[robot_description], | ||
), | ||
ComposableNode( | ||
package="tf2_ros", | ||
plugin="tf2_ros::StaticTransformBroadcasterNode", | ||
name="static_tf2_broadcaster", | ||
parameters=[{"child_frame_id": "/panda_link0", "frame_id": "/world"}], | ||
), | ||
ComposableNode( | ||
package="moveit_servo", | ||
plugin="moveit_servo::ServoServer", | ||
name="servo_server", | ||
parameters=[ | ||
servo_params, | ||
robot_description, | ||
robot_description_semantic, | ||
], | ||
extra_arguments=[{"use_intra_process_comms": True}], | ||
), | ||
ComposableNode( | ||
package="moveit_servo", | ||
plugin="moveit_servo::JoyToServoPub", | ||
name="controller_to_servo_node", | ||
extra_arguments=[{"use_intra_process_comms": True}], | ||
), | ||
ComposableNode( | ||
package="joy", | ||
plugin="joy::Joy", | ||
name="joy_node", | ||
extra_arguments=[{"use_intra_process_comms": True}], | ||
), | ||
], | ||
output="screen", | ||
) | ||
|
||
servo_node = Node( | ||
package="moveit_servo", | ||
executable="servo_server_node", | ||
parameters=[ | ||
servo_params, | ||
robot_description, | ||
robot_description_semantic, | ||
], | ||
output={ | ||
"stdout": "screen", | ||
"stderr": "screen", | ||
}, | ||
) | ||
|
||
return LaunchDescription( | ||
[rviz_node, ros2_control_node, servo_node, container] + load_controllers | ||
) |
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,54 @@ | ||
/******************************************************************************* | ||
* BSD 3-Clause License | ||
* | ||
* Copyright (c) 2021, PickNik Inc. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* * Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* * Neither the name of the copyright holder nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*******************************************************************************/ | ||
|
||
/* Title : servo_server_node.cpp | ||
* Project : moveit_servo | ||
* Created : 08/18/2021 | ||
* Author : Joe Schornak | ||
*/ | ||
|
||
#include <moveit_servo/servo_server.h> | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
rclcpp::init(argc, argv); | ||
|
||
rclcpp::NodeOptions options; | ||
options.automatically_declare_parameters_from_overrides(true); | ||
|
||
auto node = std::make_shared<moveit_servo::ServoServer>(options); | ||
|
||
rclcpp::spin(node); | ||
|
||
rclcpp::shutdown(); | ||
} |
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.
In the future I hope we can get away from this by declaring all the parameters in a better way with nicer validation. I'm working on that.
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.
TBH I'm still fuzzy on the finer differences between component nodes and standalone nodes.
The PR looks good. I'll prob give it a thumbs up after testing.