task node basic structure

This commit is contained in:
Niko Feith 2024-03-18 15:26:49 +01:00
parent e0874c3d9d
commit bffe826a74
12 changed files with 211 additions and 8 deletions

View File

@ -1,12 +1,14 @@
bool user_input bool user_input
uint16 number_of_population uint16 number_of_population
float32 duration
uint16 number_of_time_steps
# case if user_input is true # case if user_input is true
float32[] user_parameters # Length: number_of_dimensions * number_of_parameters_per_dimension float32[] user_parameters # Length: number_of_dimensions * number_of_parameters_per_dimension
float32[] user_covariance_diag # Length: number_of_dimensions * number_of_parameters_per_dimension float32[] user_covariance_diag # Length: number_of_dimensions * number_of_parameters_per_dimension
float32[] current_cma_mean # Length: number_of_dimensions * number_of_parameters_per_dimension float32[] current_cma_mean # Length: number_of_dimensions * number_of_parameters_per_dimension
float32[] conditional_points # Length: (number_of_dimensions + time_stamp[0,1]) * number_of_conditional_points float32[] conditional_points # Length: (number_of_dimensions + time_stamp[0,1]) * number_of_conditional_points
float32 weight_parameter # this parameter sets the weighted average 0 dont trust user 1 completly trust user (it is set by the user or it is decays over time i have to do some experiments on that) float32[] weight_parameter # this parameter sets the weighted average 0 dont trust user 1 completly trust user (it is set by the user or it is decays over time i have to do some experiments on that)
# case if user_input is false # case if user_input is false
uint16 number_of_dimensions # this is the number of ProMPs * 2 (Position and Velocity) uint16 number_of_dimensions # this is the number of ProMPs * 2 (Position and Velocity)

View File

@ -48,21 +48,22 @@ class CMAESOptimizationNode(Node):
self.heartbeat_timeout = 30 # secs self.heartbeat_timeout = 30 # secs
self.heartbeat_timer = self.create_timer(1.0, self.check_heartbeats) self.heartbeat_timer = self.create_timer(1.0, self.check_heartbeats)
# MR Heartbeat # Heartbeat
self.last_mr_heartbeat_time = None self.last_mr_heartbeat_time = None
self.mr_heartbeat_sub = self.create_subscription(Bool, 'interaction/mr_heartbeat', self.mr_heatbeat_callback) self.mr_heartbeat_sub = self.create_subscription(Bool, 'interaction/mr_heartbeat', self.mr_heatbeat_callback)
self.last_task_heartbeat_time = None self.last_task_heartbeat_time = None
self.task_heartbeat_sub = self.create_subscription(Bool, 'interaction/task_heartbeat', self.task_heartbeat_callback) self.task_heartbeat_sub = self.create_subscription(Bool, 'interaction/task_heartbeat', self.task_heartbeat_callback)
# Topics # Topic
# Service # Service
self.parameter_srv = self.create_service(ParameterChange, 'cmaes_parameter_srv', self.parameter_callback) self.parameter_srv = self.create_service(ParameterChange, 'interaction/cmaes_parameter_srv', self.parameter_callback)
self.query_srv = self.create_client(Query, 'query_srv') self.query_srv = self.create_client(Query, 'interaction/query_srv')
self.task_srv = self.create_client(TaskEvaluation, 'task_srv') self.task_srv = self.create_client(TaskEvaluation, 'interaction/task_srv')
self.user_interface_srv = self.create_client(UserInterface, 'user_interface_srv') self.user_interface_srv = self.create_client(UserInterface, 'interaction/user_interface_srv')
# Define states # State Machine
# States
self.states = [ self.states = [
'idle', 'idle',
'initialization', 'initialization',
@ -338,3 +339,14 @@ class CMAESOptimizationNode(Node):
self.get_logger().error(f'Task service call failed: {e}') self.get_logger().error(f'Task service call failed: {e}')
self.error_trigger() self.error_trigger()
# endregion # endregion
def main(args=None):
rclpy.init(args=args)
node = CMAESOptimizationNode()
rclpy.spin(node)
rclpy.shutdown()
if __name__ == '__main__':
main()

View File

@ -7,6 +7,9 @@
<maintainer email="nikolaus.feith@unileoben.ac.at">niko</maintainer> <maintainer email="nikolaus.feith@unileoben.ac.at">niko</maintainer>
<license>TODO: License declaration</license> <license>TODO: License declaration</license>
<exec_depend>interaction_msgs</exec_depend>
<exec_depend>rclpy</exec_depend>
<test_depend>ament_copyright</test_depend> <test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend> <test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend> <test_depend>ament_pep257</test_depend>

View File

@ -0,0 +1,63 @@
import rclpy
from rclpy.node import Node
from rclpy.parameter import Parameter
from transitions import Machine
import yaml
import numpy as np
from movement_primitives.promp import ProMP
from src.interaction_utils.serialization import flatten_population, unflatten_population
from interaction_msgs.srv import TaskEvaluation
from std_msgs.msg import Bool
class TaskNode(Node):
def __init__(self):
super().__init__('task_node')
# Task Attributes
# ROS2 Interfaces
# Heartbeat
self.heartbeat_pub = self.create_publisher(Bool, 'interaction/task_heartbeat', 10)
self.heartbeat_timer = self.create_timer(5.0, self.send_heartbeat)
# Topic
# Service
# Action
self._goal_handle = None
# State Machine
# States
self.states = [
'waiting_for_task_specs',
'processing_non_interactive_input',
'processing_interactive_inpute',
'waiting_for_robot_response',
'waiting_for_objective_function_response',
'error_recovery'
]
# initialize state machine
self.machine = Machine(self, states=self.states, initial='waiting_for_task_specs')
self.machine.add_transition(trigger='non_interactive_specs_received', source='waiting_for_task_specs', dest='processing_non_interactive_input')
self.machine.add_transition(trigger='interactive_specs_received', source='waiting_for_task_specs', dest='processing_interactive_input')
self.machine.add_transition(trigger='non_interactive_to_robot', source='processing_non_interactive_input', dest='waiting_for_robot_response')
self.machine.add_transition(trigger='non_interactive_to_obj_fun', source='processing_non_interactive_input', dest='waiting_for_objective_function_response')
self.machine.add_transition(trigger='interactive_to_robot', source='processing_interactive_input', dest='waiting_for_robot_response')
self.machine.add_transition(trigger='interactive_to_obj_fun', source='processing_interactive_input', dest='waiting_for_objective_function_response')
self.machine.add_transition(trigger='sending_robot_results', source='waiting_for_robot_response', dest='waiting_for_task_specs')
self.machine.add_transition(trigger='sending_obj_fun_results', source='waiting_for_obj_fun_response', dest='waiting_for_task_specs')
self.machine.add_transition(trigger='error_trigger', source='*', dest='error_recovery')
self.machine.add_transition(trigger='recovery_complete', source='error_recovery', dest='waiting_for_task_specs')
# State Methods
# Callback functions
def send_heartbeat(self):
msg = Bool()
self.heartbeat_pub.publish(msg)

View File

@ -0,0 +1,21 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>interaction_tasks</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="nikolaus.feith@unileoben.ac.at">niko</maintainer>
<license>TODO: License declaration</license>
<exec_depend>interaction_msgs</exec_depend>
<exec_depend>rclpy</exec_depend>
<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>
<export>
<build_type>ament_python</build_type>
</export>
</package>

View File

@ -0,0 +1,4 @@
[develop]
script_dir=$base/lib/interaction_tasks
[install]
install_scripts=$base/lib/interaction_tasks

View File

@ -0,0 +1,25 @@
from setuptools import find_packages, setup
package_name = 'interaction_tasks'
setup(
name=package_name,
version='0.0.0',
packages=find_packages(exclude=['test']),
data_files=[
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
],
install_requires=['setuptools'],
zip_safe=True,
maintainer='niko',
maintainer_email='nikolaus.feith@unileoben.ac.at',
description='TODO: Package description',
license='TODO: License declaration',
tests_require=['pytest'],
entry_points={
'console_scripts': [
],
},
)

View File

@ -0,0 +1,25 @@
# Copyright 2015 Open Source Robotics Foundation, Inc.
#
# 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.
from ament_copyright.main import main
import pytest
# Remove the `skip` decorator once the source file(s) have a copyright header
@pytest.mark.skip(reason='No copyright header has been placed in the generated source file.')
@pytest.mark.copyright
@pytest.mark.linter
def test_copyright():
rc = main(argv=['.', 'test'])
assert rc == 0, 'Found errors'

View File

@ -0,0 +1,25 @@
# Copyright 2017 Open Source Robotics Foundation, Inc.
#
# 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.
from ament_flake8.main import main_with_errors
import pytest
@pytest.mark.flake8
@pytest.mark.linter
def test_flake8():
rc, errors = main_with_errors(argv=[])
assert rc == 0, \
'Found %d code style errors / warnings:\n' % len(errors) + \
'\n'.join(errors)

View File

@ -0,0 +1,23 @@
# Copyright 2015 Open Source Robotics Foundation, Inc.
#
# 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.
from ament_pep257.main import main
import pytest
@pytest.mark.linter
@pytest.mark.pep257
def test_pep257():
rc = main(argv=['.', 'test'])
assert rc == 0, 'Found code style errors / warnings'