Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Industrial/grab pipe one robot #79

Open
wants to merge 107 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
9e66e4b
simplified version of smart interaction explorer
IvolgaDmitriy Nov 28, 2022
25923b7
Comments are taken and пут from the body is added
IvolgaDmitriy Dec 7, 2022
e33b4a4
Fixed and added generation from the body
IvolgaDmitriy Dec 7, 2022
69c6eb1
fix merge
MikhailChaikovskii Dec 19, 2022
1c487b7
add seen graphs
MikhailChaikovskii Dec 20, 2022
595d945
add temp_log to saver
Dec 21, 2022
167a895
Tests with COG new criterion
MR-KNV Dec 22, 2022
54b998d
SMC tests
MR-KNV Dec 22, 2022
ad0c04b
Test
MR-KNV Dec 23, 2022
a5f4032
Add contact poins coordinates to simout
MR-KNV Dec 23, 2022
fbddbd4
Change config
MR-KNV Dec 23, 2022
eebcb14
Add point coordinates
MR-KNV Dec 23, 2022
7f22d4e
Add criterion
MR-KNV Dec 23, 2022
555b06f
Material fix
MR-KNV Dec 23, 2022
7b745b5
Add static methods to calculate coords
MR-KNV Dec 23, 2022
0d83c5a
Chage sim_output
MR-KNV Dec 23, 2022
fcf208c
add load from log
MikhailChaikovskii Dec 23, 2022
742be7d
change state definition
Dec 26, 2022
09c5c82
Fix reward calculation
MR-KNV Dec 27, 2022
b167b00
Add description
MR-KNV Dec 27, 2022
8bb589a
Test
MR-KNV Dec 27, 2022
5bd4921
add new result saver
MikhailChaikovskii Dec 27, 2022
a5848f8
delete temp files
MikhailChaikovskii Dec 27, 2022
9d99f86
Add setter start robot frame
Huowl Dec 28, 2022
721ff2f
Fix rew
MR-KNV Dec 28, 2022
912a8d2
Reward
MR-KNV Dec 28, 2022
4c34b1b
[node_render] Fix defaults shape and example
ZharkovKirill Dec 28, 2022
12c1ff6
Merge branch 'master' into examples/common_industial_pipes
Huowl Dec 28, 2022
f932f62
Merge branch 'optimizing_simstep' into examples/common_industial_pipes
Huowl Dec 28, 2022
76dab02
add [stub] function get pipes
Huowl Dec 28, 2022
80a055d
Add plot
MR-KNV Dec 28, 2022
9b4d6e3
Materials set
MR-KNV Dec 28, 2022
e0126bd
Industrial examples
Huowl Dec 28, 2022
19fe331
Rewrite under PEP and added Crutch
IvolgaDmitriy Dec 28, 2022
54ac6ac
Plot for example_simstep
MR-KNV Dec 28, 2022
5aeb286
kaif
ZharkovKirill Dec 28, 2022
5b07ecf
Merge branch 'COG_reward' of https://github.com/aimclub/rostok into C…
ZharkovKirill Dec 28, 2022
8599417
Remove unuses imports
Huowl Dec 28, 2022
995f5b5
Merge branch 'intexp_pure' into examples/common_industial_pipes
Huowl Dec 28, 2022
f4662d5
SMC fix
Huowl Dec 28, 2022
3d8e571
Merge remote-tracking branch 'origin/COG_reward' into examples/common…
Huowl Dec 28, 2022
afc806a
Rebuild Entity for SMC
IvolgaDmitriy Dec 28, 2022
91fec0e
Merge branch 'intexp_pure' of https://github.com/aimclub/rostok into …
IvolgaDmitriy Dec 28, 2022
e7efddd
Dublicate robot
Huowl Dec 28, 2022
d3ac828
Merge remote-tracking branch 'origin/intexp_pure' into examples/commo…
Huowl Dec 28, 2022
a6a6382
Inegration intexp
Huowl Dec 29, 2022
c6e5a58
Merge remote-tracking branch 'origin/manager' into examples/common_in…
Huowl Dec 29, 2022
ab663f2
Flags on object effect
Huowl Dec 29, 2022
9161716
Scale to large object
Huowl Dec 29, 2022
07c159e
Integreted MCTSReporter
Huowl Dec 29, 2022
72789b1
add documentation for auxiliary classes
MikhailChaikovskii Jan 8, 2023
42bb8b9
Add reporter
Huowl Jan 9, 2023
7528d99
Fix bu criterion
Huowl Jan 9, 2023
07a9dd1
Add flag flying apart
Huowl Jan 9, 2023
96edfa6
Add getter base body
Huowl Jan 9, 2023
040b751
Flags two robots
Huowl Jan 9, 2023
04173a2
docs for reporter
MikhailChaikovskii Jan 9, 2023
4b6ad72
Merge branch 'master' into manager
Jan 10, 2023
bd59238
Fixation chrono version
Huowl Jan 10, 2023
70f65ef
Little fix
Huowl Jan 10, 2023
ec67f78
Merge branch 'master' into examples/common_industial_pipes
Huowl Jan 10, 2023
a9a0273
Add calculation grasp points
Huowl Jan 10, 2023
f1688b3
[wip] Temporary version
Huowl Jan 12, 2023
0af2dd3
fixes after review
Jan 13, 2023
c29fd22
fix
Jan 13, 2023
0e12435
Change sizes for example
Huowl Jan 14, 2023
2a2790d
New rules `rule_grasp_pipe` to grasping pipes
Huowl Jan 16, 2023
749ceb9
[puckup_rules] Fix bugs
Huowl Jan 16, 2023
4a7da9f
Working version but efforts isn't realistic
Huowl Jan 16, 2023
be33258
add mcts_helper class
MikhailChaikovskii Jan 16, 2023
ec02b8a
add saveable class
Jan 16, 2023
4a15886
Merge branch 'master' into industrial/grab-pipe-one-robot
Huowl Jan 17, 2023
8ea308c
Add dataclass for loading shapes
Huowl Jan 17, 2023
8cd289e
Some fix after merge from master
Huowl Jan 17, 2023
8af8420
check pickle problems
MikhailChaikovskii Jan 17, 2023
8f714dd
Merge remote-tracking branch 'origin' into mcts_helper
MikhailChaikovskii Jan 17, 2023
5929bb6
add mcts_saveable
MikhailChaikovskii Jan 17, 2023
2fbaecd
add load for saveable
MikhailChaikovskii Jan 17, 2023
068ec6f
fix
MikhailChaikovskii Jan 17, 2023
a28ec80
[simstep] Remove useless class
Huowl Jan 18, 2023
f751402
fix
Jan 18, 2023
a7e8796
add mcts_graph_env
Jan 18, 2023
d94fa43
fix spaces
Jan 18, 2023
be559f9
Fix bugs materials
Huowl Jan 19, 2023
0bd8bd0
[optimizer]Add flag of visualize&remove useless meth
Huowl Jan 19, 2023
a1b6088
Formatting
Huowl Jan 19, 2023
88e4474
add mcts_helper module
Jan 19, 2023
fcf0ac6
[graph_env]Fix imports
Huowl Jan 20, 2023
60c78f9
Light fix out format
Huowl Jan 20, 2023
cdfb4fa
Visualization flag turn off
Huowl Jan 20, 2023
29d94c3
Structuring
Huowl Jan 20, 2023
b97afc1
Fix module dependencies
Huowl Jan 20, 2023
7e0c5f1
Merge remote-tracking branch 'origin/mcts_helper_v2' into industrial/…
Huowl Jan 20, 2023
a2279f9
Change interface of algorithm
Huowl Jan 20, 2023
5fe7a9c
[industrial]Added scripys to running algorithm and loading results
Huowl Jan 20, 2023
0608225
Aligned moments on springs and controls
Huowl Jan 20, 2023
7eca237
[temp]Flag turn on gravity
Huowl Jan 20, 2023
d808c28
Linear increasing gravity
Huowl Jan 20, 2023
b970f7f
Selected spring and moments
Huowl Jan 20, 2023
369bdaa
New version rules
Huowl Jan 27, 2023
d70c0ea
Fix
Huowl Jan 27, 2023
c6b08dc
More iteration
Huowl Jan 27, 2023
ba1b5f4
Fix plot graphs
Huowl Jan 30, 2023
d22fe33
Fix rules
Huowl Jan 30, 2023
c3193b7
Out and remove unuses merhod
Huowl Jan 30, 2023
b234a43
Temporary fix bug
Huowl Jan 31, 2023
e6925d1
Gen Results
Huowl Jan 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 33 additions & 35 deletions app/app.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import rule_extention
import mcts
from pathlib import Path

import matplotlib.pyplot as plt
import mcts
# imports from standard libs
import networkx as nx

# chrono imports
import pychrono as chrono
import rule_extention
from control_optimisation import (create_grab_criterion_fun, create_traj_fun, get_object_to_grasp)

from control_optimisation import create_grab_criterion_fun, create_traj_fun, get_object_to_grasp
from rostok.graph_generators.mcts_helper import prepare_mcts_state_and_helper, make_mcts_step
from rostok.criterion.flags_simualtions import (FlagMaxTime, FlagNotContact, FlagSlipout)
from rostok.graph_grammar.node import GraphGrammar
from rostok.trajectory_optimizer.control_optimizer import ConfigRewardFunction, ControlOptimizer
from rostok.criterion.flags_simualtions import FlagMaxTime, FlagSlipout, FlagNotContact
from rostok.utils.result_saver import read_report

import rostok.graph_generators.graph_environment as env
from rostok.trajectory_optimizer.control_optimizer import (ConfigRewardFunction, ControlOptimizer)


def plot_graph(graph: GraphGrammar):
Expand All @@ -22,15 +21,13 @@ def plot_graph(graph: GraphGrammar):
pos=nx.kamada_kawai_layout(graph, dim=2),
node_size=800,
labels={n: graph.nodes[n]["Node"].label for n in graph})
plt.savefig("./results/graph.jpg")
plt.show()


# %% Create extension rule vocabulary

# %% Create extension rule vocabulary

rule_vocabul, node_features = rule_extention.init_extension_rules()
width = [0.25, 0.35, 0.5]
length_link = [0.4, 0.6, 0.8]
rule_vocabul, node_features = rule_extention.init_extension_rules(length_link, width)

# %% Create condig optimizing control

Expand All @@ -54,37 +51,38 @@ def plot_graph(graph: GraphGrammar):
cfg.params_to_timesiries_callback = traj_generator_fun

control_optimizer = ControlOptimizer(cfg)
control_optimizer.is_visualize = False

# %% Init mcts parameters

# Hyperparameters mctss
iteration_limit = 20
iteration_limit = 2

# Initialize MCTS
searcher = mcts.mcts(iterationLimit=iteration_limit)
finish = False

G = GraphGrammar()
max_numbers_rules = 10
# Create graph envirenments for algorithm (not gym)
graph_env = env.GraphVocabularyEnvironment(G, rule_vocabul, max_numbers_rules)

graph_env.set_control_optimizer(control_optimizer)

max_numbers_rules = 2
# Create graph environments for algorithm (not gym)
graph_env = prepare_mcts_state_and_helper(G, rule_vocabul, control_optimizer, max_numbers_rules, Path("./results"))
mcts_helper = graph_env.helper
n_steps = 0
#%% Run first algorithm
iter = 0
while not finish:
action = searcher.search(initialState=graph_env)
finish, final_graph, opt_trajectory, path = graph_env.step(action, False)
iter += 1
print(
f"number iteration: {iter}, counter actions: {graph_env.counter_action}, reward: {graph_env.reward}"
)


best_graph, best_control, reward = read_report(path, rule_vocabul)
best_control = [float(x) for x in best_control]
finish, graph_env = make_mcts_step(searcher, graph_env, n_steps)
n_steps += 1
print(f"number iteration: {n_steps}, counter actions: {graph_env.counter_action} " +
f"reward: {mcts_helper.report.get_best_info()[1]}")

report = mcts_helper.report
report.draw_best_graph()
best_graph, reward, best_control = mcts_helper.report.get_best_info()
func_reward = control_optimizer.create_reward_function(best_graph)
res = -func_reward(best_control, True)
plot_graph(best_graph)
print(res)
res = -func_reward(best_control)
print(res)
report.plot_means()
report.make_time_dependent_path()
report.save()
report.save_visuals()
report.save_lists()
8 changes: 3 additions & 5 deletions app/control_optimisation.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import rostok.criterion.criterion_calc as criterion
from rostok.block_builder.envbody_shapes import Box
from rostok.block_builder.node_render import (ChronoBodyEnv,
DefaultChronoMaterial,
FrameTransform)
from rostok.block_builder.node_render import (ChronoBodyEnv, DefaultChronoMaterial, FrameTransform)
from rostok.graph_grammar.node import BlockWrapper, GraphGrammar, Node
from rostok.trajectory_optimizer.trajectory_generator import \
create_torque_traj_from_x
from rostok.virtual_experiment.simulation_step import SimOut
from rostok import intexp


def get_object_to_grasp():
matich = DefaultChronoMaterial()
matich.Friction = 0.65
matich.DampingF = 0.65
shape_box = Box(0.1, 0.1, 0.1)
obj = BlockWrapper(ChronoBodyEnv,
shape=shape_box,
material=matich,
pos=FrameTransform([0, 0.5, 0], [0, -0.048, 0.706, 0.706]))
pos=FrameTransform([0, 1.5, 0], [0, -0.048, 0.706, 0.706]))

return obj

Expand Down
86 changes: 86 additions & 0 deletions app/industial_example_pickup_pipe/generation_pickuper_pipe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from pathlib import Path
import mcts

# chrono imports
import pychrono as chrono

from app.control_optimisation import create_grab_criterion_fun, create_traj_fun
from rostok.graph_generators.mcts_helper import make_mcts_step, prepare_mcts_state_and_helper
from rostok.graph_grammar.node import GraphGrammar
from rostok.trajectory_optimizer.control_optimizer import ConfigRewardFunction, ControlOptimizer
from rostok.criterion.flags_simualtions import (FlagMaxTime, FlagSlipout, FlagNotContact,
FlagFlyingApart)

import rule_grasp_pipe
import pickup_pipes_utils as ppu

PATH_TO_PIPE_OBJ = './examples/models/custom/pipe_mul_10.obj'
PATH_TO_PIPE_XML = './examples/models/custom/pipe.xml'

# # %% Create extension rule vocabulary

rule_vocabul, node_features = rule_grasp_pipe.create_rules_to_pickup_pipe_ver_2(
PATH_TO_PIPE_OBJ, PATH_TO_PIPE_XML)

# # %% Create condig optimizing control

GAIT = 2.5
WEIGHT = [3, 1, 1, 2]

max_time = 1
cfg = ConfigRewardFunction()
cfg.bound = (800, 1000)
cfg.iters = 2
cfg.sim_config = {"Set_G_acc": chrono.ChVectorD(0, 0, 0)}
cfg.time_step = 0.001
cfg.time_sim = max_time
cfg.flags = [FlagMaxTime(max_time),
FlagNotContact(max_time / 2 - 0.2),
FlagSlipout(max_time / 2 + 0.2, 0.2),
FlagFlyingApart(20)]

criterion_callback = create_grab_criterion_fun(node_features, GAIT, WEIGHT)
traj_generator_fun = create_traj_fun(cfg.time_sim, cfg.time_step)

cfg.criterion_callback = criterion_callback
cfg.get_rgab_object_callback = ppu.create_builder_grab_object(PATH_TO_PIPE_OBJ, PATH_TO_PIPE_XML)
cfg.params_to_timesiries_callback = traj_generator_fun

control_optimizer = ControlOptimizer(cfg)
control_optimizer.is_visualize = False

# # %% Init mcts parameters
if __name__ == "__main__":
# Hyperparameters mctss
iteration_limit = 4

# Initialize MCTScl
searcher = mcts.mcts(iterationLimit=iteration_limit)
finish = False

G = GraphGrammar()
max_numbers_rules = 11

# Create graph environments for algorithm (not gym)
graph_env = prepare_mcts_state_and_helper(G, rule_vocabul, control_optimizer, max_numbers_rules,
Path("./results"))
mcts_helper = graph_env.helper
n_steps = 0
#%% Run first algorithm
while not finish:
finish, graph_env = make_mcts_step(searcher, graph_env, n_steps)
n_steps += 1
print(f"number iteration: {n_steps}, counter actions: {graph_env.counter_action} " +
f"reward: {mcts_helper.report.get_best_info()[1]}")

# %% Save results

report = mcts_helper.report
best_graph, reward, best_control = mcts_helper.report.get_best_info()
func_reward = control_optimizer.create_reward_function(best_graph)
res = -func_reward(best_control)
report.plot_means()
report.make_time_dependent_path()
report.save()
report.save_visuals()
report.save_lists()
75 changes: 75 additions & 0 deletions app/industial_example_pickup_pipe/pickup_pipes_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import numpy as np
import pychrono as chrono

import rostok.intexp as intexp
from rostok.graph_grammar.node import BlockWrapper
from rostok.block_builder.node_render import ChronoBodyEnv
from rostok.block_builder.transform_srtucture import FrameTransform
from rostok.block_builder.envbody_shapes import LoadedShape


def get_main_axis_pipe(obj_db):

longest_axis_size = np.argmax(obj_db.bound_box)
shorthest_axis_size = np.argmin(obj_db.bound_box)

length_longest_dimension = obj_db.bound_box[longest_axis_size]
length_shorthest_dimension = obj_db.bound_box[shorthest_axis_size]


axis = {
0: ('x', np.array([1, 0, 0])),
1: ('y', np.array([0, 1, 0])),
2: ('z', np.array([0, 0, 1]))
}
return (longest_axis_size,length_longest_dimension), (shorthest_axis_size,length_shorthest_dimension), axis

def create_builder_grab_object(path_to_pipe_obj = None,
path_to_pipe_xml = None):

def get_pipe_object_n_pose():

# Create 3D mesh and setup parameters from files

obj = BlockWrapper(ChronoBodyEnv, LoadedShape(path_to_pipe_obj, path_to_pipe_xml))

obj_db = intexp.entity.TesteeObject()
obj_db.load_object_mesh(path_to_pipe_obj)
obj_db.load_object_description(path_to_pipe_xml)

long_dimension, short_dimension, axis = get_main_axis_pipe(obj_db)
gen_poses = intexp.poses_generator.gen_cylindrical_surface_around_object_axis(
obj_db, 1, short_dimension[1]*1.5,
long_dimension[1] / 2, axis[long_dimension[0]][0])

grab_pos = get_robot_poses_to_grasp_pipe(path_to_pipe_obj, path_to_pipe_xml)

obj_db.clear_grasping_poses_list()
obj_db.add_grasping_pose(grab_pos[0], [0, 0, 0, 1])
obj_db.add_grasping_pose(grab_pos[1], [0, 0, 0, 1])

center_pipe = FrameTransform(gen_poses[1][0],[0, 1, 0, 0])
return obj, center_pipe

return get_pipe_object_n_pose


def get_robot_poses_to_grasp_pipe(path_to_pipe_obj=None,
path_to_pipe_xml=None):

obj_db = intexp.chrono_api.ChTesteeObject()
obj_db.create_chrono_body_from_file(path_to_pipe_obj, path_to_pipe_xml)
long_dim, short_dim, axis = get_main_axis_pipe(obj_db)

gen_poses = intexp.poses_generator.gen_cylindrical_surface_around_object_axis(
obj_db, 1, short_dim[1] * 1.5,
long_dim[1]/2, axis[long_dim[0]][0])

grab_pos_1 = gen_poses[1][0] + long_dim[1] * axis[long_dim[0]][1] * 0.25

grab_pos_2 = gen_poses[1][0] - long_dim[1] * axis[long_dim[0]][1] * 0.25

grab_frame_1 = FrameTransform(grab_pos_1, [0, 1, 0, 0])
grab_frame_2 = FrameTransform(grab_pos_2, [0, 1, 0, 0])
grab_poses = [grab_frame_1, grab_frame_2]
return grab_poses
Loading