-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathStemPendulumScene.py
More file actions
69 lines (52 loc) · 2.74 KB
/
StemPendulumScene.py
File metadata and controls
69 lines (52 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
"""Create the scene with the Abstraction of Jimmy.
Units: cm, kg, s.
"""
__authors__ = ("emenager")
__contact__ = ("etienne.menager@ens-rennes.fr")
__version__ = "1.0.0"
__copyright__ = "(c) 2021, Inria"
__date__ = "August 12 2021"
VISUALISATION = False
import sys
import importlib
import pathlib
import numpy as np
sys.path.insert(0, str(pathlib.Path(__file__).parent.absolute())+"/../")
sys.path.insert(0, str(pathlib.Path(__file__).parent.absolute()))
from sofagym.header import addHeader as header
from sofagym.header import addVisu as visu
from sofagym.utils import addRigidObject
from StemPendulum import StemPendulum
from StemPendulumToolbox import rewardShaper, sceneModerator, applyAction
from Controller import ControllerStemPendulum
def createScene(rootNode, config = {"source": [0, 0, 30],
"target": [0, 0, 0],
"seed": None,
"zFar":4000,
"max_torque": 500,
"dt": 0.01},
mode = 'simu_and_visu'):
header(rootNode, alarmDistance=1.0, contactDistance=0.1, tolerance = 1e-6, maxIterations=100, gravity = [0,-981.0,0], dt = config['dt'])
position_spot = [[0, 0, -25]]
direction_spot = [[0.0, 0, 1]]
visu(rootNode, config, position_spot, direction_spot, cutoff = 250)
init_or = 360*np.random.random()
beam_config = {'init_pos': [0, 0, 0], 'tot_length': 10, 'nbSections': 10}
stempendulum_config = {"init_or": init_or, "base_size": [0.05, 0.05, 0.05], "dt": config["dt"],
"beam_config":beam_config, "max_torque": config["max_torque"]}
stempendulum = StemPendulum(stempendulum_config = stempendulum_config)
stempendulum.onEnd(rootNode)
rootNode.addObject(sceneModerator(name="sceneModerator", stempendulum = stempendulum))
rootNode.addObject(rewardShaper(name="Reward", rootNode=rootNode))
rootNode.addObject(applyAction(name="applyAction", root= rootNode, stempendulum=stempendulum))
# rootNode.addObject(ControllerStemPendulum(name="Controller", root= rootNode, stempendulum = stempendulum, max_torque = config['max_torque']))
# if VISUALISATION:
# print(">> Add runSofa visualisation")
# from common.visualisation import visualisationRunSofa, get_config
# path = str(pathlib.Path(__file__).parent.absolute())+"/../../../"
# config = get_config(path+"Results/config_abstractjimmy-v0.txt")
# config_env = config['env']
# actions = config['actions']
# scale = config_env['scale_factor']
# rootNode.addObject(visualisationRunSofa(name="visualisationRunSofa", root = rootNode, actions = actions, scale = scale) )