run server with launch file on ROS 2 [closed]
Hey all,
I'm building a system with action servers and action clients. So far, when I run each module separately everything works well, meaning that when I use ros2 run to run the servers and the clients, everything works as I intended. In order to try to automatize the creation of the servers, I would like to create a launch file for them. As such, I followed the tutorial on https://index.ros.org/doc/ros2/Tutori... in order to understand the mechanics involved.
However, after some time trying to implement this, it is my firm belief that the launch file isn't opening the servers correctly. My code is below and I believe the error has something to do with the attributes of the launch file.
On node_executable I placed the name of the python file that I used to execute for the server with ros2 run. I used to use the command: ros2 run gspn_framework server_1.
Code for the launch file:
import launch
import launch.actions
import launch.substitutions
import launch_ros.actions
def generate_launch_description():
return launch.LaunchDescription([
launch_ros.actions.Node(
package='gspn_framework',
node_executable='server_1',
node_namespace='minimal_action_server_1',
node_name='minimal_action_server_1'
)
])
Code for the server:
def main(args=None):
rclpy.init(args=args)
minimal_action_server = MinimalActionServer()
# Use a MultiThreadedExecutor to enable processing goals concurrently
executor = MultiThreadedExecutor()
rclpy.spin(minimal_action_server, executor=executor)
minimal_action_server.destroy()
rclpy.shutdown()
if __name__ == '__main__':
main()
Continuation of the code of the server (constructor):
class MinimalActionServer(Node):
def __init__(self):
super().__init__('minimal_action_server_1')
self._action_server = ActionServer(
self,
Fibonacci,
'fibonacci_1',
execute_callback=self.execute_callback,
callback_group=ReentrantCallbackGroup(),
goal_callback=self.goal_callback,
cancel_callback=self.cancel_callback)
self.get_logger().info('SERVER 1 : ONLINE')
I believe that the code isn't working because the logger doesn't print out the message "SERVER 1: ONLINE". I am using ROS 2 Eloquent with Python on Ubuntu 18.
Thank you