From f61455399354b9b99b58b8c5fc69d70747a04015 Mon Sep 17 00:00:00 2001 From: KirillZharkov Date: Fri, 27 Oct 2023 00:42:40 +0300 Subject: [PATCH 1/9] draft config --- app/generate_grasper_cfgs.py | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 app/generate_grasper_cfgs.py diff --git a/app/generate_grasper_cfgs.py b/app/generate_grasper_cfgs.py new file mode 100644 index 00000000..6a1bac9a --- /dev/null +++ b/app/generate_grasper_cfgs.py @@ -0,0 +1,45 @@ +from dataclasses import dataclass, field +from typing import Type +from rostok.block_builder_api.block_blueprints import EnvironmentBodyBlueprint +from rostok.simulation_chrono.simulation_scenario import GraspScenario, ParametrizedSimulation +import rostok.control_chrono.external_force as f_ext + + +@dataclass +class SimulationConfig: + time_step: float = 0.0001 + time_simulation: float = 10 + scenario_cls: Type[ParametrizedSimulation] = GraspScenario + obj_disturbance_forces: list[f_ext.ABCForceCalculator] = field(default_factory=list) + + +# From tis stuff generates sim_manager + + +@dataclass +class GraspObjective: + object_list: list[EnvironmentBodyBlueprint] = field(default_factory=list) + weight_list: list[float] = field(default_factory=list) + event_time_no_contact: float = 2 + event_flying_apart_time: float = 2 + event_slipout_time: float = 1 + event_grasp_time: float = 5 + event_force_test_time: float = 5 + + time_criterion_weight: float = 1 + instant_contact_link_criterion_weight: float = 1 + instant_force_criterion_weight: float = 1 + instant_cog_criterion_weight: float = 1 + grasp_time_criterion_weight: float = 1 + final_pos_criterion_weight: float = 1 + +@dataclass +class ControlOptimizationParams: + optimisation_bound: tuple = field(default_factory=tuple) + optimisation_iter: int = field(default_factory=int) + +@dataclass +class ControlBruteForceParams: + force_list: list[float] = field(default_factory=list) + staring_angle: float = field(default_factory=float) + From 1f38af08aa8996dbdfe83ac7e62c708d6e6ff29a Mon Sep 17 00:00:00 2001 From: ZharkovKirill Date: Tue, 31 Oct 2023 19:53:27 +0300 Subject: [PATCH 2/9] 1 --- app/generate_grasper_cfgs.py | 100 ++++++++++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 8 deletions(-) diff --git a/app/generate_grasper_cfgs.py b/app/generate_grasper_cfgs.py index 6a1bac9a..40187a5b 100644 --- a/app/generate_grasper_cfgs.py +++ b/app/generate_grasper_cfgs.py @@ -1,15 +1,21 @@ +from copy import deepcopy from dataclasses import dataclass, field from typing import Type from rostok.block_builder_api.block_blueprints import EnvironmentBodyBlueprint +from rostok.control_chrono.controller import ConstController, RobotControllerChrono +from rostok.criterion.criterion_calculation import FinalPositionCriterion, GraspTimeCriterion, InstantContactingLinkCriterion, InstantForceCriterion, InstantObjectCOGCriterion, SimulationReward, TimeCriterion +from rostok.criterion.simulation_flags import EventContact, EventContactTimeOut, EventFlyingApart, EventSlipOut, \ +EventGrasp, EventStopExternalForce from rostok.simulation_chrono.simulation_scenario import GraspScenario, ParametrizedSimulation import rostok.control_chrono.external_force as f_ext +from rostok.trajectory_optimizer.control_optimizer import BasePrepareOptiVar, ConstTorqueOptiVar @dataclass class SimulationConfig: time_step: float = 0.0001 time_simulation: float = 10 - scenario_cls: Type[ParametrizedSimulation] = GraspScenario + scenario_cls: Type[GraspScenario] = GraspScenario obj_disturbance_forces: list[f_ext.ABCForceCalculator] = field(default_factory=list) @@ -33,13 +39,91 @@ class GraspObjective: grasp_time_criterion_weight: float = 1 final_pos_criterion_weight: float = 1 + @dataclass -class ControlOptimizationParams: - optimisation_bound: tuple = field(default_factory=tuple) - optimisation_iter: int = field(default_factory=int) +class BaseCalculateRewardCfg: + sim_config: SimulationConfig = field(default_factory=SimulationConfig) + grasp_objective: GraspObjective = field(default_factory=GraspObjective) + prepare_reward: BasePrepareOptiVar = ConstTorqueOptiVar(SimulationReward(), None) + @dataclass -class ControlBruteForceParams: - force_list: list[float] = field(default_factory=list) - staring_angle: float = field(default_factory=float) - +class BruteForceRewardCfg(BaseCalculateRewardCfg): + pass + + +def create_base_sim(contoller_cls, sim_cfg: SimulationConfig): + """Base sim without object + + Args: + contoller_cls (_type_): _description_ + sim_cfg (SimulationConfig): _description_ + + Returns: + _type_: _description_ + """ + return sim_cfg.scenario_cls(sim_cfg.time_step, + sim_cfg.time_simulation, + contoller_cls, + obj_external_forces=sim_cfg.obj_disturbance_forces) + + +def add_grasp_events_from_cfg(sim: GraspScenario, cfg: GraspObjective): + event_contact = EventContact() + sim.add_event(event_contact) + event_timeout = EventContactTimeOut(cfg.event_time_no_contact, event_contact) + sim.add_event(event_timeout) + event_flying_apart = EventFlyingApart(cfg.event_flying_apart_time) + sim.add_event(event_flying_apart) + event_slipout = EventSlipOut(cfg.event_slipout_time) + sim.add_event(event_slipout) + event_grasp = EventGrasp(grasp_limit_time=cfg.event_grasp_time, + contact_event=event_contact, + verbosity=0, + simulation_stop=1) + sim.add_event(event_grasp) + event_stop_external_force = EventStopExternalForce(grasp_event=event_grasp, + force_test_time=cfg.event_force_test_time) + sim.add_event(event_stop_external_force) + return event_contact, event_timeout, event_flying_apart, event_slipout, event_stop_external_force + + +def create_sim_list(base_sim: GraspScenario, object_list: list[EnvironmentBodyBlueprint]): + sim_list = [] + for obj_i in object_list: + sim_i = deepcopy(base_sim) + sim_i.grasp_object_callback = obj_i + sim_list.append(sim_i) + return sim_list + + +def prepare_simulation_scenario_list(contoller_cls, sim_cfg: SimulationConfig, + grasp_objective_cfg: GraspObjective): + + base_simulation = create_base_sim(contoller_cls, sim_cfg) + event_contact, event_timeout, event_flying_apart, event_slipout, event_stop_external_force = add_grasp_events_from_cfg( + base_simulation, grasp_objective_cfg) + sim_list = create_sim_list(base_simulation, grasp_objective_cfg.object_list) + + return sim_list + + +def create_rewarder(grasp_objective_cfg: GraspObjective): + simulation_rewarder = SimulationReward(verbosity=0) + + simulation_rewarder.add_criterion(TimeCriterion(hp.GRASP_TIME, event_timeout, event_grasp), + hp.TIME_CRITERION_WEIGHT) + + simulation_rewarder.add_criterion(InstantContactingLinkCriterion(event_grasp), + hp.INSTANT_CONTACTING_LINK_CRITERION_WEIGHT) + simulation_rewarder.add_criterion(InstantForceCriterion(event_grasp), + hp.INSTANT_FORCE_CRITERION_WEIGHT) + simulation_rewarder.add_criterion(InstantObjectCOGCriterion(event_grasp), + hp.OBJECT_COG_CRITERION_WEIGHT) + n_steps = int(hp.GRASP_TIME / hp.TIME_STEP_SIMULATION) + print(n_steps) + simulation_rewarder.add_criterion(GraspTimeCriterion(event_grasp, n_steps), + hp.GRASP_TIME_CRITERION_WEIGHT) + simulation_rewarder.add_criterion( + FinalPositionCriterion(hp.REFERENCE_DISTANCE, event_grasp, event_slipout), + hp.FINAL_POSITION_CRITERION_WEIGHT) From 21d3d4a5796b1dc9ade32bbfa87c0929d6ad7d70 Mon Sep 17 00:00:00 2001 From: KirillZharkov Date: Wed, 1 Nov 2023 20:24:28 +0300 Subject: [PATCH 3/9] [pipeline] --- app/app_new_mcts.py | 27 +++ app/generate_grasper_cfgs.py | 129 ------------ app/hyperparameters.py | 31 +-- app/tendon_driven_cfg.py | 59 ++++++ app/tendon_graph_evaluators.py | 33 +++ rostok/pipeline/generate_grasper_cfgs.py | 193 ++++++++++++++++++ .../trajectory_optimizer/control_optimizer.py | 14 +- 7 files changed, 339 insertions(+), 147 deletions(-) create mode 100644 app/app_new_mcts.py delete mode 100644 app/generate_grasper_cfgs.py create mode 100644 app/tendon_driven_cfg.py create mode 100644 app/tendon_graph_evaluators.py create mode 100644 rostok/pipeline/generate_grasper_cfgs.py diff --git a/app/app_new_mcts.py b/app/app_new_mcts.py new file mode 100644 index 00000000..0333fdf1 --- /dev/null +++ b/app/app_new_mcts.py @@ -0,0 +1,27 @@ +import hyperparameters as hp +from rostok.graph_generators.environments.design_environment import (SubStringDesignEnvironment) +from rostok.graph_generators.mcts_manager import MCTSManager +from rostok.graph_generators.search_algorithms.mcts import MCTS + +from rostok.library.rule_sets.rulset_simple_fingers import create_rules +from rostok.graph_grammar.node import GraphGrammar +import hyperparameters as hp +from tendon_graph_evaluators import evaluator_tendon_standart, evaluator_tendon_standart_parallel +import tendon_driven_cfg + +if __name__ == "__main__": + rule_vocabulary = create_rules() + + init_graph = GraphGrammar() + env = SubStringDesignEnvironment(rule_vocabulary, evaluator_tendon_standart_parallel, + hp.MAX_NUMBER_RULES, init_graph, 0) + + mcts = MCTS(env, hp.MCTS_C) + name_directory = input("enter directory name: ") + mcts_manager = MCTSManager(mcts, name_directory, verbosity=2, use_date=True) + #mcts_manager.save_information_about_search( + # hp, tendon_driven_cfg.default_grasp_objective.object_list) + + for i in range(hp.FULL_LOOP_MCTS): + mcts_manager.run_search(hp.BASE_ITERATION_LIMIT_TENDON, 1, 1, 2) + mcts_manager.save_results() \ No newline at end of file diff --git a/app/generate_grasper_cfgs.py b/app/generate_grasper_cfgs.py deleted file mode 100644 index 40187a5b..00000000 --- a/app/generate_grasper_cfgs.py +++ /dev/null @@ -1,129 +0,0 @@ -from copy import deepcopy -from dataclasses import dataclass, field -from typing import Type -from rostok.block_builder_api.block_blueprints import EnvironmentBodyBlueprint -from rostok.control_chrono.controller import ConstController, RobotControllerChrono -from rostok.criterion.criterion_calculation import FinalPositionCriterion, GraspTimeCriterion, InstantContactingLinkCriterion, InstantForceCriterion, InstantObjectCOGCriterion, SimulationReward, TimeCriterion -from rostok.criterion.simulation_flags import EventContact, EventContactTimeOut, EventFlyingApart, EventSlipOut, \ -EventGrasp, EventStopExternalForce -from rostok.simulation_chrono.simulation_scenario import GraspScenario, ParametrizedSimulation -import rostok.control_chrono.external_force as f_ext -from rostok.trajectory_optimizer.control_optimizer import BasePrepareOptiVar, ConstTorqueOptiVar - - -@dataclass -class SimulationConfig: - time_step: float = 0.0001 - time_simulation: float = 10 - scenario_cls: Type[GraspScenario] = GraspScenario - obj_disturbance_forces: list[f_ext.ABCForceCalculator] = field(default_factory=list) - - -# From tis stuff generates sim_manager - - -@dataclass -class GraspObjective: - object_list: list[EnvironmentBodyBlueprint] = field(default_factory=list) - weight_list: list[float] = field(default_factory=list) - event_time_no_contact: float = 2 - event_flying_apart_time: float = 2 - event_slipout_time: float = 1 - event_grasp_time: float = 5 - event_force_test_time: float = 5 - - time_criterion_weight: float = 1 - instant_contact_link_criterion_weight: float = 1 - instant_force_criterion_weight: float = 1 - instant_cog_criterion_weight: float = 1 - grasp_time_criterion_weight: float = 1 - final_pos_criterion_weight: float = 1 - - -@dataclass -class BaseCalculateRewardCfg: - sim_config: SimulationConfig = field(default_factory=SimulationConfig) - grasp_objective: GraspObjective = field(default_factory=GraspObjective) - prepare_reward: BasePrepareOptiVar = ConstTorqueOptiVar(SimulationReward(), None) - - -@dataclass -class BruteForceRewardCfg(BaseCalculateRewardCfg): - pass - - -def create_base_sim(contoller_cls, sim_cfg: SimulationConfig): - """Base sim without object - - Args: - contoller_cls (_type_): _description_ - sim_cfg (SimulationConfig): _description_ - - Returns: - _type_: _description_ - """ - return sim_cfg.scenario_cls(sim_cfg.time_step, - sim_cfg.time_simulation, - contoller_cls, - obj_external_forces=sim_cfg.obj_disturbance_forces) - - -def add_grasp_events_from_cfg(sim: GraspScenario, cfg: GraspObjective): - event_contact = EventContact() - sim.add_event(event_contact) - event_timeout = EventContactTimeOut(cfg.event_time_no_contact, event_contact) - sim.add_event(event_timeout) - event_flying_apart = EventFlyingApart(cfg.event_flying_apart_time) - sim.add_event(event_flying_apart) - event_slipout = EventSlipOut(cfg.event_slipout_time) - sim.add_event(event_slipout) - event_grasp = EventGrasp(grasp_limit_time=cfg.event_grasp_time, - contact_event=event_contact, - verbosity=0, - simulation_stop=1) - sim.add_event(event_grasp) - event_stop_external_force = EventStopExternalForce(grasp_event=event_grasp, - force_test_time=cfg.event_force_test_time) - sim.add_event(event_stop_external_force) - return event_contact, event_timeout, event_flying_apart, event_slipout, event_stop_external_force - - -def create_sim_list(base_sim: GraspScenario, object_list: list[EnvironmentBodyBlueprint]): - sim_list = [] - for obj_i in object_list: - sim_i = deepcopy(base_sim) - sim_i.grasp_object_callback = obj_i - sim_list.append(sim_i) - return sim_list - - -def prepare_simulation_scenario_list(contoller_cls, sim_cfg: SimulationConfig, - grasp_objective_cfg: GraspObjective): - - base_simulation = create_base_sim(contoller_cls, sim_cfg) - event_contact, event_timeout, event_flying_apart, event_slipout, event_stop_external_force = add_grasp_events_from_cfg( - base_simulation, grasp_objective_cfg) - sim_list = create_sim_list(base_simulation, grasp_objective_cfg.object_list) - - return sim_list - - -def create_rewarder(grasp_objective_cfg: GraspObjective): - simulation_rewarder = SimulationReward(verbosity=0) - - simulation_rewarder.add_criterion(TimeCriterion(hp.GRASP_TIME, event_timeout, event_grasp), - hp.TIME_CRITERION_WEIGHT) - - simulation_rewarder.add_criterion(InstantContactingLinkCriterion(event_grasp), - hp.INSTANT_CONTACTING_LINK_CRITERION_WEIGHT) - simulation_rewarder.add_criterion(InstantForceCriterion(event_grasp), - hp.INSTANT_FORCE_CRITERION_WEIGHT) - simulation_rewarder.add_criterion(InstantObjectCOGCriterion(event_grasp), - hp.OBJECT_COG_CRITERION_WEIGHT) - n_steps = int(hp.GRASP_TIME / hp.TIME_STEP_SIMULATION) - print(n_steps) - simulation_rewarder.add_criterion(GraspTimeCriterion(event_grasp, n_steps), - hp.GRASP_TIME_CRITERION_WEIGHT) - simulation_rewarder.add_criterion( - FinalPositionCriterion(hp.REFERENCE_DISTANCE, event_grasp, event_slipout), - hp.FINAL_POSITION_CRITERION_WEIGHT) diff --git a/app/hyperparameters.py b/app/hyperparameters.py index 8193b570..e711b51b 100644 --- a/app/hyperparameters.py +++ b/app/hyperparameters.py @@ -1,32 +1,33 @@ -MAX_NUMBER_RULES = 13 +MAX_NUMBER_RULES = 13 + +BASE_ITERATION_LIMIT_TENDON = 10 +FULL_LOOP_MCTS = 10 +MCTS_C = 5 -BASE_ITERATION_LIMIT = 30 -BASE_ITERATION_LIMIT_GRAPH = 200 -BASE_ITERATION_LIMIT_TENDON = 100 ITERATION_REDUCTION_TIME = 0.7 TIME_CRITERION_WEIGHT = 3 -FORCE_CRITERION_WEIGHT = 1 +FORCE_CRITERION_WEIGHT = 0.5 OBJECT_COG_CRITERION_WEIGHT = 1 INSTANT_FORCE_CRITERION_WEIGHT = 1 -INSTANT_CONTACTING_LINK_CRITERION_WEIGHT = 1 +INSTANT_CONTACTING_LINK_CRITERION_WEIGHT = 2 GRASP_TIME_CRITERION_WEIGHT = 1 FINAL_POSITION_CRITERION_WEIGHT = 5 -REFERENCE_DISTANCE = 0.3 +REFERENCE_DISTANCE = 0.1 -CONTROL_OPTIMIZATION_BOUNDS = (3, 15) +CONTROL_OPTIMIZATION_BOUNDS = (5, 15) CONTROL_OPTIMIZATION_BOUNDS_TENDON = (10, 20) CONTROL_OPTIMIZATION_ITERATION = 8 CONTROL_OPTIMIZATION_ITERATION_TENDON = 20 TENDON_CONST = -5 -TENDON_DISCRETE_FORCES = [10, 15, 20] +TENDON_DISCRETE_FORCES = [10, 15, 20] -TIME_STEP_SIMULATION = 0.00001 -GRASP_TIME = 5 -FORCE_TEST_TIME = 5 -TIME_SIMULATION = 10 +TIME_STEP_SIMULATION = 0.0005 +GRASP_TIME = 1.5 +FORCE_TEST_TIME = 3 +TIME_SIMULATION = 4.5 -FLAG_TIME_NO_CONTACT = 2.5 -FLAG_TIME_SLIPOUT = 1 +FLAG_TIME_NO_CONTACT = 0.5 +FLAG_TIME_SLIPOUT = 0.4 FLAG_FLYING_APART = 10 \ No newline at end of file diff --git a/app/tendon_driven_cfg.py b/app/tendon_driven_cfg.py new file mode 100644 index 00000000..5e14bc4e --- /dev/null +++ b/app/tendon_driven_cfg.py @@ -0,0 +1,59 @@ +from rostok.control_chrono.tendon_controller import TendonControllerParameters +from rostok.library.obj_grasp.objects import get_object_parametrized_cuboctahedron, get_object_parametrized_dipyramid_3 +from rostok.pipeline.generate_grasper_cfgs import MCTSCfg, SimulationConfig, GraspObjective, BruteForceRewardCfg +from rostok.simulation_chrono.simulation_scenario import GraspScenario +import rostok.control_chrono.external_force as f_ext +from rostok.trajectory_optimizer.control_optimizer import TendonForceOptiVar +from rostok.utils.numeric_utils import Offset + + +HARD_OBJECT_SET = [ + get_object_parametrized_cuboctahedron(0.05, mass=0.100), + get_object_parametrized_dipyramid_3(0.05, mass=0.200) +] +HARD_OBJECT_SET_W = [1.0, 1.0] + + +def get_random_force_with_null_grav(amp): + obj_forces = [] + obj_forces.append(f_ext.NullGravity(0)) + obj_forces.append(f_ext.RandomForces(amp, 100, 0)) + obj_forces = f_ext.ExternalForces(obj_forces) + return obj_forces + + +def get_default_tendon_params(): + data = TendonControllerParameters() + data.amount_pulley_in_body = 2 + data.pulley_parameters_for_body = { + 0: [Offset(-0.14, True), Offset(0.005, False, True), + Offset(0, True)], + 1: [Offset(-0.14, True), Offset(-0.005, False, True), + Offset(0, True)] + } + data.starting_point_parameters = [Offset(-0.02, False), Offset(0.025, False), Offset(0, True)] + data.tip_parameters = [Offset(-0.3, True), Offset(-0.005, False, True), Offset(0, True)] + return data + + +rand_null_force = get_random_force_with_null_grav(10) +default_simulation_config = SimulationConfig(0.0005, 4.5, GraspScenario, rand_null_force) +default_grasp_objective = GraspObjective( + # Objects setup + HARD_OBJECT_SET, + HARD_OBJECT_SET_W, + # Event setup + event_time_no_contact_param=0.5, + event_flying_apart_time_param=10, + event_slipout_time_param=0.4, + event_grasp_time_param=1.5, + event_force_test_time_param=3, + # Weight setup + time_criterion_weight=3, + final_pos_criterion_weight=5, + # Object pos setup + refernece_distance=0.3) + +brute_force_opti_default_cfg = BruteForceRewardCfg([10, 15, 20]) + +hyperparams_mcts_default = MCTSCfg() diff --git a/app/tendon_graph_evaluators.py b/app/tendon_graph_evaluators.py new file mode 100644 index 00000000..e50eba98 --- /dev/null +++ b/app/tendon_graph_evaluators.py @@ -0,0 +1,33 @@ +from copy import deepcopy +from rostok.trajectory_optimizer.control_optimizer import TendonForceOptiVar +import tendon_driven_cfg +import rostok.pipeline.generate_grasper_cfgs as pipeline + +tendon_optivar_standart = TendonForceOptiVar(tendon_driven_cfg.get_default_tendon_params(), + params_start_pos=-45) + +evaluator_tendon_standart = pipeline.create_reward_calulator( + tendon_driven_cfg.default_simulation_config, tendon_driven_cfg.default_grasp_objective, + tendon_optivar_standart, tendon_driven_cfg.brute_force_opti_default_cfg) + +brute_force_opti_default_cfg_parallel = deepcopy(tendon_driven_cfg.brute_force_opti_default_cfg) +brute_force_opti_default_cfg_parallel.num_cpu_workers = 6 + +evaluator_tendon_standart_parallel = pipeline.create_reward_calulator( + tendon_driven_cfg.default_simulation_config, tendon_driven_cfg.default_grasp_objective, + tendon_optivar_standart, brute_force_opti_default_cfg_parallel) + + + +tendon_optivar_strong = TendonForceOptiVar(tendon_driven_cfg.get_default_tendon_params(), + params_start_pos=-60) +brute_force_opti_strong = deepcopy(tendon_driven_cfg.brute_force_opti_default_cfg) +brute_force_opti_strong.variants = [30, 40, 50] + +simulation_config_strong = deepcopy(tendon_driven_cfg.default_simulation_config) +simulation_config_strong.obj_disturbance_forces = tendon_driven_cfg.get_random_force_with_null_grav( + 150) + +evaluator_tendon_strong = pipeline.create_reward_calulator( + simulation_config_strong, tendon_driven_cfg.default_grasp_objective, tendon_optivar_strong, + brute_force_opti_strong) diff --git a/rostok/pipeline/generate_grasper_cfgs.py b/rostok/pipeline/generate_grasper_cfgs.py new file mode 100644 index 00000000..2dbf3e5a --- /dev/null +++ b/rostok/pipeline/generate_grasper_cfgs.py @@ -0,0 +1,193 @@ +from copy import deepcopy +from dataclasses import dataclass, field +from typing import Type + +from pyparsing import Any +from rostok.block_builder_api.block_blueprints import EnvironmentBodyBlueprint +from rostok.control_chrono.controller import ConstController, RobotControllerChrono +from rostok.criterion.criterion_calculation import FinalPositionCriterion, GraspTimeCriterion, InstantContactingLinkCriterion, InstantForceCriterion, InstantObjectCOGCriterion, SimulationReward, TimeCriterion +from rostok.criterion.simulation_flags import EventContact, EventContactTimeOut, EventFlyingApart, EventSlipOut, \ +EventGrasp, EventStopExternalForce +from rostok.simulation_chrono.simulation_scenario import GraspScenario, ParametrizedSimulation +import rostok.control_chrono.external_force as f_ext +from rostok.trajectory_optimizer.control_optimizer import BasePrepareOptiVar, BruteForceOptimisation1D, ConstTorqueOptiVar, GlobalOptimisationEachSim +from scipy.optimize import direct + + +@dataclass +class SimulationConfig: + time_step: float = 0.0001 + time_simulation: float = 10 + scenario_cls: Type[GraspScenario] = GraspScenario + obj_disturbance_forces: list[f_ext.ABCForceCalculator] = field(default_factory=list) + + +@dataclass +class GraspObjective: + object_list: list[EnvironmentBodyBlueprint] = field(default_factory=list) + weight_list: list[float] = field(default_factory=list) + event_time_no_contact_param: float = 2 + event_flying_apart_time_param: float = 2 + event_slipout_time_param: float = 1 + event_grasp_time_param: float = 5 + event_force_test_time_param: float = 5 + + time_criterion_weight: float = 1 + instant_contact_link_criterion_weight: float = 1 + instant_force_criterion_weight: float = 1 + instant_cog_criterion_weight: float = 1 + grasp_time_criterion_weight: float = 1 + final_pos_criterion_weight: float = 1 + + refernece_distance: float = 0.3 + + +@dataclass +class BruteForceRewardCfg(): + variants: list[float] = field(default_factory=list) + num_cpu_workers = 1 + timeout_parallel: float = 20 + chunksize = 'auto' + + +@dataclass +class GlobalOptimisationRewardCfg(): + optimisation_tool: Any = direct + args_for_optimiser = None + bound: tuple[float, float] = (0, 1) + + +@dataclass +class MCTSCfg(): + C: int = 5 + full_loop: int = 10 + base_iteration: int = 10 + max_number_rules: int = 13 + + +def create_base_sim(contoller_cls, sim_cfg: SimulationConfig): + """Base sim without object + + Args: + contoller_cls (_type_): _description_ + sim_cfg (SimulationConfig): _description_ + + Returns: + _type_: _description_ + """ + return sim_cfg.scenario_cls(sim_cfg.time_step, + sim_cfg.time_simulation, + contoller_cls, + obj_external_forces=sim_cfg.obj_disturbance_forces) + + +def add_grasp_events_from_cfg(sim: GraspScenario, cfg: GraspObjective): + event_contact = EventContact() + sim.add_event(event_contact) + event_timeout = EventContactTimeOut(cfg.event_time_no_contact_param, event_contact) + sim.add_event(event_timeout) + event_flying_apart = EventFlyingApart(cfg.event_flying_apart_time_param) + sim.add_event(event_flying_apart) + event_slipout = EventSlipOut(cfg.event_slipout_time_param) + sim.add_event(event_slipout) + event_grasp = EventGrasp(grasp_limit_time=cfg.event_grasp_time_param, + contact_event=event_contact, + verbosity=0, + simulation_stop=True) + sim.add_event(event_grasp) + event_stop_external_force = EventStopExternalForce( + grasp_event=event_grasp, force_test_time=cfg.event_force_test_time_param) + sim.add_event(event_stop_external_force) + return event_contact, event_timeout, event_flying_apart, event_slipout, event_stop_external_force, event_grasp + + +def create_sim_list(base_sim: GraspScenario, object_list: list[EnvironmentBodyBlueprint]): + sim_list = [] + for obj_i in object_list: + sim_i = deepcopy(base_sim) + sim_i.grasp_object_callback = obj_i + sim_list.append(sim_i) + return sim_list + + +def prepare_simulation_scenario_list(contoller_cls, sim_cfg: SimulationConfig, + grasp_objective_cfg: GraspObjective): + + base_simulation = create_base_sim(contoller_cls, sim_cfg) + # event_contact, event_timeout, event_flying_apart, event_slipout, event_stop_external_force, event_grasp = add_grasp_events_from_cfg( + # base_simulation, grasp_objective_cfg) + sim_list = create_sim_list(base_simulation, grasp_objective_cfg.object_list) + + return sim_list + + +def create_rewarder(grasp_objective_cfg: GraspObjective, sim_cfg: SimulationConfig, event_timeout, + event_grasp, event_slipout): + simulation_rewarder = SimulationReward(verbosity=0) + + simulation_rewarder.add_criterion( + TimeCriterion(grasp_objective_cfg.event_grasp_time_param, event_timeout, event_grasp), + grasp_objective_cfg.time_criterion_weight) + + simulation_rewarder.add_criterion(InstantContactingLinkCriterion(event_grasp), + grasp_objective_cfg.instant_contact_link_criterion_weight) + simulation_rewarder.add_criterion(InstantForceCriterion(event_grasp), + grasp_objective_cfg.instant_contact_link_criterion_weight) + simulation_rewarder.add_criterion(InstantObjectCOGCriterion(event_grasp), + grasp_objective_cfg.instant_cog_criterion_weight) + n_steps = int(grasp_objective_cfg.event_grasp_time_param / sim_cfg.time_step) + print(n_steps) + simulation_rewarder.add_criterion(GraspTimeCriterion(event_grasp, n_steps), + grasp_objective_cfg.grasp_time_criterion_weight) + simulation_rewarder.add_criterion( + FinalPositionCriterion(grasp_objective_cfg.refernece_distance, event_grasp, event_slipout), + grasp_objective_cfg.final_pos_criterion_weight) + + return simulation_rewarder + + +def create_global_optimisation(sim_list: list[GraspScenario], preapare_reward: BasePrepareOptiVar, + glop_cfg: GlobalOptimisationRewardCfg): + rew = GlobalOptimisationEachSim(sim_list, preapare_reward, glop_cfg.bound, + glop_cfg.args_for_optimiser, glop_cfg.optimisation_tool) + + return rew + + +def create_bruteforce_optimisation(sim_list: list[GraspScenario], + preapare_reward: BasePrepareOptiVar, + grasp_objective: GraspObjective, brute_cfg: BruteForceRewardCfg): + rew = BruteForceOptimisation1D(brute_cfg.variants, sim_list, preapare_reward, + grasp_objective.weight_list, brute_cfg.num_cpu_workers, + brute_cfg.chunksize, brute_cfg.timeout_parallel) + + return rew + + +def create_reward_calulator(sim_config: SimulationConfig, grasp_objective: GraspObjective, + prepare_reward: BasePrepareOptiVar, + optimisation_control_cgf: GlobalOptimisationRewardCfg | + BruteForceRewardCfg): + + simlist = prepare_simulation_scenario_list(prepare_reward.control_class, sim_config, + grasp_objective) + + event_timeout = event_grasp = event_slipout = None + + for sim_i in simlist: + _, event_timeout, _, event_slipout, _, event_grasp = add_grasp_events_from_cfg( + sim_i, grasp_objective) + + rewarder = create_rewarder(grasp_objective, sim_config, event_timeout, event_grasp, + event_slipout) + + prepare_reward.set_reward_fun(rewarder) + + if isinstance(optimisation_control_cgf, GlobalOptimisationRewardCfg): + return create_global_optimisation(simlist, prepare_reward, optimisation_control_cgf) + elif isinstance(optimisation_control_cgf, BruteForceRewardCfg): + return create_bruteforce_optimisation(simlist, prepare_reward, grasp_objective, + optimisation_control_cgf) + else: + raise Exception("Wrong type of optimisation_control_cgf") + diff --git a/rostok/trajectory_optimizer/control_optimizer.py b/rostok/trajectory_optimizer/control_optimizer.py index e3b5a02f..8f29368d 100644 --- a/rostok/trajectory_optimizer/control_optimizer.py +++ b/rostok/trajectory_optimizer/control_optimizer.py @@ -54,7 +54,7 @@ class BasePrepareOptiVar(): def __init__(self, each_control_params: Any, control_class: Type[RobotControllerChrono], - rewarder: SimulationReward, + rewarder: SimulationReward | None, params_start_pos=None): self.each_control_params = each_control_params self.control_class = control_class @@ -127,15 +127,23 @@ def reward_one_sim_scenario(self, x: list, graph: GraphGrammar, sim: Parametrize start_pos = self.build_starting_positions(graph) # pylint: disable=assignment-from-none is_vis = self.is_vis_decision(graph) and self.is_vis simout = sim.run_simulation(graph, control_data, start_pos, is_vis) - rew = self.rewarder.calculate_reward(simout) + rew = self.rewarder.calculate_reward(simout) return rew, x, sim + + def set_reward_fun(self, rewarder: SimulationReward): + """Set reward function. + + Args: + rewarder (SimulationReward): _description_ + """ + self.rewarder = rewarder class TendonForceOptiVar(BasePrepareOptiVar): def __init__(self, each_control_params: TendonControllerParameters, - rewarder: SimulationReward, + rewarder: SimulationReward | None = None, params_start_pos=None): super().__init__(each_control_params, TendonController_2p, rewarder, params_start_pos) From c3cee78f8c3320143419b0ff8f36a5a839cf34ee Mon Sep 17 00:00:00 2001 From: KirillZharkov Date: Thu, 2 Nov 2023 15:16:18 +0300 Subject: [PATCH 4/9] [app] --- app/app.py | 85 ---------------------------------- app/app_new_mcts.py | 19 ++++---- app/app_new_multiobject.py | 83 --------------------------------- app/tendon_app.py | 79 ------------------------------- app/tendon_driven_cfg.py | 3 ++ app/tendon_graph_evaluators.py | 21 +++++++-- 6 files changed, 31 insertions(+), 259 deletions(-) delete mode 100644 app/app.py delete mode 100644 app/app_new_multiobject.py delete mode 100644 app/tendon_app.py diff --git a/app/app.py b/app/app.py deleted file mode 100644 index df5a861d..00000000 --- a/app/app.py +++ /dev/null @@ -1,85 +0,0 @@ -import sys -import time -import pickle -from pathlib import Path - -import hyperparameters as hp -import mcts -from mcts_run_setup import config_with_standard - -from rostok.graph_generators.mcts_helper import (make_mcts_step, prepare_mcts_state_and_helper, - CheckpointMCTS) -from rostok.graph_grammar.node import GraphGrammar -from rostok.library.obj_grasp.objects import get_object_parametrized_sphere -from rostok.library.rule_sets.ruleset_old_style import create_rules - -# create rule vocabulary -rule_vocabul = create_rules() -# create blueprint for object to grasp -grasp_object_blueprint = get_object_parametrized_sphere(0.5) -# create reward counter using run setup function -control_optimizer = config_with_standard(grasp_object_blueprint) -# Initialize MCTS -base_iteration_limit = hp.BASE_ITERATION_LIMIT -max_numbers_rules = hp.MAX_NUMBER_RULES -initial_graph = GraphGrammar() -graph_env = prepare_mcts_state_and_helper(initial_graph, rule_vocabul, control_optimizer, - max_numbers_rules, Path("./results")) -mcts_helper = graph_env.helper -mcts_helper.report.non_terminal_rules_limit = max_numbers_rules -mcts_helper.report.search_parameter = base_iteration_limit - -# the constant that determines how we reduce the number of iterations in the MCTS search -iteration_reduction_rate = hp.ITERATION_REDUCTION_TIME -checkpointer = CheckpointMCTS(mcts_helper.report, "App", rewrite=True) -checkpointer.save_object(grasp_object_blueprint) - -start = time.time() -finish = False -n_steps = 0 - -while not finish: - iteration_limit = base_iteration_limit - int(graph_env.counter_action / max_numbers_rules * - (base_iteration_limit * iteration_reduction_rate)) - searcher = mcts.mcts(iterationLimit=iteration_limit) - finish, graph_env = make_mcts_step(searcher, graph_env, n_steps, checkpointer) - n_steps += 1 - print(f"number iteration: {n_steps}, counter actions: {graph_env.counter_action} " + - f"reward: {mcts_helper.report.get_best_info()[1]}") -ex = time.time() - start -print(f"time :{ex}") - -report = mcts_helper.report -path = report.make_time_dependent_path() -with open(Path(path, "object.pickle"), "wb") as file: - pickle.dump(grasp_object_blueprint, file) -report.save() -report.save_visuals() -report.save_lists() -report.save_means() - -# additions to the file -with open(Path(path, "mcts_result.txt"), "a") as file: - original_stdout = sys.stdout - sys.stdout = file - print() - print("Object to grasp:", grasp_object_blueprint.shape) - print("Time optimization:", ex) - dict = { - item: getattr(hp, item) - for item in dir(hp) - if not item.startswith("__") and not item.endswith("__") - } - for key, value in dict.items(): - print(key, "=", value) - - sys.stdout = original_stdout - -simulation_rewarder = control_optimizer.rewarder -simulation_manager = control_optimizer.simulation_scenario -# visualisation in the end of the search -best_graph, reward, best_control = mcts_helper.report.get_best_info() -data = {"initial_value": best_control} -simulation_output = simulation_manager.run_simulation(best_graph, data, True) -res = simulation_rewarder.calculate_reward(simulation_output) -print("Best reward obtained in the MCTS search:", res) \ No newline at end of file diff --git a/app/app_new_mcts.py b/app/app_new_mcts.py index 0333fdf1..8caf947e 100644 --- a/app/app_new_mcts.py +++ b/app/app_new_mcts.py @@ -1,27 +1,28 @@ -import hyperparameters as hp + from rostok.graph_generators.environments.design_environment import (SubStringDesignEnvironment) from rostok.graph_generators.mcts_manager import MCTSManager from rostok.graph_generators.search_algorithms.mcts import MCTS from rostok.library.rule_sets.rulset_simple_fingers import create_rules from rostok.graph_grammar.node import GraphGrammar -import hyperparameters as hp + from tendon_graph_evaluators import evaluator_tendon_standart, evaluator_tendon_standart_parallel +from tendon_graph_evaluators import mcts_hyper_default, evaluator_tendon_fast_debug import tendon_driven_cfg if __name__ == "__main__": rule_vocabulary = create_rules() init_graph = GraphGrammar() - env = SubStringDesignEnvironment(rule_vocabulary, evaluator_tendon_standart_parallel, - hp.MAX_NUMBER_RULES, init_graph, 0) + env = SubStringDesignEnvironment(rule_vocabulary, evaluator_tendon_fast_debug, + mcts_hyper_default.max_number_rules, init_graph, 0) - mcts = MCTS(env, hp.MCTS_C) + mcts = MCTS(env, mcts_hyper_default.C) name_directory = input("enter directory name: ") mcts_manager = MCTSManager(mcts, name_directory, verbosity=2, use_date=True) - #mcts_manager.save_information_about_search( - # hp, tendon_driven_cfg.default_grasp_objective.object_list) + mcts_manager.save_information_about_search( + mcts_hyper_default, tendon_driven_cfg.default_grasp_objective.object_list) - for i in range(hp.FULL_LOOP_MCTS): - mcts_manager.run_search(hp.BASE_ITERATION_LIMIT_TENDON, 1, 1, 2) + for i in range(mcts_hyper_default.full_loop): + mcts_manager.run_search(mcts_hyper_default.base_iteration, 1, 1, 2) mcts_manager.save_results() \ No newline at end of file diff --git a/app/app_new_multiobject.py b/app/app_new_multiobject.py deleted file mode 100644 index c8e7bee0..00000000 --- a/app/app_new_multiobject.py +++ /dev/null @@ -1,83 +0,0 @@ -import sys - -sys.path.append("./examples/") -import time -from pathlib import Path - -import hyperparameters as hp -import mcts -from mcts_run_setup import config_with_standard_multiobject - -from rostok.graph_generators.mcts_helper import (make_mcts_step, prepare_mcts_state_and_helper, CheckpointMCTS) -from rostok.graph_grammar.node import GraphGrammar -from rostok.library.obj_grasp.objects import get_object_parametrized_sphere, get_object_cylinder, get_object_box -from rostok.library.rule_sets.ruleset_new_style import create_rules - -weights = [1, 1, 1] -# create rule vocabulary -rule_vocabul = create_rules() -# create blueprint for object to grasp -grasp_object_blueprint = [] -grasp_object_blueprint.append(get_object_parametrized_sphere(0.4)) -grasp_object_blueprint.append(get_object_cylinder(0.4, 0.4, 0)) -grasp_object_blueprint.append(get_object_box(0.5,0.2,0.7,0)) -# create reward counter using run setup function -control_optimizer = config_with_standard_multiobject(grasp_object_blueprint, weights) -# Initialize MCTS -base_iteration_limit = hp.BASE_ITERATION_LIMIT -max_numbers_rules = hp.MAX_NUMBER_RULES -initial_graph = GraphGrammar() -graph_env = prepare_mcts_state_and_helper(initial_graph, rule_vocabul, control_optimizer, - max_numbers_rules, Path("./results")) -mcts_helper = graph_env.helper -mcts_helper.report.non_terminal_rules_limit = max_numbers_rules -mcts_helper.report.search_parameter = base_iteration_limit - -# the constant that determines how we reduce the number of iterations in the MCTS search -iteration_reduction_rate = hp.ITERATION_REDUCTION_TIME -checkpointer = CheckpointMCTS(mcts_helper.report, "App", rewrite=True) -start = time.time() -finish = False -n_steps = 0 - -while not finish: - iteration_limit = base_iteration_limit - int(graph_env.counter_action / max_numbers_rules * - (base_iteration_limit * iteration_reduction_rate)) - searcher = mcts.mcts(iterationLimit=iteration_limit) - finish, graph_env = make_mcts_step(searcher, graph_env, n_steps, checkpointer) - n_steps += 1 - print(f"number iteration: {n_steps}, counter actions: {graph_env.counter_action} " + - f"reward: {mcts_helper.report.get_best_info()[1]}") -ex = time.time() - start -print(f"time :{ex}") - -report = mcts_helper.report -path = report.make_time_dependent_path() -report.save() -report.save_visuals() -report.save_lists() -report.save_means() - -# additions to the file -with open(Path(path, "mcts_result.txt"), "a") as file: - original_stdout = sys.stdout - sys.stdout = file - print() - for k, (obj, weight) in enumerate(zip(grasp_object_blueprint, weights)): - print(f"Objects to grasp {k}:", obj.shape) - print(f"Object initial coordinats {k}:", obj.pos) - print(f"Object weight {k}:", weight) - print("Time optimization:", ex) - dict = {item:getattr(hp, item) for item in dir(hp) if not item.startswith("__") and not item.endswith("__")} - for key, value in dict.items(): - print(key, "=", value) - sys.stdout = original_stdout - -simulation_rewarder = control_optimizer.rewarder -simulation_manager = control_optimizer.simulation_scenario[0] -# visualisation in the end of the search -best_graph, reward, best_control = mcts_helper.report.get_best_info() -data = control_optimizer.optim_parameters2data_control(best_control) -simulation_output = simulation_manager[0].run_simulation(best_graph, data[0], True) -res = simulation_rewarder.calculate_reward(simulation_output) -print("Best reward obtained in the MCTS search:", res) \ No newline at end of file diff --git a/app/tendon_app.py b/app/tendon_app.py deleted file mode 100644 index 54f517d5..00000000 --- a/app/tendon_app.py +++ /dev/null @@ -1,79 +0,0 @@ -import sys -import time -import pickle -from pathlib import Path - -import hyperparameters as hp -import mcts -from mcts_run_setup import config_cable -from rostok.graph_generators.mcts_helper import (make_mcts_step, - prepare_mcts_state_and_helper, CheckpointMCTS) -from rostok.graph_grammar.node import GraphGrammar -from rostok.library.obj_grasp.objects import get_object_parametrized_sphere -from rostok.library.rule_sets.ruleset_old_style import create_rules - -# create rule vocabulary -rule_vocabul = create_rules() -# create blueprint for object to grasp -grasp_object_blueprint = get_object_parametrized_sphere(0.5) -# create reward counter using run setup function -control_optimizer = config_cable(grasp_object_blueprint) -# Initialize MCTS -base_iteration_limit = hp.BASE_ITERATION_LIMIT_TENDON -max_numbers_rules = hp.MAX_NUMBER_RULES -initial_graph = GraphGrammar() -graph_env = prepare_mcts_state_and_helper(initial_graph, rule_vocabul, control_optimizer, - max_numbers_rules, Path("./results")) -mcts_helper = graph_env.helper -mcts_helper.report.non_terminal_rules_limit = max_numbers_rules -mcts_helper.report.search_parameter = base_iteration_limit - -# the constant that determines how we reduce the number of iterations in the MCTS search -iteration_reduction_rate = hp.ITERATION_REDUCTION_TIME -checkpointer = CheckpointMCTS(mcts_helper.report, "App_tendon", rewrite=False) -checkpointer.save_object(grasp_object_blueprint) -start = time.time() -finish = False -n_steps = 0 - -while not finish: - iteration_limit = base_iteration_limit - int(graph_env.counter_action / max_numbers_rules * - (base_iteration_limit * iteration_reduction_rate)) - searcher = mcts.mcts(iterationLimit=iteration_limit) - finish, graph_env = make_mcts_step(searcher, graph_env, n_steps, checkpointer) - n_steps += 1 - print(f"number iteration: {n_steps}, counter actions: {graph_env.counter_action} " + - f"reward: {mcts_helper.report.get_best_info()[1]}") -ex = time.time() - start -print(f"time :{ex}") - -report = mcts_helper.report -path = report.make_time_dependent_path() -with open(Path(path, "object.pickle"), "wb") as file: - pickle.dump(grasp_object_blueprint, file) -report.save() -report.save_visuals() -report.save_lists() -report.save_means() - -# additions to the file -with open(Path(path, "mcts_result.txt"), "a") as file: - original_stdout = sys.stdout - sys.stdout = file - print() - print("Object to grasp:", grasp_object_blueprint.shape) - print("Time optimization:", ex) - dict = {item:getattr(hp, item) for item in dir(hp) if not item.startswith("__") and not item.endswith("__")} - for key, value in dict.items(): - print(key, value) - sys.stdout = original_stdout - -simulation_rewarder = control_optimizer.rewarder -simulation_manager = control_optimizer.simulation_scenario -# visualisation in the end of the search -best_graph, reward, best_control = mcts_helper.report.get_best_info() -data = control_optimizer.optim_parameters2data_control(best_control, best_graph) -#data = {"initial_value": best_control} -simulation_output = simulation_manager.run_simulation(best_graph, data, True) -res = simulation_rewarder.calculate_reward(simulation_output) -print("Best reward obtained in the MCTS search:", res) \ No newline at end of file diff --git a/app/tendon_driven_cfg.py b/app/tendon_driven_cfg.py index 5e14bc4e..206c7f3f 100644 --- a/app/tendon_driven_cfg.py +++ b/app/tendon_driven_cfg.py @@ -38,6 +38,8 @@ def get_default_tendon_params(): rand_null_force = get_random_force_with_null_grav(10) default_simulation_config = SimulationConfig(0.0005, 4.5, GraspScenario, rand_null_force) +fast_mock_simulation_config = SimulationConfig(0.001, 0.1, GraspScenario, rand_null_force) + default_grasp_objective = GraspObjective( # Objects setup HARD_OBJECT_SET, @@ -57,3 +59,4 @@ def get_default_tendon_params(): brute_force_opti_default_cfg = BruteForceRewardCfg([10, 15, 20]) hyperparams_mcts_default = MCTSCfg() +hyperparams_mcts_default_max_r15 = MCTSCfg(max_number_rules = 15) \ No newline at end of file diff --git a/app/tendon_graph_evaluators.py b/app/tendon_graph_evaluators.py index e50eba98..595e4c76 100644 --- a/app/tendon_graph_evaluators.py +++ b/app/tendon_graph_evaluators.py @@ -5,11 +5,12 @@ tendon_optivar_standart = TendonForceOptiVar(tendon_driven_cfg.get_default_tendon_params(), params_start_pos=-45) - +# Standart config evaluator_tendon_standart = pipeline.create_reward_calulator( tendon_driven_cfg.default_simulation_config, tendon_driven_cfg.default_grasp_objective, tendon_optivar_standart, tendon_driven_cfg.brute_force_opti_default_cfg) +# Standart + parallel config brute_force_opti_default_cfg_parallel = deepcopy(tendon_driven_cfg.brute_force_opti_default_cfg) brute_force_opti_default_cfg_parallel.num_cpu_workers = 6 @@ -18,10 +19,10 @@ tendon_optivar_standart, brute_force_opti_default_cfg_parallel) - +# More powerfull tendon + parallel config tendon_optivar_strong = TendonForceOptiVar(tendon_driven_cfg.get_default_tendon_params(), params_start_pos=-60) -brute_force_opti_strong = deepcopy(tendon_driven_cfg.brute_force_opti_default_cfg) +brute_force_opti_strong = deepcopy(brute_force_opti_default_cfg_parallel) brute_force_opti_strong.variants = [30, 40, 50] simulation_config_strong = deepcopy(tendon_driven_cfg.default_simulation_config) @@ -31,3 +32,17 @@ evaluator_tendon_strong = pipeline.create_reward_calulator( simulation_config_strong, tendon_driven_cfg.default_grasp_objective, tendon_optivar_strong, brute_force_opti_strong) + +# Fast single thread config for debug +tendon_optivar_debug = deepcopy(tendon_optivar_standart) +brute_force_debug_cfg = deepcopy(tendon_driven_cfg.brute_force_opti_default_cfg) +brute_force_debug_cfg.variants = [40] +tendon_optivar_debug.is_vis = True +evaluator_tendon_fast_debug = pipeline.create_reward_calulator( + tendon_driven_cfg.fast_mock_simulation_config, tendon_driven_cfg.default_grasp_objective, + tendon_optivar_debug, brute_force_debug_cfg) + + +mcts_hyper_default = pipeline.MCTSCfg() +mcts_hyper_short_fast = pipeline.MCTSCfg(max_number_rules=10, full_loop=8) +mcts_hyper_long = pipeline.MCTSCfg(max_number_rules=34) \ No newline at end of file From 0230e22ff6bd34c3778da2dc4f7f3fa56bdeb2c6 Mon Sep 17 00:00:00 2001 From: KirillZharkov Date: Thu, 2 Nov 2023 15:16:53 +0300 Subject: [PATCH 5/9] [json_encoder] Modify for MappingProxyType --- rostok/pipeline/generate_grasper_cfgs.py | 4 ++-- rostok/utils/json_encoder.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/rostok/pipeline/generate_grasper_cfgs.py b/rostok/pipeline/generate_grasper_cfgs.py index 2dbf3e5a..ee43eee4 100644 --- a/rostok/pipeline/generate_grasper_cfgs.py +++ b/rostok/pipeline/generate_grasper_cfgs.py @@ -93,7 +93,7 @@ def add_grasp_events_from_cfg(sim: GraspScenario, cfg: GraspObjective): event_grasp = EventGrasp(grasp_limit_time=cfg.event_grasp_time_param, contact_event=event_contact, verbosity=0, - simulation_stop=True) + simulation_stop=False) sim.add_event(event_grasp) event_stop_external_force = EventStopExternalForce( grasp_event=event_grasp, force_test_time=cfg.event_force_test_time_param) @@ -136,7 +136,7 @@ def create_rewarder(grasp_objective_cfg: GraspObjective, sim_cfg: SimulationConf simulation_rewarder.add_criterion(InstantObjectCOGCriterion(event_grasp), grasp_objective_cfg.instant_cog_criterion_weight) n_steps = int(grasp_objective_cfg.event_grasp_time_param / sim_cfg.time_step) - print(n_steps) + simulation_rewarder.add_criterion(GraspTimeCriterion(event_grasp, n_steps), grasp_objective_cfg.grasp_time_criterion_weight) simulation_rewarder.add_criterion( diff --git a/rostok/utils/json_encoder.py b/rostok/utils/json_encoder.py index 00abdb63..36b10efb 100644 --- a/rostok/utils/json_encoder.py +++ b/rostok/utils/json_encoder.py @@ -1,6 +1,8 @@ import json from enum import Enum +from types import MappingProxyType from typing import Any, Callable +import numpy as np class RostokJSONEncoder(json.JSONEncoder): @@ -8,4 +10,9 @@ class RostokJSONEncoder(json.JSONEncoder): def default(self, o: Any) -> Any: if isinstance(o, Enum): return o.value + elif (isinstance(o, MappingProxyType)): + return [type(o).__name__] + elif (isinstance(o, np.ndarray)): + return [type(o).__name__, str(o)] + return [type(o).__name__, o.__dict__] \ No newline at end of file From e21329b726bc27bb387d290fe7fe390109dc8d72 Mon Sep 17 00:00:00 2001 From: KirillZharkov Date: Thu, 2 Nov 2023 16:41:11 +0300 Subject: [PATCH 6/9] add objects --- app/app_new_mcts.py | 2 +- app/hyperparameters.py | 33 --- app/mcts_run_setup.py | 285 ----------------------- app/one_graph_simulation.py | 29 +-- app/tendon_driven_cfg.py | 14 +- rostok/library/obj_grasp/objects.py | 8 +- rostok/pipeline/generate_grasper_cfgs.py | 39 ++-- 7 files changed, 53 insertions(+), 357 deletions(-) delete mode 100644 app/hyperparameters.py delete mode 100644 app/mcts_run_setup.py diff --git a/app/app_new_mcts.py b/app/app_new_mcts.py index 8caf947e..53856018 100644 --- a/app/app_new_mcts.py +++ b/app/app_new_mcts.py @@ -14,7 +14,7 @@ rule_vocabulary = create_rules() init_graph = GraphGrammar() - env = SubStringDesignEnvironment(rule_vocabulary, evaluator_tendon_fast_debug, + env = SubStringDesignEnvironment(rule_vocabulary, evaluator_tendon_standart, mcts_hyper_default.max_number_rules, init_graph, 0) mcts = MCTS(env, mcts_hyper_default.C) diff --git a/app/hyperparameters.py b/app/hyperparameters.py deleted file mode 100644 index ed15eaf1..00000000 --- a/app/hyperparameters.py +++ /dev/null @@ -1,33 +0,0 @@ -MAX_NUMBER_RULES = 13 - -BASE_ITERATION_LIMIT_TENDON = 10 -FULL_LOOP_MCTS = 10 -MCTS_C = 5 - - -ITERATION_REDUCTION_TIME = 0.7 - -TIME_CRITERION_WEIGHT = 3 -FORCE_CRITERION_WEIGHT = 0.5 -OBJECT_COG_CRITERION_WEIGHT = 1 -INSTANT_FORCE_CRITERION_WEIGHT = 1 -INSTANT_CONTACTING_LINK_CRITERION_WEIGHT = 2 -GRASP_TIME_CRITERION_WEIGHT = 1 -FINAL_POSITION_CRITERION_WEIGHT = 5 -REFERENCE_DISTANCE = 0.1 - -CONTROL_OPTIMIZATION_BOUNDS = (5, 15) -CONTROL_OPTIMIZATION_BOUNDS_TENDON = (10, 20) -CONTROL_OPTIMIZATION_ITERATION = 8 -CONTROL_OPTIMIZATION_ITERATION_TENDON = 20 -TENDON_CONST = -5 -TENDON_DISCRETE_FORCES = [10, 15, 20] - -TIME_STEP_SIMULATION = 0.001 -GRASP_TIME = 1.5 -FORCE_TEST_TIME = 3 -TIME_SIMULATION = 4.5 - -FLAG_TIME_NO_CONTACT = 0.5 -FLAG_TIME_SLIPOUT = 0.4 -FLAG_FLYING_APART = 10 \ No newline at end of file diff --git a/app/mcts_run_setup.py b/app/mcts_run_setup.py deleted file mode 100644 index fa712b40..00000000 --- a/app/mcts_run_setup.py +++ /dev/null @@ -1,285 +0,0 @@ -from copy import deepcopy - -import hyperparameters as hp - -from rostok.control_chrono.tendon_controller import TendonController_2p, TendonControllerParameters -from rostok.criterion.criterion_calculation import (FinalPositionCriterion, GraspTimeCriterion, - InstantContactingLinkCriterion, - InstantForceCriterion, - InstantObjectCOGCriterion, SimulationReward, - TimeCriterion) -from rostok.criterion.simulation_flags import (EventContactBuilder, EventContactTimeOutBuilder, - EventFlyingApartBuilder, EventGraspBuilder, - EventSlipOutBuilder, EventStopExternalForceBuilder) -from rostok.simulation_chrono.simulation_scenario import GraspScenario -from rostok.trajectory_optimizer.control_optimizer import BruteForceOptimisation1D, ConstTorqueOptiVar, GlobalOptimisationEachSim, TendonForceOptiVar -from rostok.utils.numeric_utils import Offset -import rostok.control_chrono.external_force as f_ext - - -def get_tendon_cfg(): - tendon_controller_cfg = TendonControllerParameters() - tendon_controller_cfg.amount_pulley_in_body = 2 - tendon_controller_cfg.pulley_parameters_for_body = { - 0: [Offset(-0.14, True), Offset(0.005, False, True), - Offset(0, True)], - 1: [Offset(-0.14, True), Offset(-0.005, False, True), - Offset(0, True)] - } - tendon_controller_cfg.starting_point_parameters = [ - Offset(-0.02, False), Offset(0.025, False), - Offset(0, True) - ] - tendon_controller_cfg.tip_parameters = [ - Offset(-0.3, True), Offset(-0.005, False, True), - Offset(0, True) - ] - return tendon_controller_cfg - - -def config_independent_torque(grasp_object_blueprint): - - simulation_manager = GraspScenario(hp.TIME_STEP_SIMULATION, hp.TIME_SIMULATION) - - simulation_manager.grasp_object_callback = grasp_object_blueprint - event_contact_builder = EventContactBuilder() - simulation_manager.add_event_builder(event_contact_builder) - event_timeout_builder = EventContactTimeOutBuilder(hp.FLAG_TIME_NO_CONTACT, - event_contact_builder) - simulation_manager.add_event_builder(event_timeout_builder) - event_flying_apart_builder = EventFlyingApartBuilder(hp.FLAG_FLYING_APART) - simulation_manager.add_event_builder(event_flying_apart_builder) - event_slipout_builder = EventSlipOutBuilder(hp.FLAG_TIME_SLIPOUT) - simulation_manager.add_event_builder(event_slipout_builder) - event_grasp_builder = EventGraspBuilder( - grasp_limit_time=hp.GRASP_TIME, - event_contact_builder=event_contact_builder, - verbosity=0, - ) - simulation_manager.add_event_builder(event_grasp_builder) - event_stop_external_force = EventStopExternalForceBuilder( - event_grasp_builder=event_grasp_builder, force_test_time=hp.FORCE_TEST_TIME) - simulation_manager.add_event_builder(event_stop_external_force) - - #create criterion manager - simulation_rewarder = SimulationReward(verbosity=0) - #create criterions and add them to manager - simulation_rewarder.add_criterion( - TimeCriterion(hp.GRASP_TIME, event_timeout_builder, event_grasp_builder), - hp.TIME_CRITERION_WEIGHT) - #simulation_rewarder.add_criterion(ForceCriterion(event_timeout), hp.FORCE_CRITERION_WEIGHT) - simulation_rewarder.add_criterion(InstantContactingLinkCriterion(event_grasp_builder), - hp.INSTANT_CONTACTING_LINK_CRITERION_WEIGHT) - simulation_rewarder.add_criterion(InstantForceCriterion(event_grasp_builder), - hp.INSTANT_FORCE_CRITERION_WEIGHT) - simulation_rewarder.add_criterion(InstantObjectCOGCriterion(event_grasp_builder), - hp.OBJECT_COG_CRITERION_WEIGHT) - n_steps = int(hp.GRASP_TIME / hp.TIME_STEP_SIMULATION) - print(n_steps) - simulation_rewarder.add_criterion(GraspTimeCriterion(event_grasp_builder, n_steps), - hp.GRASP_TIME_CRITERION_WEIGHT) - simulation_rewarder.add_criterion( - FinalPositionCriterion(hp.REFERENCE_DISTANCE, event_grasp_builder, event_slipout_builder), - hp.FINAL_POSITION_CRITERION_WEIGHT) - - const_optivar = ConstTorqueOptiVar(simulation_rewarder, -45) - direct_args = {"maxiter": 2} - global_const = GlobalOptimisationEachSim([simulation_manager], const_optivar, (0, 10), - direct_args) - - return global_const - - -def config_tendon(grasp_object_blueprint): - obj_forces = [] - obj_forces.append(f_ext.RandomForces(1e6, 100, 20)) - obj_forces.append(f_ext.NullGravity(0)) - obj_forces = f_ext.ExternalForces(obj_forces) - simulation_manager = GraspScenario(hp.TIME_STEP_SIMULATION, hp.TIME_SIMULATION, TendonController_2p, obj_external_forces=obj_forces) - - simulation_manager.grasp_object_callback = grasp_object_blueprint - event_contact_builder = EventContactBuilder() - simulation_manager.add_event_builder(event_contact_builder) - event_timeout_builder = EventContactTimeOutBuilder(hp.FLAG_TIME_NO_CONTACT, - event_contact_builder) - simulation_manager.add_event_builder(event_timeout_builder) - event_flying_apart_builder = EventFlyingApartBuilder(hp.FLAG_FLYING_APART) - simulation_manager.add_event_builder(event_flying_apart_builder) - event_slipout_builder = EventSlipOutBuilder(hp.FLAG_TIME_SLIPOUT) - simulation_manager.add_event_builder(event_slipout_builder) - event_grasp_builder = EventGraspBuilder( - grasp_limit_time=hp.GRASP_TIME, - event_contact_builder=event_contact_builder, - verbosity=0, - ) - simulation_manager.add_event_builder(event_grasp_builder) - event_stop_external_force = EventStopExternalForceBuilder( - event_grasp_builder=event_grasp_builder, force_test_time=hp.FORCE_TEST_TIME) - simulation_manager.add_event_builder(event_stop_external_force) - - #create criterion manager - simulation_rewarder = SimulationReward(verbosity=0) - #create criterions and add them to manager - simulation_rewarder.add_criterion( - TimeCriterion(hp.GRASP_TIME, event_timeout_builder, event_grasp_builder), - hp.TIME_CRITERION_WEIGHT) - #simulation_rewarder.add_criterion(ForceCriterion(event_timeout), hp.FORCE_CRITERION_WEIGHT) - simulation_rewarder.add_criterion(InstantContactingLinkCriterion(event_grasp_builder), - hp.INSTANT_CONTACTING_LINK_CRITERION_WEIGHT) - simulation_rewarder.add_criterion(InstantForceCriterion(event_grasp_builder), - hp.INSTANT_FORCE_CRITERION_WEIGHT) - simulation_rewarder.add_criterion(InstantObjectCOGCriterion(event_grasp_builder), - hp.OBJECT_COG_CRITERION_WEIGHT) - n_steps = int(hp.GRASP_TIME / hp.TIME_STEP_SIMULATION) - print(n_steps) - simulation_rewarder.add_criterion(GraspTimeCriterion(event_grasp_builder, n_steps), - hp.GRASP_TIME_CRITERION_WEIGHT) - simulation_rewarder.add_criterion( - FinalPositionCriterion(hp.REFERENCE_DISTANCE, event_grasp_builder, event_slipout_builder), - hp.FINAL_POSITION_CRITERION_WEIGHT) - tendon_controller_cfg = get_tendon_cfg() - tendon_optivar = TendonForceOptiVar(tendon_controller_cfg, simulation_rewarder, -45) - tendon_optivar.is_vis = True - brute_tendon = BruteForceOptimisation1D(hp.TENDON_DISCRETE_FORCES, [simulation_manager], - tendon_optivar, - num_cpu_workers=1) - - return brute_tendon - -""" - -def config_with_tendon(grasp_object_blueprint): - # configurate the simulation manager - - obj_forces = [] - obj_forces.append(f_ext.NullGravity(0)) - obj_forces.append(f_ext.RandomForces(1e6, 100, 0)) - obj_forces = f_ext.ExternalForces(obj_forces) - simulation_manager = GraspScenario(hp.TIME_STEP_SIMULATION, hp.TIME_SIMULATION, TendonController_2p, obj_external_forces=obj_forces) - simulation_manager.grasp_object_callback = grasp_object_blueprint #lambda: creator.create_environment_body( - #grasp_object_blueprint) - event_contact = EventContact() - simulation_manager.add_event(event_contact) - event_timeout = EventContactTimeOut(hp.FLAG_TIME_NO_CONTACT, event_contact) - simulation_manager.add_event(event_timeout) - event_flying_apart = EventFlyingApart(hp.FLAG_FLYING_APART) - simulation_manager.add_event(event_flying_apart) - event_slipout = EventSlipOut(hp.FLAG_TIME_SLIPOUT) - simulation_manager.add_event(event_slipout) - event_grasp = EventGrasp(grasp_limit_time=hp.GRASP_TIME, - contact_event=event_contact, - verbosity=0, - simulation_stop=1) - simulation_manager.add_event(event_grasp) - event_stop_external_force = EventStopExternalForce(grasp_event=event_grasp, - force_test_time=hp.FORCE_TEST_TIME) - simulation_manager.add_event(event_stop_external_force) - - #create criterion manager - simulation_rewarder = SimulationReward(verbosity=0) - #create criterions and add them to manager - simulation_rewarder.add_criterion(TimeCriterion(hp.GRASP_TIME, event_timeout, event_grasp), - hp.TIME_CRITERION_WEIGHT) - #simulation_rewarder.add_criterion(ForceCriterion(event_timeout), hp.FORCE_CRITERION_WEIGHT) - simulation_rewarder.add_criterion(InstantContactingLinkCriterion(event_grasp), - hp.INSTANT_CONTACTING_LINK_CRITERION_WEIGHT) - simulation_rewarder.add_criterion(InstantForceCriterion(event_grasp), - hp.INSTANT_FORCE_CRITERION_WEIGHT) - simulation_rewarder.add_criterion(InstantObjectCOGCriterion(event_grasp), - hp.OBJECT_COG_CRITERION_WEIGHT) - n_steps = int(hp.GRASP_TIME / hp.TIME_STEP_SIMULATION) - print(n_steps) - simulation_rewarder.add_criterion(GraspTimeCriterion(event_grasp, n_steps), - hp.GRASP_TIME_CRITERION_WEIGHT) - simulation_rewarder.add_criterion( - FinalPositionCriterion(hp.REFERENCE_DISTANCE, event_grasp, event_slipout), - hp.FINAL_POSITION_CRITERION_WEIGHT) - - data = TendonControllerParameters() - data.amount_pulley_in_body = 2 - data.pulley_parameters_for_body = { - 0: [Offset(-0.14, True), Offset(0.005, False, True), - Offset(0, True)], - 1: [Offset(-0.14, True), Offset(-0.005, False, True), - Offset(0, True)] - } - data.starting_point_parameters = [Offset(-1., True), Offset(5 , True), Offset(0, True)] - data.tip_parameters = [Offset(-0.3, True), Offset(-0.005, False, True), Offset(0, True)] - - control_optimizer = TendonOptimizerCombinationForce(simulation_scenario = simulation_manager, rewarder = simulation_rewarder, - data = data, - starting_finger_angles=-45, - tendon_forces = hp.TENDON_DISCRETE_FORCES) - - return control_optimizer - - - -def config_combination_force_tendon_multiobject_parallel(grasp_object_blueprint, weights): - # configurate the simulation manager - simulation_manager = GraspScenario(hp.TIME_STEP_SIMULATION, hp.TIME_SIMULATION, TendonController_2p) - object_callback = grasp_object_blueprint - #[ - # (lambda obj=obj: creator.create_environment_body(obj)) for obj in grasp_object_blueprint - #] - simulation_managers = [] - for k in range(len(grasp_object_blueprint)): - simulation_managers.append((deepcopy(simulation_manager), weights[k])) - simulation_managers[-1][0].grasp_object_callback = object_callback[k] - - event_contact = EventContact() - event_timeout = EventContactTimeOut(hp.FLAG_TIME_NO_CONTACT, event_contact) - event_flying_apart = EventFlyingApart(hp.FLAG_FLYING_APART) - event_slipout = EventSlipOut(hp.FLAG_TIME_SLIPOUT) - event_grasp = EventGrasp( - grasp_limit_time=hp.GRASP_TIME, - contact_event=event_contact, - verbosity=0, - ) - event_stop_external_force = EventStopExternalForce(grasp_event=event_grasp, - force_test_time=hp.FORCE_TEST_TIME) - for manager in simulation_managers: - manager[0].add_event(event_contact) - manager[0].add_event(event_timeout) - manager[0].add_event(event_flying_apart) - manager[0].add_event(event_grasp) - manager[0].add_event(event_stop_external_force) - - #create criterion manager - simulation_rewarder = SimulationReward(verbosity=0) - #create criterions and add them to manager - simulation_rewarder.add_criterion(TimeCriterion(hp.GRASP_TIME, event_timeout, event_grasp), - hp.TIME_CRITERION_WEIGHT) - #simulation_rewarder.add_criterion(ForceCriterion(event_timeout), hp.FORCE_CRITERION_WEIGHT) - simulation_rewarder.add_criterion(InstantContactingLinkCriterion(event_grasp), - hp.INSTANT_CONTACTING_LINK_CRITERION_WEIGHT) - simulation_rewarder.add_criterion(InstantForceCriterion(event_grasp), - hp.INSTANT_FORCE_CRITERION_WEIGHT) - simulation_rewarder.add_criterion(InstantObjectCOGCriterion(event_grasp), - hp.OBJECT_COG_CRITERION_WEIGHT) - n_steps = int(hp.GRASP_TIME / hp.TIME_STEP_SIMULATION) - print(n_steps) - simulation_rewarder.add_criterion(GraspTimeCriterion(event_grasp, n_steps), - hp.GRASP_TIME_CRITERION_WEIGHT) - simulation_rewarder.add_criterion( - FinalPositionCriterion(hp.REFERENCE_DISTANCE, event_grasp, event_slipout), - hp.FINAL_POSITION_CRITERION_WEIGHT) - - data = TendonControllerParameters() - data.amount_pulley_in_body = 2 - data.pulley_parameters_for_body = { - 0: [Offset(-0.14, True), Offset(0.005, False, True), - Offset(0, True)], - 1: [Offset(-0.14, True), Offset(-0.005, False, True), - Offset(0, True)] - } - data.starting_point_parameters = [Offset(-0.02, False), Offset(0.025, False), Offset(0, True)] - data.tip_parameters = [Offset(-0.3, True), Offset(-0.005, False, True), Offset(0, True)] - - - control_optimizer = ParralelOptimizerCombinationForce(simulation_managers, - simulation_rewarder, data, hp.TENDON_DISCRETE_FORCES, starting_finger_angles=-25) - - return control_optimizer - -""" \ No newline at end of file diff --git a/app/one_graph_simulation.py b/app/one_graph_simulation.py index 110dfb2a..1553f529 100644 --- a/app/one_graph_simulation.py +++ b/app/one_graph_simulation.py @@ -1,19 +1,22 @@ -from mcts_run_setup import config_tendon +import tendon_graph_evaluators from rostok.library.obj_grasp.objects import get_object_sphere from rostok.library.rule_sets.simple_designs import ( - get_three_link_one_finger, get_three_link_one_finger_independent, get_two_link_three_finger, ) + get_three_link_one_finger, + get_three_link_one_finger_independent, + get_two_link_three_finger, +) +if __name__ == "__main__": + # create blueprint for object to grasp + grasp_object_blueprint = get_object_sphere(0.05, mass=0.2) -# create blueprint for object to grasp -grasp_object_blueprint = get_object_sphere(0.05, mass=0.2) + control_optimizer = tendon_graph_evaluators.evaluator_tendon_standart_parallel -# create reward counter using run setup function -# control_optimizer = config_with_const_troques(grasp_object_blueprint) - -control_optimizer = config_tendon(grasp_object_blueprint) - -graph = get_three_link_one_finger_independent() -graph = graph = get_two_link_three_finger() + graph = get_three_link_one_finger_independent() + graph = graph = get_two_link_three_finger() -rewsss = control_optimizer.calculate_reward(graph) -pass \ No newline at end of file + rewsss = control_optimizer.calculate_reward(graph) + + first_object = control_optimizer.prepare_reward.reward_one_sim_scenario( + x=rewsss[1][0], graph=graph, sim=control_optimizer.simulation_scenario[0]) + print(rewsss) \ No newline at end of file diff --git a/app/tendon_driven_cfg.py b/app/tendon_driven_cfg.py index 206c7f3f..453106b3 100644 --- a/app/tendon_driven_cfg.py +++ b/app/tendon_driven_cfg.py @@ -1,5 +1,5 @@ from rostok.control_chrono.tendon_controller import TendonControllerParameters -from rostok.library.obj_grasp.objects import get_object_parametrized_cuboctahedron, get_object_parametrized_dipyramid_3 +from rostok.library.obj_grasp.objects import get_object_box, get_object_ellipsoid, get_object_parametrized_cuboctahedron, get_object_parametrized_dipyramid_3, get_object_parametrized_trapezohedron from rostok.pipeline.generate_grasper_cfgs import MCTSCfg, SimulationConfig, GraspObjective, BruteForceRewardCfg from rostok.simulation_chrono.simulation_scenario import GraspScenario import rostok.control_chrono.external_force as f_ext @@ -14,6 +14,14 @@ HARD_OBJECT_SET_W = [1.0, 1.0] +NORMAL_OBJECT_SET = [ + get_object_box(0.14, 0.19, 0.28, 0, mass = 0.268), + get_object_parametrized_trapezohedron(0.15, mass = 0.2), + get_object_ellipsoid(0.14, 0.14, 0.22, 0, mass=0.188) +] +NORMAL_OBJECT_SET_W = [1.0, 1.0, 1.0] + + def get_random_force_with_null_grav(amp): obj_forces = [] obj_forces.append(f_ext.NullGravity(0)) @@ -42,8 +50,8 @@ def get_default_tendon_params(): default_grasp_objective = GraspObjective( # Objects setup - HARD_OBJECT_SET, - HARD_OBJECT_SET_W, + NORMAL_OBJECT_SET, + NORMAL_OBJECT_SET_W, # Event setup event_time_no_contact_param=0.5, event_flying_apart_time_param=10, diff --git a/rostok/library/obj_grasp/objects.py b/rostok/library/obj_grasp/objects.py index bde8ab86..e8e05e83 100644 --- a/rostok/library/obj_grasp/objects.py +++ b/rostok/library/obj_grasp/objects.py @@ -43,7 +43,7 @@ def get_object_sphere(r, mass=100, smc=False) -> EnvironmentBodyBlueprint: # object functions return a blueprint of an object -def get_object_box(x, y, z, alpha): +def get_object_box(x, y, z, alpha, mass): material = DefaultChronoMaterialNSC() material.Friction = 0.65 material.DampingF = 0.65 @@ -53,6 +53,8 @@ def get_object_box(x, y, z, alpha): pos=FrameTransform([0, 0, 0], rotation_x(alpha)), color=[215, 255, 0]) + volume = calc_volume_body(object_blueprint) + object_blueprint.density = mass / volume return object_blueprint def get_object_box_rotation(x,y,z, yaw=0, pitch=0, roll=0): @@ -108,7 +110,7 @@ def get_object_parametrized_sphere(r) -> EnvironmentBodyBlueprint: return obj -def get_object_ellipsoid(x, y, z, alpha): +def get_object_ellipsoid(x, y, z, alpha, mass): shape = easy_body_shapes.Ellipsoid() shape.radius_x = x shape.radius_y = y @@ -122,6 +124,8 @@ def get_object_ellipsoid(x, y, z, alpha): material=mat, pos=FrameTransform([0, 0, 0], rotation_x(alpha)), color=[215, 255, 0]) + volume = calc_volume_body(obj) + obj.density = mass / volume return obj # special objects diff --git a/rostok/pipeline/generate_grasper_cfgs.py b/rostok/pipeline/generate_grasper_cfgs.py index ee43eee4..5c45c56d 100644 --- a/rostok/pipeline/generate_grasper_cfgs.py +++ b/rostok/pipeline/generate_grasper_cfgs.py @@ -6,8 +6,8 @@ from rostok.block_builder_api.block_blueprints import EnvironmentBodyBlueprint from rostok.control_chrono.controller import ConstController, RobotControllerChrono from rostok.criterion.criterion_calculation import FinalPositionCriterion, GraspTimeCriterion, InstantContactingLinkCriterion, InstantForceCriterion, InstantObjectCOGCriterion, SimulationReward, TimeCriterion -from rostok.criterion.simulation_flags import EventContact, EventContactTimeOut, EventFlyingApart, EventSlipOut, \ -EventGrasp, EventStopExternalForce +from rostok.criterion.simulation_flags import EventContactBuilder, EventContactTimeOutBuilder, EventFlyingApartBuilder, EventSlipOutBuilder, \ +EventGraspBuilder, EventStopExternalForceBuilder from rostok.simulation_chrono.simulation_scenario import GraspScenario, ParametrizedSimulation import rostok.control_chrono.external_force as f_ext from rostok.trajectory_optimizer.control_optimizer import BasePrepareOptiVar, BruteForceOptimisation1D, ConstTorqueOptiVar, GlobalOptimisationEachSim @@ -82,22 +82,22 @@ def create_base_sim(contoller_cls, sim_cfg: SimulationConfig): def add_grasp_events_from_cfg(sim: GraspScenario, cfg: GraspObjective): - event_contact = EventContact() - sim.add_event(event_contact) - event_timeout = EventContactTimeOut(cfg.event_time_no_contact_param, event_contact) - sim.add_event(event_timeout) - event_flying_apart = EventFlyingApart(cfg.event_flying_apart_time_param) - sim.add_event(event_flying_apart) - event_slipout = EventSlipOut(cfg.event_slipout_time_param) - sim.add_event(event_slipout) - event_grasp = EventGrasp(grasp_limit_time=cfg.event_grasp_time_param, - contact_event=event_contact, - verbosity=0, - simulation_stop=False) - sim.add_event(event_grasp) - event_stop_external_force = EventStopExternalForce( - grasp_event=event_grasp, force_test_time=cfg.event_force_test_time_param) - sim.add_event(event_stop_external_force) + event_contact = EventContactBuilder() + sim.add_event_builder(event_contact) + event_timeout = EventContactTimeOutBuilder(cfg.event_time_no_contact_param, event_contact) + sim.add_event_builder(event_timeout) + event_flying_apart = EventFlyingApartBuilder(cfg.event_flying_apart_time_param) + sim.add_event_builder(event_flying_apart) + event_slipout = EventSlipOutBuilder(cfg.event_slipout_time_param) + sim.add_event_builder(event_slipout) + event_grasp = EventGraspBuilder(grasp_limit_time=cfg.event_grasp_time_param, + event_contact_builder=event_contact, + verbosity=0, + simulation_stop=False) + sim.add_event_builder(event_grasp) + event_stop_external_force = EventStopExternalForceBuilder( + event_grasp_builder=event_grasp, force_test_time=cfg.event_force_test_time_param) + sim.add_event_builder(event_stop_external_force) return event_contact, event_timeout, event_flying_apart, event_slipout, event_stop_external_force, event_grasp @@ -136,7 +136,7 @@ def create_rewarder(grasp_objective_cfg: GraspObjective, sim_cfg: SimulationConf simulation_rewarder.add_criterion(InstantObjectCOGCriterion(event_grasp), grasp_objective_cfg.instant_cog_criterion_weight) n_steps = int(grasp_objective_cfg.event_grasp_time_param / sim_cfg.time_step) - + simulation_rewarder.add_criterion(GraspTimeCriterion(event_grasp, n_steps), grasp_objective_cfg.grasp_time_criterion_weight) simulation_rewarder.add_criterion( @@ -190,4 +190,3 @@ def create_reward_calulator(sim_config: SimulationConfig, grasp_objective: Grasp optimisation_control_cgf) else: raise Exception("Wrong type of optimisation_control_cgf") - From e741609968d9b2d4843e7ad64c1917d4607a0934 Mon Sep 17 00:00:00 2001 From: KirillZharkov Date: Thu, 2 Nov 2023 16:56:50 +0300 Subject: [PATCH 7/9] add magic do stuff --- app/app_new_mcts.py | 28 ----------- app/mcts_run.py | 10 ++++ app/mcts_runner.py | 30 ++++++++++++ app/reoptimisation.py | 84 --------------------------------- app/top_graphs_visualisation.py | 72 ---------------------------- 5 files changed, 40 insertions(+), 184 deletions(-) delete mode 100644 app/app_new_mcts.py create mode 100644 app/mcts_run.py create mode 100644 app/mcts_runner.py delete mode 100644 app/reoptimisation.py delete mode 100644 app/top_graphs_visualisation.py diff --git a/app/app_new_mcts.py b/app/app_new_mcts.py deleted file mode 100644 index 53856018..00000000 --- a/app/app_new_mcts.py +++ /dev/null @@ -1,28 +0,0 @@ - -from rostok.graph_generators.environments.design_environment import (SubStringDesignEnvironment) -from rostok.graph_generators.mcts_manager import MCTSManager -from rostok.graph_generators.search_algorithms.mcts import MCTS - -from rostok.library.rule_sets.rulset_simple_fingers import create_rules -from rostok.graph_grammar.node import GraphGrammar - -from tendon_graph_evaluators import evaluator_tendon_standart, evaluator_tendon_standart_parallel -from tendon_graph_evaluators import mcts_hyper_default, evaluator_tendon_fast_debug -import tendon_driven_cfg - -if __name__ == "__main__": - rule_vocabulary = create_rules() - - init_graph = GraphGrammar() - env = SubStringDesignEnvironment(rule_vocabulary, evaluator_tendon_standart, - mcts_hyper_default.max_number_rules, init_graph, 0) - - mcts = MCTS(env, mcts_hyper_default.C) - name_directory = input("enter directory name: ") - mcts_manager = MCTSManager(mcts, name_directory, verbosity=2, use_date=True) - mcts_manager.save_information_about_search( - mcts_hyper_default, tendon_driven_cfg.default_grasp_objective.object_list) - - for i in range(mcts_hyper_default.full_loop): - mcts_manager.run_search(mcts_hyper_default.base_iteration, 1, 1, 2) - mcts_manager.save_results() \ No newline at end of file diff --git a/app/mcts_run.py b/app/mcts_run.py new file mode 100644 index 00000000..a1c4d0e8 --- /dev/null +++ b/app/mcts_run.py @@ -0,0 +1,10 @@ +import mcts_runner + +from tendon_graph_evaluators import evaluator_tendon_standart, evaluator_tendon_standart_parallel +from tendon_graph_evaluators import mcts_hyper_default, evaluator_tendon_fast_debug +import tendon_driven_cfg +from rostok.library.rule_sets.rulset_simple_fingers import create_rules + +if __name__ == "__main__": + rules_vocab = create_rules() + mcts_runner.run_mcts(rules_vocab, evaluator_tendon_standart_parallel, mcts_hyper_default) \ No newline at end of file diff --git a/app/mcts_runner.py b/app/mcts_runner.py new file mode 100644 index 00000000..9cc27bea --- /dev/null +++ b/app/mcts_runner.py @@ -0,0 +1,30 @@ +from rostok.graph_generators.environments.design_environment import (SubStringDesignEnvironment) +from rostok.graph_generators.mcts_manager import MCTSManager +from rostok.graph_generators.search_algorithms.mcts import MCTS +from rostok.graph_grammar.rule_vocabulary import RuleVocabulary + +from rostok.library.rule_sets.rulset_simple_fingers import create_rules +from rostok.graph_grammar.node import GraphGrammar +from rostok.pipeline.generate_grasper_cfgs import MCTSCfg +from rostok.trajectory_optimizer.control_optimizer import GraphRewardCalculator + +#from tendon_graph_evaluators import evaluator_tendon_standart, evaluator_tendon_standart_parallel +#from tendon_graph_evaluators import mcts_hyper_default, evaluator_tendon_fast_debug +#import tendon_driven_cfg + + +def run_mcts(rule_vocabulary: RuleVocabulary, graph_evaluate_object: GraphRewardCalculator, + mcts_hyper: MCTSCfg): + init_graph = GraphGrammar() + env = SubStringDesignEnvironment(rule_vocabulary, graph_evaluate_object, + mcts_hyper.max_number_rules, init_graph, 0) + + mcts = MCTS(env, mcts_hyper.C) + name_directory = input("enter directory name: ") + mcts_manager = MCTSManager(mcts, name_directory, verbosity=2, use_date=True) + mcts_manager.save_information_about_search(mcts_hyper, + graph_evaluate_object.simulation_scenario) + + for i in range(mcts_hyper.full_loop): + mcts_manager.run_search(mcts_hyper.base_iteration, 1, 1, 2) + mcts_manager.save_results() \ No newline at end of file diff --git a/app/reoptimisation.py b/app/reoptimisation.py deleted file mode 100644 index ef5695cb..00000000 --- a/app/reoptimisation.py +++ /dev/null @@ -1,84 +0,0 @@ -from pathlib import Path - -from tkinter import filedialog, ttk, Tk, NW, END -from typing import Any, Dict, List, Optional, Tuple - -import matplotlib.pyplot as plt -import numpy as np -from mcts_run_setup import config_with_standard_multiobject - -from rostok.block_builder_api.block_blueprints import EnvironmentBodyBlueprint -from rostok.graph_generators.mcts_helper import (MCTSSaveable, OptimizedGraphReport) -from rostok.library.obj_grasp.objects import (get_obj_hard_mesh_piramida, - get_object_parametrized_sphere, get_object_cylinder, - get_object_box, get_object_ellipsoid) -#from rostok.library.rule_sets.ruleset_old_style import create_rules -from rostok.utils.pickle_save import load_saveable - - -def reoptimize_nth_graph(n: int, objects_and_weights: Tuple[List[EnvironmentBodyBlueprint],List[int]]): - root = Tk() - root.geometry("400x300") - root.title("Report loader") - label = ttk.Label(text="Choose path to report!") - label.pack() - label_file = ttk.Label(text="Enter path to report:") - label_file.pack(anchor=NW, padx=8) - entry_browse = ttk.Entry(width=30, font=12) - entry_browse.pack(anchor=NW, padx=8) - entry_browse.place(x=8, y=40) - report_path = None - - def func_browse(): - path = filedialog.askopenfilename() - nonlocal entry_browse - entry_browse.delete(first=0, last=END) - entry_browse.insert(0, path) - - def func_add(): - nonlocal report_path - report_path = Path(entry_browse.get()) - nonlocal root - root.destroy() - - btn_browse = ttk.Button(text="browse", command=func_browse) # создаем кнопку из пакета ttk - btn_browse.place(x=300, y=40) - btn_add = ttk.Button(text="add report", command=func_add) # создаем кнопку из пакета ttk - btn_add.place(x=300, y=85) - - root.mainloop() - report = load_saveable(report_path) - graph_report = report.seen_graphs - control_optimizer = config_with_standard_multiobject(*objects_and_weights) - control_optimizer.limit = 8 - control_optimizer.bounds = (6, 20) - simulation_rewarder = control_optimizer.rewarder - simulation_managers = control_optimizer.simulation_scenario - graph_list = graph_report.graph_list - - sorted_graph_list = sorted(graph_list, key=lambda x: -x.reward) - graph = sorted_graph_list[n] - G = graph.graph - reward = graph.reward - print(graph.control) - reward, optim_parameters = control_optimizer.calculate_reward(G) - control = control_optimizer.optim_parameters2data_control(optim_parameters, G) - print(control) - simulation_rewarder.verbosity = 1 - i = 0 - for simulation_scenario in simulation_managers: - - simulation_output = simulation_scenario[0].run_simulation(G, control[i], True, False) - res = simulation_rewarder.calculate_reward(simulation_output) - print(res) - print() - i += 1 - - -if __name__ == "__main__": - grasp_object_blueprints = ([ - get_object_box(0.8, 1, 0.4, 10), - get_object_cylinder(0.6, 0.9, 10), - get_object_parametrized_sphere(0.6) - ], [1, 1, 1]) - reoptimize_nth_graph(2, grasp_object_blueprints) diff --git a/app/top_graphs_visualisation.py b/app/top_graphs_visualisation.py deleted file mode 100644 index b07ccb1d..00000000 --- a/app/top_graphs_visualisation.py +++ /dev/null @@ -1,72 +0,0 @@ -from pathlib import Path -from tkinter import * -from tkinter import filedialog, ttk -from typing import Any, Dict, List, Optional, Tuple - -import matplotlib.pyplot as plt -import numpy as np -from mcts_run_setup import config_with_standard, config_with_standard_graph - -from rostok.block_builder_api.block_blueprints import EnvironmentBodyBlueprint -from rostok.graph_generators.mcts_helper import (MCTSSaveable, OptimizedGraphReport) -from rostok.library.obj_grasp.objects import (get_obj_hard_mesh_piramida, - get_object_parametrized_sphere) -#from rostok.library.rule_sets.ruleset_old_style import create_rules -from rostok.utils.pickle_save import load_saveable - - -def vis_top_n_mechs(n: int, object: EnvironmentBodyBlueprint): - root = Tk() - root.geometry("400x300") - root.title("Report loader") - label = ttk.Label(text="Choose path to report!") - label.pack() - label_file = ttk.Label(text="Enter path to report:") - label_file.pack(anchor=NW, padx=8) - entry_browse = ttk.Entry(width=30, font=12) - entry_browse.pack(anchor=NW, padx=8) - entry_browse.place(x=8, y=40) - report_path = None - - def func_browse(): - path = filedialog.askopenfilename() - nonlocal entry_browse - entry_browse.delete(first=0, last=END) - entry_browse.insert(0, path) - - def func_add(): - nonlocal report_path - report_path = Path(entry_browse.get()) - nonlocal root - root.destroy() - - btn_browse = ttk.Button(text="browse", command=func_browse) # создаем кнопку из пакета ttk - btn_browse.place(x=300, y=40) - btn_add = ttk.Button(text="add report", command=func_add) # создаем кнопку из пакета ttk - btn_add.place(x=300, y=85) - - root.mainloop() - report = load_saveable(report_path) - graph_report = report.seen_graphs - control_optimizer = config_with_standard(grasp_object_blueprint) - simulation_rewarder = control_optimizer.rewarder - simulation_manager = control_optimizer.simulation_scenario - graph_list = graph_report.graph_list - - sorted_graph_list = sorted(graph_list, key=lambda x: x.reward) - some_top = sorted_graph_list[-1:-(n + 1):-1] - for graph in some_top: - G = graph.graph - reward = graph.reward - control = graph.control - data = {"initial_value": control} - simulation_output = simulation_manager.run_simulation(G, data, True) - res = simulation_rewarder.calculate_reward(simulation_output) - print(reward) - print(res) - print() - - -if __name__ == "__main__": - grasp_object_blueprint = get_object_parametrized_sphere(0.5) - vis_top_n_mechs(3, grasp_object_blueprint) From 0ae03ddeaf7899ba00c44508c5255566ab8346ec Mon Sep 17 00:00:00 2001 From: KirillZharkov Date: Thu, 2 Nov 2023 17:03:50 +0300 Subject: [PATCH 8/9] docs --- rostok/pipeline/generate_grasper_cfgs.py | 51 ++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/rostok/pipeline/generate_grasper_cfgs.py b/rostok/pipeline/generate_grasper_cfgs.py index 5c45c56d..962ea1b4 100644 --- a/rostok/pipeline/generate_grasper_cfgs.py +++ b/rostok/pipeline/generate_grasper_cfgs.py @@ -102,6 +102,15 @@ def add_grasp_events_from_cfg(sim: GraspScenario, cfg: GraspObjective): def create_sim_list(base_sim: GraspScenario, object_list: list[EnvironmentBodyBlueprint]): + """Create simulation for each object in object_list + + Args: + base_sim (GraspScenario): _description_ + object_list (list[EnvironmentBodyBlueprint]): _description_ + + Returns: + _type_: simulation list + """ sim_list = [] for obj_i in object_list: sim_i = deepcopy(base_sim) @@ -112,7 +121,16 @@ def create_sim_list(base_sim: GraspScenario, object_list: list[EnvironmentBodyBl def prepare_simulation_scenario_list(contoller_cls, sim_cfg: SimulationConfig, grasp_objective_cfg: GraspObjective): + """Combine create_sim_list and create_base_sim for construct from highlevel configs + + Args: + contoller_cls (_type_): _description_ + sim_cfg (SimulationConfig): _description_ + grasp_objective_cfg (GraspObjective): _description_ + Returns: + _type_: _description_ + """ base_simulation = create_base_sim(contoller_cls, sim_cfg) # event_contact, event_timeout, event_flying_apart, event_slipout, event_stop_external_force, event_grasp = add_grasp_events_from_cfg( # base_simulation, grasp_objective_cfg) @@ -123,6 +141,18 @@ def prepare_simulation_scenario_list(contoller_cls, sim_cfg: SimulationConfig, def create_rewarder(grasp_objective_cfg: GraspObjective, sim_cfg: SimulationConfig, event_timeout, event_grasp, event_slipout): + """Create rewarder for BasePrepareOptiVar childs + + Args: + grasp_objective_cfg (GraspObjective): _description_ + sim_cfg (SimulationConfig): _description_ + event_timeout (_type_): _description_ + event_grasp (_type_): _description_ + event_slipout (_type_): _description_ + + Returns: + _type_: _description_ + """ simulation_rewarder = SimulationReward(verbosity=0) simulation_rewarder.add_criterion( @@ -148,6 +178,16 @@ def create_rewarder(grasp_objective_cfg: GraspObjective, sim_cfg: SimulationConf def create_global_optimisation(sim_list: list[GraspScenario], preapare_reward: BasePrepareOptiVar, glop_cfg: GlobalOptimisationRewardCfg): + """For create GlobalOptimisationEachSim + + Args: + sim_list (list[GraspScenario]): _description_ + preapare_reward (BasePrepareOptiVar): _description_ + glop_cfg (GlobalOptimisationRewardCfg): _description_ + + Returns: + _type_: _description_ + """ rew = GlobalOptimisationEachSim(sim_list, preapare_reward, glop_cfg.bound, glop_cfg.args_for_optimiser, glop_cfg.optimisation_tool) @@ -157,6 +197,17 @@ def create_global_optimisation(sim_list: list[GraspScenario], preapare_reward: B def create_bruteforce_optimisation(sim_list: list[GraspScenario], preapare_reward: BasePrepareOptiVar, grasp_objective: GraspObjective, brute_cfg: BruteForceRewardCfg): + """For create BruteForceOptimisation1D + + Args: + sim_list (list[GraspScenario]): _description_ + preapare_reward (BasePrepareOptiVar): _description_ + grasp_objective (GraspObjective): _description_ + brute_cfg (BruteForceRewardCfg): _description_ + + Returns: + _type_: _description_ + """ rew = BruteForceOptimisation1D(brute_cfg.variants, sim_list, preapare_reward, grasp_objective.weight_list, brute_cfg.num_cpu_workers, brute_cfg.chunksize, brute_cfg.timeout_parallel) From 7b06b571b7eb15b520d03ca34569d605f3de461d Mon Sep 17 00:00:00 2001 From: KirillZharkov Date: Wed, 15 Nov 2023 22:26:23 +0300 Subject: [PATCH 9/9] add --- app/mcts_runner.py | 3 ++- rostok/pipeline/generate_grasper_cfgs.py | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/mcts_runner.py b/app/mcts_runner.py index 9cc27bea..089c6d62 100644 --- a/app/mcts_runner.py +++ b/app/mcts_runner.py @@ -26,5 +26,6 @@ def run_mcts(rule_vocabulary: RuleVocabulary, graph_evaluate_object: GraphReward graph_evaluate_object.simulation_scenario) for i in range(mcts_hyper.full_loop): - mcts_manager.run_search(mcts_hyper.base_iteration, 1, 1, 2) + mcts_manager.run_search(mcts_hyper.base_iteration, mcts_hyper.max_number_sim_per_step, + mcts_hyper.iteration_checkpoint, mcts_hyper.num_test) mcts_manager.save_results() \ No newline at end of file diff --git a/rostok/pipeline/generate_grasper_cfgs.py b/rostok/pipeline/generate_grasper_cfgs.py index 962ea1b4..84c62e82 100644 --- a/rostok/pipeline/generate_grasper_cfgs.py +++ b/rostok/pipeline/generate_grasper_cfgs.py @@ -63,6 +63,9 @@ class MCTSCfg(): full_loop: int = 10 base_iteration: int = 10 max_number_rules: int = 13 + max_number_sim_per_step: int = 1 + iteration_checkpoint: int = 1 + num_test: int = 2 def create_base_sim(contoller_cls, sim_cfg: SimulationConfig): @@ -81,7 +84,16 @@ def create_base_sim(contoller_cls, sim_cfg: SimulationConfig): obj_external_forces=sim_cfg.obj_disturbance_forces) -def add_grasp_events_from_cfg(sim: GraspScenario, cfg: GraspObjective): +def add_default_events(sim: GraspScenario, cfg: GraspObjective): + """Add events to sim and return list of added events + + Args: + sim (GraspScenario): _description_ + cfg (GraspObjective): _description_ + + Returns: + list: _description_ + """ event_contact = EventContactBuilder() sim.add_event_builder(event_contact) event_timeout = EventContactTimeOutBuilder(cfg.event_time_no_contact_param, event_contact) @@ -109,7 +121,7 @@ def create_sim_list(base_sim: GraspScenario, object_list: list[EnvironmentBodyBl object_list (list[EnvironmentBodyBlueprint]): _description_ Returns: - _type_: simulation list + list[GraspScenario]: simulation list """ sim_list = [] for obj_i in object_list: @@ -129,7 +141,7 @@ def prepare_simulation_scenario_list(contoller_cls, sim_cfg: SimulationConfig, grasp_objective_cfg (GraspObjective): _description_ Returns: - _type_: _description_ + list[GraspScenario]: _description_ """ base_simulation = create_base_sim(contoller_cls, sim_cfg) # event_contact, event_timeout, event_flying_apart, event_slipout, event_stop_external_force, event_grasp = add_grasp_events_from_cfg( @@ -151,7 +163,7 @@ def create_rewarder(grasp_objective_cfg: GraspObjective, sim_cfg: SimulationConf event_slipout (_type_): _description_ Returns: - _type_: _description_ + SimulationReward: _description_ """ simulation_rewarder = SimulationReward(verbosity=0) @@ -226,7 +238,7 @@ def create_reward_calulator(sim_config: SimulationConfig, grasp_objective: Grasp event_timeout = event_grasp = event_slipout = None for sim_i in simlist: - _, event_timeout, _, event_slipout, _, event_grasp = add_grasp_events_from_cfg( + _, event_timeout, _, event_slipout, _, event_grasp = add_default_events( sim_i, grasp_objective) rewarder = create_rewarder(grasp_objective, sim_config, event_timeout, event_grasp,